Example usage for org.eclipse.jdt.internal.compiler.ast FieldDeclaration isStatic

List of usage examples for org.eclipse.jdt.internal.compiler.ast FieldDeclaration isStatic

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.compiler.ast FieldDeclaration isStatic.

Prototype

public boolean isStatic() 

Source Link

Usage

From source file:lombok.eclipse.handlers.HandleRelations.java

License:Open Source License

private static void handle(AnnotationValues<?> annotation, Annotation ast, EclipseNode annotationNode) {
    Object anno = annotation.getInstance();

    EclipseNode fieldNode = annotationNode.up();
    EclipseNode typeNode = fieldNode.up();

    if (fieldNode.getKind() != Kind.FIELD) {
        annotationNode.addError("@" + anno.getClass().getSimpleName() + " is only supported on a field.");
        return;/*ww  w .j a  va2s .c  om*/
    }

    FieldDeclaration field = (FieldDeclaration) fieldNode.get();

    if (field.isStatic()) {
        annotationNode.addError("@" + anno.getClass().getSimpleName() + " is not legal on static fields.");
        return;
    }

    if (fieldExists(toProperCase(new String(field.name)), fieldNode) == MemberExistsResult.NOT_EXISTS) {
        FieldDeclaration fieldDecl = createField(anno, fieldNode, ast);
        injectFieldSuppressWarnings(typeNode, fieldDecl);

        typeNode.rebuild();
    }
}

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.statemachine.copyinheritance.CopyInheritance.java

License:Open Source License

/**
 * Nothing exciting here, just create a new field declaration.
 * @param field/*w w  w.j  av a  2 s.co  m*/
 * @param roleDeclaration
 */
private static void copyField(FieldBinding field, TypeDeclaration roleDeclaration) {
    // avoid copying twice (see copyGeneratedFeatures()):
    roleDeclaration.getRoleModel().recordCopiedFeature(field);

    if ((field.modifiers & AccSynthetic) != 0) {
        roleDeclaration.binding.addCopiedSyntheticFied(field);
        return;
    }
    if ((field.tagBits & TagBits.IsFakedField) != 0)
        return; // don't copy fakes.

    if (roleDeclaration.fields != null) {
        for (int i = 0; i < roleDeclaration.fields.length; i++) {
            FieldDeclaration currentField = roleDeclaration.fields[i];
            if (CharOperation.equals(currentField.name, field.name)) {
                if (currentField.binding != null && currentField.binding.copyInheritanceSrc != null
                        && currentField.binding.copyInheritanceSrc == field.copyInheritanceSrc)
                    return; // not a problem: repeated inheritance of the same field!

                ProblemReporter problemReporter = currentField.isStatic()
                        ? roleDeclaration.staticInitializerScope.problemReporter()
                        : roleDeclaration.initializerScope.problemReporter();
                problemReporter.implicitlyHideField(currentField);
                return;
            }
        }
    }
    AstGenerator gen = new AstGenerator(roleDeclaration.sourceStart, roleDeclaration.sourceEnd);
    gen.replaceableEnclosingClass = roleDeclaration.binding.enclosingType();
    FieldDeclaration fieldDeclaration = AstConverter.createField(field, roleDeclaration, gen);
    AstEdit.addField(roleDeclaration, fieldDeclaration, true, false/*typeProblem*/, false);
    if (fieldDeclaration.binding != null) {
        fieldDeclaration.binding.modifiers |= ExtraCompilerModifiers.AccLocallyUsed;
        fieldDeclaration.binding.modifiers |= (field.modifiers & ExtraCompilerModifiers.AccBlankFinal); // BlankFinal was omitted on the fieldDecl
    }

}

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.statemachine.transformer.RoleSplitter.java

License:Open Source License

/**
* createInterfaceStatements//from   w w w.ja v  a  2  s.com
 * add to the interface:
 * + static final fields (move)
 * + method declarations (copy)
 *
 * This methods adds declarations to the interface, which may have to be
 * discarded later: If a role method overrides an implicitly inherited method,
 * the interface should not repeat the method for the sake of signature weakening.
 * CopyInheritance.weakenInterfaceSignatures does the job of cleanup.
*/
private static void createInterfaceStatements(final TypeDeclaration teamDecl, TypeDeclaration roleIfcDecl,
        final TypeDeclaration roleClassDecl) {
    // Alle Methoden und Felder in memberType durchgehen und in transformiertem Zustand in das interface einf?gen

    FieldDeclaration[] fields;
    AbstractMethodDeclaration[] methods;

    fields = roleClassDecl.fields;
    methods = roleClassDecl.methods;

    if (fields != null) {
        int fieldsLength = fields.length;
        for (int i = 0; i < fieldsLength; i++) {
            FieldDeclaration field = fields[i];
            // Only static final fields which are not private
            if (field.isStatic() && (field.modifiers & AccFinal) != 0 && (field.modifiers & AccPrivate) == 0) {
                // move the field:
                AstEdit.addField(roleIfcDecl, field, false, false/*typeProblem*/, false);
                AstEdit.removeField(roleClassDecl, field);
            }
        }
    }

    if (methods != null) {
        int methodsLength = methods.length;
        for (int i = 0; i < methodsLength; i++) {
            AbstractMethodDeclaration abstractMethod = methods[i];

            // Interface can't take constructors.
            if (abstractMethod instanceof MethodDeclaration) {
                final MethodDeclaration method = (MethodDeclaration) abstractMethod;

                // callin methods are actually copied because the wrapper calling the actual
                // role method would otherwise be quite difficult to translate.

                if (((abstractMethod.modifiers) & AccPrivate) == 0) {
                    final MethodDeclaration newmethod = AstConverter.genRoleIfcMethod(teamDecl, method);
                    AstEdit.addMethod(roleIfcDecl, newmethod);
                    roleIfcDecl.getRoleModel()._state.addJob(ITranslationStates.STATE_ROLE_HIERARCHY_ANALYZED, // calls methods(); 
                            new Runnable() {
                                public void run() {
                                    if (method.binding != null
                                            && (method.binding.modifiers
                                                    & ClassFileConstants.AccDeprecated) != 0
                                            && newmethod.binding != null) {
                                        newmethod.binding.modifiers |= ClassFileConstants.AccDeprecated;
                                        newmethod.binding.tagBits |= TagBits.AnnotationDeprecated;
                                    }
                                }
                            });
                }
            }
        }
    }
}

From source file:org.nabucco.framework.generator.compiler.transformation.java.common.ast.util.equals.DefaultObjectMethodStrategy.java

License:Open Source License

/**
 * Checks whether a field is generated or not.
 * /*  ww  w .j  a v  a 2  s  .c  o m*/
 * @param field
 *            the field to check
 * 
 * @return <b>true</b> if the field should be generated, <b>false</b> if not
 */
boolean isValid(FieldDeclaration field) {
    return !field.isStatic();
}