List of usage examples for org.eclipse.jdt.core.compiler CharOperation NO_CHAR
null NO_CHAR
To view the source code for org.eclipse.jdt.core.compiler CharOperation NO_CHAR.
Click Source Link
From source file:com.codenvy.ide.ext.java.server.internal.codeassist.impl.Engine.java
License:Open Source License
public void initializePackageCache() { if (this.unitScope.fPackage != null) { this.currentPackageName = CharOperation.concatWith(this.unitScope.fPackage.compoundName, '.'); } else if (this.unitScope.referenceContext != null && this.unitScope.referenceContext.currentPackage != null) { this.currentPackageName = CharOperation .concatWith(this.unitScope.referenceContext.currentPackage.tokens, '.'); } else {/* w ww.j a va 2s . co m*/ this.currentPackageName = CharOperation.NO_CHAR; } }
From source file:com.codenvy.ide.ext.java.server.internal.codeassist.SelectionEngine.java
License:Open Source License
private boolean checkSelection(char[] source, int selectionStart, int selectionEnd) { Scanner scanner = new Scanner(false /*comment*/, false /*whitespace*/, false /*nls*/, this.compilerOptions.sourceLevel, this.compilerOptions.complianceLevel, null/*taskTag*/, null/*taskPriorities*/, true /*taskCaseSensitive*/); scanner.setSource(source);//from ww w . ja va 2 s . c om int lastIdentifierStart = -1; int lastIdentifierEnd = -1; char[] lastIdentifier = null; int token; if (selectionStart > selectionEnd) { int end = source.length - 1; // compute start position of current line int currentPosition = selectionStart - 1; int nextCharacterPosition = selectionStart; char currentCharacter = ' '; try { lineLoop: while (currentPosition > 0) { if (source[currentPosition] == '\\' && source[currentPosition + 1] == 'u') { int pos = currentPosition + 2; int c1 = 0, c2 = 0, c3 = 0, c4 = 0; while (source[pos] == 'u') { pos++; } int endOfUnicode = pos + 3; if (end < endOfUnicode) { if (endOfUnicode < source.length) { end = endOfUnicode; } else { return false; // not enough characters to decode an unicode } } if ((c1 = ScannerHelper.getHexadecimalValue(source[pos++])) > 15 || c1 < 0 || (c2 = ScannerHelper.getHexadecimalValue(source[pos++])) > 15 || c2 < 0 || (c3 = ScannerHelper.getHexadecimalValue(source[pos++])) > 15 || c3 < 0 || (c4 = ScannerHelper.getHexadecimalValue(source[pos++])) > 15 || c4 < 0) { return false; } else { currentCharacter = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4); nextCharacterPosition = pos; } } else { currentCharacter = source[currentPosition]; nextCharacterPosition = currentPosition + 1; } switch (currentCharacter) { case '\r': case '\n': case '/': case '"': case '\'': break lineLoop; } currentPosition--; } } catch (ArrayIndexOutOfBoundsException e) { return false; } // compute start and end of the last token scanner.resetTo(nextCharacterPosition, end); isolateLastName: do { try { token = scanner.getNextToken(); } catch (InvalidInputException e) { return false; } switch (token) { case TerminalTokens.TokenNamethis: case TerminalTokens.TokenNamesuper: case TerminalTokens.TokenNamenew: case TerminalTokens.TokenNameIdentifier: if (scanner.startPosition <= selectionStart && selectionStart <= scanner.currentPosition) { if (scanner.currentPosition == scanner.eofPosition) { int temp = scanner.eofPosition; scanner.eofPosition = scanner.source.length; while (scanner.getNextCharAsJavaIdentifierPart()) { /*empty*/} scanner.eofPosition = temp; } lastIdentifierStart = scanner.startPosition; lastIdentifierEnd = scanner.currentPosition - 1; lastIdentifier = scanner.getCurrentTokenSource(); break isolateLastName; } break; } } while (token != TerminalTokens.TokenNameEOF); } else { if (selectionStart == selectionEnd) { // Widen the selection to scan -> || :: if needed. No unicode handling for now. if (selectionStart > 0 && selectionEnd < source.length - 1) { if ((source[selectionStart] == '>' && source[selectionStart - 1] == '-') || source[selectionStart] == ':' && source[selectionStart - 1] == ':') { selectionStart--; } else { if ((source[selectionStart] == '-' && source[selectionEnd + 1] == '>') || source[selectionStart] == ':' && source[selectionEnd + 1] == ':') { selectionEnd++; } } } } // there could be some innocuous widening, shouldn't matter. scanner.resetTo(selectionStart, selectionEnd); boolean expectingIdentifier = true; do { try { token = scanner.getNextToken(); } catch (InvalidInputException e) { return false; } switch (token) { case TerminalTokens.TokenNamethis: case TerminalTokens.TokenNamesuper: case TerminalTokens.TokenNamenew: case TerminalTokens.TokenNameIdentifier: if (!expectingIdentifier) return false; lastIdentifier = scanner.getCurrentTokenSource(); lastIdentifierStart = scanner.startPosition; lastIdentifierEnd = scanner.currentPosition - 1; if (lastIdentifierEnd > selectionEnd) { lastIdentifierEnd = selectionEnd; lastIdentifier = CharOperation.subarray(lastIdentifier, 0, lastIdentifierEnd - lastIdentifierStart + 1); } expectingIdentifier = false; break; case TerminalTokens.TokenNameCOLON_COLON: if (selectionStart >= scanner.startPosition && selectionEnd < scanner.currentPosition) { this.actualSelectionStart = selectionStart; this.actualSelectionEnd = selectionEnd; this.selectedIdentifier = CharOperation.NO_CHAR; return true; } //$FALL-THROUGH$ case TerminalTokens.TokenNameDOT: if (expectingIdentifier) return false; expectingIdentifier = true; break; case TerminalTokens.TokenNameEOF: if (expectingIdentifier) return false; break; case TerminalTokens.TokenNameLESS: if (!checkTypeArgument(scanner)) return false; break; case TerminalTokens.TokenNameAT: if (scanner.startPosition != scanner.initialPosition) return false; break; case TerminalTokens.TokenNameARROW: if (selectionStart >= scanner.startPosition && selectionEnd < scanner.currentPosition) { this.actualSelectionStart = selectionStart; this.actualSelectionEnd = selectionEnd; this.selectedIdentifier = CharOperation.NO_CHAR; return true; } return false; default: return false; } } while (token != TerminalTokens.TokenNameEOF); } if (lastIdentifierStart > 0) { this.actualSelectionStart = lastIdentifierStart; this.actualSelectionEnd = lastIdentifierEnd; this.selectedIdentifier = lastIdentifier; return true; } return false; }
From source file:com.codenvy.ide.ext.java.server.internal.codeassist.SelectionEngine.java
License:Open Source License
private boolean selectDeclaration(CompilationUnitDeclaration compilationUnit) { // the selected identifier is not identical to the parser one (equals but not identical), // for traversing the parse tree, the parser assist identifier is necessary for identitiy checks char[] assistIdentifier = getParser().assistIdentifier(); if (assistIdentifier == null) return false; ImportReference currentPackage = compilationUnit.currentPackage; char[] packageName = currentPackage == null ? CharOperation.NO_CHAR : CharOperation.concatWith(currentPackage.tokens, '.'); // iterate over the types TypeDeclaration[] types = compilationUnit.types; for (int i = 0, length = types == null ? 0 : types.length; i < length; i++) { if (selectDeclaration(types[i], assistIdentifier, packageName)) return true; }// ww w.j av a 2 s. c om return false; }
From source file:com.codenvy.ide.ext.java.server.internal.compiler.parser.SourceTypeConverter.java
License:Open Source License
private TypeDeclaration convert(SourceType typeHandle, CompilationResult compilationResult) throws JavaModelException { SourceTypeElementInfo typeInfo = (SourceTypeElementInfo) typeHandle.getElementInfo(); if (typeInfo.isAnonymousMember()) throw new AnonymousMemberFound(); /* create type declaration - can be member type */ TypeDeclaration type = new TypeDeclaration(compilationResult); if (typeInfo.getEnclosingType() == null) { if (typeHandle.isAnonymous()) { type.name = CharOperation.NO_CHAR; type.bits |= (ASTNode.IsAnonymousType | ASTNode.IsLocalType); } else {//w ww . ja v a 2s . co m if (typeHandle.isLocal()) { type.bits |= ASTNode.IsLocalType; } } } else { type.bits |= ASTNode.IsMemberType; } if ((type.bits & ASTNode.IsAnonymousType) == 0) { type.name = typeInfo.getName(); } type.name = typeInfo.getName(); int start, end; // only positions available type.sourceStart = start = typeInfo.getNameSourceStart(); type.sourceEnd = end = typeInfo.getNameSourceEnd(); type.modifiers = typeInfo.getModifiers(); type.declarationSourceStart = typeInfo.getDeclarationSourceStart(); type.declarationSourceEnd = typeInfo.getDeclarationSourceEnd(); type.bodyEnd = type.declarationSourceEnd; // convert 1.5 specific constructs only if compliance is 1.5 or above if (this.has1_5Compliance) { /* convert annotations */ type.annotations = convertAnnotations(typeHandle); } /* https://bugs.eclipse.org/bugs/show_bug.cgi?id=324850, even in a 1.4 project, we must internalize type variables and observe any parameterization of super class and/or super interfaces in order to be able to detect overriding in the presence of generics. */ char[][] typeParameterNames = typeInfo.getTypeParameterNames(); if (typeParameterNames.length > 0) { int parameterCount = typeParameterNames.length; char[][][] typeParameterBounds = typeInfo.getTypeParameterBounds(); type.typeParameters = new TypeParameter[parameterCount]; for (int i = 0; i < parameterCount; i++) { type.typeParameters[i] = createTypeParameter(typeParameterNames[i], typeParameterBounds[i], start, end); } } /* set superclass and superinterfaces */ if (typeInfo.getSuperclassName() != null) { type.superclass = createTypeReference(typeInfo.getSuperclassName(), start, end, true /* include generics */); type.superclass.bits |= ASTNode.IsSuperType; } char[][] interfaceNames = typeInfo.getInterfaceNames(); int interfaceCount = interfaceNames == null ? 0 : interfaceNames.length; if (interfaceCount > 0) { type.superInterfaces = new TypeReference[interfaceCount]; for (int i = 0; i < interfaceCount; i++) { type.superInterfaces[i] = createTypeReference(interfaceNames[i], start, end, true /* include generics */); type.superInterfaces[i].bits |= ASTNode.IsSuperType; } } /* convert member types */ if ((this.flags & MEMBER_TYPE) != 0) { SourceType[] sourceMemberTypes = typeInfo.getMemberTypeHandles(); int sourceMemberTypeCount = sourceMemberTypes.length; type.memberTypes = new TypeDeclaration[sourceMemberTypeCount]; for (int i = 0; i < sourceMemberTypeCount; i++) { type.memberTypes[i] = convert(sourceMemberTypes[i], compilationResult); type.memberTypes[i].enclosingType = type; } } /* convert intializers and fields*/ InitializerElementInfo[] initializers = null; int initializerCount = 0; if ((this.flags & LOCAL_TYPE) != 0) { initializers = typeInfo.getInitializers(); initializerCount = initializers.length; } SourceField[] sourceFields = null; int sourceFieldCount = 0; if ((this.flags & FIELD) != 0) { sourceFields = typeInfo.getFieldHandles(); sourceFieldCount = sourceFields.length; } int length = initializerCount + sourceFieldCount; if (length > 0) { type.fields = new FieldDeclaration[length]; for (int i = 0; i < initializerCount; i++) { type.fields[i] = convert(initializers[i], compilationResult); } int index = 0; for (int i = initializerCount; i < length; i++) { type.fields[i] = convert(sourceFields[index++], type, compilationResult); } } /* convert methods - need to add default constructor if necessary */ boolean needConstructor = (this.flags & CONSTRUCTOR) != 0; boolean needMethod = (this.flags & METHOD) != 0; if (needConstructor || needMethod) { SourceMethod[] sourceMethods = typeInfo.getMethodHandles(); int sourceMethodCount = sourceMethods.length; /* source type has a constructor ? */ /* by default, we assume that one is needed. */ int extraConstructor = 0; int methodCount = 0; int kind = TypeDeclaration.kind(type.modifiers); boolean isAbstract = kind == TypeDeclaration.INTERFACE_DECL || kind == TypeDeclaration.ANNOTATION_TYPE_DECL; if (!isAbstract) { extraConstructor = needConstructor ? 1 : 0; for (int i = 0; i < sourceMethodCount; i++) { if (sourceMethods[i].isConstructor()) { if (needConstructor) { extraConstructor = 0; // Does not need the extra constructor since one constructor already exists. methodCount++; } } else if (needMethod) { methodCount++; } } } else { methodCount = needMethod ? sourceMethodCount : 0; } type.methods = new AbstractMethodDeclaration[methodCount + extraConstructor]; if (extraConstructor != 0) { // add default constructor in first position type.methods[0] = type.createDefaultConstructor(false, false); } int index = 0; boolean hasAbstractMethods = false; for (int i = 0; i < sourceMethodCount; i++) { SourceMethod sourceMethod = sourceMethods[i]; SourceMethodElementInfo methodInfo = (SourceMethodElementInfo) sourceMethod.getElementInfo(); boolean isConstructor = methodInfo.isConstructor(); if ((methodInfo.getModifiers() & ClassFileConstants.AccAbstract) != 0) { hasAbstractMethods = true; } if ((isConstructor && needConstructor) || (!isConstructor && needMethod)) { AbstractMethodDeclaration method = convert(sourceMethod, methodInfo, compilationResult); if (isAbstract || method.isAbstract()) { // fix-up flag method.modifiers |= ExtraCompilerModifiers.AccSemicolonBody; } type.methods[extraConstructor + index++] = method; } } if (hasAbstractMethods) type.bits |= ASTNode.HasAbstractMethods; } return type; }
From source file:com.codenvy.ide.ext.java.server.internal.core.BasicCompilationUnit.java
License:Open Source License
public char[] getContents() { if (this.contents != null) return this.contents; // answer the cached source // otherwise retrieve it try {//from w w w . j ava 2s. co m return Util.getFileCharContent(new File(new String(this.fileName)), this.encoding); } catch (IOException e) { // could not read file: returns an empty array } return CharOperation.NO_CHAR; }
From source file:com.codenvy.ide.ext.java.server.internal.core.CompilationUnit.java
License:Open Source License
/** * @see org.eclipse.jdt.internal.compiler.env.ICompilationUnit#getContents() *///from w w w . j a va 2 s.co m public char[] getContents() { IBuffer buffer = getBufferManager().getBuffer(this); if (buffer == null) { // no need to force opening of CU to get the content // also this cannot be a working copy, as its buffer is never closed while the working copy is alive File file = resource(); // Get encoding from file String encoding; encoding = "UTF-8"; //file.getCharset(); try { return Util.getResourceContentsAsCharArray(file, encoding); } catch (JavaModelException e) { if (manager.abortOnMissingSource.get() == Boolean.TRUE) { IOException ioException = e.getJavaModelStatus() .getCode() == IJavaModelStatusConstants.IO_EXCEPTION ? (IOException) e.getException() : new IOException(e.getMessage()); throw new AbortCompilationUnit(null, ioException, encoding); } else { Util.log(e, Messages.bind(Messages.file_notFound, file.getAbsolutePath())); } return CharOperation.NO_CHAR; } } char[] contents = buffer.getCharacters(); if (contents == null) { // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=129814 if (manager.abortOnMissingSource.get() == Boolean.TRUE) { IOException ioException = new IOException(Messages.buffer_closed); IFile file = (IFile) getResource(); // Get encoding from file String encoding; try { encoding = file.getCharset(); } catch (CoreException ce) { // do not use any encoding encoding = null; } throw new AbortCompilationUnit(null, ioException, encoding); } return CharOperation.NO_CHAR; } return contents; }
From source file:com.codenvy.ide.ext.java.server.internal.core.CompilationUnit.java
License:Open Source License
/** * @see Openable#openBuffer(org.eclipse.core.runtime.IProgressMonitor, Object) */// w ww . j a v a 2 s . c o m protected IBuffer openBuffer(IProgressMonitor pm, Object info) throws JavaModelException { // create buffer BufferManager bufManager = getBufferManager(); boolean isWorkingCopy = isWorkingCopy(); IBuffer buffer = isWorkingCopy ? this.owner.createBuffer(this) : BufferManager.createBuffer(this); if (buffer == null) return null; ICompilationUnit original = null; boolean mustSetToOriginalContent = false; if (isWorkingCopy) { // ensure that isOpen() is called outside the bufManager synchronized block // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=237772 mustSetToOriginalContent = !isPrimary() && (original = new CompilationUnit((PackageFragment) getParent(), manager, getElementName(), DefaultWorkingCopyOwner.PRIMARY)).isOpen(); } // synchronize to ensure that 2 threads are not putting 2 different buffers at the same time // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=146331 synchronized (bufManager) { IBuffer existingBuffer = bufManager.getBuffer(this); if (existingBuffer != null) return existingBuffer; // set the buffer source if (buffer.getCharacters() == null) { if (isWorkingCopy) { if (mustSetToOriginalContent) { buffer.setContents(original.getSource()); } else { File file = resource(); if (file == null || !file.exists()) { // initialize buffer with empty contents buffer.setContents(CharOperation.NO_CHAR); } else { buffer.setContents(Util.getResourceContentsAsCharArray(file)); } } } else { File file = resource(); if (file == null || !file.exists()) throw newNotPresentException(); buffer.setContents(Util.getResourceContentsAsCharArray(file)); } } // add buffer to buffer cache // note this may cause existing buffers to be removed from the buffer cache, but only primary compilation unit's buffer // can be closed, thus no call to a client's IBuffer#close() can be done in this synchronized block. bufManager.addBuffer(buffer); // listen to buffer changes buffer.addBufferChangedListener(this); } return buffer; }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.BasicSearchEngine.java
License:Open Source License
public void searchAllConstructorDeclarations(final char[] packageName, final char[] typeName, final int typeMatchRule, IJavaSearchScope scope, final IRestrictedAccessConstructorRequestor nameRequestor, int waitingPolicy, IProgressMonitor progressMonitor) throws JavaModelException { // Validate match rule first final int validatedTypeMatchRule = SearchPattern .validateMatchRule(typeName == null ? null : new String(typeName), typeMatchRule); final int pkgMatchRule = SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE; final char NoSuffix = IIndexConstants.TYPE_SUFFIX; // Used as TYPE_SUFFIX has no effect in method #match(char, char[] , int, char[], int , int, char[], char[]) // Debug// w ww . j av a2 s . co m if (VERBOSE) { Util.verbose( "BasicSearchEngine.searchAllConstructorDeclarations(char[], char[], int, IJavaSearchScope, IRestrictedAccessConstructorRequestor, int, IProgressMonitor)"); //$NON-NLS-1$ Util.verbose(" - package name: " + (packageName == null ? "null" : new String(packageName))); //$NON-NLS-1$ //$NON-NLS-2$ Util.verbose(" - type name: " + (typeName == null ? "null" : new String(typeName))); //$NON-NLS-1$ //$NON-NLS-2$ Util.verbose(" - type match rule: " + getMatchRuleString(typeMatchRule)); //$NON-NLS-1$ if (validatedTypeMatchRule != typeMatchRule) { Util.verbose(" - validated type match rule: " + getMatchRuleString(validatedTypeMatchRule)); //$NON-NLS-1$ } Util.verbose(" - scope: " + scope); //$NON-NLS-1$ } if (validatedTypeMatchRule == -1) return; // invalid match rule => return no results // Create pattern final ConstructorDeclarationPattern pattern = new ConstructorDeclarationPattern(packageName, typeName, validatedTypeMatchRule); // Get working copy path(s). Store in a single string in case of only one to optimize comparison in requestor final HashSet workingCopyPaths = new HashSet(); String workingCopyPath = null; ICompilationUnit[] copies = getWorkingCopies(); final int copiesLength = copies == null ? 0 : copies.length; if (copies != null) { if (copiesLength == 1) { workingCopyPath = copies[0].getPath().toString(); } else { for (int i = 0; i < copiesLength; i++) { ICompilationUnit workingCopy = copies[i]; workingCopyPaths.add(workingCopy.getPath().toString()); } } } final String singleWkcpPath = workingCopyPath; // Index requestor IndexQueryRequestor searchRequestor = new IndexQueryRequestor() { public boolean acceptIndexMatch(String documentPath, SearchPattern indexRecord, SearchParticipant participant, AccessRuleSet access) { // Filter unexpected types ConstructorDeclarationPattern record = (ConstructorDeclarationPattern) indexRecord; if ((record.extraFlags & ExtraFlags.IsMemberType) != 0) { return true; // filter out member classes } if ((record.extraFlags & ExtraFlags.IsLocalType) != 0) { return true; // filter out local and anonymous classes } switch (copiesLength) { case 0: break; case 1: if (singleWkcpPath.equals(documentPath)) { return true; // filter out *the* working copy } break; default: if (workingCopyPaths.contains(documentPath)) { return true; // filter out working copies } break; } // Accept document path AccessRestriction accessRestriction = null; if (access != null) { // Compute document relative path int pkgLength = (record.declaringPackageName == null || record.declaringPackageName.length == 0) ? 0 : record.declaringPackageName.length + 1; int nameLength = record.declaringSimpleName == null ? 0 : record.declaringSimpleName.length; char[] path = new char[pkgLength + nameLength]; int pos = 0; if (pkgLength > 0) { System.arraycopy(record.declaringPackageName, 0, path, pos, pkgLength - 1); CharOperation.replace(path, '.', '/'); path[pkgLength - 1] = '/'; pos += pkgLength; } if (nameLength > 0) { System.arraycopy(record.declaringSimpleName, 0, path, pos, nameLength); pos += nameLength; } // Update access restriction if path is not empty if (pos > 0) { accessRestriction = access.getViolatedRestriction(path); } } nameRequestor.acceptConstructor(record.modifiers, record.declaringSimpleName, record.parameterCount, record.signature, record.parameterTypes, record.parameterNames, record.declaringTypeModifiers, record.declaringPackageName, record.extraFlags, documentPath, accessRestriction); return true; } }; try { if (progressMonitor != null) { progressMonitor.beginTask(Messages.engine_searching, 1000); } // add type names from indexes indexManager.performConcurrentJob( new PatternSearchJob(pattern, getDefaultSearchParticipant(indexManager), // Java search only scope, searchRequestor, indexManager), waitingPolicy, progressMonitor == null ? null : new SubProgressMonitor(progressMonitor, 1000 - copiesLength)); // add type names from working copies if (copies != null) { for (int i = 0; i < copiesLength; i++) { final ICompilationUnit workingCopy = copies[i]; if (scope instanceof HierarchyScope) { if (!((HierarchyScope) scope).encloses(workingCopy, progressMonitor)) continue; } else { if (!scope.encloses(workingCopy)) continue; } final String path = workingCopy.getPath().toString(); if (workingCopy.isConsistent()) { IPackageDeclaration[] packageDeclarations = workingCopy.getPackageDeclarations(); char[] packageDeclaration = packageDeclarations.length == 0 ? CharOperation.NO_CHAR : packageDeclarations[0].getElementName().toCharArray(); IType[] allTypes = workingCopy.getAllTypes(); for (int j = 0, allTypesLength = allTypes.length; j < allTypesLength; j++) { IType type = allTypes[j]; char[] simpleName = type.getElementName().toCharArray(); if (match(NoSuffix, packageName, pkgMatchRule, typeName, validatedTypeMatchRule, 0/*no kind*/, packageDeclaration, simpleName) && !type.isMember()) { int extraFlags = ExtraFlags.getExtraFlags(type); boolean hasConstructor = false; IMethod[] methods = type.getMethods(); for (int k = 0; k < methods.length; k++) { IMethod method = methods[k]; if (method.isConstructor()) { hasConstructor = true; String[] stringParameterNames = method.getParameterNames(); String[] stringParameterTypes = method.getParameterTypes(); int length = stringParameterNames.length; char[][] parameterNames = new char[length][]; char[][] parameterTypes = new char[length][]; for (int l = 0; l < length; l++) { parameterNames[l] = stringParameterNames[l].toCharArray(); parameterTypes[l] = Signature.toCharArray(Signature .getTypeErasure(stringParameterTypes[l]).toCharArray()); } nameRequestor.acceptConstructor(method.getFlags(), simpleName, parameterNames.length, null, // signature is not used for source type parameterTypes, parameterNames, type.getFlags(), packageDeclaration, extraFlags, path, null); } } if (!hasConstructor) { nameRequestor.acceptConstructor(Flags.AccPublic, simpleName, -1, null, // signature is not used for source type CharOperation.NO_CHAR_CHAR, CharOperation.NO_CHAR_CHAR, type.getFlags(), packageDeclaration, extraFlags, path, null); } } } } else { Parser basicParser = getParser(); org.eclipse.jdt.internal.compiler.env.ICompilationUnit unit = (org.eclipse.jdt.internal.compiler.env.ICompilationUnit) workingCopy; CompilationResult compilationUnitResult = new CompilationResult(unit, 0, 0, this.compilerOptions.maxProblemsPerUnit); CompilationUnitDeclaration parsedUnit = basicParser.dietParse(unit, compilationUnitResult); if (parsedUnit != null) { final char[] packageDeclaration = parsedUnit.currentPackage == null ? CharOperation.NO_CHAR : CharOperation.concatWith(parsedUnit.currentPackage.getImportName(), '.'); class AllConstructorDeclarationsVisitor extends ASTVisitor { private TypeDeclaration[] declaringTypes = new TypeDeclaration[0]; private int declaringTypesPtr = -1; private void endVisit(TypeDeclaration typeDeclaration) { if (!hasConstructor(typeDeclaration) && typeDeclaration.enclosingType == null) { if (match(NoSuffix, packageName, pkgMatchRule, typeName, validatedTypeMatchRule, 0/*no kind*/, packageDeclaration, typeDeclaration.name)) { nameRequestor.acceptConstructor(Flags.AccPublic, typeName, -1, null, // signature is not used for source type CharOperation.NO_CHAR_CHAR, CharOperation.NO_CHAR_CHAR, typeDeclaration.modifiers, packageDeclaration, ExtraFlags.getExtraFlags(typeDeclaration), path, null); } } this.declaringTypes[this.declaringTypesPtr] = null; this.declaringTypesPtr--; } public void endVisit(TypeDeclaration typeDeclaration, CompilationUnitScope s) { endVisit(typeDeclaration); } public void endVisit(TypeDeclaration memberTypeDeclaration, ClassScope s) { endVisit(memberTypeDeclaration); } private boolean hasConstructor(TypeDeclaration typeDeclaration) { AbstractMethodDeclaration[] methods = typeDeclaration.methods; int length = methods == null ? 0 : methods.length; for (int j = 0; j < length; j++) { if (methods[j].isConstructor()) { return true; } } return false; } public boolean visit(ConstructorDeclaration constructorDeclaration, ClassScope classScope) { TypeDeclaration typeDeclaration = this.declaringTypes[this.declaringTypesPtr]; if (match(NoSuffix, packageName, pkgMatchRule, typeName, validatedTypeMatchRule, 0/*no kind*/, packageDeclaration, typeDeclaration.name)) { Argument[] arguments = constructorDeclaration.arguments; int length = arguments == null ? 0 : arguments.length; char[][] parameterNames = new char[length][]; char[][] parameterTypes = new char[length][]; for (int l = 0; l < length; l++) { Argument argument = arguments[l]; parameterNames[l] = argument.name; if (argument.type instanceof SingleTypeReference) { parameterTypes[l] = ((SingleTypeReference) argument.type).token; } else { parameterTypes[l] = CharOperation.concatWith( ((QualifiedTypeReference) argument.type).tokens, '.'); } } TypeDeclaration enclosing = typeDeclaration.enclosingType; char[][] enclosingTypeNames = CharOperation.NO_CHAR_CHAR; while (enclosing != null) { enclosingTypeNames = CharOperation.arrayConcat( new char[][] { enclosing.name }, enclosingTypeNames); if ((enclosing.bits & ASTNode.IsMemberType) != 0) { enclosing = enclosing.enclosingType; } else { enclosing = null; } } nameRequestor.acceptConstructor(constructorDeclaration.modifiers, typeName, parameterNames.length, null, // signature is not used for source type parameterTypes, parameterNames, typeDeclaration.modifiers, packageDeclaration, ExtraFlags.getExtraFlags(typeDeclaration), path, null); } return false; // no need to find constructors from local/anonymous type } public boolean visit(TypeDeclaration typeDeclaration, BlockScope blockScope) { return false; } private boolean visit(TypeDeclaration typeDeclaration) { if (this.declaringTypes.length <= ++this.declaringTypesPtr) { int length = this.declaringTypesPtr; System.arraycopy(this.declaringTypes, 0, this.declaringTypes = new TypeDeclaration[length * 2 + 1], 0, length); } this.declaringTypes[this.declaringTypesPtr] = typeDeclaration; return true; } public boolean visit(TypeDeclaration typeDeclaration, CompilationUnitScope s) { return visit(typeDeclaration); } public boolean visit(TypeDeclaration memberTypeDeclaration, ClassScope s) { return visit(memberTypeDeclaration); } } parsedUnit.traverse(new AllConstructorDeclarationsVisitor(), parsedUnit.scope); } } if (progressMonitor != null) { if (progressMonitor.isCanceled()) throw new OperationCanceledException(); progressMonitor.worked(1); } } } } finally { if (progressMonitor != null) { progressMonitor.done(); } } }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.BasicSearchEngine.java
License:Open Source License
/** * Searches for all top-level types and member types in the given scope. * The search can be selecting specific types (given a package or a type name * prefix and match modes)./* w ww.j a v a2 s . com*/ * * @see org.eclipse.jdt.core.search.SearchEngine#searchAllTypeNames(char[], int, char[], int, int, * org.eclipse.jdt.core.search.IJavaSearchScope, org.eclipse.jdt.core.search.TypeNameRequestor, int, * org.eclipse.core.runtime.IProgressMonitor) * for detailed comment */ public void searchAllTypeNames(final char[] packageName, final int packageMatchRule, final char[] typeName, final int typeMatchRule, int searchFor, IJavaSearchScope scope, final IRestrictedAccessTypeRequestor nameRequestor, int waitingPolicy, IProgressMonitor progressMonitor) throws JavaModelException { // Validate match rule first final int validatedTypeMatchRule = SearchPattern .validateMatchRule(typeName == null ? null : new String(typeName), typeMatchRule); // Debug if (VERBOSE) { Util.verbose( "BasicSearchEngine.searchAllTypeNames(char[], char[], int, int, IJavaSearchScope, IRestrictedAccessTypeRequestor, " + "int, IProgressMonitor)"); //$NON-NLS-1$ Util.verbose(" - package name: " + (packageName == null ? "null" : new String(packageName))); //$NON-NLS-1$ //$NON-NLS-2$ Util.verbose(" - package match rule: " + getMatchRuleString(packageMatchRule)); //$NON-NLS-1$ Util.verbose(" - type name: " + (typeName == null ? "null" : new String(typeName))); //$NON-NLS-1$ //$NON-NLS-2$ Util.verbose(" - type match rule: " + getMatchRuleString(typeMatchRule)); //$NON-NLS-1$ if (validatedTypeMatchRule != typeMatchRule) { Util.verbose(" - validated type match rule: " + getMatchRuleString(validatedTypeMatchRule)); //$NON-NLS-1$ } Util.verbose(" - search for: " + searchFor); //$NON-NLS-1$ Util.verbose(" - scope: " + scope); //$NON-NLS-1$ } if (validatedTypeMatchRule == -1) return; // invalid match rule => return no results final char typeSuffix; switch (searchFor) { case IJavaSearchConstants.CLASS: typeSuffix = IIndexConstants.CLASS_SUFFIX; break; case IJavaSearchConstants.CLASS_AND_INTERFACE: typeSuffix = IIndexConstants.CLASS_AND_INTERFACE_SUFFIX; break; case IJavaSearchConstants.CLASS_AND_ENUM: typeSuffix = IIndexConstants.CLASS_AND_ENUM_SUFFIX; break; case IJavaSearchConstants.INTERFACE: typeSuffix = IIndexConstants.INTERFACE_SUFFIX; break; case IJavaSearchConstants.INTERFACE_AND_ANNOTATION: typeSuffix = IIndexConstants.INTERFACE_AND_ANNOTATION_SUFFIX; break; case IJavaSearchConstants.ENUM: typeSuffix = IIndexConstants.ENUM_SUFFIX; break; case IJavaSearchConstants.ANNOTATION_TYPE: typeSuffix = IIndexConstants.ANNOTATION_TYPE_SUFFIX; break; default: typeSuffix = IIndexConstants.TYPE_SUFFIX; break; } final TypeDeclarationPattern pattern = packageMatchRule == SearchPattern.R_EXACT_MATCH ? new TypeDeclarationPattern(packageName, null, typeName, typeSuffix, validatedTypeMatchRule) : new QualifiedTypeDeclarationPattern(packageName, packageMatchRule, typeName, typeSuffix, validatedTypeMatchRule); // Get working copy path(s). Store in a single string in case of only one to optimize comparison in requestor final HashSet workingCopyPaths = new HashSet(); String workingCopyPath = null; ICompilationUnit[] copies = getWorkingCopies(); final int copiesLength = copies == null ? 0 : copies.length; if (copies != null) { if (copiesLength == 1) { workingCopyPath = copies[0].getPath().toString(); } else { for (int i = 0; i < copiesLength; i++) { ICompilationUnit workingCopy = copies[i]; workingCopyPaths.add(workingCopy.getPath().toString()); } } } final String singleWkcpPath = workingCopyPath; // Index requestor IndexQueryRequestor searchRequestor = new IndexQueryRequestor() { public boolean acceptIndexMatch(String documentPath, SearchPattern indexRecord, SearchParticipant participant, AccessRuleSet access) { // Filter unexpected types TypeDeclarationPattern record = (TypeDeclarationPattern) indexRecord; if (record.enclosingTypeNames == IIndexConstants.ONE_ZERO_CHAR) { return true; // filter out local and anonymous classes } switch (copiesLength) { case 0: break; case 1: if (singleWkcpPath.equals(documentPath)) { return true; // filter out *the* working copy } break; default: if (workingCopyPaths.contains(documentPath)) { return true; // filter out working copies } break; } // Accept document path AccessRestriction accessRestriction = null; if (access != null) { // Compute document relative path int pkgLength = (record.pkg == null || record.pkg.length == 0) ? 0 : record.pkg.length + 1; int nameLength = record.simpleName == null ? 0 : record.simpleName.length; char[] path = new char[pkgLength + nameLength]; int pos = 0; if (pkgLength > 0) { System.arraycopy(record.pkg, 0, path, pos, pkgLength - 1); CharOperation.replace(path, '.', '/'); path[pkgLength - 1] = '/'; pos += pkgLength; } if (nameLength > 0) { System.arraycopy(record.simpleName, 0, path, pos, nameLength); pos += nameLength; } // Update access restriction if path is not empty if (pos > 0) { accessRestriction = access.getViolatedRestriction(path); } } if (match(record.typeSuffix, record.modifiers)) { nameRequestor.acceptType(record.modifiers, record.pkg, record.simpleName, record.enclosingTypeNames, documentPath, accessRestriction); } return true; } }; try { if (progressMonitor != null) { progressMonitor.beginTask(Messages.engine_searching, 1000); } // add type names from indexes indexManager.performConcurrentJob( new PatternSearchJob(pattern, getDefaultSearchParticipant(indexManager), // Java search only scope, searchRequestor, indexManager), waitingPolicy, progressMonitor == null ? null : new SubProgressMonitor(progressMonitor, 1000 - copiesLength)); // add type names from working copies if (copies != null) { for (int i = 0; i < copiesLength; i++) { final ICompilationUnit workingCopy = copies[i]; if (scope instanceof HierarchyScope) { if (!((HierarchyScope) scope).encloses(workingCopy, progressMonitor)) continue; } else { if (!scope.encloses(workingCopy)) continue; } final String path = workingCopy.getPath().toString(); if (workingCopy.isConsistent()) { IPackageDeclaration[] packageDeclarations = workingCopy.getPackageDeclarations(); char[] packageDeclaration = packageDeclarations.length == 0 ? CharOperation.NO_CHAR : packageDeclarations[0].getElementName().toCharArray(); IType[] allTypes = workingCopy.getAllTypes(); for (int j = 0, allTypesLength = allTypes.length; j < allTypesLength; j++) { IType type = allTypes[j]; IJavaElement parent = type.getParent(); char[][] enclosingTypeNames; if (parent instanceof IType) { char[] parentQualifiedName = ((IType) parent).getTypeQualifiedName('.') .toCharArray(); enclosingTypeNames = CharOperation.splitOn('.', parentQualifiedName); } else { enclosingTypeNames = CharOperation.NO_CHAR_CHAR; } char[] simpleName = type.getElementName().toCharArray(); int kind; if (type.isEnum()) { kind = TypeDeclaration.ENUM_DECL; } else if (type.isAnnotation()) { kind = TypeDeclaration.ANNOTATION_TYPE_DECL; } else if (type.isClass()) { kind = TypeDeclaration.CLASS_DECL; } else /*if (type.isInterface())*/ { kind = TypeDeclaration.INTERFACE_DECL; } if (match(typeSuffix, packageName, packageMatchRule, typeName, validatedTypeMatchRule, kind, packageDeclaration, simpleName)) { if (nameRequestor instanceof TypeNameMatchRequestorWrapper) { ((TypeNameMatchRequestorWrapper) nameRequestor).requestor.acceptTypeNameMatch( new JavaSearchTypeNameMatch(type, type.getFlags())); } else { nameRequestor.acceptType(type.getFlags(), packageDeclaration, simpleName, enclosingTypeNames, path, null); } } } } else { Parser basicParser = getParser(); org.eclipse.jdt.internal.compiler.env.ICompilationUnit unit = (org.eclipse.jdt.internal.compiler.env.ICompilationUnit) workingCopy; CompilationResult compilationUnitResult = new CompilationResult(unit, 0, 0, this.compilerOptions.maxProblemsPerUnit); CompilationUnitDeclaration parsedUnit = basicParser.dietParse(unit, compilationUnitResult); if (parsedUnit != null) { final char[] packageDeclaration = parsedUnit.currentPackage == null ? CharOperation.NO_CHAR : CharOperation.concatWith(parsedUnit.currentPackage.getImportName(), '.'); class AllTypeDeclarationsVisitor extends ASTVisitor { public boolean visit(TypeDeclaration typeDeclaration, BlockScope blockScope) { return false; // no local/anonymous type } public boolean visit(TypeDeclaration typeDeclaration, CompilationUnitScope compilationUnitScope) { if (match(typeSuffix, packageName, packageMatchRule, typeName, validatedTypeMatchRule, TypeDeclaration.kind(typeDeclaration.modifiers), packageDeclaration, typeDeclaration.name)) { if (nameRequestor instanceof TypeNameMatchRequestorWrapper) { IType type = workingCopy.getType(new String(typeName)); ((TypeNameMatchRequestorWrapper) nameRequestor).requestor .acceptTypeNameMatch(new JavaSearchTypeNameMatch(type, typeDeclaration.modifiers)); } else { nameRequestor.acceptType(typeDeclaration.modifiers, packageDeclaration, typeDeclaration.name, CharOperation.NO_CHAR_CHAR, path, null); } } return true; } public boolean visit(TypeDeclaration memberTypeDeclaration, ClassScope classScope) { if (match(typeSuffix, packageName, packageMatchRule, typeName, validatedTypeMatchRule, TypeDeclaration.kind(memberTypeDeclaration.modifiers), packageDeclaration, memberTypeDeclaration.name)) { // compute enclosing type names TypeDeclaration enclosing = memberTypeDeclaration.enclosingType; char[][] enclosingTypeNames = CharOperation.NO_CHAR_CHAR; while (enclosing != null) { enclosingTypeNames = CharOperation.arrayConcat( new char[][] { enclosing.name }, enclosingTypeNames); if ((enclosing.bits & ASTNode.IsMemberType) != 0) { enclosing = enclosing.enclosingType; } else { enclosing = null; } } // report if (nameRequestor instanceof TypeNameMatchRequestorWrapper) { IType type = workingCopy.getType(new String(enclosingTypeNames[0])); for (int j = 1, l = enclosingTypeNames.length; j < l; j++) { type = type.getType(new String(enclosingTypeNames[j])); } ((TypeNameMatchRequestorWrapper) nameRequestor).requestor .acceptTypeNameMatch(new JavaSearchTypeNameMatch(type, 0)); } else { nameRequestor.acceptType(memberTypeDeclaration.modifiers, packageDeclaration, memberTypeDeclaration.name, enclosingTypeNames, path, null); } } return true; } } parsedUnit.traverse(new AllTypeDeclarationsVisitor(), parsedUnit.scope); } } if (progressMonitor != null) { if (progressMonitor.isCanceled()) throw new OperationCanceledException(); progressMonitor.worked(1); } } } } finally { if (progressMonitor != null) { progressMonitor.done(); } } }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.BasicSearchEngine.java
License:Open Source License
/** * Searches for all top-level types and member types in the given scope using a case sensitive exact match * with the given qualified names and type names. * * @see org.eclipse.jdt.core.search.SearchEngine#searchAllTypeNames(char[][], char[][], org.eclipse.jdt.core.search.IJavaSearchScope, * org.eclipse.jdt.core.search.TypeNameRequestor, int, org.eclipse.core.runtime.IProgressMonitor) * for detailed comment/*ww w .j a va2 s.c om*/ */ public void searchAllTypeNames(final char[][] qualifications, final char[][] typeNames, final int matchRule, int searchFor, IJavaSearchScope scope, final IRestrictedAccessTypeRequestor nameRequestor, int waitingPolicy, IProgressMonitor progressMonitor) throws JavaModelException { // Debug if (VERBOSE) { Util.verbose( "BasicSearchEngine.searchAllTypeNames(char[][], char[][], int, int, IJavaSearchScope, IRestrictedAccessTypeRequestor, int, IProgressMonitor)"); //$NON-NLS-1$ Util.verbose(" - package name: " + (qualifications == null ? "null" : new String(CharOperation.concatWith(qualifications, ',')))); //$NON-NLS-1$ //$NON-NLS-2$ Util.verbose(" - type name: " + (typeNames == null ? "null" : new String(CharOperation.concatWith(typeNames, ',')))); //$NON-NLS-1$ //$NON-NLS-2$ Util.verbose(" - match rule: " + getMatchRuleString(matchRule)); //$NON-NLS-1$ Util.verbose(" - search for: " + searchFor); //$NON-NLS-1$ Util.verbose(" - scope: " + scope); //$NON-NLS-1$ } // Create pattern final char typeSuffix; switch (searchFor) { case IJavaSearchConstants.CLASS: typeSuffix = IIndexConstants.CLASS_SUFFIX; break; case IJavaSearchConstants.CLASS_AND_INTERFACE: typeSuffix = IIndexConstants.CLASS_AND_INTERFACE_SUFFIX; break; case IJavaSearchConstants.CLASS_AND_ENUM: typeSuffix = IIndexConstants.CLASS_AND_ENUM_SUFFIX; break; case IJavaSearchConstants.INTERFACE: typeSuffix = IIndexConstants.INTERFACE_SUFFIX; break; case IJavaSearchConstants.INTERFACE_AND_ANNOTATION: typeSuffix = IIndexConstants.INTERFACE_AND_ANNOTATION_SUFFIX; break; case IJavaSearchConstants.ENUM: typeSuffix = IIndexConstants.ENUM_SUFFIX; break; case IJavaSearchConstants.ANNOTATION_TYPE: typeSuffix = IIndexConstants.ANNOTATION_TYPE_SUFFIX; break; default: typeSuffix = IIndexConstants.TYPE_SUFFIX; break; } final MultiTypeDeclarationPattern pattern = new MultiTypeDeclarationPattern(qualifications, typeNames, typeSuffix, matchRule); // Get working copy path(s). Store in a single string in case of only one to optimize comparison in requestor final HashSet workingCopyPaths = new HashSet(); String workingCopyPath = null; ICompilationUnit[] copies = getWorkingCopies(); final int copiesLength = copies == null ? 0 : copies.length; if (copies != null) { if (copiesLength == 1) { workingCopyPath = copies[0].getPath().toString(); } else { for (int i = 0; i < copiesLength; i++) { ICompilationUnit workingCopy = copies[i]; workingCopyPaths.add(workingCopy.getPath().toString()); } } } final String singleWkcpPath = workingCopyPath; // Index requestor IndexQueryRequestor searchRequestor = new IndexQueryRequestor() { public boolean acceptIndexMatch(String documentPath, SearchPattern indexRecord, SearchParticipant participant, AccessRuleSet access) { // Filter unexpected types QualifiedTypeDeclarationPattern record = (QualifiedTypeDeclarationPattern) indexRecord; if (record.enclosingTypeNames == IIndexConstants.ONE_ZERO_CHAR) { return true; // filter out local and anonymous classes } switch (copiesLength) { case 0: break; case 1: if (singleWkcpPath.equals(documentPath)) { return true; // filter out *the* working copy } break; default: if (workingCopyPaths.contains(documentPath)) { return true; // filter out working copies } break; } // Accept document path AccessRestriction accessRestriction = null; if (access != null) { // Compute document relative path int qualificationLength = (record.qualification == null || record.qualification.length == 0) ? 0 : record.qualification.length + 1; int nameLength = record.simpleName == null ? 0 : record.simpleName.length; char[] path = new char[qualificationLength + nameLength]; int pos = 0; if (qualificationLength > 0) { System.arraycopy(record.qualification, 0, path, pos, qualificationLength - 1); CharOperation.replace(path, '.', '/'); path[qualificationLength - 1] = '/'; pos += qualificationLength; } if (nameLength > 0) { System.arraycopy(record.simpleName, 0, path, pos, nameLength); pos += nameLength; } // Update access restriction if path is not empty if (pos > 0) { accessRestriction = access.getViolatedRestriction(path); } } nameRequestor.acceptType(record.modifiers, record.pkg, record.simpleName, record.enclosingTypeNames, documentPath, accessRestriction); return true; } }; try { if (progressMonitor != null) { progressMonitor.beginTask(Messages.engine_searching, 100); } // add type names from indexes indexManager.performConcurrentJob( new PatternSearchJob(pattern, getDefaultSearchParticipant(indexManager), // Java search only scope, searchRequestor, indexManager), waitingPolicy, progressMonitor == null ? null : new SubProgressMonitor(progressMonitor, 100)); // add type names from working copies if (copies != null) { for (int i = 0, length = copies.length; i < length; i++) { ICompilationUnit workingCopy = copies[i]; final String path = workingCopy.getPath().toString(); if (workingCopy.isConsistent()) { IPackageDeclaration[] packageDeclarations = workingCopy.getPackageDeclarations(); char[] packageDeclaration = packageDeclarations.length == 0 ? CharOperation.NO_CHAR : packageDeclarations[0].getElementName().toCharArray(); IType[] allTypes = workingCopy.getAllTypes(); for (int j = 0, allTypesLength = allTypes.length; j < allTypesLength; j++) { IType type = allTypes[j]; IJavaElement parent = type.getParent(); char[][] enclosingTypeNames; char[] qualification = packageDeclaration; if (parent instanceof IType) { char[] parentQualifiedName = ((IType) parent).getTypeQualifiedName('.') .toCharArray(); enclosingTypeNames = CharOperation.splitOn('.', parentQualifiedName); qualification = CharOperation.concat(qualification, parentQualifiedName); } else { enclosingTypeNames = CharOperation.NO_CHAR_CHAR; } char[] simpleName = type.getElementName().toCharArray(); char suffix = IIndexConstants.TYPE_SUFFIX; if (type.isClass()) { suffix = IIndexConstants.CLASS_SUFFIX; } else if (type.isInterface()) { suffix = IIndexConstants.INTERFACE_SUFFIX; } else if (type.isEnum()) { suffix = IIndexConstants.ENUM_SUFFIX; } else if (type.isAnnotation()) { suffix = IIndexConstants.ANNOTATION_TYPE_SUFFIX; } if (pattern.matchesDecodedKey(new QualifiedTypeDeclarationPattern(qualification, simpleName, suffix, matchRule))) { nameRequestor.acceptType(type.getFlags(), packageDeclaration, simpleName, enclosingTypeNames, path, null); } } } else { Parser basicParser = getParser(); org.eclipse.jdt.internal.compiler.env.ICompilationUnit unit = (org.eclipse.jdt.internal.compiler.env.ICompilationUnit) workingCopy; CompilationResult compilationUnitResult = new CompilationResult(unit, 0, 0, this.compilerOptions.maxProblemsPerUnit); CompilationUnitDeclaration parsedUnit = basicParser.dietParse(unit, compilationUnitResult); if (parsedUnit != null) { final char[] packageDeclaration = parsedUnit.currentPackage == null ? CharOperation.NO_CHAR : CharOperation.concatWith(parsedUnit.currentPackage.getImportName(), '.'); class AllTypeDeclarationsVisitor extends ASTVisitor { public boolean visit(TypeDeclaration typeDeclaration, BlockScope blockScope) { return false; // no local/anonymous type } public boolean visit(TypeDeclaration typeDeclaration, CompilationUnitScope compilationUnitScope) { SearchPattern decodedPattern = new QualifiedTypeDeclarationPattern( packageDeclaration, typeDeclaration.name, convertTypeKind(TypeDeclaration.kind(typeDeclaration.modifiers)), matchRule); if (pattern.matchesDecodedKey(decodedPattern)) { nameRequestor.acceptType(typeDeclaration.modifiers, packageDeclaration, typeDeclaration.name, CharOperation.NO_CHAR_CHAR, path, null); } return true; } public boolean visit(TypeDeclaration memberTypeDeclaration, ClassScope classScope) { // compute enclosing type names char[] qualification = packageDeclaration; TypeDeclaration enclosing = memberTypeDeclaration.enclosingType; char[][] enclosingTypeNames = CharOperation.NO_CHAR_CHAR; while (enclosing != null) { qualification = CharOperation.concat(qualification, enclosing.name, '.'); enclosingTypeNames = CharOperation .arrayConcat(new char[][] { enclosing.name }, enclosingTypeNames); if ((enclosing.bits & ASTNode.IsMemberType) != 0) { enclosing = enclosing.enclosingType; } else { enclosing = null; } } SearchPattern decodedPattern = new QualifiedTypeDeclarationPattern( qualification, memberTypeDeclaration.name, convertTypeKind(TypeDeclaration.kind(memberTypeDeclaration.modifiers)), matchRule); if (pattern.matchesDecodedKey(decodedPattern)) { nameRequestor.acceptType(memberTypeDeclaration.modifiers, packageDeclaration, memberTypeDeclaration.name, enclosingTypeNames, path, null); } return true; } } parsedUnit.traverse(new AllTypeDeclarationsVisitor(), parsedUnit.scope); } } } } } finally { if (progressMonitor != null) { progressMonitor.done(); } } }