Java Code Examples for org.codehaus.groovy.ast.ClassNode#getProperty()
The following examples show how to use
org.codehaus.groovy.ast.ClassNode#getProperty() .
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: BeanUtils.java From groovy with Apache License 2.0 | 6 votes |
private static void addIfMissing(ClassNode cNode, List<PropertyNode> result, Set<String> names, MethodNode mNode, ClassNode returnType, String propName, Statement getter, Statement setter) { if (cNode.getProperty(propName) != null) return; if (names.contains(propName)) { for (PropertyNode pn : result) { if (pn.getName().equals(propName) && getter != null && pn.getGetterBlock() == null) { pn.setGetterBlock(getter); } if (pn.getName().equals(propName) && setter != null && pn.getSetterBlock() == null) { pn.setSetterBlock(setter); } } } else { result.add(new PropertyNode(propName, mNode.getModifiers(), returnType, cNode, null, getter, setter)); names.add(propName); } }
Example 2
Source File: Verifier.java From groovy with Apache License 2.0 | 6 votes |
private static ASTNode sourceOf(MethodNode methodNode) { if (methodNode.getLineNumber() < 1) { ClassNode declaringClass = methodNode.getDeclaringClass(); if (methodNode.isSynthetic()) { String propertyName = getPropertyName(methodNode); if (propertyName != null) { PropertyNode propertyNode = declaringClass.getProperty(propertyName); if (propertyNode != null && propertyNode.getLineNumber() > 0) { return propertyNode; } } } return declaringClass; } return methodNode; }
Example 3
Source File: DefaultPropertyHandler.java From groovy with Apache License 2.0 | 6 votes |
@Override public Statement createPropInit(AbstractASTTransformation xform, AnnotationNode anno, ClassNode cNode, PropertyNode pNode, Parameter namedArgsMap) { String name = pNode.getName(); FieldNode fNode = pNode.getField(); boolean useSetters = xform.memberHasValue(anno, "useSetters", true); boolean hasSetter = cNode.getProperty(name) != null && !fNode.isFinal(); if (namedArgsMap != null) { return assignFieldS(useSetters, namedArgsMap, name); } else { Expression var = varX(name); if (useSetters && hasSetter) { return setViaSetterS(name, var); } else { return assignToFieldS(name, var); } } }
Example 4
Source File: GroovyASTUtils.java From groovy-language-server with Apache License 2.0 | 5 votes |
public static PropertyNode getPropertyFromExpression(PropertyExpression node, ASTNodeVisitor astVisitor) { ClassNode classNode = getTypeOfNode(node.getObjectExpression(), astVisitor); if (classNode != null) { return classNode.getProperty(node.getProperty().getText()); } return null; }
Example 5
Source File: DelegateASTTransformation.java From groovy with Apache License 2.0 | 5 votes |
private static void extractAccessorInfo(ClassNode owner, String name, Reference<Boolean> willHaveGetAccessor, Reference<Boolean> willHaveIsAccessor) { String suffix = Verifier.capitalize(name); boolean hasGetAccessor = owner.getGetterMethod("get" + suffix) != null; boolean hasIsAccessor = owner.getGetterMethod("is" + suffix) != null; PropertyNode prop = owner.getProperty(name); willHaveGetAccessor.set(hasGetAccessor || (prop != null && !hasIsAccessor)); willHaveIsAccessor.set(hasIsAccessor || (prop != null && !hasGetAccessor && prop.getOriginType().equals(ClassHelper.boolean_TYPE))); }
Example 6
Source File: IndexedPropertyASTTransformation.java From groovy with Apache License 2.0 | 5 votes |
public void visit(ASTNode[] nodes, SourceUnit source) { init(nodes, source); AnnotatedNode parent = (AnnotatedNode) nodes[1]; AnnotationNode node = (AnnotationNode) nodes[0]; if (!MY_TYPE.equals(node.getClassNode())) return; if (parent instanceof FieldNode) { FieldNode fNode = (FieldNode) parent; ClassNode cNode = fNode.getDeclaringClass(); if (cNode.getProperty(fNode.getName()) == null) { addError("Error during " + MY_TYPE_NAME + " processing. Field '" + fNode.getName() + "' doesn't appear to be a property; incorrect visibility?", fNode); return; } ClassNode fType = fNode.getType(); if (fType.isArray()) { addArraySetter(fNode); addArrayGetter(fNode); } else if (fType.isDerivedFrom(LIST_TYPE)) { addListSetter(fNode); addListGetter(fNode); } else { addError("Error during " + MY_TYPE_NAME + " processing. Non-Indexable property '" + fNode.getName() + "' found. Type must be array or list but found " + fType.getName(), fNode); } } }
Example 7
Source File: TraitComposer.java From groovy with Apache License 2.0 | 5 votes |
private static boolean isExistingProperty(final String methodName, final ClassNode cNode, final Parameter[] params) { String propertyName = methodName; boolean getter = false; if (methodName.startsWith("get")) { propertyName = propertyName.substring(3); getter = true; } else if (methodName.startsWith("is")) { propertyName = propertyName.substring(2); getter = true; } else if (methodName.startsWith("set")) { propertyName = propertyName.substring(3); } else { return false; } if (getter && params.length>0) { return false; } if (!getter && params.length!=1) { return false; } if (propertyName.length()==0) { return false; } propertyName = MetaClassHelper.convertPropertyName(propertyName); PropertyNode pNode = cNode.getProperty(propertyName); return pNode != null; }
Example 8
Source File: GeneralUtils.java From groovy with Apache License 2.0 | 5 votes |
public static List<FieldNode> getInstanceNonPropertyFields(final ClassNode cNode) { List<FieldNode> result = new ArrayList<>(); for (FieldNode fNode : cNode.getFields()) { if (!fNode.isStatic() && cNode.getProperty(fNode.getName()) == null) { result.add(fNode); } } return result; }
Example 9
Source File: GeneralUtils.java From groovy with Apache License 2.0 | 5 votes |
public static List<FieldNode> getSuperNonPropertyFields(final ClassNode cNode) { List<FieldNode> result; if (cNode == ClassHelper.OBJECT_TYPE) { result = new ArrayList<>(); } else { result = getSuperNonPropertyFields(cNode.getSuperClass()); } for (FieldNode fNode : cNode.getFields()) { if (!fNode.isStatic() && cNode.getProperty(fNode.getName()) == null) { result.add(fNode); } } return result; }
Example 10
Source File: DriverCompilationCustomizer.java From arcusplatform with Apache License 2.0 | 4 votes |
@Override public void call(SourceUnit source, GeneratorContext context, ClassNode classNode) throws CompilationFailedException { LOGGER.trace("Customize [phase: {} {}, classNode: {}]", source.getPhase(), source.getPhaseDescription(), classNode); if(classNode.getField("_HASH") == null) { String hash = hash(source); if(hash != null) { classNode.addField( "_HASH", Modifier.PUBLIC | Modifier.FINAL, new ClassNode(String.class), new ConstantExpression(hash) ); } } ClassNode groovyCapabilityDefinition = new ClassNode(GroovyCapabilityDefinition.class); for(CapabilityDefinition definition: capabilityRegistry.listCapabilityDefinitions()) { if(classNode.getProperty(definition.getCapabilityName()) != null) { continue; } if(!isDeviceCapability(definition)) { continue; } String fieldName = definition.getNamespace(); FieldNode field = classNode.addField( fieldName, Modifier.PRIVATE | Modifier.FINAL, groovyCapabilityDefinition, new StaticMethodCallExpression( new ClassNode(GroovyCapabilityDefinitionFactory.class), "create", new TupleExpression( new ConstantExpression(definition.getCapabilityName()), VariableExpression.THIS_EXPRESSION ) ) ); classNode.addProperty( definition.getCapabilityName(), Modifier.PUBLIC | Modifier.FINAL, groovyCapabilityDefinition, new FieldExpression(field), new ReturnStatement(new FieldExpression(field)), null ); } }
Example 11
Source File: GeneralUtils.java From groovy with Apache License 2.0 | 4 votes |
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; }