本文整理汇总了Java中org.eclipse.jdt.core.IImportDeclaration类的典型用法代码示例。如果您正苦于以下问题:Java IImportDeclaration类的具体用法?Java IImportDeclaration怎么用?Java IImportDeclaration使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IImportDeclaration类属于org.eclipse.jdt.core包,在下文中一共展示了IImportDeclaration类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: getFullQualifiedName
import org.eclipse.jdt.core.IImportDeclaration; //导入依赖的package包/类
private static String getFullQualifiedName(IImportDeclaration[] imports,
String paramType) {
if (imports == null) {
return null;
}
String importFullQualifiedName;
String importType;
for (IImportDeclaration importDeclaration : imports) {
importFullQualifiedName = importDeclaration.getElementName();
importType = importFullQualifiedName
.substring(importFullQualifiedName.lastIndexOf(".") + 1);
if (paramType.equals(importType)) {
return importFullQualifiedName;
}
}
return null;
}
开发者ID:junit-tools-team,项目名称:junit-tools,代码行数:21,代码来源:JDTUtils.java
示例2: getDeclarationNodes
import org.eclipse.jdt.core.IImportDeclaration; //导入依赖的package包/类
public static ASTNode[] getDeclarationNodes(IJavaElement element, CompilationUnit cuNode)
throws JavaModelException {
switch (element.getElementType()) {
case IJavaElement.FIELD:
return new ASTNode[] {getFieldOrEnumConstantDeclaration((IField) element, cuNode)};
case IJavaElement.IMPORT_CONTAINER:
return getImportNodes((IImportContainer) element, cuNode);
case IJavaElement.IMPORT_DECLARATION:
return new ASTNode[] {getImportDeclarationNode((IImportDeclaration) element, cuNode)};
case IJavaElement.INITIALIZER:
return new ASTNode[] {getInitializerNode((IInitializer) element, cuNode)};
case IJavaElement.METHOD:
return new ASTNode[] {
getMethodOrAnnotationTypeMemberDeclarationNode((IMethod) element, cuNode)
};
case IJavaElement.PACKAGE_DECLARATION:
return new ASTNode[] {getPackageDeclarationNode((IPackageDeclaration) element, cuNode)};
case IJavaElement.TYPE:
return new ASTNode[] {getAbstractTypeDeclarationNode((IType) element, cuNode)};
default:
Assert.isTrue(false, String.valueOf(element.getElementType()));
return null;
}
}
开发者ID:eclipse,项目名称:che,代码行数:25,代码来源:ASTNodeSearchUtil.java
示例3: checkTypesImportedInCu
import org.eclipse.jdt.core.IImportDeclaration; //导入依赖的package包/类
private RefactoringStatus checkTypesImportedInCu() throws CoreException {
IImportDeclaration imp = getImportedType(fType.getCompilationUnit(), getNewElementName());
if (imp == null) return null;
String msg =
Messages.format(
RefactoringCoreMessages.RenameTypeRefactoring_imported,
new Object[] {
getNewElementLabel(),
BasicElementLabels.getPathLabel(
fType.getCompilationUnit().getResource().getFullPath(), false)
});
IJavaElement grandParent = imp.getParent().getParent();
if (grandParent instanceof ICompilationUnit)
return RefactoringStatus.createErrorStatus(msg, JavaStatusContext.create(imp));
return null;
}
开发者ID:eclipse,项目名称:che,代码行数:20,代码来源:RenameTypeProcessor.java
示例4: analyzeImportedTypes
import org.eclipse.jdt.core.IImportDeclaration; //导入依赖的package包/类
private void analyzeImportedTypes(IType[] types, RefactoringStatus result, IImportDeclaration imp)
throws CoreException {
for (int i = 0; i < types.length; i++) {
// could this be a problem (same package imports)?
if (JdtFlags.isPublic(types[i]) && types[i].getElementName().equals(getNewElementName())) {
String msg =
Messages.format(
RefactoringCoreMessages.RenameTypeRefactoring_name_conflict1,
new Object[] {
JavaElementLabels.getElementLabel(
types[i], JavaElementLabels.ALL_FULLY_QUALIFIED),
BasicElementLabels.getPathLabel(getCompilationUnit(imp).getPath(), false)
});
result.addError(msg, JavaStatusContext.create(imp));
}
}
}
开发者ID:eclipse,项目名称:che,代码行数:18,代码来源:RenameTypeProcessor.java
示例5: analyzeImportDeclaration
import org.eclipse.jdt.core.IImportDeclaration; //导入依赖的package包/类
private void analyzeImportDeclaration(IImportDeclaration imp, RefactoringStatus result)
throws CoreException {
if (!imp.isOnDemand()) return; // analyzed earlier
IJavaElement imported = convertFromImportDeclaration(imp);
if (imported == null) return;
if (imported instanceof IPackageFragment) {
ICompilationUnit[] cus = ((IPackageFragment) imported).getCompilationUnits();
for (int i = 0; i < cus.length; i++) {
analyzeImportedTypes(cus[i].getTypes(), result, imp);
}
} else {
// cast safe: see JavaModelUtility.convertFromImportDeclaration
analyzeImportedTypes(((IType) imported).getTypes(), result, imp);
}
}
开发者ID:eclipse,项目名称:che,代码行数:18,代码来源:RenameTypeProcessor.java
示例6: addTypeImports
import org.eclipse.jdt.core.IImportDeclaration; //导入依赖的package包/类
/**
* Add new imports to types in <code>typeReferences</code> with package <code>fPackage</code>.
*
* @param typeReferences type references
* @throws CoreException should not happen
*/
private void addTypeImports(SearchResultGroup typeReferences) throws CoreException {
SearchMatch[] searchResults = typeReferences.getSearchResults();
for (int i = 0; i < searchResults.length; i++) {
SearchMatch result = searchResults[i];
IJavaElement enclosingElement = SearchUtils.getEnclosingJavaElement(result);
if (!(enclosingElement instanceof IImportDeclaration)) {
String reference = getNormalizedTypeReference(result);
if (!reference.startsWith(fPackage.getElementName())) {
// is unqualified
reference = cutOffInnerTypes(reference);
ImportChange importChange =
fImportsManager.getImportChange(typeReferences.getCompilationUnit());
importChange.addImport(fPackage.getElementName() + '.' + reference);
}
}
}
}
开发者ID:eclipse,项目名称:che,代码行数:24,代码来源:RenamePackageProcessor.java
示例7: updateTypeImports
import org.eclipse.jdt.core.IImportDeclaration; //导入依赖的package包/类
/**
* Add new imports to types in <code>typeReferences</code> with package <code>fNewElementName
* </code> and remove old import with <code>fPackage</code>.
*
* @param typeReferences type references
* @throws CoreException should not happen
*/
private void updateTypeImports(SearchResultGroup typeReferences) throws CoreException {
SearchMatch[] searchResults = typeReferences.getSearchResults();
for (int i = 0; i < searchResults.length; i++) {
SearchMatch result = searchResults[i];
IJavaElement enclosingElement = SearchUtils.getEnclosingJavaElement(result);
if (enclosingElement instanceof IImportDeclaration) {
IImportDeclaration importDeclaration = (IImportDeclaration) enclosingElement;
updateImport(
typeReferences.getCompilationUnit(),
importDeclaration,
getUpdatedImport(importDeclaration));
} else {
String reference = getNormalizedTypeReference(result);
if (!reference.startsWith(fPackage.getElementName())) {
reference = cutOffInnerTypes(reference);
ImportChange importChange =
fImportsManager.getImportChange(typeReferences.getCompilationUnit());
importChange.removeImport(fPackage.getElementName() + '.' + reference);
importChange.addImport(getNewPackageName() + '.' + reference);
} // else: already found & updated with package reference search
}
}
}
开发者ID:eclipse,项目名称:che,代码行数:31,代码来源:RenamePackageProcessor.java
示例8: copyImportsToDestination
import org.eclipse.jdt.core.IImportDeclaration; //导入依赖的package包/类
private void copyImportsToDestination(
IImportContainer container,
ASTRewrite rewrite,
CompilationUnit sourceCuNode,
CompilationUnit destinationCuNode)
throws JavaModelException {
ListRewrite listRewrite =
rewrite.getListRewrite(destinationCuNode, CompilationUnit.IMPORTS_PROPERTY);
IJavaElement[] importDeclarations = container.getChildren();
for (int i = 0; i < importDeclarations.length; i++) {
IImportDeclaration declaration = (IImportDeclaration) importDeclarations[i];
ImportDeclaration sourceNode =
ASTNodeSearchUtil.getImportDeclarationNode(declaration, sourceCuNode);
ImportDeclaration copiedNode =
(ImportDeclaration) ASTNode.copySubtree(rewrite.getAST(), sourceNode);
if (getLocation() == IReorgDestination.LOCATION_BEFORE) {
listRewrite.insertFirst(copiedNode, null);
} else {
listRewrite.insertLast(copiedNode, null);
}
}
}
开发者ID:eclipse,项目名称:che,代码行数:26,代码来源:ReorgPolicyFactory.java
示例9: copyImportToDestination
import org.eclipse.jdt.core.IImportDeclaration; //导入依赖的package包/类
private void copyImportToDestination(
IImportDeclaration declaration,
ASTRewrite targetRewrite,
CompilationUnit sourceCuNode,
CompilationUnit destinationCuNode)
throws JavaModelException {
ImportDeclaration sourceNode =
ASTNodeSearchUtil.getImportDeclarationNode(declaration, sourceCuNode);
ImportDeclaration copiedNode =
(ImportDeclaration) ASTNode.copySubtree(targetRewrite.getAST(), sourceNode);
ListRewrite listRewrite =
targetRewrite.getListRewrite(destinationCuNode, CompilationUnit.IMPORTS_PROPERTY);
if (getJavaElementDestination() instanceof IImportDeclaration) {
ImportDeclaration destinationNode =
ASTNodeSearchUtil.getImportDeclarationNode(
(IImportDeclaration) getJavaElementDestination(), destinationCuNode);
insertRelative(copiedNode, destinationNode, listRewrite);
} else {
// dropped on container, we could be better here
listRewrite.insertLast(copiedNode, null);
}
}
开发者ID:eclipse,项目名称:che,代码行数:24,代码来源:ReorgPolicyFactory.java
示例10: addStaticImport
import org.eclipse.jdt.core.IImportDeclaration; //导入依赖的package包/类
private void addStaticImport(
ICompilationUnit movedUnit, IImportDeclaration importDecl, ImportRewrite rewrite) {
String old = importDecl.getElementName();
int oldPackLength = movedUnit.getParent().getElementName().length();
StringBuffer result = new StringBuffer(fDestination.getElementName());
if (oldPackLength == 0) // move FROM default package
result.append('.').append(old);
else if (result.length() == 0) // move TO default package
result.append(old.substring(oldPackLength + 1)); // cut "."
else result.append(old.substring(oldPackLength));
int index = result.lastIndexOf("."); // $NON-NLS-1$
if (index > 0 && index < result.length() - 1)
rewrite.addStaticImport(
result.substring(0, index), result.substring(index + 1, result.length()), true);
}
开发者ID:eclipse,项目名称:che,代码行数:17,代码来源:MoveCuUpdateCreator.java
示例11: isImportOfTestAnnotationExist
import org.eclipse.jdt.core.IImportDeclaration; //导入依赖的package包/类
private boolean isImportOfTestAnnotationExist(
ICompilationUnit compilationUnit, String testAnnotation) {
try {
IImportDeclaration[] imports = compilationUnit.getImports();
for (IImportDeclaration importDeclaration : imports) {
String elementName = importDeclaration.getElementName();
if (testAnnotation.equals(elementName)) {
return true;
}
if (importDeclaration.isOnDemand()
&& testAnnotation.startsWith(
elementName.substring(0, elementName.length() - 3))) { // remove .*
return true;
}
}
} catch (JavaModelException e) {
LOG.info("Can't read class imports.", e);
return false;
}
return false;
}
开发者ID:eclipse,项目名称:che,代码行数:22,代码来源:JavaTestFinder.java
示例12: getDeclarationNodes
import org.eclipse.jdt.core.IImportDeclaration; //导入依赖的package包/类
public static ASTNode[] getDeclarationNodes(IJavaElement element, CompilationUnit cuNode) throws JavaModelException {
switch(element.getElementType()){
case IJavaElement.FIELD:
return new ASTNode[]{getFieldOrEnumConstantDeclaration((IField) element, cuNode)};
case IJavaElement.IMPORT_CONTAINER:
return getImportNodes((IImportContainer)element, cuNode);
case IJavaElement.IMPORT_DECLARATION:
return new ASTNode[]{getImportDeclarationNode((IImportDeclaration)element, cuNode)};
case IJavaElement.INITIALIZER:
return new ASTNode[]{getInitializerNode((IInitializer)element, cuNode)};
case IJavaElement.METHOD:
return new ASTNode[]{getMethodOrAnnotationTypeMemberDeclarationNode((IMethod) element, cuNode)};
case IJavaElement.PACKAGE_DECLARATION:
return new ASTNode[]{getPackageDeclarationNode((IPackageDeclaration)element, cuNode)};
case IJavaElement.TYPE:
return new ASTNode[]{getAbstractTypeDeclarationNode((IType) element, cuNode)};
default:
Assert.isTrue(false, String.valueOf(element.getElementType()));
return null;
}
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:22,代码来源:ASTNodeSearchUtil.java
示例13: analyzeImportDeclaration
import org.eclipse.jdt.core.IImportDeclaration; //导入依赖的package包/类
private void analyzeImportDeclaration(IImportDeclaration imp, RefactoringStatus result) throws CoreException{
if (!imp.isOnDemand())
return; //analyzed earlier
IJavaElement imported= convertFromImportDeclaration(imp);
if (imported == null)
return;
if (imported instanceof IPackageFragment){
ICompilationUnit[] cus= ((IPackageFragment)imported).getCompilationUnits();
for (int i= 0; i < cus.length; i++) {
analyzeImportedTypes(cus[i].getTypes(), result, imp);
}
} else {
//cast safe: see JavaModelUtility.convertFromImportDeclaration
analyzeImportedTypes(((IType)imported).getTypes(), result, imp);
}
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:19,代码来源:RenameTypeProcessor.java
示例14: addTypeImports
import org.eclipse.jdt.core.IImportDeclaration; //导入依赖的package包/类
/**
* Add new imports to types in <code>typeReferences</code> with package <code>fPackage</code>.
* @param typeReferences type references
* @throws CoreException should not happen
*/
private void addTypeImports(SearchResultGroup typeReferences) throws CoreException {
SearchMatch[] searchResults= typeReferences.getSearchResults();
for (int i= 0; i < searchResults.length; i++) {
SearchMatch result= searchResults[i];
IJavaElement enclosingElement= SearchUtils.getEnclosingJavaElement(result);
if (! (enclosingElement instanceof IImportDeclaration)) {
String reference= getNormalizedTypeReference(result);
if (! reference.startsWith(fPackage.getElementName())) {
// is unqualified
reference= cutOffInnerTypes(reference);
ImportChange importChange= fImportsManager.getImportChange(typeReferences.getCompilationUnit());
importChange.addImport(fPackage.getElementName() + '.' + reference);
}
}
}
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:22,代码来源:RenamePackageProcessor.java
示例15: updateTypeImports
import org.eclipse.jdt.core.IImportDeclaration; //导入依赖的package包/类
/**
* Add new imports to types in <code>typeReferences</code> with package <code>fNewElementName</code>
* and remove old import with <code>fPackage</code>.
* @param typeReferences type references
* @throws CoreException should not happen
*/
private void updateTypeImports(SearchResultGroup typeReferences) throws CoreException {
SearchMatch[] searchResults= typeReferences.getSearchResults();
for (int i= 0; i < searchResults.length; i++) {
SearchMatch result= searchResults[i];
IJavaElement enclosingElement= SearchUtils.getEnclosingJavaElement(result);
if (enclosingElement instanceof IImportDeclaration) {
IImportDeclaration importDeclaration= (IImportDeclaration) enclosingElement;
updateImport(typeReferences.getCompilationUnit(), importDeclaration, getUpdatedImport(importDeclaration));
} else {
String reference= getNormalizedTypeReference(result);
if (! reference.startsWith(fPackage.getElementName())) {
reference= cutOffInnerTypes(reference);
ImportChange importChange= fImportsManager.getImportChange(typeReferences.getCompilationUnit());
importChange.removeImport(fPackage.getElementName() + '.' + reference);
importChange.addImport(getNewPackageName() + '.' + reference);
} // else: already found & updated with package reference search
}
}
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:26,代码来源:RenamePackageProcessor.java
示例16: copyImportsToDestination
import org.eclipse.jdt.core.IImportDeclaration; //导入依赖的package包/类
private void copyImportsToDestination(IImportContainer container, ASTRewrite rewrite, CompilationUnit sourceCuNode, CompilationUnit destinationCuNode) throws JavaModelException {
ListRewrite listRewrite= rewrite.getListRewrite(destinationCuNode, CompilationUnit.IMPORTS_PROPERTY);
IJavaElement[] importDeclarations= container.getChildren();
for (int i= 0; i < importDeclarations.length; i++) {
IImportDeclaration declaration= (IImportDeclaration) importDeclarations[i];
ImportDeclaration sourceNode= ASTNodeSearchUtil.getImportDeclarationNode(declaration, sourceCuNode);
ImportDeclaration copiedNode= (ImportDeclaration) ASTNode.copySubtree(rewrite.getAST(), sourceNode);
if (getLocation() == IReorgDestination.LOCATION_BEFORE) {
listRewrite.insertFirst(copiedNode, null);
} else {
listRewrite.insertLast(copiedNode, null);
}
}
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:18,代码来源:ReorgPolicyFactory.java
示例17: getInput
import org.eclipse.jdt.core.IImportDeclaration; //导入依赖的package包/类
/**
* Returns the input for the given element. The Java breadcrumb does not show some elements of
* the model:
* <ul>
* <li><code>ITypeRoots</li>
* <li><code>IPackageDeclaration</li>
* <li><code>IImportContainer</li>
* <li><code>IImportDeclaration</li>
* </ul>
*
* @param element the potential input element
* @return the element to use as input
*/
private IJavaElement getInput(IJavaElement element) {
try {
if (element instanceof IImportDeclaration)
element= element.getParent();
if (element instanceof IImportContainer)
element= element.getParent();
if (element instanceof IPackageDeclaration)
element= element.getParent();
if (element instanceof ICompilationUnit) {
IType[] types= ((ICompilationUnit) element).getTypes();
if (types.length > 0)
element= types[0];
}
if (element instanceof IClassFile)
element= ((IClassFile) element).getType();
return element;
} catch (JavaModelException e) {
return null;
}
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:39,代码来源:JavaEditorBreadcrumb.java
示例18: isValidElement
import org.eclipse.jdt.core.IImportDeclaration; //导入依赖的package包/类
/**
* Answers if the given <code>element</code> is a valid
* element for this part.
*
* @param element the object to test
* @return <true> if the given element is a valid element
*/
@Override
protected boolean isValidElement(Object element) {
if (element instanceof IMember)
return super.isValidElement(((IMember)element).getDeclaringType());
else if (element instanceof IImportDeclaration)
return isValidElement(((IJavaElement)element).getParent());
else if (element instanceof IImportContainer) {
Object input= getViewer().getInput();
if (input instanceof IJavaElement) {
ICompilationUnit cu= (ICompilationUnit)((IJavaElement)input).getAncestor(IJavaElement.COMPILATION_UNIT);
if (cu != null) {
ICompilationUnit importContainerCu= (ICompilationUnit)((IJavaElement)element).getAncestor(IJavaElement.COMPILATION_UNIT);
return cu.equals(importContainerCu);
} else {
IClassFile cf= (IClassFile)((IJavaElement)input).getAncestor(IJavaElement.CLASS_FILE);
IClassFile importContainerCf= (IClassFile)((IJavaElement)element).getAncestor(IJavaElement.CLASS_FILE);
return cf != null && cf.equals(importContainerCf);
}
}
}
return false;
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:30,代码来源:MembersView.java
示例19: initializeDefaultPosition
import org.eclipse.jdt.core.IImportDeclaration; //导入依赖的package包/类
/**
* Sets the correct position for new package declaration:<ul>
* <li> before the first import
* <li> if no imports, before the first type
* <li> if no type - first thing in the CU
* <li>
*/
protected void initializeDefaultPosition() {
try {
ICompilationUnit cu = getCompilationUnit();
IImportDeclaration[] imports = cu.getImports();
if (imports.length > 0) {
createBefore(imports[0]);
return;
}
IType[] types = cu.getTypes();
if (types.length > 0) {
createBefore(types[0]);
return;
}
} catch (JavaModelException e) {
// cu doesn't exist: ignore
}
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:25,代码来源:CreatePackageDeclarationOperation.java
示例20: initializeDefaultPosition
import org.eclipse.jdt.core.IImportDeclaration; //导入依赖的package包/类
/**
* Sets the correct position for the new import:<ul>
* <li> after the last import
* <li> if no imports, before the first type
* <li> if no type, after the package statement
* <li> and if no package statement - first thing in the CU
*/
protected void initializeDefaultPosition() {
try {
ICompilationUnit cu = getCompilationUnit();
IImportDeclaration[] imports = cu.getImports();
if (imports.length > 0) {
createAfter(imports[imports.length - 1]);
return;
}
IType[] types = cu.getTypes();
if (types.length > 0) {
createBefore(types[0]);
return;
}
IJavaElement[] children = cu.getChildren();
//look for the package declaration
for (int i = 0; i < children.length; i++) {
if (children[i].getElementType() == IJavaElement.PACKAGE_DECLARATION) {
createAfter(children[i]);
return;
}
}
} catch (JavaModelException e) {
// cu doesn't exit: ignore
}
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:33,代码来源:CreateImportOperation.java
注:本文中的org.eclipse.jdt.core.IImportDeclaration类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论