List of usage examples for org.eclipse.jdt.internal.compiler.classfmt ClassFileConstants AccEnum
int AccEnum
To view the source code for org.eclipse.jdt.internal.compiler.classfmt ClassFileConstants AccEnum.
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; }//w w w . java 2s . 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.compiler.parser.SourceTypeConverter.java
License:Open Source License
private FieldDeclaration convert(SourceField fieldHandle, TypeDeclaration type, CompilationResult compilationResult) throws JavaModelException { SourceFieldElementInfo fieldInfo = (SourceFieldElementInfo) fieldHandle.getElementInfo(); FieldDeclaration field = new FieldDeclaration(); int start = fieldInfo.getNameSourceStart(); int end = fieldInfo.getNameSourceEnd(); field.name = fieldHandle.getElementName().toCharArray(); field.sourceStart = start;//from w w w . j av a 2s .co m field.sourceEnd = end; field.declarationSourceStart = fieldInfo.getDeclarationSourceStart(); field.declarationSourceEnd = fieldInfo.getDeclarationSourceEnd(); int modifiers = fieldInfo.getModifiers(); boolean isEnumConstant = (modifiers & ClassFileConstants.AccEnum) != 0; if (isEnumConstant) { field.modifiers = modifiers & ~ClassFileConstants.AccEnum; // clear AccEnum bit onto AST (binding will add it) } else { field.modifiers = modifiers; field.type = createTypeReference(fieldInfo.getTypeName(), start, end); } // convert 1.5 specific constructs only if compliance is 1.5 or above if (this.has1_5Compliance) { /* convert annotations */ field.annotations = convertAnnotations(fieldHandle); } /* conversion of field constant */ if ((this.flags & FIELD_INITIALIZATION) != 0) { char[] initializationSource = fieldInfo.getInitializationSource(); if (initializationSource != null) { if (this.parser == null) { this.parser = new Parser(this.problemReporter, true); } this.parser.parse(field, type, this.unit, initializationSource); } } /* conversion of local and anonymous types */ if ((this.flags & LOCAL_TYPE) != 0) { IJavaElement[] children = fieldInfo.getChildren(); int childrenLength = children.length; if (childrenLength == 1) { field.initialization = convert(children[0], isEnumConstant ? field : null, compilationResult); } else if (childrenLength > 1) { ArrayInitializer initializer = new ArrayInitializer(); field.initialization = initializer; Expression[] expressions = new Expression[childrenLength]; initializer.expressions = expressions; for (int i = 0; i < childrenLength; i++) { expressions[i] = convert(children[i], isEnumConstant ? field : null, compilationResult); } } } return field; }
From source file:com.codenvy.ide.ext.java.server.internal.compiler.parser.SourceTypeConverter.java
License:Open Source License
private QualifiedAllocationExpression convert(IJavaElement localType, FieldDeclaration enumConstant, CompilationResult compilationResult) throws JavaModelException { TypeDeclaration anonymousLocalTypeDeclaration = convert((SourceType) localType, compilationResult); QualifiedAllocationExpression expression = new QualifiedAllocationExpression(anonymousLocalTypeDeclaration); expression.type = anonymousLocalTypeDeclaration.superclass; anonymousLocalTypeDeclaration.superclass = null; anonymousLocalTypeDeclaration.superInterfaces = null; anonymousLocalTypeDeclaration.allocation = expression; if (enumConstant != null) { anonymousLocalTypeDeclaration.modifiers &= ~ClassFileConstants.AccEnum; expression.enumConstant = enumConstant; expression.type = null;//from w w w .j ava 2 s . c o m } return expression; }
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;//www. j av a 2 s . c om 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
public static ConstructorDeclaration createConstructor(AccessLevel level, EclipseNode type, Collection<EclipseNode> fields, boolean allToDefault, Boolean suppressConstructorProperties, EclipseNode sourceNode, List<Annotation> onConstructor) { ASTNode source = sourceNode.get();/* ww w. j ava 2 s . com*/ TypeDeclaration typeDeclaration = ((TypeDeclaration) type.get()); long p = (long) source.sourceStart << 32 | source.sourceEnd; boolean isEnum = (((TypeDeclaration) type.get()).modifiers & ClassFileConstants.AccEnum) != 0; if (isEnum) level = AccessLevel.PRIVATE; if (suppressConstructorProperties == null) { if (fields.isEmpty()) { suppressConstructorProperties = false; } else { suppressConstructorProperties = Boolean.TRUE.equals(type.getAst() .readConfiguration(ConfigurationKeys.ANY_CONSTRUCTOR_SUPPRESS_CONSTRUCTOR_PROPERTIES)); } } ConstructorDeclaration constructor = new ConstructorDeclaration( ((CompilationUnitDeclaration) type.top().get()).compilationResult); constructor.modifiers = toEclipseModifier(level); constructor.selector = typeDeclaration.name; constructor.constructorCall = new ExplicitConstructorCall(ExplicitConstructorCall.ImplicitSuper); constructor.constructorCall.sourceStart = source.sourceStart; constructor.constructorCall.sourceEnd = source.sourceEnd; constructor.thrownExceptions = null; constructor.typeParameters = null; constructor.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG; constructor.bodyStart = constructor.declarationSourceStart = constructor.sourceStart = source.sourceStart; constructor.bodyEnd = constructor.declarationSourceEnd = constructor.sourceEnd = source.sourceEnd; constructor.arguments = null; List<Argument> params = new ArrayList<Argument>(); List<Statement> assigns = new ArrayList<Statement>(); List<Statement> nullChecks = new ArrayList<Statement>(); for (EclipseNode fieldNode : fields) { FieldDeclaration field = (FieldDeclaration) fieldNode.get(); char[] rawName = field.name; char[] fieldName = removePrefixFromField(fieldNode); FieldReference thisX = new FieldReference(rawName, p); int s = (int) (p >> 32); int e = (int) p; thisX.receiver = new ThisReference(s, e); Expression assignmentExpr = allToDefault ? getDefaultExpr(field.type, s, e) : new SingleNameReference(fieldName, p); Assignment assignment = new Assignment(thisX, assignmentExpr, (int) p); assignment.sourceStart = (int) (p >> 32); assignment.sourceEnd = assignment.statementEnd = (int) (p >> 32); assigns.add(assignment); if (!allToDefault) { long fieldPos = (((long) field.sourceStart) << 32) | field.sourceEnd; Argument parameter = new Argument(fieldName, fieldPos, copyType(field.type, source), Modifier.FINAL); Annotation[] nonNulls = findAnnotations(field, NON_NULL_PATTERN); Annotation[] nullables = findAnnotations(field, NULLABLE_PATTERN); if (nonNulls.length != 0) { Statement nullCheck = generateNullCheck(field, sourceNode); if (nullCheck != null) nullChecks.add(nullCheck); } parameter.annotations = copyAnnotations(source, nonNulls, nullables); params.add(parameter); } } nullChecks.addAll(assigns); constructor.statements = nullChecks.isEmpty() ? null : nullChecks.toArray(new Statement[nullChecks.size()]); constructor.arguments = params.isEmpty() ? null : params.toArray(new Argument[params.size()]); /* Generate annotations that must be put on the generated method, and attach them. */ { Annotation[] constructorProperties = null; if (!allToDefault && !suppressConstructorProperties && level != AccessLevel.PRIVATE && level != AccessLevel.PACKAGE && !isLocalType(type)) { constructorProperties = createConstructorProperties(source, fields); } constructor.annotations = copyAnnotations(source, onConstructor.toArray(new Annotation[0]), constructorProperties); } constructor.traverse(new SetGeneratedByVisitor(source), typeDeclaration.scope); return constructor; }
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;/*from w w w .j av a 2 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 | 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;//ww w .j a v a 2 s. com 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;/*from ww w. j a 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 | 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.HandleFieldNameConstants.java
License:Open Source License
private void createInnerTypeFieldNameConstants(EclipseNode typeNode, EclipseNode errorNode, ASTNode source, AccessLevel level, List<EclipseNode> fields, boolean asEnum, String innerTypeName) { if (fields.isEmpty()) return;/*from w w w. jav a 2 s .c o m*/ ASTVisitor generatedByVisitor = new SetGeneratedByVisitor(source); TypeDeclaration parent = (TypeDeclaration) typeNode.get(); EclipseNode fieldsType = findInnerClass(typeNode, innerTypeName); boolean genConstr = false, genClinit = false; char[] name = innerTypeName.toCharArray(); TypeDeclaration generatedInnerType = null; if (fieldsType == null) { generatedInnerType = new TypeDeclaration(parent.compilationResult); generatedInnerType.bits |= Eclipse.ECLIPSE_DO_NOT_TOUCH_FLAG; generatedInnerType.modifiers = toEclipseModifier(level) | (asEnum ? ClassFileConstants.AccEnum : (ClassFileConstants.AccStatic | ClassFileConstants.AccFinal)); generatedInnerType.name = name; fieldsType = injectType(typeNode, generatedInnerType); genConstr = true; genClinit = asEnum; generatedInnerType.traverse(generatedByVisitor, ((TypeDeclaration) typeNode.get()).scope); } else { TypeDeclaration builderTypeDeclaration = (TypeDeclaration) fieldsType.get(); if (asEnum && (builderTypeDeclaration.modifiers & ClassFileConstants.AccEnum) == 0) { errorNode.addError("Existing " + innerTypeName + " must be declared as an 'enum'."); return; } if (!asEnum && (builderTypeDeclaration.modifiers & ClassFileConstants.AccStatic) == 0) { errorNode.addError("Existing " + innerTypeName + " must be declared as a 'static class'."); return; } genConstr = constructorExists(fieldsType) == MemberExistsResult.NOT_EXISTS; } if (genConstr) { ConstructorDeclaration constructor = new ConstructorDeclaration(parent.compilationResult); constructor.selector = name; constructor.modifiers = ClassFileConstants.AccPrivate; ExplicitConstructorCall superCall = new ExplicitConstructorCall(0); superCall.sourceStart = source.sourceStart; superCall.sourceEnd = source.sourceEnd; superCall.bits |= Eclipse.ECLIPSE_DO_NOT_TOUCH_FLAG; constructor.constructorCall = superCall; if (!asEnum) constructor.statements = new Statement[0]; injectMethod(fieldsType, constructor); } if (genClinit) { Clinit cli = new Clinit(parent.compilationResult); injectMethod(fieldsType, cli); cli.traverse(generatedByVisitor, ((TypeDeclaration) fieldsType.get()).scope); } for (EclipseNode fieldNode : fields) { FieldDeclaration field = (FieldDeclaration) fieldNode.get(); char[] fName = field.name; if (fieldExists(new String(fName), fieldsType) != MemberExistsResult.NOT_EXISTS) continue; int pS = source.sourceStart, pE = source.sourceEnd; long p = (long) pS << 32 | pE; FieldDeclaration constantField = new FieldDeclaration(fName, pS, pE); constantField.bits |= Eclipse.ECLIPSE_DO_NOT_TOUCH_FLAG; if (asEnum) { AllocationExpression ac = new AllocationExpression(); ac.enumConstant = constantField; ac.sourceStart = source.sourceStart; ac.sourceEnd = source.sourceEnd; constantField.initialization = ac; constantField.modifiers = 0; } else { constantField.type = new QualifiedTypeReference(TypeConstants.JAVA_LANG_STRING, new long[] { p, p, p }); constantField.initialization = new StringLiteral(field.name, pS, pE, 0); constantField.modifiers = ClassFileConstants.AccPublic | ClassFileConstants.AccStatic | ClassFileConstants.AccFinal; } injectField(fieldsType, constantField); constantField.traverse(generatedByVisitor, ((TypeDeclaration) fieldsType.get()).initializerScope); } }
From source file:lombok.eclipse.handlers.HandleSetter.java
License:Open Source License
public boolean generateSetterForType(EclipseNode typeNode, EclipseNode pos, AccessLevel level, boolean checkForTypeLevelSetter) { if (checkForTypeLevelSetter) { if (hasAnnotation(Setter.class, typeNode)) { //The annotation will make it happen, so we can skip it. return true; }// w ww .ja v a 2s . 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 | ClassFileConstants.AccEnum)) != 0; if (typeDecl == null || notAClass) { pos.addError("@Setter is only supported on a class or a field."); return false; } for (EclipseNode field : typeNode.down()) { if (field.getKind() != Kind.FIELD) continue; FieldDeclaration fieldDecl = (FieldDeclaration) field.get(); if (!filterField(fieldDecl)) continue; //Skip final fields. if ((fieldDecl.modifiers & ClassFileConstants.AccFinal) != 0) continue; generateSetterForField(field, pos, level); } return true; }