List of usage examples for org.eclipse.jdt.internal.compiler.classfmt ClassFileConstants AccStatic
int AccStatic
To view the source code for org.eclipse.jdt.internal.compiler.classfmt ClassFileConstants AccStatic.
Click Source Link
From source file:ch.uzh.ifi.seal.changedistiller.ast.java.JavaASTHelper.java
License:Apache License
private boolean isStatic(int ecjModifier) { return (ecjModifier & ClassFileConstants.AccStatic) != 0; }
From source file:com.android.tools.lint.psi.EcjPsiBuilder.java
License:Apache License
private EcjPsiModifierList toModifierList(@NonNull EcjPsiSourceElement parent, int modifiers, Annotation[] annotations) { int flags = 0; if ((modifiers & ClassFileConstants.AccStatic) != 0) { flags |= Modifier.STATIC; }//from w w w .ja v a2 s . co m if ((modifiers & ClassFileConstants.AccFinal) != 0) { flags |= Modifier.FINAL; } if ((modifiers & ClassFileConstants.AccAbstract) != 0) { flags |= Modifier.ABSTRACT; } if ((modifiers & ClassFileConstants.AccPrivate) != 0) { flags |= Modifier.PRIVATE; } if ((modifiers & ClassFileConstants.AccProtected) != 0) { flags |= Modifier.PROTECTED; } if ((modifiers & ClassFileConstants.AccPublic) != 0) { flags |= Modifier.PUBLIC; } if ((modifiers & ClassFileConstants.AccSynchronized) != 0) { flags |= Modifier.SYNCHRONIZED; } if ((modifiers & ClassFileConstants.AccVolatile) != 0) { flags |= Modifier.VOLATILE; } if ((modifiers & ExtraCompilerModifiers.AccDefaultMethod) != 0) { flags |= EcjPsiModifierList.DEFAULT_MASK; } EcjPsiModifierList modifierList = new EcjPsiModifierList(mManager, flags); parent.adoptChild(modifierList); EcjPsiAnnotation[] psiAnnotations = toAnnotations(modifierList, annotations); modifierList.setAnnotations(psiAnnotations); return modifierList; }
From source file:com.android.tools.lint.psi.EcjPsiBuilder.java
License:Apache License
private EcjPsiImport toImport(EcjPsiImportList parent, ImportReference importReference) { String typeName = getTypeName(importReference.getImportName()); boolean onDemand = (importReference.bits & ASTNode.OnDemand) != 0; EcjPsiImport ref;/*from w ww. j a v a 2 s . co m*/ if ((importReference.modifiers & ClassFileConstants.AccStatic) != 0) { ref = new EcjPsiStaticImport(mManager, importReference, typeName, onDemand); } else { ref = new EcjPsiImport(mManager, importReference, typeName, onDemand); } ref.setReference(toImportReference(ref, importReference)); parent.adoptChild(ref); return ref; }
From source file:com.android.tools.lint.psi.EcjPsiBuilder.java
License:Apache License
@NonNull private PsiClassInitializer toClassInitializer(@NonNull EcjPsiClass parent, Clinit clinit) { EcjPsiClassInitializer initializer = new EcjPsiClassInitializer(mManager, parent, clinit); parent.adoptChild(initializer);/*from ww w . ja va 2s . c om*/ if ((clinit.modifiers & ClassFileConstants.AccStatic) != 0) { initializer.setRange(clinit.declarationSourceStart, clinit.sourceEnd + 1); } initializer.setModifierList(toModifierList(initializer, clinit.modifiers, clinit.annotations)); EcjPsiCodeBlock body = toBlock(initializer, clinit.statements, null, clinit.declarationSourceStart, clinit.declarationSourceEnd + 1); initializer.setBody(body); return initializer; }
From source file:com.codenvy.ide.ext.java.server.internal.codeassist.impl.Engine.java
License:Open Source License
protected boolean mustQualifyType(char[] packageName, char[] typeName, char[] enclosingTypeNames, int modifiers) { // If there are no types defined into the current CU yet. if (this.unitScope == null) return true; if (!this.importCachesInitialized) { initializeImportCaches();//from w w w. jav a2 s. c o m } for (int i = 0; i < this.importCacheCount; i++) { char[][] importName = this.importsCache[i]; if (CharOperation.equals(typeName, importName[0])) { char[] fullyQualifiedTypeName = enclosingTypeNames == null || enclosingTypeNames.length == 0 ? CharOperation.concat(packageName, typeName, '.') : CharOperation.concat(CharOperation.concat(packageName, enclosingTypeNames, '.'), typeName, '.'); return !CharOperation.equals(fullyQualifiedTypeName, importName[1]); } } if ((enclosingTypeNames == null || enclosingTypeNames.length == 0) && CharOperation.equals(this.currentPackageName, packageName)) return false; char[] fullyQualifiedEnclosingTypeName = null; for (int i = 0; i < this.onDemandImportCacheCount; i++) { ImportBinding importBinding = this.onDemandImportsCache[i]; Binding resolvedImport = importBinding.resolvedImport; char[][] importName = importBinding.compoundName; char[] importFlatName = CharOperation.concatWith(importName, '.'); boolean isFound = false; // resolvedImport is a ReferenceBindng or a PackageBinding if (resolvedImport instanceof ReferenceBinding) { if (enclosingTypeNames != null && enclosingTypeNames.length != 0) { if (fullyQualifiedEnclosingTypeName == null) { fullyQualifiedEnclosingTypeName = CharOperation.concat(packageName, enclosingTypeNames, '.'); } if (CharOperation.equals(fullyQualifiedEnclosingTypeName, importFlatName)) { if (importBinding.isStatic()) { isFound = (modifiers & ClassFileConstants.AccStatic) != 0; } else { isFound = true; } } } } else { if (enclosingTypeNames == null || enclosingTypeNames.length == 0) { if (CharOperation.equals(packageName, importFlatName)) { if (importBinding.isStatic()) { isFound = (modifiers & ClassFileConstants.AccStatic) != 0; } else { isFound = true; } } } } // find potential conflict with another import if (isFound) { for (int j = 0; j < this.onDemandImportCacheCount; j++) { if (i != j) { ImportBinding conflictingImportBinding = this.onDemandImportsCache[j]; if (conflictingImportBinding.resolvedImport instanceof ReferenceBinding) { ReferenceBinding refBinding = (ReferenceBinding) conflictingImportBinding.resolvedImport; if (refBinding.getMemberType(typeName) != null) { return true; } } else { char[] conflictingImportName = CharOperation .concatWith(conflictingImportBinding.compoundName, '.'); if (this.nameEnvironment.nameLookup.findType(String.valueOf(typeName), String.valueOf(conflictingImportName), false, NameLookup.ACCEPT_ALL, false/*don't check restrictions*/) != null) { return true; } } } } return false; } } return true; }
From source file:com.codenvy.ide.ext.java.server.internal.core.BinaryMethod.java
License:Open Source License
public int getFlags() throws JavaModelException { IBinaryMethod info = (IBinaryMethod) getElementInfo(); int modifiers = info.getModifiers(); if (((IType) this.parent).isInterface() && (modifiers & (ClassFileConstants.AccAbstract | ClassFileConstants.AccStatic)) == 0) modifiers |= ExtraCompilerModifiers.AccDefaultMethod; return modifiers; }
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.j a v a 2 s . c o m*/ 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.redhat.ceylon.eclipse.core.model.mirror.UnknownClassMirror.java
License:Open Source License
public JDTClass(ReferenceBinding klass, IType type) { this.type = type; bindingRef = new WeakReference<ReferenceBinding>(klass); pkg = new JDTPackage(klass.getPackage()); simpleName = new String(klass.sourceName()); qualifiedName = JDTUtils.getFullyQualifiedName(klass); isPublic = klass.isPublic();/*from w w w . java 2 s . c om*/ isInterface = klass.isInterface(); isAbstract = klass.isAbstract(); isProtected = klass.isProtected(); isDefaultAccess = klass.isDefault(); isLocalType = klass.isLocalType(); isStatic = (klass.modifiers & ClassFileConstants.AccStatic) != 0; isFinal = klass.isFinal(); isEnum = klass.isEnum(); isBinary = klass.isBinaryBinding(); isAnonymous = klass.isAnonymousType(); isJavaSource = (klass instanceof SourceTypeBinding) && new String(((SourceTypeBinding) klass).getFileName()).endsWith(".java"); isAnnotationType = klass.isAnnotationType(); bindingKey = klass.computeUniqueKey(); char[] bindingFileName = klass.getFileName(); int start = CharOperation.lastIndexOf('/', bindingFileName) + 1; if (start == 0 || start < CharOperation.lastIndexOf('\\', bindingFileName)) start = CharOperation.lastIndexOf('\\', bindingFileName) + 1; fileName = new String(CharOperation.subarray(bindingFileName, start, -1)); int jarFileEntrySeparatorIndex = CharOperation.indexOf(IDependent.JAR_FILE_ENTRY_SEPARATOR, bindingFileName); if (jarFileEntrySeparatorIndex > 0) { char[] jarPart = CharOperation.subarray(bindingFileName, 0, jarFileEntrySeparatorIndex); IJavaElement jarPackageFragmentRoot = JavaCore.create(new String(jarPart)); String jarPath = jarPackageFragmentRoot.getPath().toOSString(); char[] entryPart = CharOperation.subarray(bindingFileName, jarFileEntrySeparatorIndex + 1, bindingFileName.length); fullPath = new StringBuilder(jarPath).append("!/").append(entryPart).toString(); } else { fullPath = new String(bindingFileName); } ReferenceBinding sourceOrClass = klass; if (!klass.isBinaryBinding()) { sourceOrClass = klass.outermostEnclosingType(); } char[] classFullName = new char[0]; for (char[] part : sourceOrClass.compoundName) { classFullName = CharOperation.concat(classFullName, part, '/'); } char[][] temp = CharOperation.splitOn('.', sourceOrClass.getFileName()); String extension = temp.length > 1 ? "." + new String(temp[temp.length - 1]) : ""; javaModelPath = new String(classFullName) + extension; if (type == null) { annotations = new HashMap<>(); methods = Collections.emptyList(); interfaces = Collections.emptyList(); typeParams = Collections.emptyList(); fields = Collections.emptyList(); innerClasses = Collections.emptyList(); } }
From source file:lombok.eclipse.agent.PatchDelegate.java
License:Open Source License
private static void fillMethodBindingsForFields(CompilationUnitDeclaration cud, ClassScope scope, List<BindingTuple> methodsToDelegate) { TypeDeclaration decl = scope.referenceContext; if (decl == null) return;//from w w w . j a v a2s. c o m if (decl.fields != null) for (FieldDeclaration field : decl.fields) { if (field.annotations == null) continue; for (Annotation ann : field.annotations) { if (!isDelegate(ann, decl)) continue; if (Annotation_applied.getAndSet(ann, true)) continue; if ((field.modifiers & ClassFileConstants.AccStatic) != 0) { EclipseAST eclipseAst = TransformEclipseAST.getAST(cud, true); eclipseAst.get(ann).addError(LEGALITY_OF_DELEGATE); break; } List<ClassLiteralAccess> rawTypes = rawTypes(ann, "types"); List<ClassLiteralAccess> excludedRawTypes = rawTypes(ann, "excludes"); List<BindingTuple> methodsToExclude = new ArrayList<BindingTuple>(); List<BindingTuple> methodsToDelegateForThisAnn = new ArrayList<BindingTuple>(); try { for (ClassLiteralAccess cla : excludedRawTypes) { addAllMethodBindings(methodsToExclude, cla.type.resolveType(decl.initializerScope), new HashSet<String>(), field.name, ann); } Set<String> banList = new HashSet<String>(); for (BindingTuple excluded : methodsToExclude) banList.add(printSig(excluded.parameterized)); if (rawTypes.isEmpty()) { addAllMethodBindings(methodsToDelegateForThisAnn, field.type.resolveType(decl.initializerScope), banList, field.name, ann); } else { for (ClassLiteralAccess cla : rawTypes) { addAllMethodBindings(methodsToDelegateForThisAnn, cla.type.resolveType(decl.initializerScope), banList, field.name, ann); } } } catch (DelegateRecursion e) { EclipseAST eclipseAst = TransformEclipseAST.getAST(cud, true); eclipseAst.get(ann).addError( String.format(RECURSION_NOT_ALLOWED, new String(e.member), new String(e.type))); break; } // Not doing this right now because of problems - see commented-out-method for info. // removeExistingMethods(methodsToDelegate, decl, scope); String dupe = containsDuplicates(methodsToDelegateForThisAnn); if (dupe != null) { EclipseAST eclipseAst = TransformEclipseAST.getAST(cud, true); eclipseAst.get(ann).addError( "The method '" + dupe + "' is being delegated by more than one specified type."); } else { methodsToDelegate.addAll(methodsToDelegateForThisAnn); } } } }
From source file:lombok.eclipse.agent.PatchDelegate.java
License:Open Source License
private static void fillMethodBindingsForMethods(CompilationUnitDeclaration cud, ClassScope scope, List<BindingTuple> methodsToDelegate) { TypeDeclaration decl = scope.referenceContext; if (decl == null) return;//from www . j a v a2 s. c o m if (decl.methods != null) for (AbstractMethodDeclaration methodDecl : decl.methods) { if (methodDecl.annotations == null) continue; for (Annotation ann : methodDecl.annotations) { if (!isDelegate(ann, decl)) continue; if (Annotation_applied.getAndSet(ann, true)) continue; if (!(methodDecl instanceof MethodDeclaration)) { EclipseAST eclipseAst = TransformEclipseAST.getAST(cud, true); eclipseAst.get(ann).addError(LEGALITY_OF_DELEGATE); break; } if (methodDecl.arguments != null) { EclipseAST eclipseAst = TransformEclipseAST.getAST(cud, true); eclipseAst.get(ann).addError(LEGALITY_OF_DELEGATE); break; } if ((methodDecl.modifiers & ClassFileConstants.AccStatic) != 0) { EclipseAST eclipseAst = TransformEclipseAST.getAST(cud, true); eclipseAst.get(ann).addError(LEGALITY_OF_DELEGATE); break; } MethodDeclaration method = (MethodDeclaration) methodDecl; List<ClassLiteralAccess> rawTypes = rawTypes(ann, "types"); List<ClassLiteralAccess> excludedRawTypes = rawTypes(ann, "excludes"); List<BindingTuple> methodsToExclude = new ArrayList<BindingTuple>(); List<BindingTuple> methodsToDelegateForThisAnn = new ArrayList<BindingTuple>(); try { for (ClassLiteralAccess cla : excludedRawTypes) { addAllMethodBindings(methodsToExclude, cla.type.resolveType(decl.initializerScope), new HashSet<String>(), method.selector, ann); } Set<String> banList = new HashSet<String>(); for (BindingTuple excluded : methodsToExclude) banList.add(printSig(excluded.parameterized)); if (rawTypes.isEmpty()) { if (method.returnType == null) continue; addAllMethodBindings(methodsToDelegateForThisAnn, method.returnType.resolveType(decl.initializerScope), banList, method.selector, ann); } else { for (ClassLiteralAccess cla : rawTypes) { addAllMethodBindings(methodsToDelegateForThisAnn, cla.type.resolveType(decl.initializerScope), banList, method.selector, ann); } } } catch (DelegateRecursion e) { EclipseAST eclipseAst = TransformEclipseAST.getAST(cud, true); eclipseAst.get(ann).addError( String.format(RECURSION_NOT_ALLOWED, new String(e.member), new String(e.type))); break; } // Not doing this right now because of problems - see commented-out-method for info. // removeExistingMethods(methodsToDelegate, decl, scope); String dupe = containsDuplicates(methodsToDelegateForThisAnn); if (dupe != null) { EclipseAST eclipseAst = TransformEclipseAST.getAST(cud, true); eclipseAst.get(ann).addError( "The method '" + dupe + "' is being delegated by more than one specified type."); } else { methodsToDelegate.addAll(methodsToDelegateForThisAnn); } } } }