本文整理汇总了Java中org.eclipse.jdt.core.IImportDeclaration.getElementName方法的典型用法代码示例。如果您正苦于以下问题:Java IImportDeclaration.getElementName方法的具体用法?Java IImportDeclaration.getElementName怎么用?Java IImportDeclaration.getElementName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jdt.core.IImportDeclaration
的用法示例。
在下文中一共展示了IImportDeclaration.getElementName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例2: 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);
}
示例3: 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;
}
示例4: getImportDeclaration
import org.eclipse.jdt.core.IImportDeclaration; //导入方法依赖的package包/类
public static String getImportDeclaration(IFile file, String className)
throws JavaModelException {
String fullyQualifiedName = null;
ICompilationUnit currentFile = JavaCore.createCompilationUnitFrom(file);
IImportDeclaration[] imports = currentFile.getImports();
for (IImportDeclaration iImportDeclaration : imports) {
if (iImportDeclaration.getElementName().endsWith(
MethodUtil.PACKAGE_DOT + className)) {
fullyQualifiedName = iImportDeclaration.getElementName();
break;
}
}
if (fullyQualifiedName == null || fullyQualifiedName.length() <= 0) {
IPackageDeclaration packageDeclaration = currentFile
.getPackageDeclarations()[0];
fullyQualifiedName = packageDeclaration.getElementName()
+ MethodUtil.PACKAGE_DOT + className;
}
return fullyQualifiedName;
}
示例5: getMatchedPackage
import org.eclipse.jdt.core.IImportDeclaration; //导入方法依赖的package包/类
public static String getMatchedPackage(String className, ICompilationUnit cUnit) throws JavaModelException {
int higherAccuracy = 0;
String matchedPackage = cUnit.getPackageDeclarations()[0].getElementName();
IImportDeclaration[] imports = cUnit.getImports();
for (IImportDeclaration impDec : imports) {
String fullName = impDec.getElementName();
int dotIndex = fullName.lastIndexOf('.');
String lastNameOfImport = fullName.substring(dotIndex + 1);
if (lastNameOfImport.equals(className) && higherAccuracy < 2) {
matchedPackage = fullName.substring(0, dotIndex);
higherAccuracy = 2;
} else if (lastNameOfImport.equals("*") && higherAccuracy < 1) {
matchedPackage = fullName.substring(0, dotIndex);
higherAccuracy = 1;
}
}
if (higherAccuracy > 0) return matchedPackage;
if (cUnit.getType(className) != null) return cUnit.getPackageDeclarations()[0].getElementName();
return "java.lang";
}
示例6: addSeeds
import org.eclipse.jdt.core.IImportDeclaration; //导入方法依赖的package包/类
/**
* Adds locals, constants, and imports to seed the search.
* @param typeConstraint The type constraint.
* @throws DebugException
* @throws JavaModelException
*/
private void addSeeds(TypeConstraint typeConstraint) throws DebugException, JavaModelException {
for (IJavaVariable l : stack.getLocalVariables())
candidates.addWeighted(expressionMaker.makeVar(l.getName(), (IJavaValue)l.getValue(), EclipseUtils.getTypeOfVariableAndLoadIfNeeded(l, stack), thread));
if (!stack.isStatic())
objects.addWeighted(expressionMaker.makeThis(stack.getThis(), thisType, thread));
if (!(typeConstraint instanceof MethodConstraint) && !(typeConstraint instanceof FieldConstraint)) // If we have a method or field constraint, we can't have null.)
nulls.addWeighted(expressionMaker.makeNull(thread));
if (stack.isStatic() || stack.isConstructor())
names.addWeighted(expressionMaker.makeStaticName(stack.getReceivingTypeName(), thisType, thread));
for (IImportDeclaration imp : imports) {
// TODO: Handle static imports.
// TODO: Decomp with deterministic version?
if (!imp.isOnDemand()) {
String fullName = imp.getElementName();
String shortName = EclipseUtils.getUnqualifiedName(fullName); // Use the unqualified typename for brevity.
if (!Flags.isStatic(imp.getFlags())) {
IJavaReferenceType importedType = (IJavaReferenceType)EclipseUtils.getTypeAndLoadIfNeeded(fullName, stack, target, typeCache);
if (importedType != null) {
if (hasPublicStaticFieldOrMethod(importedType))
names.addWeighted(expressionMaker.makeStaticName(shortName, importedType, thread));
}
}
}
}
}
示例7: getImportedTypes
import org.eclipse.jdt.core.IImportDeclaration; //导入方法依赖的package包/类
private List<IImport> getImportedTypes(final IImportDeclaration[] importDeclarations) {
final List<IImport> importedTypes = new ArrayList<>();
for (final IImportDeclaration importDeclaration : importDeclarations) {
final String importName = importDeclaration.getElementName();
final Path importPath = create(null, importName);
importedTypes.add(new Import(importName, importName.endsWith("*") //$NON-NLS-1$
? importPath.getParent()
: importPath));
}
return importedTypes;
}
示例8: getUpdatedImport
import org.eclipse.jdt.core.IImportDeclaration; //导入方法依赖的package包/类
private String getUpdatedImport(IImportDeclaration importDeclaration) {
String fullyQualifiedImportType = importDeclaration.getElementName();
int offsetOfDotBeforeTypeName = fPackage.getElementName().length();
String result =
getNewPackageName() + fullyQualifiedImportType.substring(offsetOfDotBeforeTypeName);
return result;
}
示例9: createStringForNewImport
import org.eclipse.jdt.core.IImportDeclaration; //导入方法依赖的package包/类
private String createStringForNewImport(
ICompilationUnit movedUnit, IImportDeclaration importDecl) {
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));
return result.toString();
}
示例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);
}
示例11: createStringForNewImport
import org.eclipse.jdt.core.IImportDeclaration; //导入方法依赖的package包/类
private String createStringForNewImport(ICompilationUnit movedUnit, IImportDeclaration importDecl) {
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));
return result.toString();
}
示例12: matchParameterType
import org.eclipse.jdt.core.IImportDeclaration; //导入方法依赖的package包/类
private static final boolean matchParameterType(IType type, String parameter, String targetParameter) throws JavaModelException {
// FQCN or primitive
if(parameter.equals(targetParameter)) {
return true;
}
// inner class
if(parameter.indexOf("$") != -1) {
if(parameter.replace("$", ".").equals(targetParameter)) {
return true;
}
if(parameter.substring(parameter.indexOf("$") + 1).equals(targetParameter)) {
return true;
}
}
// generics type parameter
if(targetParameter.indexOf("<") != -1 && parameter.equals(targetParameter.substring(0, targetParameter.indexOf("<")))) {
return true;
}
// targetParameter is not FQCN
if(parameter.startsWith("java.lang.") && parameter.equals("java.lang." + targetParameter)) {
return true;
}
// same package
if(parameter.equals(type.getPackageFragment().getElementName() + "." + targetParameter)) {
return true;
}
ICompilationUnit unit = type.getCompilationUnit();
if(unit != null) {
for(IImportDeclaration imp : unit.getImports()) {
String importClass = imp.getElementName();
if(importClass.endsWith("." + targetParameter) && parameter.equals(importClass)) {
return true;
} else if(importClass.endsWith(".*") && parameter.equals(importClass.substring(0, importClass.length() - 1) + targetParameter)) {
return true;
}
}
}
return false;
}
示例13: checkConflictingTypes
import org.eclipse.jdt.core.IImportDeclaration; //导入方法依赖的package包/类
private RefactoringStatus checkConflictingTypes(IProgressMonitor pm) throws CoreException {
RefactoringStatus result = new RefactoringStatus();
IJavaSearchScope scope = RefactoringScopeFactory.create(fType);
SearchPattern pattern =
SearchPattern.createPattern(
getNewElementName(),
IJavaSearchConstants.TYPE,
IJavaSearchConstants.ALL_OCCURRENCES,
SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE);
ICompilationUnit[] cusWithReferencesToConflictingTypes =
RefactoringSearchEngine.findAffectedCompilationUnits(pattern, scope, pm, result);
if (cusWithReferencesToConflictingTypes.length == 0) return result;
ICompilationUnit[] cusWithReferencesToRenamedType = getCus(fReferences);
Set<ICompilationUnit> conflicts =
getIntersection(cusWithReferencesToRenamedType, cusWithReferencesToConflictingTypes);
if (cusWithReferencesToConflictingTypes.length > 0) {
cus:
for (ICompilationUnit cu : cusWithReferencesToConflictingTypes) {
String packageName = fType.getPackageFragment().getElementName();
if (((IPackageFragment) cu.getParent()).getElementName().equals(packageName)) {
boolean hasOnDemandImport = false;
IImportDeclaration[] imports = cu.getImports();
for (IImportDeclaration importDecl : imports) {
if (importDecl.isOnDemand()) {
hasOnDemandImport = true;
} else {
String importName = importDecl.getElementName();
int packageLength = importName.length() - getNewElementName().length() - 1;
if (packageLength > 0
&& importName.endsWith(getNewElementName())
&& importName.charAt(packageLength) == '.') {
continue cus; // explicit import from another package => no problem
}
}
}
if (hasOnDemandImport) {
// the renamed type in the same package will shadow the *-imported type
conflicts.add(cu);
}
}
}
}
for (ICompilationUnit conflict : conflicts) {
RefactoringStatusContext context = JavaStatusContext.create(conflict);
String message =
Messages.format(
RefactoringCoreMessages.RenameTypeRefactoring_another_type,
new String[] {getNewElementLabel(), BasicElementLabels.getFileName(conflict)});
result.addError(message, context);
}
return result;
}
示例14: checkConflictingTypes
import org.eclipse.jdt.core.IImportDeclaration; //导入方法依赖的package包/类
private RefactoringStatus checkConflictingTypes(IProgressMonitor pm) throws CoreException {
RefactoringStatus result= new RefactoringStatus();
IJavaSearchScope scope= RefactoringScopeFactory.create(fType);
SearchPattern pattern= SearchPattern.createPattern(getNewElementName(),
IJavaSearchConstants.TYPE, IJavaSearchConstants.ALL_OCCURRENCES, SearchUtils.GENERICS_AGNOSTIC_MATCH_RULE);
ICompilationUnit[] cusWithReferencesToConflictingTypes= RefactoringSearchEngine.findAffectedCompilationUnits(pattern, scope, pm, result);
if (cusWithReferencesToConflictingTypes.length == 0)
return result;
ICompilationUnit[] cusWithReferencesToRenamedType= getCus(fReferences);
Set<ICompilationUnit> conflicts= getIntersection(cusWithReferencesToRenamedType, cusWithReferencesToConflictingTypes);
if (cusWithReferencesToConflictingTypes.length > 0) {
cus: for (ICompilationUnit cu : cusWithReferencesToConflictingTypes) {
String packageName= fType.getPackageFragment().getElementName();
if (((IPackageFragment) cu.getParent()).getElementName().equals(packageName)) {
boolean hasOnDemandImport= false;
IImportDeclaration[] imports= cu.getImports();
for (IImportDeclaration importDecl : imports) {
if (importDecl.isOnDemand()) {
hasOnDemandImport= true;
} else {
String importName= importDecl.getElementName();
int packageLength= importName.length() - getNewElementName().length() - 1;
if (packageLength > 0
&& importName.endsWith(getNewElementName())
&& importName.charAt(packageLength) == '.') {
continue cus; // explicit import from another package => no problem
}
}
}
if (hasOnDemandImport) {
// the renamed type in the same package will shadow the *-imported type
conflicts.add(cu);
}
}
}
}
for (ICompilationUnit conflict : conflicts) {
RefactoringStatusContext context= JavaStatusContext.create(conflict);
String message= Messages.format(RefactoringCoreMessages.RenameTypeRefactoring_another_type,
new String[] { getNewElementLabel(), BasicElementLabels.getFileName(conflict)});
result.addError(message, context);
}
return result;
}
示例15: getUpdatedImport
import org.eclipse.jdt.core.IImportDeclaration; //导入方法依赖的package包/类
private String getUpdatedImport(IImportDeclaration importDeclaration) {
String fullyQualifiedImportType= importDeclaration.getElementName();
int offsetOfDotBeforeTypeName= fPackage.getElementName().length();
String result= getNewPackageName() + fullyQualifiedImportType.substring(offsetOfDotBeforeTypeName);
return result;
}