List of usage examples for org.eclipse.jdt.internal.compiler.ast TypeDeclaration CLASS_DECL
int CLASS_DECL
To view the source code for org.eclipse.jdt.internal.compiler.ast TypeDeclaration CLASS_DECL.
Click Source Link
From source file:ch.uzh.ifi.seal.changedistiller.structuredifferencing.java.JavaStructureTreeBuilder.java
License:Apache License
@Override public boolean visit(TypeDeclaration typeDeclaration, CompilationUnitScope scope) { int kind = TypeDeclaration.kind(typeDeclaration.modifiers); Type type = null;//w w w.j av a2s.co m switch (kind) { case TypeDeclaration.INTERFACE_DECL: type = Type.INTERFACE; break; case TypeDeclaration.CLASS_DECL: type = Type.CLASS; break; case TypeDeclaration.ANNOTATION_TYPE_DECL: type = Type.ANNOTATION; break; case TypeDeclaration.ENUM_DECL: type = Type.ENUM; break; default: assert (false); } push(type, String.valueOf(typeDeclaration.name), typeDeclaration); fQualifiers.push(typeDeclaration.name); return true; }
From source file:com.android.tools.lint.psi.EcjPsiBuilder.java
License:Apache License
@NonNull private EcjPsiClass toClass(@NonNull EcjPsiSourceElement parent, @NonNull TypeDeclaration declaration) { EcjPsiClass cls = new EcjPsiClass(mManager, declaration, new String(declaration.name)); parent.adoptChild(cls);//from www . j av a 2s . co m cls.setRange(declaration.declarationSourceStart, declaration.declarationSourceEnd + 1); EcjPsiModifierList modifierList = toModifierList(cls, declaration); cls.setNameIdentifier(toIdentifier(cls, declaration.name, toRange(declaration))); cls.setModifierList(modifierList); int kind = TypeDeclaration.kind(declaration.modifiers); switch (kind) { case TypeDeclaration.CLASS_DECL: { // Class: set body, super class, extended interfaces, and type variables cls.setSuperClass(declaration.superclass); cls.setSuperInterfaces(declaration.superInterfaces); cls.setTypeParameterList(toTypeParameterList(cls, declaration.typeParameters)); cls.setExtendsList(toTypeReferenceList(cls, declaration.superclass, Role.EXTENDS_LIST)); cls.setImplementsList(toTypeReferenceList(cls, declaration.superInterfaces, Role.IMPLEMENTS_LIST)); initializeClassBody(cls, declaration); break; } case TypeDeclaration.INTERFACE_DECL: { // Interface: set body, super interface, and type variables modifierList.setModifiers(modifierList.getModifiers() | Modifier.STATIC | Modifier.ABSTRACT); cls.setSuperInterfaces(declaration.superInterfaces); cls.setTypeParameterList(toTypeParameterList(cls, declaration.typeParameters)); cls.setImplementsList(toTypeReferenceList(cls, declaration.superInterfaces, Role.EXTENDS_LIST)); initializeClassBody(cls, declaration); break; } case TypeDeclaration.ENUM_DECL: { // Enum: set enum body, and implemented interfaces cls.setSuperInterfaces(declaration.superInterfaces); cls.setImplementsList(toTypeReferenceList(cls, declaration.superInterfaces, Role.IMPLEMENTS_LIST)); modifierList.setModifiers(modifierList.getModifiers() | Modifier.STATIC | Modifier.FINAL); initializeClassBody(cls, declaration); break; } case TypeDeclaration.ANNOTATION_TYPE_DECL: { // Annotation: set body modifierList.setModifiers(modifierList.getModifiers() | Modifier.STATIC | Modifier.ABSTRACT); initializeClassBody(cls, declaration); break; } } return cls; }
From source file:com.codenvy.ide.ext.java.server.internal.core.BinaryType.java
License:Open Source License
public boolean isClass() throws JavaModelException { IBinaryType info = (IBinaryType) getElementInfo(); return TypeDeclaration.kind(info.getModifiers()) == TypeDeclaration.CLASS_DECL; }
From source file:com.codenvy.ide.ext.java.server.internal.core.NameLookup.java
License:Open Source License
/** * Returns true if:<ul>// w w w . j a v a2 s. c o m * <li>the given type is an existing class and the flag's <code>ACCEPT_CLASSES</code> * bit is on * <li>the given type is an existing interface and the <code>ACCEPT_INTERFACES</code> * bit is on * <li>neither the <code>ACCEPT_CLASSES</code> or <code>ACCEPT_INTERFACES</code> * bit is on * </ul> * Otherwise, false is returned. */ protected boolean acceptType(IType type, int acceptFlags, boolean isSourceType) { if (acceptFlags == 0 || acceptFlags == ACCEPT_ALL) return true; // no flags or all flags, always accepted try { int kind = isSourceType ? TypeDeclaration .kind(((SourceTypeElementInfo) ((SourceType) type).getElementInfo()).getModifiers()) : TypeDeclaration.kind(((IBinaryType) ((BinaryType) type).getElementInfo()).getModifiers()); switch (kind) { case TypeDeclaration.CLASS_DECL: return (acceptFlags & ACCEPT_CLASSES) != 0; case TypeDeclaration.INTERFACE_DECL: return (acceptFlags & ACCEPT_INTERFACES) != 0; case TypeDeclaration.ENUM_DECL: return (acceptFlags & ACCEPT_ENUMS) != 0; default: //case IGenericType.ANNOTATION_TYPE : return (acceptFlags & ACCEPT_ANNOTATIONS) != 0; } } catch (JavaModelException npe) { return false; // the class is not present, do not accept. } }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.BasicSearchEngine.java
License:Open Source License
char convertTypeKind(int typeDeclarationKind) { switch (typeDeclarationKind) { case TypeDeclaration.CLASS_DECL: return IIndexConstants.CLASS_SUFFIX; case TypeDeclaration.INTERFACE_DECL: return IIndexConstants.INTERFACE_SUFFIX; case TypeDeclaration.ENUM_DECL: return IIndexConstants.ENUM_SUFFIX; case TypeDeclaration.ANNOTATION_TYPE_DECL: return IIndexConstants.ANNOTATION_TYPE_SUFFIX; default:/* www.j a v a 2s. c om*/ return IIndexConstants.TYPE_SUFFIX; } }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.BasicSearchEngine.java
License:Open Source License
boolean match(char patternTypeSuffix, char[] patternPkg, int matchRulePkg, char[] patternTypeName, int matchRuleType, int typeKind, char[] pkg, char[] typeName) { switch (patternTypeSuffix) { case IIndexConstants.CLASS_SUFFIX: if (typeKind != TypeDeclaration.CLASS_DECL) return false; break;//from w w w .j a va 2 s. co m case IIndexConstants.CLASS_AND_INTERFACE_SUFFIX: if (typeKind != TypeDeclaration.CLASS_DECL && typeKind != TypeDeclaration.INTERFACE_DECL) return false; break; case IIndexConstants.CLASS_AND_ENUM_SUFFIX: if (typeKind != TypeDeclaration.CLASS_DECL && typeKind != TypeDeclaration.ENUM_DECL) return false; break; case IIndexConstants.INTERFACE_SUFFIX: if (typeKind != TypeDeclaration.INTERFACE_DECL) return false; break; case IIndexConstants.INTERFACE_AND_ANNOTATION_SUFFIX: if (typeKind != TypeDeclaration.INTERFACE_DECL && typeKind != TypeDeclaration.ANNOTATION_TYPE_DECL) return false; break; case IIndexConstants.ENUM_SUFFIX: if (typeKind != TypeDeclaration.ENUM_DECL) return false; break; case IIndexConstants.ANNOTATION_TYPE_SUFFIX: if (typeKind != TypeDeclaration.ANNOTATION_TYPE_DECL) return false; break; case IIndexConstants.TYPE_SUFFIX: // nothing } boolean isPkgCaseSensitive = (matchRulePkg & SearchPattern.R_CASE_SENSITIVE) != 0; if (patternPkg != null && !CharOperation.equals(patternPkg, pkg, isPkgCaseSensitive)) return false; boolean isCaseSensitive = (matchRuleType & SearchPattern.R_CASE_SENSITIVE) != 0; if (patternTypeName != null) { boolean isCamelCase = (matchRuleType & (SearchPattern.R_CAMELCASE_MATCH | SearchPattern.R_CAMELCASE_SAME_PART_COUNT_MATCH)) != 0; int matchMode = matchRuleType & JavaSearchPattern.MATCH_MODE_MASK; if (!isCaseSensitive && !isCamelCase) { patternTypeName = CharOperation.toLowerCase(patternTypeName); } boolean matchFirstChar = !isCaseSensitive || patternTypeName[0] == typeName[0]; switch (matchMode) { case SearchPattern.R_EXACT_MATCH: return matchFirstChar && CharOperation.equals(patternTypeName, typeName, isCaseSensitive); case SearchPattern.R_PREFIX_MATCH: return matchFirstChar && CharOperation.prefixEquals(patternTypeName, typeName, isCaseSensitive); case SearchPattern.R_PATTERN_MATCH: return CharOperation.match(patternTypeName, typeName, isCaseSensitive); case SearchPattern.R_REGEXP_MATCH: // TODO (frederic) implement regular expression match break; case SearchPattern.R_CAMELCASE_MATCH: if (matchFirstChar && CharOperation.camelCaseMatch(patternTypeName, typeName, false)) { return true; } return !isCaseSensitive && matchFirstChar && CharOperation.prefixEquals(patternTypeName, typeName, false); case SearchPattern.R_CAMELCASE_SAME_PART_COUNT_MATCH: return matchFirstChar && CharOperation.camelCaseMatch(patternTypeName, typeName, true); } } return true; }
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).//from w w w .j a v a2 s . c o m * * @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.indexing.BinaryIndexer.java
License:Open Source License
public void indexDocument() { try {// w ww . ja v a 2 s .c om final byte[] contents = this.document.getByteContents(); // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=107124 // contents can potentially be null if a IOException occurs while retrieving the contents if (contents == null) return; final String path = this.document.getPath(); ClassFileReader reader = new ClassFileReader(contents, path == null ? null : path.toCharArray()); // first add type references char[] className = replace('/', '.', reader.getName()); // looks like java/lang/String // need to extract the package name and the simple name int packageNameIndex = CharOperation.lastIndexOf('.', className); char[] packageName = null; char[] name = null; if (packageNameIndex >= 0) { packageName = CharOperation.subarray(className, 0, packageNameIndex); name = CharOperation.subarray(className, packageNameIndex + 1, className.length); } else { packageName = CharOperation.NO_CHAR; name = className; } char[] enclosingTypeName = null; boolean isNestedType = reader.isNestedType(); if (isNestedType) { if (reader.isAnonymous()) { name = CharOperation.NO_CHAR; } else { name = reader.getInnerSourceName(); } if (reader.isLocal() || reader.isAnonymous()) { // set specific ['0'] value for local and anonymous to be able to filter them enclosingTypeName = ONE_ZERO; } else { char[] fullEnclosingName = reader.getEnclosingTypeName(); int nameLength = fullEnclosingName.length - packageNameIndex - 1; if (nameLength <= 0) { // See PR 1GIR345: ITPJCORE:ALL - Indexer: NegativeArraySizeException return; } enclosingTypeName = new char[nameLength]; System.arraycopy(fullEnclosingName, packageNameIndex + 1, enclosingTypeName, 0, nameLength); } } // type parameters char[][] typeParameterSignatures = null; char[] genericSignature = reader.getGenericSignature(); if (genericSignature != null) { CharOperation.replace(genericSignature, '/', '.'); typeParameterSignatures = Signature.getTypeParameters(genericSignature); } // eliminate invalid innerclasses (1G4KCF7) if (name == null) return; char[][] superinterfaces = replace('/', '.', reader.getInterfaceNames()); char[][] enclosingTypeNames = enclosingTypeName == null ? null : new char[][] { enclosingTypeName }; int modifiers = reader.getModifiers(); switch (TypeDeclaration.kind(modifiers)) { case TypeDeclaration.CLASS_DECL: char[] superclass = replace('/', '.', reader.getSuperclassName()); addClassDeclaration(modifiers, packageName, name, enclosingTypeNames, superclass, superinterfaces, typeParameterSignatures, false); break; case TypeDeclaration.INTERFACE_DECL: addInterfaceDeclaration(modifiers, packageName, name, enclosingTypeNames, superinterfaces, typeParameterSignatures, false); break; case TypeDeclaration.ENUM_DECL: superclass = replace('/', '.', reader.getSuperclassName()); addEnumDeclaration(modifiers, packageName, name, enclosingTypeNames, superclass, superinterfaces, false); break; case TypeDeclaration.ANNOTATION_TYPE_DECL: addAnnotationTypeDeclaration(modifiers, packageName, name, enclosingTypeNames, false); break; } // Look for references in class annotations IBinaryAnnotation[] annotations = reader.getAnnotations(); if (annotations != null) { for (int a = 0, length = annotations.length; a < length; a++) { IBinaryAnnotation annotation = annotations[a]; addBinaryAnnotation(annotation); } } long tagBits = reader.getTagBits() & TagBits.AllStandardAnnotationsMask; if (tagBits != 0) { addBinaryStandardAnnotations(tagBits); } int extraFlags = ExtraFlags.getExtraFlags(reader); // first reference all methods declarations and field declarations MethodInfo[] methods = (MethodInfo[]) reader.getMethods(); boolean noConstructor = true; if (methods != null) { for (int i = 0, max = methods.length; i < max; i++) { MethodInfo method = methods[i]; boolean isConstructor = method.isConstructor(); char[] descriptor = method.getMethodDescriptor(); char[][] parameterTypes = decodeParameterTypes(descriptor, isConstructor && isNestedType); char[] returnType = decodeReturnType(descriptor); char[][] exceptionTypes = replace('/', '.', method.getExceptionTypeNames()); if (isConstructor) { noConstructor = false; char[] signature = method.getGenericSignature(); if (signature == null) { if (reader.isNestedType() && ((modifiers & ClassFileConstants.AccStatic) == 0)) { signature = removeFirstSyntheticParameter(descriptor); } else { signature = descriptor; } } addConstructorDeclaration(name, parameterTypes == null ? 0 : parameterTypes.length, signature, parameterTypes, method.getArgumentNames(), method.getModifiers(), packageName, modifiers, exceptionTypes, extraFlags); } else { if (!method.isClinit()) { addMethodDeclaration(method.getSelector(), parameterTypes, returnType, exceptionTypes); } } // look for references in method annotations annotations = method.getAnnotations(); if (annotations != null) { for (int a = 0, length = annotations.length; a < length; a++) { IBinaryAnnotation annotation = annotations[a]; addBinaryAnnotation(annotation); } } tagBits = method.getTagBits() & TagBits.AllStandardAnnotationsMask; if (tagBits != 0) { addBinaryStandardAnnotations(tagBits); } } } if (noConstructor) { addDefaultConstructorDeclaration(className, packageName, modifiers, extraFlags); } FieldInfo[] fields = (FieldInfo[]) reader.getFields(); if (fields != null) { for (int i = 0, max = fields.length; i < max; i++) { FieldInfo field = fields[i]; char[] fieldName = field.getName(); char[] fieldType = decodeFieldType(replace('/', '.', field.getTypeName())); addFieldDeclaration(fieldType, fieldName); // look for references in field annotations annotations = field.getAnnotations(); if (annotations != null) { for (int a = 0, length = annotations.length; a < length; a++) { IBinaryAnnotation annotation = annotations[a]; addBinaryAnnotation(annotation); } } tagBits = field.getTagBits() & TagBits.AllStandardAnnotationsMask; if (tagBits != 0) { addBinaryStandardAnnotations(tagBits); } } } // record all references found inside the .class file extractReferenceFromConstantPool(contents, reader); } catch (ClassFormatException e) { // ignore this.document.removeAllIndexEntries(); Util.log(IStatus.WARNING, "The Java indexing could not index " + this.document.getPath() + ". This .class file doesn't follow the class file format specification. Please report this issue against the .class file vendor"); //$NON-NLS-1$ //$NON-NLS-2$ } catch (RuntimeException e) { // https://bugs.eclipse.org/bugs/show_bug.cgi?id=182154 // logging the entry that could not be indexed and continue with the next one // we remove all entries relative to the boggus document this.document.removeAllIndexEntries(); Util.log(IStatus.WARNING, "The Java indexing could not index " + this.document.getPath() + ". This .class file doesn't follow the class file format specification. Please report this issue against the .class file vendor"); //$NON-NLS-1$ //$NON-NLS-2$ } }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.indexing.SourceIndexerRequestor.java
License:Open Source License
/** * @see org.eclipse.jdt.internal.compiler.ISourceElementRequestor#enterType(org.eclipse.jdt.internal.compiler.ISourceElementRequestor.TypeInfo) *//* w w w .j a va 2 s. com*/ public void enterType(TypeInfo typeInfo) { // TODO (jerome) might want to merge the 4 methods switch (TypeDeclaration.kind(typeInfo.modifiers)) { case TypeDeclaration.CLASS_DECL: enterClass(typeInfo); break; case TypeDeclaration.ANNOTATION_TYPE_DECL: enterAnnotationType(typeInfo); break; case TypeDeclaration.INTERFACE_DECL: enterInterface(typeInfo); break; case TypeDeclaration.ENUM_DECL: enterEnum(typeInfo); break; } }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.ClassFileMatchLocator.java
License:Open Source License
boolean matchTypeDeclaration(TypeDeclarationPattern pattern, Object binaryInfo, IBinaryType enclosingBinaryType) { if (!(binaryInfo instanceof IBinaryType)) return false; IBinaryType type = (IBinaryType) binaryInfo; char[] fullyQualifiedTypeName = convertClassFileFormat(type.getName()); boolean qualifiedPattern = pattern instanceof QualifiedTypeDeclarationPattern; if (pattern.enclosingTypeNames == null || qualifiedPattern) { char[] simpleName = (pattern.getMatchMode() == SearchPattern.R_PREFIX_MATCH) ? CharOperation.concat(pattern.simpleName, IIndexConstants.ONE_STAR) : pattern.simpleName;/*from w w w. j a v a2s .c o m*/ char[] pkg = qualifiedPattern ? ((QualifiedTypeDeclarationPattern) pattern).qualification : pattern.pkg; if (!checkTypeName(simpleName, pkg, fullyQualifiedTypeName, pattern.isCaseSensitive(), pattern.isCamelCase())) return false; } else { char[] enclosingTypeName = CharOperation.concatWith(pattern.enclosingTypeNames, '.'); char[] patternString = pattern.pkg == null ? enclosingTypeName : CharOperation.concat(pattern.pkg, enclosingTypeName, '.'); if (!checkTypeName(pattern.simpleName, patternString, fullyQualifiedTypeName, pattern.isCaseSensitive(), pattern.isCamelCase())) return false; } int kind = TypeDeclaration.kind(type.getModifiers()); switch (pattern.typeSuffix) { case CLASS_SUFFIX: return kind == TypeDeclaration.CLASS_DECL; case INTERFACE_SUFFIX: return kind == TypeDeclaration.INTERFACE_DECL; case ENUM_SUFFIX: return kind == TypeDeclaration.ENUM_DECL; case ANNOTATION_TYPE_SUFFIX: return kind == TypeDeclaration.ANNOTATION_TYPE_DECL; case CLASS_AND_INTERFACE_SUFFIX: return kind == TypeDeclaration.CLASS_DECL || kind == TypeDeclaration.INTERFACE_DECL; case CLASS_AND_ENUM_SUFFIX: return kind == TypeDeclaration.CLASS_DECL || kind == TypeDeclaration.ENUM_DECL; case INTERFACE_AND_ANNOTATION_SUFFIX: return kind == TypeDeclaration.INTERFACE_DECL || kind == TypeDeclaration.ANNOTATION_TYPE_DECL; case TYPE_SUFFIX: // nothing } return true; }