Java Code Examples for com.sun.tools.javac.code.Flags#FINAL

The following examples show how to use com.sun.tools.javac.code.Flags#FINAL . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TreeMaker.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public ModifiersTree addModifiersModifier(ModifiersTree modifiers, Modifier modifier) {
    long c = ((JCModifiers) modifiers).flags & ~Flags.GENERATEDCONSTR;
    switch (modifier) {
        case ABSTRACT: c = c | Flags.ABSTRACT; break;
        case FINAL: c = c | Flags.FINAL; break;
        case NATIVE: c = c | Flags.NATIVE; break;
        case PRIVATE: c = c | Flags.PRIVATE; break;
        case PROTECTED: c = c | Flags.PROTECTED; break;
        case PUBLIC: c = c | Flags.PUBLIC; break;
        case STATIC: c = c | Flags.STATIC; break;
        case STRICTFP: c = c | Flags.STRICTFP; break;
        case SYNCHRONIZED: c = c | Flags.SYNCHRONIZED; break;
        case TRANSIENT: c = c | Flags.TRANSIENT; break;
        case VOLATILE: c = c | Flags.VOLATILE; break;
        case DEFAULT: c = c | Flags.DEFAULT; break;
        default:
            break;
    }
    return Modifiers(c, modifiers.getAnnotations());
}
 
Example 2
Source File: TreeMaker.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public ModifiersTree removeModifiersModifier(ModifiersTree modifiers, Modifier modifier) {
    long c = ((JCModifiers) modifiers).flags & ~Flags.GENERATEDCONSTR;
    switch (modifier) {
        case ABSTRACT: c = c & ~Flags.ABSTRACT; break;
        case FINAL: c = c & ~Flags.FINAL; break;
        case NATIVE: c = c & ~Flags.NATIVE; break;
        case PRIVATE: c = c & ~Flags.PRIVATE; break;
        case PROTECTED: c = c & ~Flags.PROTECTED; break;
        case PUBLIC: c = c & ~Flags.PUBLIC; break;
        case STATIC: c = c & ~Flags.STATIC; break;
        case STRICTFP: c = c & ~Flags.STRICTFP; break;
        case SYNCHRONIZED: c = c & ~Flags.SYNCHRONIZED; break;
        case TRANSIENT: c = c & ~Flags.TRANSIENT; break;
        case VOLATILE: c = c & ~Flags.VOLATILE; break;
        case DEFAULT: c = c & ~Flags.DEFAULT; break;
        default:
            break;
    }
    return Modifiers(c, modifiers.getAnnotations());
}
 
Example 3
Source File: PackageGenerator.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
ListBuffer<JCTree> processConstants(Element constNode, HashMap<String, Integer> scope) {
    String baseName = constNode.getAttribute("basename");
    int count = 1;
    try {
        count = Integer.parseInt(constNode.getAttribute("count"));
    } catch (Exception e) {} // nothing to do, will use count = 1

    long declFlags = Flags.PUBLIC | Flags.STATIC | Flags.FINAL | Flags.ENUM;
    ListBuffer<JCTree> fields = new ListBuffer<>();

    for (int i = 0; i < count; i++) {
        String declName = baseName +
                          ((count == 1) ? "" : getUniqIndex(scope, baseName));

        JCVariableDecl constDecl = make.VarDef(
                                       make.Modifiers(declFlags),
                                       names.fromString(declName),
                                       null,  // no need for type in enum decl
                                       null); // no init

        fields.append(constDecl);
    }
    return fields;
}
 
Example 4
Source File: PackageGenerator.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
long getFlagByName(String modifierName) {
    switch (modifierName) {
        case "public":
            return Flags.PUBLIC;
        case "private":
            return Flags.PRIVATE;
        case "protected":
            return Flags.PROTECTED;
        case "static":
            return Flags.STATIC;
        case "final":
            return Flags.FINAL;
        case "abstract":
            return Flags.ABSTRACT;
        case "strictfp":
            return Flags.STRICTFP;
        default:
            return 0;
    }
}
 
Example 5
Source File: HandleConstructor.java    From EasyMPermission with MIT License 6 votes vote down vote up
public static List<JavacNode> findRequiredFields(JavacNode typeNode) {
	ListBuffer<JavacNode> fields = new ListBuffer<JavacNode>();
	for (JavacNode child : typeNode.down()) {
		if (child.getKind() != Kind.FIELD) continue;
		JCVariableDecl fieldDecl = (JCVariableDecl) child.get();
		//Skip fields that start with $
		if (fieldDecl.name.toString().startsWith("$")) continue;
		long fieldFlags = fieldDecl.mods.flags;
		//Skip static fields.
		if ((fieldFlags & Flags.STATIC) != 0) continue;
		boolean isFinal = (fieldFlags & Flags.FINAL) != 0;
		boolean isNonNull = !findAnnotations(child, NON_NULL_PATTERN).isEmpty();
		if ((isFinal || isNonNull) && fieldDecl.init == null) fields.append(child);
	}
	return fields.toList();
}
 
Example 6
Source File: TreeFactory.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public static long modifiersToFlags(Set<Modifier> flagset) {
    long flags = 0L;
    for (Modifier mod : flagset)
        switch (mod) {
            case PUBLIC: flags |= Flags.PUBLIC; break;
            case PROTECTED: flags |= Flags.PROTECTED; break;
            case PRIVATE: flags |= Flags.PRIVATE; break;
            case ABSTRACT: flags |= Flags.ABSTRACT; break;
            case STATIC: flags |= Flags.STATIC; break;
            case FINAL: flags |= Flags.FINAL; break;
            case TRANSIENT: flags |= Flags.TRANSIENT; break;
            case VOLATILE: flags |= Flags.VOLATILE; break;
            case SYNCHRONIZED: flags |= Flags.SYNCHRONIZED; break;
            case NATIVE: flags |= Flags.NATIVE; break;
            case STRICTFP: flags |= Flags.STRICTFP; break;
            case DEFAULT: flags |= Flags.DEFAULT; break;
            default:
                throw new AssertionError("Unknown Modifier: " + mod); //NOI18N
        }
    return flags;
}
 
Example 7
Source File: HandleFieldDefaults.java    From EasyMPermission with MIT License 6 votes vote down vote up
public void setFieldDefaultsForField(JavacNode fieldNode, DiagnosticPosition pos, AccessLevel level, boolean makeFinal) {
	JCVariableDecl field = (JCVariableDecl) fieldNode.get();
	if (level != null && level != AccessLevel.NONE) {
		if ((field.mods.flags & (Flags.PUBLIC | Flags.PRIVATE | Flags.PROTECTED)) == 0) {
			if (!hasAnnotationAndDeleteIfNeccessary(PackagePrivate.class, fieldNode)) {
				field.mods.flags |= toJavacModifier(level);
			}
		}
	}
	
	if (makeFinal && (field.mods.flags & Flags.FINAL) == 0) {
		if (!hasAnnotationAndDeleteIfNeccessary(NonFinal.class, fieldNode)) {
			field.mods.flags |= Flags.FINAL;
		}
	}
	
	fieldNode.rebuild();
}
 
Example 8
Source File: HandleWither.java    From EasyMPermission with MIT License 5 votes vote down vote up
public void generateWitherForType(JavacNode typeNode, JavacNode errorNode, AccessLevel level, boolean checkForTypeLevelWither) {
	if (checkForTypeLevelWither) {
		if (hasAnnotation(Wither.class, typeNode)) {
			//The annotation will make it happen, so we can skip it.
			return;
		}
	}
	
	JCClassDecl typeDecl = null;
	if (typeNode.get() instanceof JCClassDecl) typeDecl = (JCClassDecl) typeNode.get();
	long modifiers = typeDecl == null ? 0 : typeDecl.mods.flags;
	boolean notAClass = (modifiers & (Flags.INTERFACE | Flags.ANNOTATION | Flags.ENUM)) != 0;
	
	if (typeDecl == null || notAClass) {
		errorNode.addError("@Wither is only supported on a class or a field.");
		return;
	}
	
	for (JavacNode field : typeNode.down()) {
		if (field.getKind() != Kind.FIELD) continue;
		JCVariableDecl fieldDecl = (JCVariableDecl) field.get();
		//Skip fields that start with $
		if (fieldDecl.name.toString().startsWith("$")) continue;
		//Skip static fields.
		if ((fieldDecl.mods.flags & Flags.STATIC) != 0) continue;
		//Skip final initialized fields.
		if ((fieldDecl.mods.flags & Flags.FINAL) != 0 && fieldDecl.init != null) continue;
		
		generateWitherForField(field, errorNode.get(), level);
	}
}
 
Example 9
Source File: HandleColumn.java    From sqlitemagic with Apache License 2.0 5 votes vote down vote up
@Override
public void handle(AnnotationValues<Column> annotation, JCTree.JCAnnotation ast, JavacNode annotationNode) {
  // FIXME: 9.04.16 remove
  JavacNode node = annotationNode.up();
  if (node.getKind() == AST.Kind.FIELD) {
    JCTree.JCVariableDecl fieldDec = (JCTree.JCVariableDecl) node.get();
    if ((fieldDec.mods.flags & Flags.PRIVATE) != 0 && (fieldDec.mods.flags & (Flags.STATIC | Flags.FINAL)) == 0) {
      fieldDec.mods.flags &= ~Flags.PRIVATE;
    }
    node.rebuild();
  }
}
 
Example 10
Source File: PrettyCommentsPrinter.java    From EasyMPermission with MIT License 5 votes vote down vote up
private void removeImplicitModifiersForInterfaceMembers(List<JCTree> defs) {
	for (JCTree def :defs) {
		if (def instanceof JCVariableDecl) {
			((JCVariableDecl) def).mods.flags &= ~(Flags.PUBLIC | Flags.STATIC | Flags.FINAL);
		}
		if (def instanceof JCMethodDecl) {
			((JCMethodDecl) def).mods.flags &= ~(Flags.PUBLIC | Flags.ABSTRACT);
		}
		if (def instanceof JCClassDecl) {
			((JCClassDecl) def).mods.flags &= ~(Flags.PUBLIC | Flags.STATIC);
		}
	}
}
 
Example 11
Source File: HandleValue.java    From EasyMPermission with MIT License 5 votes vote down vote up
@Override public void handle(AnnotationValues<Value> annotation, JCAnnotation ast, JavacNode annotationNode) {
	@SuppressWarnings("deprecation")
	Class<? extends Annotation> oldExperimentalValue = lombok.experimental.Value.class;
	
	handleFlagUsage(annotationNode, ConfigurationKeys.VALUE_FLAG_USAGE, "@Value");
	
	deleteAnnotationIfNeccessary(annotationNode, Value.class, oldExperimentalValue);
	JavacNode typeNode = annotationNode.up();
	boolean notAClass = !isClass(typeNode);
	
	if (notAClass) {
		annotationNode.addError("@Value is only supported on a class.");
		return;
	}
	
	String staticConstructorName = annotation.getInstance().staticConstructor();
	
	if (!hasAnnotationAndDeleteIfNeccessary(NonFinal.class, typeNode)) {
		JCModifiers jcm = ((JCClassDecl) typeNode.get()).mods;
		if ((jcm.flags & Flags.FINAL) == 0) {
			jcm.flags |= Flags.FINAL;
			typeNode.rebuild();
		}
	}
	new HandleFieldDefaults().generateFieldDefaultsForType(typeNode, annotationNode, AccessLevel.PRIVATE, true, true);
	
	// TODO move this to the end OR move it to the top in eclipse.
	new HandleConstructor().generateAllArgsConstructor(typeNode, AccessLevel.PUBLIC, staticConstructorName, SkipIfConstructorExists.YES, annotationNode);
	new HandleGetter().generateGetterForType(typeNode, annotationNode, AccessLevel.PUBLIC, true);
	new HandleEqualsAndHashCode().generateEqualsAndHashCodeForType(typeNode, annotationNode);
	new HandleToString().generateToStringForType(typeNode, annotationNode);
}
 
Example 12
Source File: HandleUtilityClass.java    From EasyMPermission with MIT License 5 votes vote down vote up
private void changeModifiersAndGenerateConstructor(JavacNode typeNode, JavacNode errorNode) {
	JCClassDecl classDecl = (JCClassDecl) typeNode.get();
	
	boolean makeConstructor = true;
	
	classDecl.mods.flags |= Flags.FINAL;
	
	boolean markStatic = true;
	
	if (typeNode.up().getKind() == Kind.COMPILATION_UNIT) markStatic = false;
	if (markStatic && typeNode.up().getKind() == Kind.TYPE) {
		JCClassDecl typeDecl = (JCClassDecl) typeNode.up().get();
		if ((typeDecl.mods.flags & Flags.INTERFACE) != 0) markStatic = false;
	}
	
	if (markStatic) classDecl.mods.flags |= Flags.STATIC;
	
	for (JavacNode element : typeNode.down()) {
		if (element.getKind() == Kind.FIELD) {
			JCVariableDecl fieldDecl = (JCVariableDecl) element.get();
			fieldDecl.mods.flags |= Flags.STATIC;
		} else if (element.getKind() == Kind.METHOD) {
			JCMethodDecl methodDecl = (JCMethodDecl) element.get();
			if (methodDecl.name.contentEquals("<init>")) {
				if (getGeneratedBy(methodDecl) == null && (methodDecl.mods.flags & Flags.GENERATEDCONSTR) == 0) {
					element.addError("@UtilityClasses cannot have declared constructors.");
					makeConstructor = false;
					continue;
				}
			}
			
			methodDecl.mods.flags |= Flags.STATIC;
		} else if (element.getKind() == Kind.TYPE) {
			JCClassDecl innerClassDecl = (JCClassDecl) element.get();
			innerClassDecl.mods.flags |= Flags.STATIC;
		}
	}
	
	if (makeConstructor) createPrivateDefaultConstructor(typeNode);
}
 
Example 13
Source File: HandleSetter.java    From EasyMPermission with MIT License 5 votes vote down vote up
public void generateSetterForType(JavacNode typeNode, JavacNode errorNode, AccessLevel level, boolean checkForTypeLevelSetter) {
	if (checkForTypeLevelSetter) {
		if (hasAnnotation(Setter.class, typeNode)) {
			//The annotation will make it happen, so we can skip it.
			return;
		}
	}
	
	JCClassDecl typeDecl = null;
	if (typeNode.get() instanceof JCClassDecl) typeDecl = (JCClassDecl) typeNode.get();
	long modifiers = typeDecl == null ? 0 : typeDecl.mods.flags;
	boolean notAClass = (modifiers & (Flags.INTERFACE | Flags.ANNOTATION | Flags.ENUM)) != 0;
	
	if (typeDecl == null || notAClass) {
		errorNode.addError("@Setter is only supported on a class or a field.");
		return;
	}
	
	for (JavacNode field : typeNode.down()) {
		if (field.getKind() != Kind.FIELD) continue;
		JCVariableDecl fieldDecl = (JCVariableDecl) field.get();
		//Skip fields that start with $
		if (fieldDecl.name.toString().startsWith("$")) continue;
		//Skip static fields.
		if ((fieldDecl.mods.flags & Flags.STATIC) != 0) continue;
		//Skip final fields.
		if ((fieldDecl.mods.flags & Flags.FINAL) != 0) continue;
		
		generateSetterForField(field, errorNode, level);
	}
}
 
Example 14
Source File: HandleWither.java    From EasyMPermission with MIT License 4 votes vote down vote up
public JCMethodDecl createWither(long access, JavacNode field, JavacTreeMaker maker, JavacNode source, List<JCAnnotation> onMethod, List<JCAnnotation> onParam) {
	String witherName = toWitherName(field);
	if (witherName == null) return null;
	
	JCVariableDecl fieldDecl = (JCVariableDecl) field.get();
	
	ListBuffer<JCStatement> statements = new ListBuffer<JCStatement>();
	List<JCAnnotation> nonNulls = findAnnotations(field, NON_NULL_PATTERN);
	List<JCAnnotation> nullables = findAnnotations(field, NULLABLE_PATTERN);
	
	Name methodName = field.toName(witherName);
	List<JCAnnotation> annsOnParam = copyAnnotations(onParam).appendList(nonNulls).appendList(nullables);
	
	long flags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, field.getContext());
	JCVariableDecl param = maker.VarDef(maker.Modifiers(flags, annsOnParam), fieldDecl.name, fieldDecl.vartype, null);
	
	JCExpression selfType = cloneSelfType(field);
	if (selfType == null) return null;
	
	ListBuffer<JCExpression> args = new ListBuffer<JCExpression>();
	for (JavacNode child : field.up().down()) {
		if (child.getKind() != Kind.FIELD) continue;
		JCVariableDecl childDecl = (JCVariableDecl) child.get();
		// Skip fields that start with $
		if (childDecl.name.toString().startsWith("$")) continue;
		long fieldFlags = childDecl.mods.flags;
		// Skip static fields.
		if ((fieldFlags & Flags.STATIC) != 0) continue;
		// Skip initialized final fields.
		if (((fieldFlags & Flags.FINAL) != 0) && childDecl.init != null) continue;
		if (child.get() == field.get()) {
			args.append(maker.Ident(fieldDecl.name));
		} else {
			args.append(createFieldAccessor(maker, child, FieldAccess.ALWAYS_FIELD));
		}
	}
	
	JCNewClass newClass = maker.NewClass(null, List.<JCExpression>nil(), selfType, args.toList(), null);
	JCExpression identityCheck = maker.Binary(CTC_EQUAL, createFieldAccessor(maker, field, FieldAccess.ALWAYS_FIELD), maker.Ident(fieldDecl.name));
	JCConditional conditional = maker.Conditional(identityCheck, maker.Ident(field.toName("this")), newClass);
	JCReturn returnStatement = maker.Return(conditional);
	
	if (nonNulls.isEmpty()) {
		statements.append(returnStatement);
	} else {
		JCStatement nullCheck = generateNullCheck(maker, field, source);
		if (nullCheck != null) statements.append(nullCheck);
		statements.append(returnStatement);
	}
	
	JCExpression returnType = cloneSelfType(field);
	
	JCBlock methodBody = maker.Block(0, statements.toList());
	List<JCTypeParameter> methodGenericParams = List.nil();
	List<JCVariableDecl> parameters = List.of(param);
	List<JCExpression> throwsClauses = List.nil();
	JCExpression annotationMethodDefaultValue = null;
	
	List<JCAnnotation> annsOnMethod = copyAnnotations(onMethod);
	
	if (isFieldDeprecated(field)) {
		annsOnMethod = annsOnMethod.prepend(maker.Annotation(genJavaLangTypeRef(field, "Deprecated"), List.<JCExpression>nil()));
	}
	JCMethodDecl decl = recursiveSetGeneratedBy(maker.MethodDef(maker.Modifiers(access, annsOnMethod), methodName, returnType,
			methodGenericParams, parameters, throwsClauses, methodBody, annotationMethodDefaultValue), source.get(), field.getContext());
	copyJavadoc(field, decl, CopyJavadoc.WITHER);
	return decl;
}
 
Example 15
Source File: HandleWither.java    From EasyMPermission with MIT License 4 votes vote down vote up
public void createWitherForField(AccessLevel level, JavacNode fieldNode, JavacNode source, boolean whineIfExists, List<JCAnnotation> onMethod, List<JCAnnotation> onParam) {
	if (fieldNode.getKind() != Kind.FIELD) {
		fieldNode.addError("@Wither is only supported on a class or a field.");
		return;
	}
	
	JCVariableDecl fieldDecl = (JCVariableDecl)fieldNode.get();
	String methodName = toWitherName(fieldNode);
	
	if (methodName == null) {
		fieldNode.addWarning("Not generating wither for this field: It does not fit your @Accessors prefix list.");
		return;
	}
	
	if ((fieldDecl.mods.flags & Flags.STATIC) != 0) {
		fieldNode.addWarning("Not generating wither for this field: Withers cannot be generated for static fields.");
		return;
	}
	
	if ((fieldDecl.mods.flags & Flags.FINAL) != 0 && fieldDecl.init != null) {
		fieldNode.addWarning("Not generating wither for this field: Withers cannot be generated for final, initialized fields.");
		return;
	}
	
	if (fieldDecl.name.toString().startsWith("$")) {
		fieldNode.addWarning("Not generating wither for this field: Withers cannot be generated for fields starting with $.");
		return;
	}
	
	for (String altName : toAllWitherNames(fieldNode)) {
		switch (methodExists(altName, fieldNode, false, 1)) {
		case EXISTS_BY_LOMBOK:
			return;
		case EXISTS_BY_USER:
			if (whineIfExists) {
				String altNameExpl = "";
				if (!altName.equals(methodName)) altNameExpl = String.format(" (%s)", altName);
				fieldNode.addWarning(
					String.format("Not generating %s(): A method with that name already exists%s", methodName, altNameExpl));
			}
			return;
		default:
		case NOT_EXISTS:
			//continue scanning the other alt names.
		}
	}
	
	long access = toJavacModifier(level);
	
	JCMethodDecl createdWither = createWither(access, fieldNode, fieldNode.getTreeMaker(), source, onMethod, onParam);
	injectMethod(fieldNode.up(), createdWither);
}
 
Example 16
Source File: JavacHandlerUtil.java    From EasyMPermission with MIT License 4 votes vote down vote up
public static long addFinalIfNeeded(long flags, Context context) {
	boolean addFinal = LombokOptionsFactory.getDelombokOptions(context).getFormatPreferences().generateFinalParams();
	
	if (addFinal) flags |= Flags.FINAL;
	return flags;
}
 
Example 17
Source File: HandleSetter.java    From EasyMPermission with MIT License 4 votes vote down vote up
public void createSetterForField(AccessLevel level, JavacNode fieldNode, JavacNode sourceNode, boolean whineIfExists, List<JCAnnotation> onMethod, List<JCAnnotation> onParam) {
	if (fieldNode.getKind() != Kind.FIELD) {
		fieldNode.addError("@Setter is only supported on a class or a field.");
		return;
	}
	
	JCVariableDecl fieldDecl = (JCVariableDecl)fieldNode.get();
	String methodName = toSetterName(fieldNode);
	
	if (methodName == null) {
		fieldNode.addWarning("Not generating setter for this field: It does not fit your @Accessors prefix list.");
		return;
	}
	
	if ((fieldDecl.mods.flags & Flags.FINAL) != 0) {
		fieldNode.addWarning("Not generating setter for this field: Setters cannot be generated for final fields.");
		return;
	}
	
	for (String altName : toAllSetterNames(fieldNode)) {
		switch (methodExists(altName, fieldNode, false, 1)) {
		case EXISTS_BY_LOMBOK:
			return;
		case EXISTS_BY_USER:
			if (whineIfExists) {
				String altNameExpl = "";
				if (!altName.equals(methodName)) altNameExpl = String.format(" (%s)", altName);
				fieldNode.addWarning(
					String.format("Not generating %s(): A method with that name already exists%s", methodName, altNameExpl));
			}
			return;
		default:
		case NOT_EXISTS:
			//continue scanning the other alt names.
		}
	}
	
	long access = toJavacModifier(level) | (fieldDecl.mods.flags & Flags.STATIC);
	
	JCMethodDecl createdSetter = createSetter(access, fieldNode, fieldNode.getTreeMaker(), sourceNode, onMethod, onParam);
	injectMethod(fieldNode.up(), createdSetter);
}
 
Example 18
Source File: HandleGetter.java    From EasyMPermission with MIT License 4 votes vote down vote up
public void createGetterForField(AccessLevel level,
		JavacNode fieldNode, JavacNode source, boolean whineIfExists, boolean lazy, List<JCAnnotation> onMethod) {
	if (fieldNode.getKind() != Kind.FIELD) {
		source.addError("@Getter is only supported on a class or a field.");
		return;
	}
	
	JCVariableDecl fieldDecl = (JCVariableDecl)fieldNode.get();
	
	if (lazy) {
		if ((fieldDecl.mods.flags & Flags.PRIVATE) == 0 || (fieldDecl.mods.flags & Flags.FINAL) == 0) {
			source.addError("'lazy' requires the field to be private and final.");
			return;
		}
		if (fieldDecl.init == null) {
			source.addError("'lazy' requires field initialization.");
			return;
		}
	}
	
	String methodName = toGetterName(fieldNode);
	
	if (methodName == null) {
		source.addWarning("Not generating getter for this field: It does not fit your @Accessors prefix list.");
		return;
	}
	
	for (String altName : toAllGetterNames(fieldNode)) {
		switch (methodExists(altName, fieldNode, false, 0)) {
		case EXISTS_BY_LOMBOK:
			return;
		case EXISTS_BY_USER:
			if (whineIfExists) {
				String altNameExpl = "";
				if (!altName.equals(methodName)) altNameExpl = String.format(" (%s)", altName);
				source.addWarning(
					String.format("Not generating %s(): A method with that name already exists%s", methodName, altNameExpl));
			}
			return;
		default:
		case NOT_EXISTS:
			//continue scanning the other alt names.
		}
	}
	
	long access = toJavacModifier(level) | (fieldDecl.mods.flags & Flags.STATIC);
	
	injectMethod(fieldNode.up(), createGetter(access, fieldNode, fieldNode.getTreeMaker(), source.get(), lazy, onMethod));
}
 
Example 19
Source File: SourceCodeAnalysisImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
private Element createArrayLengthSymbol(AnalyzeTask at, TypeMirror site) {
    Name length = Names.instance(at.getContext()).length;
    Type intType = Symtab.instance(at.getContext()).intType;

    return new VarSymbol(Flags.PUBLIC | Flags.FINAL, length, intType, ((Type) site).tsym);
}
 
Example 20
Source File: ElementUtilities.java    From netbeans with Apache License 2.0 2 votes vote down vote up
/** Check whether the given variable is effectively final or final.
 * 
 * @param e variable to check for effectively final status
 * @return true if the given variable is effectively final or final
 * @since 0.112
 */
public boolean isEffectivelyFinal(VariableElement e) {
    return (((Symbol) e).flags() & (Flags.EFFECTIVELY_FINAL | Flags.FINAL)) != 0;
}