Java Code Examples for org.codehaus.groovy.ast.FieldNode#isSynthetic()

The following examples show how to use org.codehaus.groovy.ast.FieldNode#isSynthetic() . 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: GroovyVirtualSourceProvider.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void genField(FieldNode fieldNode, PrintWriter out) {
    // <netbeans>
    if (fieldNode.isSynthetic() || "metaClass".equals(fieldNode.getName())) { // NOI18N
        return;
    }
    // </netbeans>
    if ((fieldNode.getModifiers() & Opcodes.ACC_PRIVATE) != 0) {
        return;
    }
    printModifiers(out, fieldNode.getModifiers());

    printType(fieldNode.getType(), out);

    out.print(" ");
    out.print(fieldNode.getName());
    out.println(";");
}
 
Example 2
Source File: PathFinderVisitor.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void visitField(FieldNode node) {
    // we don't want synthetic fields duplicating property initial expressions
    if (!node.isSynthetic() && isInside(node, line, column)) {
        super.visitField(node);
    }
}
 
Example 3
Source File: FindVariableUsages.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public void visitField(FieldNode field) {
    if (!field.isSynthetic()) {
        addField(field);
    }
    super.visitField(field);
}
 
Example 4
Source File: GeneralUtils.java    From groovy with Apache License 2.0 4 votes vote down vote up
public static List<PropertyNode> getAllProperties(final Set<String> names, final ClassNode origType, final ClassNode cNode, final boolean includeProperties,
                                                  final boolean includeFields, final boolean includePseudoGetters, final boolean includePseudoSetters,
                                                  final boolean traverseSuperClasses, final boolean skipReadonly, final boolean reverse, final boolean allNames, final boolean includeStatic) {
    List<PropertyNode> result = new ArrayList<>();
    if (cNode != ClassHelper.OBJECT_TYPE && traverseSuperClasses && !reverse) {
        result.addAll(getAllProperties(names, origType, cNode.getSuperClass(), includeProperties, includeFields, includePseudoGetters, includePseudoSetters, true, skipReadonly));
    }
    if (includeProperties) {
        for (PropertyNode pNode : cNode.getProperties()) {
            if ((!pNode.isStatic() || includeStatic) && !names.contains(pNode.getName())) {
                result.add(pNode);
                names.add(pNode.getName());
            }
        }
        if (includePseudoGetters || includePseudoSetters) {
            BeanUtils.addPseudoProperties(origType, cNode, result, names, includeStatic, includePseudoGetters, includePseudoSetters);
        }
    }
    if (includeFields) {
        for (FieldNode fNode : cNode.getFields()) {
            if ((fNode.isStatic() && !includeStatic) || fNode.isSynthetic() || cNode.getProperty(fNode.getName()) != null || names.contains(fNode.getName())) {
                continue;
            }

            // internal field
            if (fNode.getName().contains("$") && !allNames) {
                continue;
            }

            if (fNode.isPrivate() && !cNode.equals(origType)) {
                continue;
            }
            if (fNode.isFinal() && fNode.getInitialExpression() != null && skipReadonly) {
                continue;
            }
            result.add(new PropertyNode(fNode, fNode.getModifiers(), null, null));
            names.add(fNode.getName());
        }
    }
    if (cNode != ClassHelper.OBJECT_TYPE && traverseSuperClasses && reverse) {
        result.addAll(getAllProperties(names, origType, cNode.getSuperClass(), includeProperties, includeFields, includePseudoGetters, includePseudoSetters, true, skipReadonly));
    }
    return result;
}
 
Example 5
Source File: Verifier.java    From groovy with Apache License 2.0 4 votes vote down vote up
protected void addInitialization(ClassNode node, ConstructorNode constructorNode) {
    Statement firstStatement = constructorNode.getFirstStatement();
    // if some transformation decided to generate constructor then it probably knows who it does
    if (firstStatement instanceof BytecodeSequence)
        return;

    ConstructorCallExpression first = getFirstIfSpecialConstructorCall(firstStatement);

    // in case of this(...) let the other constructor do the init
    if (first != null && (first.isThisCall())) return;

    List<Statement> statements = new ArrayList<Statement>();
    List<Statement> staticStatements = new ArrayList<Statement>();
    final boolean isEnum = node.isEnum();
    List<Statement> initStmtsAfterEnumValuesInit = new ArrayList<Statement>();
    Set<String> explicitStaticPropsInEnum = new HashSet<String>();
    if (isEnum) {
        for (PropertyNode propNode : node.getProperties()) {
            if (!propNode.isSynthetic() && propNode.getField().isStatic()) {
                explicitStaticPropsInEnum.add(propNode.getField().getName());
            }
        }
        for (FieldNode fieldNode : node.getFields()) {
            if (!fieldNode.isSynthetic() && fieldNode.isStatic() && fieldNode.getType() != node) {
                explicitStaticPropsInEnum.add(fieldNode.getName());
            }
        }
    }

    if (!Traits.isTrait(node)) {
        for (FieldNode fn : node.getFields()) {
            addFieldInitialization(statements, staticStatements, fn, isEnum,
                    initStmtsAfterEnumValuesInit, explicitStaticPropsInEnum);
        }
    }

    statements.addAll(node.getObjectInitializerStatements());

    BlockStatement block = getCodeAsBlock(constructorNode);
    List<Statement> otherStatements = block.getStatements();
    if (!otherStatements.isEmpty()) {
        if (first != null) {
            // it is super(..) since this(..) is already covered
            otherStatements.remove(0);
            statements.add(0, firstStatement);
        }
        Statement stmtThis$0 = getImplicitThis$0StmtIfInnerClass(otherStatements);
        if (stmtThis$0 != null) {
            // since there can be field init statements that depend on method/property dispatching
            // that uses this$0, it needs to bubble up before the super call itself (GROOVY-4471)
            statements.add(0, stmtThis$0);
        }
        statements.addAll(otherStatements);
    }
    BlockStatement newBlock = new BlockStatement(statements, block.getVariableScope());
    newBlock.setSourcePosition(block);
    constructorNode.setCode(newBlock);


    if (!staticStatements.isEmpty()) {
        if (isEnum) {
            /*
             * GROOVY-3161: initialize statements for explicitly declared static fields
             * inside an enum should come after enum values are initialized
             */
            staticStatements.removeAll(initStmtsAfterEnumValuesInit);
            node.addStaticInitializerStatements(staticStatements, true);
            if (!initStmtsAfterEnumValuesInit.isEmpty()) {
                node.positionStmtsAfterEnumInitStmts(initStmtsAfterEnumValuesInit);
            }
        } else {
            node.addStaticInitializerStatements(staticStatements, true);
        }
    }
}