protected boolean checkIncludeExcludeUndefinedAware(AnnotationNode node, List<String> excludes, List<String> includes, String typeName) { if (includes != null && excludes != null && !excludes.isEmpty()) { addError("Error during " + typeName + " processing: Only one of 'includes' and 'excludes' should be supplied not both.", node); return false; } return true; }
public boolean checkPropertyList(ClassNode cNode, List<String> propertyNameList, String listName, AnnotationNode anno, String typeName, boolean includeFields, boolean includeSuperProperties, boolean allProperties) { return checkPropertyList(cNode, propertyNameList, listName, anno, typeName, includeFields, includeSuperProperties, allProperties, false, false); }
public static boolean shouldSkipUndefinedAware(String name, List<String> excludes, List<String> includes, boolean allNames) { return (excludes != null && excludes.contains(name)) || (!allNames && deemedInternalName(name)) || (includes != null && !includes.contains(name)); }
protected boolean isValidAttribute(AbstractASTTransformation xform, AnnotationNode anno, String memberName) { if (xform.getMemberValue(anno, memberName) != null) { xform.addError("Error during " + xform.getAnnotationName() + " processing: Annotation attribute '" + memberName + "' not supported for property handler " + getClass().getSimpleName(), anno); return false; } return true; }
public static List<String> getMemberStringList(AnnotationNode anno, String name) { Expression expr = anno.getMember(name); if (expr == null) { return null; } if (expr instanceof ListExpression) { final ListExpression listExpression = (ListExpression) expr; if (isUndefinedMarkerList(listExpression)) { return null; } return getValueStringList(listExpression); } return tokenize(getMemberStringValue(anno, name)); }
@Deprecated public static List<String> getMemberList(AnnotationNode anno, String name) { List<String> list; Expression expr = anno.getMember(name); if (expr instanceof ListExpression) { final ListExpression listExpression = (ListExpression) expr; list = getValueStringList(listExpression); } else { list = tokenize(getMemberStringValue(anno, name)); } return list; }
private static String getPrefix(AnnotationNode anno) { return getMemberStringValue(anno, "prefix", ""); }
if (anno == null) return new groovy.transform.options.DefaultPropertyHandler(); ClassNode handlerClass = xform.getMemberClassValue(anno, "propertyHandler", ClassHelper.make(groovy.transform.options.DefaultPropertyHandler.class)); xform.addError("Couldn't determine propertyHandler class", anno); return null; Object instance = loader.loadClass(className).newInstance(); if (instance == null) { xform.addError("Can't load propertyHandler '" + className + "'", anno); return null; xform.addError("The propertyHandler class '" + handlerClass.getName() + "' on " + xform.getAnnotationName() + " is not a propertyHandler", anno); return null; xform.addError("Can't load propertyHandler '" + className + "' " + e, anno); return null;
@Override public boolean validateProperties(AbstractASTTransformation xform, BlockStatement body, ClassNode cNode, List<PropertyNode> props) { if (!(props.size() == 1 && props.get(0).getType().equals(HMAP_TYPE))) { xform.addError("Error during " + xform.getAnnotationName() + " processing. Property handler " + getClass().getName() + " only accepts a single HashMap property", props.size() == 1 ? props.get(0) : cNode); return false; } return true; }
public static List<String> getKnownImmutables(AbstractASTTransformation xform, ClassNode cNode) { List<AnnotationNode> annotations = cNode.getAnnotations(ImmutablePropertyUtils.IMMUTABLE_OPTIONS_TYPE); AnnotationNode anno = annotations.isEmpty() ? null : annotations.get(0); final List<String> immutables = new ArrayList<String>(); if (anno == null) return immutables; final Expression expression = anno.getMember(MEMBER_KNOWN_IMMUTABLES); if (expression == null) return immutables; if (!(expression instanceof ListExpression)) { xform.addError("Use the Groovy list notation [el1, el2] to specify known immutable property names via \"" + MEMBER_KNOWN_IMMUTABLES + "\"", anno); return immutables; } final ListExpression listExpression = (ListExpression) expression; for (Expression listItemExpression : listExpression.getExpressions()) { if (listItemExpression instanceof ConstantExpression) { immutables.add((String) ((ConstantExpression) listItemExpression).getValue()); } } if (!xform.checkPropertyList(cNode, immutables, "knownImmutables", anno, "immutable class", false)) return immutables; return immutables; }
if (!getIncludeExclude(transform, anno, buildee, excludes, includes)) return; if (includes.size() == 1 && Undefined.isUndefined(includes.get(0))) includes = null; String prefix = getMemberStringValue(anno, "prefix", "set"); List<FieldNode> fields = getFields(transform, anno, buildee); if (includes != null) { if (!AbstractASTTransformation.shouldSkipUndefinedAware(fieldName, excludes, includes, allNames)) { String methodName = getSetterName(prefix, fieldName); Parameter parameter = param(field.getType(), fieldName);
List<String> excludes, final List<String> includes, boolean allNames, boolean allProperties, SourceUnit sourceUnit, PropertyHandler handler, ClosureExpression pre, ClosureExpression post) { boolean callSuper = xform.memberHasValue(anno, "callSuper", true); boolean force = xform.memberHasValue(anno, "force", true); boolean defaults = !xform.memberHasValue(anno, "defaults", false); Set<String> names = new HashSet<String>(); List<PropertyNode> superList; superInPre = copyStatementsWithSuperAdjustment(pre, preBody); if (superInPre && callSuper) { xform.addError("Error during " + MY_TYPE_NAME + " processing, can't have a super call in 'pre' " + "closure and also 'callSuper' enabled", cNode);
public List<ClassNode> getMemberClassList(AnnotationNode anno, String name) { List<ClassNode> list = new ArrayList<ClassNode>(); Expression expr = anno.getMember(name); if (expr == null) { return null; } if (expr instanceof ListExpression) { final ListExpression listExpression = (ListExpression) expr; if (isUndefinedMarkerList(listExpression)) { return null; } list = getTypeList(listExpression); } else if (expr instanceof ClassExpression) { ClassNode cn = expr.getType(); if (isUndefined(cn)) return null; if (cn != null) list.add(cn); } return list; }
public int getMemberIntValue(AnnotationNode node, String name) { Object value = getMemberValue(node, name); if (value instanceof Integer) { return (Integer) value; } return 0; }
public ClassNode getMemberClassValue(AnnotationNode node, String name) { return getMemberClassValue(node, name, null); }
private void checkForSystemProperties(AnnotationNode node) { systemProperties = new HashMap<String, String>(); List<String> nameValueList = AbstractASTTransformation.getMemberStringList(node, SYSTEM_PROPERTIES_SETTING); if (nameValueList != null) { for (String nameValue : nameValueList) { int equalsDelim = nameValue.indexOf('='); if (equalsDelim != -1) { systemProperties.put(nameValue.substring(0, equalsDelim), nameValue.substring(equalsDelim + 1)); } } } }
@Deprecated public List<ClassNode> getClassList(AnnotationNode anno, String name) { List<ClassNode> list = new ArrayList<ClassNode>(); Expression expr = anno.getMember(name); if (expr instanceof ListExpression) { final ListExpression listExpression = (ListExpression) expr; list = getTypeList(listExpression); } else if (expr instanceof ClassExpression) { ClassNode cn = expr.getType(); if (cn != null) list.add(cn); } return list; }
public static String getMemberStringValue(AnnotationNode node, String name) { return getMemberStringValue(node, name, null); }
/** * Determine if an explicit (non-generated) constructor is in the class. * * @param xform if non null, add an error if an explicit constructor is found * @param cNode the type of the containing class * @return true if an explicit (non-generated) constructor was found */ public static boolean hasExplicitConstructor(AbstractASTTransformation xform, ClassNode cNode) { List<ConstructorNode> declaredConstructors = cNode.getDeclaredConstructors(); for (ConstructorNode constructorNode : declaredConstructors) { // allow constructors added by other transforms if flagged as Generated if (hasAnnotation(constructorNode, GENERATED_TYPE)) { continue; } if (xform != null) { xform.addError("Error during " + xform.getAnnotationName() + " processing. Explicit constructors not allowed for class: " + cNode.getNameWithoutPackage(), constructorNode); } return true; } return false; }
protected void checkIncludeExcludeUndefinedAware(AnnotationNode node, List<String> excludes, List<String> includes, List<ClassNode> excludeTypes, List<ClassNode> includeTypes, String typeName) { int found = 0; if (includes != null) found++; if (excludes != null && !excludes.isEmpty()) found++; if (includeTypes != null) found++; if (excludeTypes != null && !excludeTypes.isEmpty()) found++; if (found > 1) { addError("Error during " + typeName + " processing: Only one of 'includes', 'excludes', 'includeTypes' and 'excludeTypes' should be supplied.", node); } }