/** * Returns the package fragments whose name matches the given * (qualified) name, or <code>null</code> if none exist. * * The name can be: * <ul> * <li>empty: ""</li> * <li>qualified: "pack.pack1.pack2"</li> * </ul> * @param partialMatch partial name matches qualify when <code>true</code>, * only exact name matches qualify when <code>false</code> */ public IPackageFragment[] findPackageFragments(String name, boolean partialMatch) { return findPackageFragments(name, partialMatch, false); }
public Answer findType(String name, boolean partialMatch, int acceptFlags, boolean checkRestrictions) { return findType(name, partialMatch, acceptFlags, true/*consider secondary types*/, true/*wait for indexes*/, checkRestrictions, null); } public Answer findType(String name, boolean partialMatch, int acceptFlags, boolean considerSecondaryTypes, boolean waitForIndexes, boolean checkRestrictions, IProgressMonitor monitor) {
protected boolean seekTypesInTopLevelType(String prefix, int firstDot, IType topLevelType, IJavaElementRequestor requestor, int acceptFlags) { if (!topLevelType.getElementName().toLowerCase().startsWith(prefix)) return false; if (firstDot == -1) { if (acceptType(topLevelType, acceptFlags, true/*a source type*/)) { requestor.acceptType(topLevelType); return true; } } else { return seekTypesInType(prefix, firstDot, topLevelType, requestor, acceptFlags); } return false; }
private class Selector implements IJavaElementRequestor { public List<IPackageFragment> pkgFragments; public Selector(String moduleName) { this.pkgFragments = new ArrayList<>(); } @Override public void acceptField(IField field) { // do nothing } @Override public void acceptInitializer(IInitializer initializer) { // do nothing } @Override public void acceptMemberType(IType type) { // do nothing } @Override public void acceptMethod(IMethod method) { // do nothing } @Override public void acceptPackageFragment(IPackageFragment packageFragment) { this.pkgFragments.add(packageFragment);
findAllTypes(matchName, partialMatch, acceptFlags, requestor); return; if (seekTypesInWorkingCopies(matchName, pkg, firstDot, partialMatch, topLevelTypeName, acceptFlags, requestor)) return; case IPackageFragmentRoot.K_BINARY : matchName= matchName.replace('.', '$'); seekTypesInBinaryPackage(matchName, pkg, partialMatch, acceptFlags, requestor); break; case IPackageFragmentRoot.K_SOURCE : seekTypesInSourcePackage(matchName, pkg, firstDot, partialMatch, topLevelTypeName, acceptFlags, requestor); break; default :
Object object = typeMap.get(topLevelTypeName); if (object instanceof IType) { IType type = getMemberType((IType) object, name, firstDot); if (!considerSecondaryTypes && !isPrimaryType(name, (IType) object, false)) return false; if (acceptType(type, acceptFlags, true/*a source type*/)) { requestor.acceptType(type); return true; // don't continue with compilation unit if (requestor.isCanceled()) return false; IType type = getMemberType(topLevelTypes[i], name, firstDot); if (acceptType(type, acceptFlags, true/*a source type*/)) { requestor.acceptType(type); return true; // return the first one Object object = iterator.next(); if (object instanceof IType) { if (!considerSecondaryTypes && !isPrimaryType(name, (IType) object, true)) continue; seekTypesInTopLevelType(name, firstDot, (IType) object, requestor, acceptFlags); } else if (object instanceof IType[]) { IType[] topLevelTypes = (IType[]) object; for (int i = 0, length = topLevelTypes.length; i < length; i++) seekTypesInTopLevelType(name, firstDot, topLevelTypes[i], requestor, acceptFlags);
Object object = typeMap.get(topLevelTypeName); if (object instanceof IType) { IType type = getMemberType((IType) object, name, firstDot); if (acceptType(type, acceptFlags, true/*a source type*/)) { requestor.acceptType(type); return true; // don't continue with compilation unit if (requestor.isCanceled()) return false; IType type = getMemberType(topLevelTypes[i], name, firstDot); if (acceptType(type, acceptFlags, true/*a source type*/)) { requestor.acceptType(type); return true; // return the first one Object object = iterator.next(); if (object instanceof IType) { seekTypesInTopLevelType(name, firstDot, (IType) object, requestor, acceptFlags); } else if (object instanceof IType[]) { IType[] topLevelTypes = (IType[]) object; for (int i = 0, length = topLevelTypes.length; i < length; i++) seekTypesInTopLevelType(name, firstDot, topLevelTypes[i], requestor, acceptFlags);
seekTypes(name, pkg, partialMatch, acceptFlags, typeRequestor, considerSecondaryTypes); IType type = typeRequestor.getType(); type = findSecondaryType(pkg.getElementName(), name, pkg.getJavaProject(), waitForIndices, null);
if (classFile.existsUsingJarTypeCache()) { IType type = classFile.getType(); if (acceptType(type, acceptFlags, false/*not a source type*/)) { requestor.acceptType(type); String typeName = type.getElementName(); if (typeName.length() > 0 && !Character.isDigit(typeName.charAt(0))) { //not an anonymous type if (nameMatches(unqualifiedName, type, true/*partial match*/) && acceptType(type, acceptFlags, false/*not a source type*/)) requestor.acceptType(type);
/** * Returns the first type in the given package whose name * matches the given (unqualified) name, or <code>null</code> if none * exist. Specifying a <code>null</code> package will result in no matches. * The domain of the search is bounded by the Java project from which * this name lookup was obtained. * * @param name the name of the type to find * @param pkg the package to search * @param partialMatch partial name matches qualify when <code>true</code>, * only exact name matches qualify when <code>false</code> * @param acceptFlags a bit mask describing if classes, interfaces or both classes and interfaces * are desired results. If no flags are specified, all types are returned. * @param considerSecondaryTypes flag to know whether secondary types has to be considered * during the search * * @see #ACCEPT_CLASSES * @see #ACCEPT_INTERFACES * @see #ACCEPT_ENUMS * @see #ACCEPT_ANNOTATIONS */ public IType findType(String name, IPackageFragment pkg, boolean partialMatch, int acceptFlags, boolean considerSecondaryTypes) { IType type = findType(name, pkg, partialMatch, acceptFlags); if (type == null && considerSecondaryTypes) { type = findSecondaryType(pkg.getElementName(), name, pkg.getJavaProject(), false, null); } return type; }
private IPackageFragment findPackageFragment0(IPath path) throws JavaModelException { NameLookup lookup = newNameLookup((WorkingCopyOwner)null/*no need to look at working copies for pkgs*/); return lookup.findPackageFragment(path); }
return findCompilationUnit(pkgName, cuName, (PackageFragmentRoot) value); } else { IPackageFragmentRoot[] roots = (IPackageFragmentRoot[]) value; for (int i= 0; i < roots.length; i++) { PackageFragmentRoot root= (PackageFragmentRoot) roots[i]; ICompilationUnit cu = findCompilationUnit(pkgName, cuName, root); if (cu != null) return cu;
return new NameLookup(cache.allPkgFragmentRootsCache, cache.allPkgFragmentsCache, workingCopies, cache.rootToResolvedEntries);
private class Selector implements IJavaElementRequestor { public List<IPackageFragment> pkgFragments; public Selector(String moduleName) { this.pkgFragments = new ArrayList<>(); } @Override public void acceptField(IField field) { // do nothing } @Override public void acceptInitializer(IInitializer initializer) { // do nothing } @Override public void acceptMemberType(IType type) { // do nothing } @Override public void acceptMethod(IMethod method) { // do nothing } @Override public void acceptPackageFragment(IPackageFragment packageFragment) { this.pkgFragments.add(packageFragment);
findAllTypes(matchName, partialMatch, acceptFlags, requestor); return; if (seekTypesInWorkingCopies(matchName, pkg, firstDot, partialMatch, topLevelTypeName, acceptFlags, requestor, considerSecondaryTypes)) return; case IPackageFragmentRoot.K_BINARY : matchName= matchName.replace('.', '$'); seekTypesInBinaryPackage(matchName, pkg, partialMatch, acceptFlags, requestor); break; case IPackageFragmentRoot.K_SOURCE : seekTypesInSourcePackage(matchName, pkg, firstDot, partialMatch, topLevelTypeName, acceptFlags, requestor); if (matchName.indexOf('$') != -1) { matchName= matchName.replace('$', '.'); if (!partialMatch) topLevelTypeName = firstDot == -1 ? matchName : matchName.substring(0, firstDot); seekTypesInSourcePackage(matchName, pkg, firstDot, partialMatch, topLevelTypeName, acceptFlags, requestor);
Object object = typeMap.get(topLevelTypeName); if (object instanceof IType) { IType type = getMemberType((IType) object, name, firstDot); if (!considerSecondaryTypes && !isPrimaryType(name, (IType) object, false)) return false; if (acceptType(type, acceptFlags, true/*a source type*/)) { requestor.acceptType(type); return true; // don't continue with compilation unit if (requestor.isCanceled()) return false; IType type = getMemberType(topLevelTypes[i], name, firstDot); if (acceptType(type, acceptFlags, true/*a source type*/)) { requestor.acceptType(type); return true; // return the first one Object object = iterator.next(); if (object instanceof IType) { if (!considerSecondaryTypes && !isPrimaryType(name, (IType) object, true)) continue; seekTypesInTopLevelType(name, firstDot, (IType) object, requestor, acceptFlags); } else if (object instanceof IType[]) { IType[] topLevelTypes = (IType[]) object; for (int i = 0, length = topLevelTypes.length; i < length; i++) seekTypesInTopLevelType(name, firstDot, topLevelTypes[i], requestor, acceptFlags);
continue; IType type = ((ICompilationUnit) cu).getType(topLevelTypeName); type = getMemberType(type, name, firstDot); if (acceptType(type, acceptFlags, true/*a source type*/)) { // accept type checks for existence requestor.acceptType(type); break; // since an exact match was requested, no other matching type can exist IType[] types = ((ICompilationUnit) cu).getTypes(); for (int j = 0, typeLength = types.length; j < typeLength; j++) seekTypesInTopLevelType(name, firstDot, types[j], requestor, acceptFlags); } catch (JavaModelException e) {
seekTypes(name, pkg, partialMatch, acceptFlags, typeRequestor, considerSecondaryTypes); IType type = typeRequestor.getType(); type = findSecondaryType(pkg.getElementName(), name, pkg.getJavaProject(), waitForIndices, null);
if (classFile.existsUsingJarTypeCache()) { IType type = classFile.getType(); if (acceptType(type, acceptFlags, false/*not a source type*/)) { requestor.acceptType(type); String typeName = type.getElementName(); if (typeName.length() > 0 && !Character.isDigit(typeName.charAt(0))) { //not an anonymous type if (nameMatches(unqualifiedName, type, true/*partial match*/) && acceptType(type, acceptFlags, false/*not a source type*/)) requestor.acceptType(type);
private IPackageFragment findPackageFragment0(IPath path) throws JavaModelException { NameLookup lookup = newNameLookup((WorkingCopyOwner)null/*no need to look at working copies for pkgs*/); return lookup.findPackageFragment(path); }