@Override public void visitProperty(PropertyNode node) { // GROOVY-8233 skip static properties for traits since they don't make the interface if (!node.isStatic() || !Traits.isTrait(node.getDeclaringClass())) { super.visitProperty(node); } }
public static BooleanExpression hasSamePropertyX(PropertyNode pNode, Expression other) { ClassNode cNode = pNode.getDeclaringClass(); return sameX(getterThisX(cNode, pNode), getterX(cNode, other, pNode)); }
public void visitProperty(PropertyNode node) { Map<GenericsTypeName, GenericsType> oldPNames = genericParameterNames; if (node.isStatic() && !Traits.isTrait(node.getDeclaringClass())) { genericParameterNames = new HashMap<GenericsTypeName, GenericsType>(); } ClassNode t = node.getType(); resolveOrFail(t, node); super.visitProperty(node); fieldTypesChecked.add(node.getField()); genericParameterNames = oldPNames; }
@Override public void visitProperty(final PropertyNode node) { if (visitor!=null) visitor.visitProperty(node); ClassNode declaringClass = node.getDeclaringClass(); if (declaringClass!=null) { if (StaticTypeCheckingSupport.implementsInterfaceOrIsSubclassOf(declaringClass, ClassHelper.LIST_TYPE)) { List<PropertyNode> properties = declaringClass.getProperties(); boolean spread = true; for (PropertyNode propertyNode : properties) { if (propertyNode==node) { spread = false; break; } } // it's no real property but a property of the component pexp.setSpreadSafe(spread); } rType.set(declaringClass); } } };
private void checkDuplicateProperties(PropertyNode node) { ClassNode cn = node.getDeclaringClass(); String name = node.getName(); String getterName = "get" + MetaClassHelper.capitalize(name); if (Character.isUpperCase(name.charAt(0))) { for (PropertyNode propNode : cn.getProperties()) { String otherName = propNode.getField().getName(); String otherGetterName = "get" + MetaClassHelper.capitalize(otherName); if (node != propNode && getterName.equals(otherGetterName)) { String msg = "The field " + name + " and " + otherName + " on the class " + cn.getName() + " will result in duplicate JavaBean properties, which is not allowed"; addError(msg, node); } } } }
private boolean storeProperty(PropertyNode propertyNode, PropertyExpression expressionToStoreOn, ClassNode receiver, ClassCodeVisitorSupport visitor, String delegationData) { if (propertyNode == null) return false; if (visitor != null) visitor.visitProperty(propertyNode); storeWithResolve(propertyNode.getOriginType(), receiver, propertyNode.getDeclaringClass(), propertyNode.isStatic(), expressionToStoreOn); if (delegationData != null) { expressionToStoreOn.putNodeMetaData(StaticTypesMarker.IMPLICIT_RECEIVER, delegationData); } return true; }
/** * This method is similar to {@link #propX(Expression, Expression)} but will make sure that if the property * being accessed is defined inside the classnode provided as a parameter, then a getter call is generated * instead of a field access. * @param annotatedNode the class node where the property node is accessed from * @param receiver the object having the property * @param pNode the property being accessed * @return a method call expression or a property expression */ public static Expression getterX(ClassNode annotatedNode, Expression receiver, PropertyNode pNode) { ClassNode owner = pNode.getDeclaringClass(); if (annotatedNode.equals(owner)) { return callX(receiver, getterName(annotatedNode, pNode)); } return propX(receiver, pNode.getName()); }
private static void addGetterIfNeeded(DelegateDescription delegate, PropertyNode prop, String name, boolean allNames) { boolean isPrimBool = prop.getOriginType().equals(ClassHelper.boolean_TYPE); // do a little bit of pre-work since Groovy compiler hasn't added property accessors yet boolean willHaveGetAccessor = true; boolean willHaveIsAccessor = isPrimBool; String suffix = Verifier.capitalize(name); if (isPrimBool) { ClassNode cNode = prop.getDeclaringClass(); if (cNode.getGetterMethod("is" + suffix) != null && cNode.getGetterMethod("get" + suffix) == null) willHaveGetAccessor = false; if (cNode.getGetterMethod("get" + suffix) != null && cNode.getGetterMethod("is" + suffix) == null) willHaveIsAccessor = false; } Reference<Boolean> ownerWillHaveGetAccessor = new Reference<Boolean>(); Reference<Boolean> ownerWillHaveIsAccessor = new Reference<Boolean>(); extractAccessorInfo(delegate.owner, name, ownerWillHaveGetAccessor, ownerWillHaveIsAccessor); for (String prefix : new String[]{"get", "is"}) { String getterName = prefix + suffix; if ((prefix.equals("get") && willHaveGetAccessor && !ownerWillHaveGetAccessor.get() || prefix.equals("is") && willHaveIsAccessor && !ownerWillHaveIsAccessor.get()) && !shouldSkipPropertyMethod(name, getterName, delegate.excludes, delegate.includes, allNames)) { addGeneratedMethod(delegate.owner, getterName, ACC_PUBLIC, GenericsUtils.nonGeneric(prop.getType()), Parameter.EMPTY_ARRAY, null, returnS(propX(delegate.getOp, name))); } } }
/** * This method is similar to {@link #propX(Expression, Expression)} but will make sure that if the property * being accessed is defined inside the classnode provided as a parameter, then a getter call is generated * instead of a field access. * @param annotatedNode the class node where the property node is accessed from * @param pNode the property being accessed * @return a method call expression or a property expression */ public static Expression getterThisX(ClassNode annotatedNode, PropertyNode pNode) { ClassNode owner = pNode.getDeclaringClass(); if (annotatedNode.equals(owner)) { return callThisX(getterName(annotatedNode, pNode)); } return propX(new VariableExpression("this"), pNode.getName()); }
private void checkDuplicateProperties(PropertyNode node) { ClassNode cn = node.getDeclaringClass(); String name = node.getName(); String getterName = "get" + MetaClassHelper.capitalize(name); if (Character.isUpperCase(name.charAt(0))) { for (PropertyNode propNode : cn.getProperties()) { String otherName = propNode.getField().getName(); String otherGetterName = "get" + MetaClassHelper.capitalize(otherName); if (node != propNode && getterName.equals(otherGetterName)) { String msg = "The field " + name + " and " + otherName + " on the class " + cn.getName() + " will result in duplicate JavaBean properties, which is not allowed"; addError(msg, node); } } } }
private void checkDuplicateProperties(PropertyNode node) { ClassNode cn = node.getDeclaringClass(); String name = node.getName(); String getterName = "get" + MetaClassHelper.capitalize(name); if(Character.isUpperCase(name.charAt(0))) { for (Object propObj : cn.getProperties()) { PropertyNode propNode = (PropertyNode) propObj; String otherName = propNode.getField().getName(); String otherGetterName = "get" + MetaClassHelper.capitalize(otherName); if(node != propNode && getterName.equals(otherGetterName)) { String msg = "The field " + name + " and " + otherName + " on the class " + cn.getName() + " will result in duplicate JavaBean properties, which is not allowed"; addError(msg, node); } } } }
@Override public void visitProperty(PropertyNode node) { final ClassNode classNode = node.getDeclaringClass(); final String setterName = "set" + MetaClassHelper.capitalize(node.getName()); final Statement setterBlock = node.getSetterBlock(); final Parameter parameter = new Parameter(node.getType(), "value"); if (CandidateChecks.isClassInvariantCandidate(node) && (setterBlock == null && classNode.getMethod(setterName, new Parameter[]{ parameter } ) == null)) { final Statement setterBlockStatement = createSetterBlock(classNode, node.getField(), parameter); node.setSetterBlock(setterBlockStatement); } }
return ((FieldNode) node).getDeclaringClass(); } else if (node instanceof PropertyNode) { return ((PropertyNode) node).getDeclaringClass(); } else if (node instanceof Parameter) { return ((Parameter) node).getDeclaringClass();