本文整理汇总了Java中org.eclipse.jdt.core.IImportDeclaration.isOnDemand方法的典型用法代码示例。如果您正苦于以下问题:Java IImportDeclaration.isOnDemand方法的具体用法?Java IImportDeclaration.isOnDemand怎么用?Java IImportDeclaration.isOnDemand使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jdt.core.IImportDeclaration
的用法示例。
在下文中一共展示了IImportDeclaration.isOnDemand方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
}
示例2: 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;
}
示例3: 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);
}
}
示例4: 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));
}
}
}
}
}
示例5: convertFromImportDeclaration
import org.eclipse.jdt.core.IImportDeclaration; //导入方法依赖的package包/类
private static IJavaElement convertFromImportDeclaration(IImportDeclaration declaration)
throws CoreException {
if (declaration.isOnDemand()) {
String packageName =
declaration.getElementName().substring(0, declaration.getElementName().length() - 2);
return JavaModelUtil.findTypeContainer(declaration.getJavaProject(), packageName);
} else
return JavaModelUtil.findTypeContainer(
declaration.getJavaProject(), declaration.getElementName());
}
示例6: convertFromImportDeclaration
import org.eclipse.jdt.core.IImportDeclaration; //导入方法依赖的package包/类
private static IJavaElement convertFromImportDeclaration(IImportDeclaration declaration) throws CoreException {
if (declaration.isOnDemand()){
String packageName= declaration.getElementName().substring(0, declaration.getElementName().length() - 2);
return JavaModelUtil.findTypeContainer(declaration.getJavaProject(), packageName);
} else
return JavaModelUtil.findTypeContainer(declaration.getJavaProject(), declaration.getElementName());
}
示例7: 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;
}
示例8: 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;
}
示例9: compileCandidates
import org.eclipse.jdt.core.IImportDeclaration; //导入方法依赖的package包/类
private static IStatus compileCandidates(List<IJavaElement> result, List<IJavaElement> elements) {
IStatus ok= Status.OK_STATUS;
boolean onlyContainers= true;
for (Iterator<IJavaElement> iter= elements.iterator(); iter.hasNext();) {
IJavaElement elem= iter.next();
try {
switch (elem.getElementType()) {
case IJavaElement.INITIALIZER:
case IJavaElement.METHOD:
case IJavaElement.FIELD:
case IJavaElement.TYPE:
onlyContainers= false;
//$FALL-THROUGH$
case IJavaElement.PACKAGE_FRAGMENT_ROOT:
case IJavaElement.JAVA_PROJECT:
result.add(elem);
break;
case IJavaElement.PACKAGE_FRAGMENT:
if (((IPackageFragment)elem).containsJavaResources())
result.add(elem);
break;
case IJavaElement.PACKAGE_DECLARATION:
result.add(elem.getAncestor(IJavaElement.PACKAGE_FRAGMENT));
break;
case IJavaElement.IMPORT_DECLARATION:
IImportDeclaration decl= (IImportDeclaration)elem;
if (decl.isOnDemand())
elem= JavaModelUtil.findTypeContainer(elem.getJavaProject(), Signature.getQualifier(elem.getElementName()));
else
elem= elem.getJavaProject().findType(elem.getElementName());
if (elem != null) {
onlyContainers= false;
result.add(elem);
}
break;
case IJavaElement.CLASS_FILE:
onlyContainers= false;
result.add(((IClassFile)elem).getType());
break;
case IJavaElement.COMPILATION_UNIT:
ICompilationUnit cu= (ICompilationUnit)elem;
IType[] types= cu.getTypes();
if (types.length > 0) {
onlyContainers= false;
result.addAll(Arrays.asList(types));
}
}
} catch (JavaModelException e) {
return e.getStatus();
}
}
int size= result.size();
if (size == 0 || (size > 1 && !onlyContainers))
return createStatus(ActionMessages.OpenTypeHierarchyAction_messages_no_valid_java_element);
return ok;
}
示例10: getCandidates
import org.eclipse.jdt.core.IImportDeclaration; //导入方法依赖的package包/类
/**
* Converts the input to a possible input candidates
* @param input input
* @return the possible candidates
*/
public static IJavaElement[] getCandidates(Object input) {
if (!(input instanceof IJavaElement)) {
return null;
}
try {
IJavaElement elem= (IJavaElement) input;
switch (elem.getElementType()) {
case IJavaElement.INITIALIZER:
case IJavaElement.METHOD:
case IJavaElement.FIELD:
case IJavaElement.TYPE:
case IJavaElement.PACKAGE_FRAGMENT_ROOT:
case IJavaElement.JAVA_PROJECT:
return new IJavaElement[] { elem };
case IJavaElement.PACKAGE_FRAGMENT:
if (((IPackageFragment)elem).containsJavaResources())
return new IJavaElement[] {elem};
break;
case IJavaElement.PACKAGE_DECLARATION:
return new IJavaElement[] { elem.getAncestor(IJavaElement.PACKAGE_FRAGMENT) };
case IJavaElement.IMPORT_DECLARATION:
IImportDeclaration decl= (IImportDeclaration) elem;
if (decl.isOnDemand()) {
elem= JavaModelUtil.findTypeContainer(elem.getJavaProject(), Signature.getQualifier(elem.getElementName()));
} else {
elem= elem.getJavaProject().findType(elem.getElementName());
}
if (elem == null)
return null;
return new IJavaElement[] {elem};
case IJavaElement.CLASS_FILE:
return new IJavaElement[] { ((IClassFile)input).getType() };
case IJavaElement.COMPILATION_UNIT: {
ICompilationUnit cu= (ICompilationUnit) elem.getAncestor(IJavaElement.COMPILATION_UNIT);
if (cu != null) {
IType[] types= cu.getTypes();
if (types.length > 0) {
return types;
}
}
break;
}
default:
}
} catch (JavaModelException e) {
JavaPlugin.log(e);
}
return null;
}
示例11: toClassNameFromImports
import org.eclipse.jdt.core.IImportDeclaration; //导入方法依赖的package包/类
public static String toClassNameFromImports(IProject project, IType relativeTo, String className)
throws JavaModelException
{
if (!className.contains("."))
{
ICompilationUnit compilationUnit = relativeTo.getCompilationUnit();
if (compilationUnit != null)
{
IImportDeclaration[] imports = compilationUnit.getImports();
if (imports.length > 0)
{
for (IImportDeclaration importDecl : imports)
{
if (importDecl.getElementName().endsWith("." + className))
{
return importDecl.getElementName();
}
if (importDecl.isOnDemand())
{
String packageName = importDecl.getElementName()
.substring(0, importDecl.getElementName().length() - 2);
String candidate = packageName + "." + className;
if (EclipseUtils.findTypeDeclarationExact(
project,
IJavaSearchConstants.CLASS_AND_INTERFACE,
packageName,
className) != null)
{
return candidate;
}
}
}
}
// Class is from the same package
return relativeTo.getPackageFragment().getElementName() + "." + className;
}
}
return className;
}