@Override public List<FieldNode> getFields() { List<FieldNode> nodes = new LinkedList<FieldNode>(); for (ClassNode delegate : delegates) { List<FieldNode> fields = delegate.getFields(); if (fields != null) nodes.addAll(fields); } return nodes; }
@Override public List<FieldNode> getFields() { lazyInitMembers(); return super.getFields(); }
/** * @return the list of FieldNode's associated with this ClassNode */ public List<FieldNode> getFields() { if (redirect!=null) return redirect().getFields(); lazyClassInit(); if (fields == null) fields = new LinkedList<FieldNode> (); return fields; }
public static List<FieldNode> getInstanceNonPropertyFields(ClassNode cNode) { final List<FieldNode> result = new ArrayList<FieldNode>(); for (FieldNode fNode : cNode.getFields()) { if (!fNode.isStatic() && cNode.getProperty(fNode.getName()) == null) { result.add(fNode); } } return result; }
private void printFields(PrintWriter out, ClassNode classNode) { boolean isInterface = isInterfaceOrTrait(classNode); List<FieldNode> fields = classNode.getFields(); if (fields == null) return; List<FieldNode> enumFields = new ArrayList<FieldNode>(fields.size()); List<FieldNode> normalFields = new ArrayList<FieldNode>(fields.size()); for (FieldNode field : fields) { boolean isSynthetic = (field.getModifiers() & Opcodes.ACC_SYNTHETIC) != 0; if (field.isEnum()) { enumFields.add(field); } else if (!isSynthetic) { normalFields.add(field); } } printEnumFields(out, enumFields); for (FieldNode normalField : normalFields) { printField(out, normalField, isInterface); } }
public static List<FieldNode> getSuperNonPropertyFields(ClassNode cNode) { final List<FieldNode> result; if (cNode == ClassHelper.OBJECT_TYPE) { result = new ArrayList<FieldNode>(); } else { result = getSuperNonPropertyFields(cNode.getSuperClass()); } for (FieldNode fNode : cNode.getFields()) { if (!fNode.isStatic() && cNode.getProperty(fNode.getName()) == null) { result.add(fNode); } } return result; }
/** * If we are in a constructor, that is static compiled, but in a class, that * is not, it may happen that init code from object initializers, fields * or properties is added into the constructor code. The backend assumes * a purely static constructor, so it may fail if it encounters dynamic * code here. Thus we make this kind of code fail */ private void checkForConstructorWithCSButClassWithout(MethodNode node) { if (!(node instanceof ConstructorNode)) return; Object meta = node.getNodeMetaData(STATIC_COMPILE_NODE); if (!Boolean.TRUE.equals(meta)) return; ClassNode clz = typeCheckingContext.getEnclosingClassNode(); meta = clz.getNodeMetaData(STATIC_COMPILE_NODE); if (Boolean.TRUE.equals(meta)) return; if ( clz.getObjectInitializerStatements().isEmpty() && clz.getFields().isEmpty() && clz.getProperties().isEmpty()) { return; } addStaticTypeError("Cannot statically compile constructor implicitly including non static elements from object initializers, properties or fields.",node); }
private static void addProperty(ClassNode cNode, PropertyNode pNode) { final FieldNode fn = pNode.getField(); cNode.getFields().remove(fn); cNode.addProperty(pNode.getName(), pNode.getModifiers() | ACC_FINAL, pNode.getType(), pNode.getInitialExpression(), pNode.getGetterBlock(), pNode.getSetterBlock()); final FieldNode newfn = cNode.getField(fn.getName()); cNode.getFields().remove(newfn); cNode.addField(fn); }
pList.remove(pNode); final List<FieldNode> fList = cNode.getFields(); for (FieldNode fNode : fList) { if (foundNames.contains(fNode.getName())) {
for (FieldNode fNode : cNode.getFields()) { if ((fNode.isStatic() && !includeStatic) || fNode.isSynthetic() || cNode.getProperty(fNode.getName()) != null || names.contains(fNode.getName())) { continue;
for (FieldNode fieldNode : node.getFields()) { if (!fieldNode.isSynthetic() && fieldNode.isStatic() && fieldNode.getType() != node) { explicitStaticPropsInEnum.add(fieldNode.getName()); for (FieldNode fn : node.getFields()) { addFieldInitialization(statements, staticStatements, fn, isEnum, initStmtsAfterEnumValuesInit, explicitStaticPropsInEnum);
public void visitContents(GroovyClassVisitor visitor) { // now let's visit the contents of the class for (PropertyNode pn : getProperties()) { visitor.visitProperty(pn); } for (FieldNode fn : getFields()) { visitor.visitField(fn); } for (ConstructorNode cn : getDeclaredConstructors()) { visitor.visitConstructor(cn); } for (MethodNode mn : getMethods()) { visitor.visitMethod(mn); } }
private static boolean ensureNoInstanceFieldOrProperty(final SourceUnit source, final ClassNode parent) { boolean valid = true; for (FieldNode fieldNode : parent.getFields()) { if (!fieldNode.isStatic() && fieldNode.getLineNumber()>0) { // if <0, probably an AST transform or internal code (like generated metaclass field, ...) addUnsupportedError(fieldNode, source); valid = false; } } for (PropertyNode propertyNode : parent.getProperties()) { if (!propertyNode.isStatic() && propertyNode.getLineNumber()>0) { // if <0, probably an AST transform or internal code (like generated metaclass field, ...) addUnsupportedError(propertyNode, source); valid = false; } } return valid; }
while (consideredClass!=null) { if (hasVetoableAnnotation(consideredClass)) return false; for (FieldNode field : consideredClass.getFields()) { if (hasVetoableAnnotation(field)) return false;
while (consideredClass!=null) { if (hasBindableAnnotation(consideredClass)) return false; for (FieldNode field : consideredClass.getFields()) { if (hasBindableAnnotation(field)) return false;
addProperty(cNode, pNode); final List<FieldNode> fList = cNode.getFields(); for (FieldNode fNode : fList) { ensureNotPublic(this, cName, fNode);
private Variable findClassMember(ClassNode cn, String name) { if (cn == null) return null; if (cn.isScript()) { return new DynamicVariable(name, false); } for (FieldNode fn : cn.getFields()) { if (fn.getName().equals(name)) return fn; } for (MethodNode mn : cn.getMethods()) { String pName = getPropertyName(mn); if (name.equals(pName)) { PropertyNode property = new PropertyNode(name, mn.getModifiers(), ClassHelper.OBJECT_TYPE, cn, null, null, null); property.getField().setHasNoRealSourcePosition(true); property.getField().setSynthetic(true); property.getField().setDeclaringClass(cn); property.setDeclaringClass(cn); return property; } } for (PropertyNode pn : cn.getProperties()) { if (pn.getName().equals(name)) return pn; } Variable ret = findClassMember(cn.getSuperClass(), name); if (ret != null) return ret; return findClassMember(cn.getOuterClass(), name); }
privateFieldMutators = mutatedFields != null ? new HashMap<String, MethodNode>() : null; final int access = Opcodes.ACC_STATIC | Opcodes.ACC_PUBLIC | Opcodes.ACC_SYNTHETIC; for (FieldNode fieldNode : node.getFields()) { boolean generateAccessor = accessedFields != null && accessedFields.contains(fieldNode); boolean generateMutator = mutatedFields != null && mutatedFields.contains(fieldNode);
for (FieldNode fn : node.getFields()) { if (!fn.isStatic() || !fn.isSynthetic() || !fn.getName().startsWith("$const$")) continue; if (fn.getInitialExpression() == null) continue;