List of usage examples for org.eclipse.jdt.internal.compiler.classfmt ClassFileConstants AccInterface
int AccInterface
To view the source code for org.eclipse.jdt.internal.compiler.classfmt ClassFileConstants AccInterface.
Click Source Link
From source file:com.codenvy.ide.ext.java.server.internal.codeassist.SelectionEngine.java
License:Open Source License
public void acceptType(char[] packageName, char[] simpleTypeName, char[][] enclosingTypeNames, int modifiers, AccessRestriction accessRestriction) { char[] typeName = enclosingTypeNames == null ? simpleTypeName : CharOperation.concat(CharOperation.concatWith(enclosingTypeNames, '.'), simpleTypeName, '.'); if (CharOperation.equals(simpleTypeName, this.selectedIdentifier)) { char[] flatEnclosingTypeNames = enclosingTypeNames == null || enclosingTypeNames.length == 0 ? null : CharOperation.concatWith(enclosingTypeNames, '.'); if (mustQualifyType(packageName, simpleTypeName, flatEnclosingTypeNames, modifiers)) { int length = 0; int kind = modifiers & (ClassFileConstants.AccInterface | ClassFileConstants.AccEnum | ClassFileConstants.AccAnnotation); switch (kind) { case ClassFileConstants.AccAnnotation: case ClassFileConstants.AccAnnotation | ClassFileConstants.AccInterface: char[][] acceptedAnnotation = new char[2][]; acceptedAnnotation[0] = packageName; acceptedAnnotation[1] = typeName; if (this.acceptedAnnotations == null) { this.acceptedAnnotations = new char[10][][]; this.acceptedAnnotationsModifiers = new int[10]; this.acceptedAnnotationsCount = 0; }/*from w w w .ja va2 s. c om*/ length = this.acceptedAnnotations.length; if (length == this.acceptedAnnotationsCount) { int newLength = (length + 1) * 2; System.arraycopy(this.acceptedAnnotations, 0, this.acceptedAnnotations = new char[newLength][][], 0, length); System.arraycopy(this.acceptedAnnotationsModifiers, 0, this.acceptedAnnotationsModifiers = new int[newLength], 0, length); } this.acceptedAnnotationsModifiers[this.acceptedAnnotationsCount] = modifiers; this.acceptedAnnotations[this.acceptedAnnotationsCount++] = acceptedAnnotation; break; case ClassFileConstants.AccEnum: char[][] acceptedEnum = new char[2][]; acceptedEnum[0] = packageName; acceptedEnum[1] = typeName; if (this.acceptedEnums == null) { this.acceptedEnums = new char[10][][]; this.acceptedEnumsModifiers = new int[10]; this.acceptedEnumsCount = 0; } length = this.acceptedEnums.length; if (length == this.acceptedEnumsCount) { int newLength = (length + 1) * 2; System.arraycopy(this.acceptedEnums, 0, this.acceptedEnums = new char[newLength][][], 0, length); System.arraycopy(this.acceptedEnumsModifiers, 0, this.acceptedEnumsModifiers = new int[newLength], 0, length); } this.acceptedEnumsModifiers[this.acceptedEnumsCount] = modifiers; this.acceptedEnums[this.acceptedEnumsCount++] = acceptedEnum; break; case ClassFileConstants.AccInterface: char[][] acceptedInterface = new char[2][]; acceptedInterface[0] = packageName; acceptedInterface[1] = typeName; if (this.acceptedInterfaces == null) { this.acceptedInterfaces = new char[10][][]; this.acceptedInterfacesModifiers = new int[10]; this.acceptedInterfacesCount = 0; } length = this.acceptedInterfaces.length; if (length == this.acceptedInterfacesCount) { int newLength = (length + 1) * 2; System.arraycopy(this.acceptedInterfaces, 0, this.acceptedInterfaces = new char[newLength][][], 0, length); System.arraycopy(this.acceptedInterfacesModifiers, 0, this.acceptedInterfacesModifiers = new int[newLength], 0, length); } this.acceptedInterfacesModifiers[this.acceptedInterfacesCount] = modifiers; this.acceptedInterfaces[this.acceptedInterfacesCount++] = acceptedInterface; break; default: char[][] acceptedClass = new char[2][]; acceptedClass[0] = packageName; acceptedClass[1] = typeName; if (this.acceptedClasses == null) { this.acceptedClasses = new char[10][][]; this.acceptedClassesModifiers = new int[10]; this.acceptedClassesCount = 0; } length = this.acceptedClasses.length; if (length == this.acceptedClassesCount) { int newLength = (length + 1) * 2; System.arraycopy(this.acceptedClasses, 0, this.acceptedClasses = new char[newLength][][], 0, length); System.arraycopy(this.acceptedClassesModifiers, 0, this.acceptedClassesModifiers = new int[newLength], 0, length); } this.acceptedClassesModifiers[this.acceptedClassesCount] = modifiers; this.acceptedClasses[this.acceptedClassesCount++] = acceptedClass; break; } } else { this.noProposal = false; this.requestor.acceptType(packageName, typeName, modifiers, false, null, this.actualSelectionStart, this.actualSelectionEnd); this.acceptedAnswer = true; } } }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.TypeDeclarationPattern.java
License:Open Source License
protected void decodeModifiers() { // Extract suffix from modifiers instead of index key switch (this.modifiers & (ClassFileConstants.AccInterface | ClassFileConstants.AccEnum | ClassFileConstants.AccAnnotation)) { case ClassFileConstants.AccAnnotation: case ClassFileConstants.AccAnnotation + ClassFileConstants.AccInterface: this.typeSuffix = ANNOTATION_TYPE_SUFFIX; break;//from w ww. j av a 2s . c o m case ClassFileConstants.AccEnum: this.typeSuffix = ENUM_SUFFIX; break; case ClassFileConstants.AccInterface: this.typeSuffix = INTERFACE_SUFFIX; break; default: this.typeSuffix = CLASS_SUFFIX; break; } }
From source file:lombok.eclipse.handlers.HandleConstructor.java
License:Open Source License
static boolean checkLegality(EclipseNode typeNode, EclipseNode errorNode, String name) { TypeDeclaration typeDecl = null;/*from ww w. ja v a2 s . c om*/ if (typeNode.get() instanceof TypeDeclaration) typeDecl = (TypeDeclaration) typeNode.get(); int modifiers = typeDecl == null ? 0 : typeDecl.modifiers; boolean notAClass = (modifiers & (ClassFileConstants.AccInterface | ClassFileConstants.AccAnnotation)) != 0; if (typeDecl == null || notAClass) { errorNode.addError(name + " is only supported on a class or an enum."); return false; } return true; }
From source file:lombok.eclipse.handlers.HandleData.java
License:Open Source License
@Override public void handle(AnnotationValues<Data> annotation, Annotation ast, EclipseNode annotationNode) { handleFlagUsage(annotationNode, ConfigurationKeys.DATA_FLAG_USAGE, "@Data"); Data ann = annotation.getInstance(); EclipseNode typeNode = annotationNode.up(); TypeDeclaration typeDecl = null;/* w ww .j a v a 2s .c om*/ if (typeNode.get() instanceof TypeDeclaration) typeDecl = (TypeDeclaration) typeNode.get(); int modifiers = typeDecl == null ? 0 : typeDecl.modifiers; boolean notAClass = (modifiers & (ClassFileConstants.AccInterface | ClassFileConstants.AccAnnotation | ClassFileConstants.AccEnum)) != 0; if (typeDecl == null || notAClass) { annotationNode.addError("@Data is only supported on a class."); return; } //Careful: Generate the public static constructor (if there is one) LAST, so that any attempt to //'find callers' on the annotation node will find callers of the constructor, which is by far the //most useful of the many methods built by @Data. This trick won't work for the non-static constructor, //for whatever reason, though you can find callers of that one by focusing on the class name itself //and hitting 'find callers'. new HandleGetter().generateGetterForType(typeNode, annotationNode, AccessLevel.PUBLIC, true); new HandleSetter().generateSetterForType(typeNode, annotationNode, AccessLevel.PUBLIC, true); new HandleEqualsAndHashCode().generateEqualsAndHashCodeForType(typeNode, annotationNode); new HandleToString().generateToStringForType(typeNode, annotationNode); new HandleConstructor().generateRequiredArgsConstructor(typeNode, AccessLevel.PUBLIC, ann.staticConstructor(), SkipIfConstructorExists.YES, Collections.<Annotation>emptyList(), annotationNode); }
From source file:lombok.eclipse.handlers.HandleDataVersionable.java
License:Open Source License
@Override public void handle(AnnotationValues<DataVersionable> annotation, Annotation ast, EclipseNode annotationNode) { handleFlagUsage(annotationNode, ConfigurationKeys.DATA_VERSIONABLE_FLAG_USAGE, "@DataVersionable"); DataVersionable annData = annotation.getInstance(); EclipseNode typeNode = annotationNode.up(); TypeDeclaration typeDecl = null;//from w w w. j a v a 2s .co m if (typeNode.get() instanceof TypeDeclaration) typeDecl = (TypeDeclaration) typeNode.get(); int modifiers = typeDecl == null ? 0 : typeDecl.modifiers; boolean notAClass = (modifiers & (ClassFileConstants.AccInterface | ClassFileConstants.AccAnnotation | ClassFileConstants.AccEnum)) != 0; if (typeDecl == null || notAClass) { annotationNode.addError("@DataVersionable is only supported on a class."); return; } //Careful: Generate the public static constructor (if there is one) LAST, so that any attempt to //'find callers' on the annotation node will find callers of the constructor, which is by far the //most useful of the many methods built by @DataVersionable. This trick won't work for the non-static constructor, //for whatever reason, though you can find callers of that one by focusing on the class name itself //and hitting 'find callers' new HandleGetter().generateGetterForType(typeNode, annotationNode, AccessLevel.PUBLIC, true); new HandleSetterVersionable().generateSetterForType(typeNode, annotationNode, AccessLevel.PUBLIC, true, annData); new HandleEqualsAndHashCode().generateEqualsAndHashCodeForType(typeNode, annotationNode); new HandleToString().generateToStringForType(typeNode, annotationNode); new HandleConstructor().generateRequiredArgsConstructor(typeNode, AccessLevel.PUBLIC, annData.staticConstructor(), SkipIfConstructorExists.YES, Collections.<Annotation>emptyList(), annotationNode); }
From source file:lombok.eclipse.handlers.HandleEqualsAndHashCode.java
License:Open Source License
public void generateMethods(EclipseNode typeNode, EclipseNode errorNode, List<String> excludes, List<String> includes, Boolean callSuper, boolean whineIfExists, FieldAccess fieldAccess, List<Annotation> onParam) { assert excludes == null || includes == null; TypeDeclaration typeDecl = null;/*w w w. java 2 s. c o m*/ if (typeNode.get() instanceof TypeDeclaration) typeDecl = (TypeDeclaration) typeNode.get(); int modifiers = typeDecl == null ? 0 : typeDecl.modifiers; boolean notAClass = (modifiers & (ClassFileConstants.AccInterface | ClassFileConstants.AccAnnotation | ClassFileConstants.AccEnum)) != 0; if (typeDecl == null || notAClass) { errorNode.addError("@EqualsAndHashCode is only supported on a class."); return; } boolean implicitCallSuper = callSuper == null; if (callSuper == null) { try { callSuper = ((Boolean) EqualsAndHashCode.class.getMethod("callSuper").getDefaultValue()) .booleanValue(); } catch (Exception ignore) { throw new InternalError( "Lombok bug - this cannot happen - can't find callSuper field in EqualsAndHashCode annotation."); } } boolean isDirectDescendantOfObject = true; if (typeDecl.superclass != null) { String p = typeDecl.superclass.toString(); isDirectDescendantOfObject = p.equals("Object") || p.equals("java.lang.Object"); } if (isDirectDescendantOfObject && callSuper) { errorNode.addError("Generating equals/hashCode with a supercall to java.lang.Object is pointless."); return; } if (!isDirectDescendantOfObject && !callSuper && implicitCallSuper) { errorNode.addWarning( "Generating equals/hashCode implementation but without a call to superclass, even though this class does not extend java.lang.Object. If this is intentional, add '@EqualsAndHashCode(callSuper=false)' to your type."); } List<EclipseNode> nodesForEquality = new ArrayList<EclipseNode>(); if (includes != null) { for (EclipseNode child : typeNode.down()) { if (child.getKind() != Kind.FIELD) continue; FieldDeclaration fieldDecl = (FieldDeclaration) child.get(); if (includes.contains(new String(fieldDecl.name))) nodesForEquality.add(child); } } else { for (EclipseNode child : typeNode.down()) { if (child.getKind() != Kind.FIELD) continue; FieldDeclaration fieldDecl = (FieldDeclaration) child.get(); if (!filterField(fieldDecl)) continue; //Skip transient fields. if ((fieldDecl.modifiers & ClassFileConstants.AccTransient) != 0) continue; //Skip excluded fields. if (excludes != null && excludes.contains(new String(fieldDecl.name))) continue; nodesForEquality.add(child); } } boolean isFinal = (typeDecl.modifiers & ClassFileConstants.AccFinal) != 0; boolean needsCanEqual = !isFinal || !isDirectDescendantOfObject; MemberExistsResult equalsExists = methodExists("equals", typeNode, 1); MemberExistsResult hashCodeExists = methodExists("hashCode", typeNode, 0); MemberExistsResult canEqualExists = methodExists("canEqual", typeNode, 1); switch (Collections.max(Arrays.asList(equalsExists, hashCodeExists))) { case EXISTS_BY_LOMBOK: return; case EXISTS_BY_USER: if (whineIfExists) { String msg = "Not generating equals and hashCode: A method with one of those names already exists. (Either both or none of these methods will be generated)."; errorNode.addWarning(msg); } else if (equalsExists == MemberExistsResult.NOT_EXISTS || hashCodeExists == MemberExistsResult.NOT_EXISTS) { // This means equals OR hashCode exists and not both. // Even though we should suppress the message about not generating these, this is such a weird and surprising situation we should ALWAYS generate a warning. // The user code couldn't possibly (barring really weird subclassing shenanigans) be in a shippable state anyway; the implementations of these 2 methods are // all inter-related and should be written by the same entity. String msg = String.format("Not generating %s: One of equals or hashCode exists. " + "You should either write both of these or none of these (in the latter case, lombok generates them).", equalsExists == MemberExistsResult.NOT_EXISTS ? "equals" : "hashCode"); errorNode.addWarning(msg); } return; case NOT_EXISTS: default: //fallthrough } MethodDeclaration equalsMethod = createEquals(typeNode, nodesForEquality, callSuper, errorNode.get(), fieldAccess, needsCanEqual, onParam); equalsMethod.traverse(new SetGeneratedByVisitor(errorNode.get()), ((TypeDeclaration) typeNode.get()).scope); injectMethod(typeNode, equalsMethod); if (needsCanEqual && canEqualExists == MemberExistsResult.NOT_EXISTS) { MethodDeclaration canEqualMethod = createCanEqual(typeNode, errorNode.get(), onParam); canEqualMethod.traverse(new SetGeneratedByVisitor(errorNode.get()), ((TypeDeclaration) typeNode.get()).scope); injectMethod(typeNode, canEqualMethod); } MethodDeclaration hashCodeMethod = createHashCode(typeNode, nodesForEquality, callSuper, errorNode.get(), fieldAccess); hashCodeMethod.traverse(new SetGeneratedByVisitor(errorNode.get()), ((TypeDeclaration) typeNode.get()).scope); injectMethod(typeNode, hashCodeMethod); }
From source file:lombok.eclipse.handlers.HandleExtensionMethod.java
License:Open Source License
@Override public void handle(AnnotationValues<ExtensionMethod> annotation, Annotation ast, EclipseNode annotationNode) { handleExperimentalFlagUsage(annotationNode, ConfigurationKeys.EXTENSION_METHOD_FLAG_USAGE, "@ExtensionMethod"); TypeDeclaration typeDecl = null;/*from ww w . j ava2 s . c o m*/ EclipseNode owner = annotationNode.up(); if (owner.get() instanceof TypeDeclaration) typeDecl = (TypeDeclaration) owner.get(); int modifiers = typeDecl == null ? 0 : typeDecl.modifiers; boolean notAClass = (modifiers & (ClassFileConstants.AccInterface | ClassFileConstants.AccAnnotation)) != 0; if (typeDecl == null || notAClass) { annotationNode.addError("@ExtensionMethod is legal only on classes and enums."); return; } List<Object> listenerInterfaces = annotation.getActualExpressions("value"); if (listenerInterfaces.isEmpty()) { annotationNode.addWarning( String.format("@ExtensionMethod has no effect since no extension types were specified.")); return; } }
From source file:lombok.eclipse.handlers.HandleFieldDefaults.java
License:Open Source License
public boolean generateFieldDefaultsForType(EclipseNode typeNode, EclipseNode pos, AccessLevel level, boolean makeFinal, boolean checkForTypeLevelFieldDefaults) { if (checkForTypeLevelFieldDefaults) { if (hasAnnotation(FieldDefaults.class, typeNode)) { //The annotation will make it happen, so we can skip it. return true; }//from www . j a v a2s . c o m } TypeDeclaration typeDecl = null; if (typeNode.get() instanceof TypeDeclaration) typeDecl = (TypeDeclaration) typeNode.get(); int modifiers = typeDecl == null ? 0 : typeDecl.modifiers; boolean notAClass = (modifiers & (ClassFileConstants.AccInterface | ClassFileConstants.AccAnnotation)) != 0; if (typeDecl == null || notAClass) { pos.addError("@FieldDefaults is only supported on a class or an enum."); return false; } for (EclipseNode field : typeNode.down()) { if (field.getKind() != Kind.FIELD) continue; FieldDeclaration fieldDecl = (FieldDeclaration) field.get(); if (!filterField(fieldDecl, false)) continue; Class<?> t = field.get().getClass(); if (t == FieldDeclaration.class) { // There are various other things that extend FieldDeclaration that really // aren't field declarations. Typing 'ma' in an otherwise blank class is a // CompletionOnFieldType object (extends FieldDeclaration). If we mess with the // modifiers of such a thing, you take away template suggestions such as // 'main method'. See issue 411. setFieldDefaultsForField(field, pos.get(), level, makeFinal); } } return true; }
From source file:lombok.eclipse.handlers.HandleFieldNameConstants.java
License:Open Source License
public void generateFieldNameConstantsForType(EclipseNode typeNode, EclipseNode errorNode, AccessLevel level, boolean asEnum, String innerTypeName, boolean onlyExplicit) { TypeDeclaration typeDecl = null;// w w w . j av a2s .c om if (typeNode.get() instanceof TypeDeclaration) typeDecl = (TypeDeclaration) typeNode.get(); int modifiers = typeDecl == null ? 0 : typeDecl.modifiers; boolean notAClass = (modifiers & (ClassFileConstants.AccInterface | ClassFileConstants.AccAnnotation)) != 0; if (typeDecl == null || notAClass) { errorNode.addError("@FieldNameConstants is only supported on a class or an enum."); return; } List<EclipseNode> qualified = new ArrayList<EclipseNode>(); for (EclipseNode field : typeNode.down()) { if (fieldQualifiesForFieldNameConstantsGeneration(field, onlyExplicit)) qualified.add(field); } if (qualified.isEmpty()) { errorNode.addWarning( "No fields qualify for @FieldNameConstants, therefore this annotation does nothing"); } else { createInnerTypeFieldNameConstants(typeNode, errorNode, errorNode.get(), level, qualified, asEnum, innerTypeName); } }
From source file:lombok.eclipse.handlers.HandleGetter.java
License:Open Source License
public boolean generateGetterForType(EclipseNode typeNode, EclipseNode pos, AccessLevel level, boolean checkForTypeLevelGetter) { if (checkForTypeLevelGetter) { if (hasAnnotation(Getter.class, typeNode)) { //The annotation will make it happen, so we can skip it. return true; }//w ww .j av a 2 s. co m } TypeDeclaration typeDecl = null; if (typeNode.get() instanceof TypeDeclaration) typeDecl = (TypeDeclaration) typeNode.get(); int modifiers = typeDecl == null ? 0 : typeDecl.modifiers; boolean notAClass = (modifiers & (ClassFileConstants.AccInterface | ClassFileConstants.AccAnnotation)) != 0; if (typeDecl == null || notAClass) { pos.addError("@Getter is only supported on a class, an enum, or a field."); return false; } for (EclipseNode field : typeNode.down()) { if (fieldQualifiesForGetterGeneration(field)) generateGetterForField(field, pos.get(), level, false); } return true; }