List of usage examples for org.eclipse.jdt.internal.core IJavaElementRequestor isCanceled
boolean isCanceled();
true if this IJavaElementRequestor does not want to receive any more results. From source file:com.codenvy.ide.ext.java.server.internal.core.NameLookup.java
License:Open Source License
/** * Finds every type in the project whose simple name matches * the prefix, informing the requestor of each hit. The requestor * is polled for cancellation at regular intervals. * <p/>/*from ww w.j a v a 2 s. c o m*/ * <p>The <code>partialMatch</code> argument indicates partial matches * should be considered. */ private void findAllTypes(String prefix, boolean partialMatch, int acceptFlags, IJavaElementRequestor requestor) { int count = this.packageFragmentRoots.length; for (int i = 0; i < count; i++) { if (requestor.isCanceled()) return; IPackageFragmentRoot root = this.packageFragmentRoots[i]; IJavaElement[] packages = null; try { packages = root.getChildren(); } catch (JavaModelException npe) { continue; // the root is not present, continue; } if (packages != null) { for (int j = 0, packageCount = packages.length; j < packageCount; j++) { if (requestor.isCanceled()) return; seekTypes(prefix, (IPackageFragment) packages[j], partialMatch, acceptFlags, requestor); } } } }
From source file:com.codenvy.ide.ext.java.server.internal.core.NameLookup.java
License:Open Source License
/** * Notifies the given requestor of all package fragments with the * given name. Checks the requestor at regular intervals to see if the * requestor has canceled. The domain of * the search is bounded by the <code>IJavaProject</code> * this <code>NameLookup</code> was obtained from. * * @param partialMatch//from w w w. java2s . c o m * partial name matches qualify when <code>true</code>; * only exact name matches qualify when <code>false</code> */ public void seekPackageFragments(String name, boolean partialMatch, IJavaElementRequestor requestor) { /* if (VERBOSE) { Util.verbose(" SEEKING PACKAGE FRAGMENTS"); //$NON-NLS-1$ Util.verbose(" -> name: " + name); //$NON-NLS-1$ Util.verbose(" -> partial match:" + partialMatch); //$NON-NLS-1$ } */ if (partialMatch) { String[] splittedName = Util.splitOn('.', name, 0, name.length()); Object[][] keys = this.packageFragments.keyTable; for (int i = 0, length = keys.length; i < length; i++) { if (requestor.isCanceled()) return; String[] pkgName = (String[]) keys[i]; if (pkgName != null && Util.startsWithIgnoreCase(pkgName, splittedName, partialMatch)) { Object value = this.packageFragments.valueTable[i]; if (value instanceof PackageFragmentRoot) { PackageFragmentRoot root = (PackageFragmentRoot) value; requestor.acceptPackageFragment(root.getPackageFragment(pkgName)); } else { IPackageFragmentRoot[] roots = (IPackageFragmentRoot[]) value; for (int j = 0, length2 = roots.length; j < length2; j++) { if (requestor.isCanceled()) return; PackageFragmentRoot root = (PackageFragmentRoot) roots[j]; requestor.acceptPackageFragment(root.getPackageFragment(pkgName)); } } } } } else { String[] splittedName = Util.splitOn('.', name, 0, name.length()); int pkgIndex = this.packageFragments.getIndex(splittedName); if (pkgIndex != -1) { Object value = this.packageFragments.valueTable[pkgIndex]; // reuse existing String[] String[] pkgName = (String[]) this.packageFragments.keyTable[pkgIndex]; if (value instanceof PackageFragmentRoot) { requestor.acceptPackageFragment(((PackageFragmentRoot) value).getPackageFragment(pkgName)); } else { IPackageFragmentRoot[] roots = (IPackageFragmentRoot[]) value; if (roots != null) { for (int i = 0, length = roots.length; i < length; i++) { if (requestor.isCanceled()) return; PackageFragmentRoot root = (PackageFragmentRoot) roots[i]; requestor.acceptPackageFragment(root.getPackageFragment(pkgName)); } } } } } }
From source file:com.codenvy.ide.ext.java.server.internal.core.NameLookup.java
License:Open Source License
/** * Performs type search in a binary package. *//* ww w .jav a2s . c o m*/ protected void seekTypesInBinaryPackage(String name, IPackageFragment pkg, boolean partialMatch, int acceptFlags, IJavaElementRequestor requestor) { long start = -1; if (VERBOSE) start = System.currentTimeMillis(); try { if (!partialMatch) { // exact match if (requestor.isCanceled()) return; ClassFile classFile = new ClassFile((PackageFragment) pkg, manager, name); if (classFile.existsUsingJarTypeCache()) { IType type = classFile.getType(); if (acceptType(type, acceptFlags, false/*not a source type*/)) { requestor.acceptType(type); } } } else { IJavaElement[] classFiles = null; try { classFiles = pkg.getChildren(); } catch (JavaModelException npe) { return; // the package is not present } int length = classFiles.length; String unqualifiedName = name; int index = name.lastIndexOf('$'); if (index != -1) { //the type name of the inner type unqualifiedName = Util.localTypeName(name, index, name.length()); // unqualifiedName is empty if the name ends with a '$' sign. // See http://dev.eclipse.org/bugs/show_bug.cgi?id=14642 } int matchLength = name.length(); for (int i = 0; i < length; i++) { if (requestor.isCanceled()) return; IJavaElement classFile = classFiles[i]; // MatchName will never have the extension ".class" and the elementName always will. String elementName = classFile.getElementName(); if (elementName.regionMatches(true /*ignore case*/, 0, name, 0, matchLength)) { IType type = ((ClassFile) classFile).getType(); 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); } } } } } finally { if (VERBOSE) this.timeSpentInSeekTypesInBinaryPackage += System.currentTimeMillis() - start; } }
From source file:com.codenvy.ide.ext.java.server.internal.core.NameLookup.java
License:Open Source License
/** * Performs type search in a source package. *///from ww w.java 2 s . c om protected void seekTypesInSourcePackage(String name, IPackageFragment pkg, int firstDot, boolean partialMatch, String topLevelTypeName, int acceptFlags, IJavaElementRequestor requestor) { long start = -1; if (VERBOSE) start = System.currentTimeMillis(); try { if (!partialMatch) { try { IJavaElement[] compilationUnits = pkg.getChildren(); for (int i = 0, length = compilationUnits.length; i < length; i++) { if (requestor.isCanceled()) return; IJavaElement cu = compilationUnits[i]; String cuName = cu.getElementName(); int lastDot = cuName.lastIndexOf('.'); if (lastDot != topLevelTypeName.length() || !topLevelTypeName.regionMatches(0, cuName, 0, lastDot)) continue; // https://bugs.eclipse.org/bugs/show_bug.cgi?id=351697 // If we are looking at source location, just ignore binary types if (!(cu instanceof ICompilationUnit)) 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 } } } catch (JavaModelException e) { // package doesn't exist -> ignore } } else { try { String cuPrefix = firstDot == -1 ? name : name.substring(0, firstDot); IJavaElement[] compilationUnits = pkg.getChildren(); for (int i = 0, length = compilationUnits.length; i < length; i++) { if (requestor.isCanceled()) return; IJavaElement cu = compilationUnits[i]; if (!cu.getElementName().toLowerCase().startsWith(cuPrefix)) continue; try { 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) { // cu doesn't exist -> ignore } } } catch (JavaModelException e) { // package doesn't exist -> ignore } } } finally { if (VERBOSE) this.timeSpentInSeekTypesInSourcePackage += System.currentTimeMillis() - start; } }
From source file:com.codenvy.ide.ext.java.server.internal.core.NameLookup.java
License:Open Source License
/** * Notifies the given requestor of all types (classes and interfaces) in the * given type with the given (possibly qualified) name. Checks * the requestor at regular intervals to see if the requestor * has canceled.//from ww w . j av a2 s .c om */ protected boolean seekTypesInType(String prefix, int firstDot, IType type, IJavaElementRequestor requestor, int acceptFlags) { IType[] types = null; try { types = type.getTypes(); } catch (JavaModelException npe) { return false; // the enclosing type is not present } int length = types.length; if (length == 0) return false; String memberPrefix = prefix; boolean isMemberTypePrefix = false; if (firstDot != -1) { memberPrefix = prefix.substring(0, firstDot); isMemberTypePrefix = true; } for (int i = 0; i < length; i++) { if (requestor.isCanceled()) return false; IType memberType = types[i]; if (memberType.getElementName().toLowerCase().startsWith(memberPrefix)) if (isMemberTypePrefix) { String subPrefix = prefix.substring(firstDot + 1, prefix.length()); return seekTypesInType(subPrefix, subPrefix.indexOf('.'), memberType, requestor, acceptFlags); } else { if (acceptType(memberType, acceptFlags, true/*a source type*/)) { requestor.acceptMemberType(memberType); return true; } } } return false; }
From source file:com.codenvy.ide.ext.java.server.internal.core.NameLookup.java
License:Open Source License
protected boolean seekTypesInWorkingCopies(String name, IPackageFragment pkg, int firstDot, boolean partialMatch, String topLevelTypeName, int acceptFlags, IJavaElementRequestor requestor, boolean considerSecondaryTypes) { if (!partialMatch) { HashMap typeMap = (HashMap) (this.typesInWorkingCopies == null ? null : this.typesInWorkingCopies.get(pkg)); if (typeMap != null) { 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 }/*from ww w . j a v a 2 s . co m*/ } else if (object instanceof IType[]) { if (object == NO_TYPES) { // all types where deleted -> type is hidden, OR it is the fake type package-info String packageInfoName = String.valueOf(TypeConstants.PACKAGE_INFO_NAME); if (packageInfoName.equals(name)) requestor.acceptType(pkg.getCompilationUnit(packageInfoName.concat(SUFFIX_STRING_java)) .getType(name)); return true; } IType[] topLevelTypes = (IType[]) object; for (int i = 0, length = topLevelTypes.length; i < length; i++) { 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 } } } } } else { HashMap typeMap = (HashMap) (this.typesInWorkingCopies == null ? null : this.typesInWorkingCopies.get(pkg)); if (typeMap != null) { Iterator iterator = typeMap.values().iterator(); while (iterator.hasNext()) { if (requestor.isCanceled()) return false; 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); } } } } return false; }
From source file:org.codehaus.groovy.eclipse.core.builder.GroovyNameLookup.java
License:Apache License
/** * Copied from parent class//from w ww . j ava 2 s . c o m * Changes marked with // GROOVY begin and // GROOVY end */ @Override protected void seekTypesInSourcePackage(String name, IPackageFragment pkg, int firstDot, boolean partialMatch, String topLevelTypeName, int acceptFlags, IJavaElementRequestor requestor) { long start = -1; if (VERBOSE) start = System.currentTimeMillis(); try { if (!partialMatch) { try { IJavaElement[] compilationUnits = pkg.getChildren(); for (int i = 0, length = compilationUnits.length; i < length; i++) { if (requestor.isCanceled()) return; // GROOVY begin // removed statements that continue if type is not the same name as the compilation unit ICompilationUnit cu = (ICompilationUnit) compilationUnits[i]; IType[] allTypes = cu.getAllTypes(); IType type = cu.getType(name); if ( // GROOVY begin type.exists() && // GROOVY end 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 } // now look for member types String mainType = cu.getElementName(); int dotIndex = mainType.indexOf('.'); mainType = mainType.substring(0, dotIndex); type = cu.getType(mainType); if (type.exists()) { type = getMemberType(type, name, firstDot); if ( // GROOVY begin type.exists() && // GROOVY end 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 } } // GROOVY end } } catch (JavaModelException e) { // package doesn't exist -> ignore } } else { try { String cuPrefix = firstDot == -1 ? name : name.substring(0, firstDot); IJavaElement[] compilationUnits = pkg.getChildren(); for (int i = 0, length = compilationUnits.length; i < length; i++) { if (requestor.isCanceled()) return; IJavaElement cu = compilationUnits[i]; if (!cu.getElementName().toLowerCase().startsWith(cuPrefix)) continue; try { 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) { // cu doesn't exist -> ignore } } } catch (JavaModelException e) { // package doesn't exist -> ignore } } } finally { if (VERBOSE) this.timeSpentInSeekTypesInSourcePackage += System.currentTimeMillis() - start; } }
From source file:org.codehaus.groovy.eclipse.core.builder.GroovyNameLookup.java
License:Apache License
/** * Copied from parent class/* www . ja v a2 s . c om*/ * Changes marked with // GROOVY begin and // GROOVY end */ @Override protected void seekTypesInBinaryPackage(String name, IPackageFragment pkg, boolean partialMatch, int acceptFlags, IJavaElementRequestor requestor) { long start = -1; if (VERBOSE) start = System.currentTimeMillis(); try { // GROOVY begin // ensure ends with .class if (!name.endsWith(".class")) { name += ".class"; } // GROOVY end if (!partialMatch) { // exact match if (requestor.isCanceled()) return; ClassFile classFile = (ClassFile) pkg.getClassFile(name); if (classFile.existsUsingJarTypeCache()) { IType type = classFile.getType(); if (acceptType(type, acceptFlags, false/*not a source type*/)) { requestor.acceptType(type); } } // GROOVY begin // class file may still exist as an inner type IJavaElement[] classFiles = null; try { classFiles = pkg.getChildren(); } catch (JavaModelException npe) { return; // the package is not present } for (IJavaElement elt : classFiles) { classFile = (ClassFile) elt; if (classFile.getElementName().endsWith("$" + name)) { IType type = classFile.getType(); if (acceptType(type, acceptFlags, false/*not a source type*/)) { requestor.acceptType(type); } } } // GROOVY end } else { IJavaElement[] classFiles = null; try { classFiles = pkg.getChildren(); } catch (JavaModelException npe) { return; // the package is not present } int length = classFiles.length; String unqualifiedName = name; int index = name.lastIndexOf('$'); if (index != -1) { //the type name of the inner type unqualifiedName = Util.localTypeName(name, index, name.length()); // unqualifiedName is empty if the name ends with a '$' sign. // See http://dev.eclipse.org/bugs/show_bug.cgi?id=14642 } int matchLength = name.length(); for (int i = 0; i < length; i++) { if (requestor.isCanceled()) return; IJavaElement classFile = classFiles[i]; // MatchName will never have the extension ".class" and the elementName always will. String elementName = classFile.getElementName(); if (elementName.regionMatches(true /*ignore case*/, 0, name, 0, matchLength)) { IType type = ((ClassFile) classFile).getType(); 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); } } } } } finally { if (VERBOSE) this.timeSpentInSeekTypesInBinaryPackage += System.currentTimeMillis() - start; } }