private static void copyMembers(final Map<String, Expression> members, final AnnotationNode to) { for (Map.Entry<String, Expression> entry : members.entrySet()) { to.addMember(entry.getKey(), entry.getValue()); } }
private static void addMemberIfFound(AsmReferenceResolver resolver, AnnotationNode node, Map.Entry<String, Object> entry) { Expression value = annotationValueToExpression(entry.getValue(), resolver); if (value != null) { node.addMember(entry.getKey(), value); } }
private AnnotationNode createDataProviderAnnotation(Expression dataProviderExpr, int nextDataVariableIndex) { AnnotationNode ann = new AnnotationNode(resources.getAstNodeCache().DataProviderMetadata); ann.addMember(DataProviderMetadata.LINE, new ConstantExpression(dataProviderExpr.getLineNumber())); List<Expression> dataVariableNames = new ArrayList<>(); for (int i = nextDataVariableIndex; i < dataProcessorVars.size(); i++) dataVariableNames.add(new ConstantExpression(dataProcessorVars.get(i).getName())); ann.addMember(DataProviderMetadata.DATA_VARIABLES, new ListExpression(dataVariableNames)); return ann; }
ConstantExpression value = constX(isBool ? Boolean.valueOf(attrValue) : attrValue); value.setSourcePosition(node); node.addMember(attrName, value); int lastSemi = allstr.lastIndexOf(';'); if (lastSemi == -1) { if (!m.find()) return; if (m.group(1) == null || m.group(2) == null) return; node.addMember("module", constX(m.group(2))); node.addMember("group", constX(m.group(1))); if (m.group(6) != null) node.addMember("conf", constX(m.group(6))); if (m.group(4) != null) node.addMember("version", constX(m.group(4))); else if (!exclude && node.getMember("version") == null) node.addMember("version", constX("*")); node.getMembers().remove("value"); } else if (allstr.contains(":")) { String value = entry.getValue().toString(); if (!key.equals("version") || !value.equals("*") || !exclude) { node.addMember(key, constX(value));
public List<AnnotationNode> visit(AnnotationNode collector, AnnotationNode aliasAnnotationUsage, AnnotatedNode aliasAnnotated, SourceUnit source) { AnnotationNode node = new AnnotationNode(COMPILESTATIC_NODE); node.addMember("value", new PropertyExpression(new ClassExpression(TYPECHECKINGMODE_NODE), "SKIP")); return Collections.singletonList(node); } }
private boolean processImplicitNamedParam(MethodNode mNode, Parameter mapParam, ArgumentListExpression args, List<String> propNames, Parameter fromParam) { boolean required = fromParam.hasInitialExpression(); String name = fromParam.getName(); if (hasDuplicates(mNode, propNames, name)) return false; AnnotationNode namedParam = new AnnotationNode(NAMED_PARAM_TYPE); namedParam.addMember("value", constX(name)); namedParam.addMember("type", classX(fromParam.getType())); namedParam.addMember("required", constX(required, true)); mapParam.addAnnotation(namedParam); args.addExpression(propX(varX(mapParam), name)); return true; }
annos.add(new AnnotationConstantExpression(an)); collector.addMember("value", new ListExpression(annos)); node.addAnnotation(collector); node.getAnnotations().removeAll(next.getValue());
AnnotationNode newAnnotation = new AnnotationNode(annotation.getClassNode()); for (Map.Entry<String, Expression> member : annotation.getMembers().entrySet()) { newAnnotation.addMember(member.getKey(), member.getValue());
private boolean processDelegateParam(MethodNode mNode, Parameter mapParam, ArgumentListExpression args, List<String> propNames, Parameter fromParam) { if (isInnerClass(fromParam.getType())) { if (mNode.isStatic()) { addError("Error during " + MY_TYPE_NAME + " processing. Delegate type '" + fromParam.getType().getNameWithoutPackage() + "' is an inner class which is not supported.", mNode); return false; } } Set<String> names = new HashSet<String>(); List<PropertyNode> props = getAllProperties(names, fromParam.getType(), true, false, false, true, false, true); for (String next : names) { if (hasDuplicates(mNode, propNames, next)) return false; } List<MapEntryExpression> entries = new ArrayList<MapEntryExpression>(); for (PropertyNode pNode : props) { String name = pNode.getName(); entries.add(new MapEntryExpression(constX(name), propX(varX(mapParam), name))); AnnotationNode namedParam = new AnnotationNode(NAMED_PARAM_TYPE); namedParam.addMember("value", constX(name)); namedParam.addMember("type", classX(pNode.getType())); mapParam.addAnnotation(namedParam); } Expression delegateMap = new MapExpression(entries); args.addExpression(castX(fromParam.getType(), delegateMap)); return true; }
private boolean processExplicitNamedParam(MethodNode mNode, Parameter mapParam, BlockStatement inner, ArgumentListExpression args, List<String> propNames, Parameter fromParam) { AnnotationNode namedParam = fromParam.getAnnotations(NAMED_PARAM_TYPE).get(0); boolean required = memberHasValue(namedParam, "required", true); if (getMemberStringValue(namedParam, "value") == null) { namedParam.addMember("value", constX(fromParam.getName())); } String name = getMemberStringValue(namedParam, "value"); if (getMemberValue(namedParam, "type") == null) { namedParam.addMember("type", classX(fromParam.getType())); } if (hasDuplicates(mNode, propNames, name)) return false; // TODO check specified type is assignable from declared param type? // ClassNode type = getMemberClassValue(namedParam, "type"); if (required) { if (fromParam.hasInitialExpression()) { addError("Error during " + MY_TYPE_NAME + " processing. A required parameter can't have an initial value.", mNode); return false; } inner.addStatement(new AssertStatement(boolX(callX(varX(mapParam), "containsKey", args(constX(name)))), plusX(new ConstantExpression("Missing required named argument '" + name + "'. Keys found: "), callX(varX(mapParam), "keySet")))); } args.addExpression(propX(varX(mapParam), name)); mapParam.addAnnotation(namedParam); fromParam.getAnnotations().remove(namedParam); return true; }
private AnnotationNode createGrabAnnotation(String group, String module, String version, String classifier, String type, boolean transitive) { AnnotationNode annotationNode = new AnnotationNode(new ClassNode(Grab.class)); annotationNode.addMember("group", new ConstantExpression(group)); annotationNode.addMember("module", new ConstantExpression(module)); annotationNode.addMember("version", new ConstantExpression(version)); if (classifier != null) { annotationNode.addMember("classifier", new ConstantExpression(classifier)); } if (type != null) { annotationNode.addMember("type", new ConstantExpression(type)); } annotationNode.addMember("transitive", new ConstantExpression(transitive)); annotationNode.addMember("initClass", new ConstantExpression(false)); return annotationNode; }
public static FieldExpression injectedField(@Nonnull ClassNode owner, @Nonnull ClassNode type, @Nonnull String name, @Nullable String qualifierName) { FieldNode fieldNode = GriffonASTUtils.injectField(owner, name, Modifier.PRIVATE, type, null, false); List<AnnotationNode> annotations = fieldNode.getAnnotations(INJECT_TYPE); if (annotations == null || annotations.isEmpty()) { fieldNode.addAnnotation(new AnnotationNode(INJECT_TYPE)); } if (isNotBlank(qualifierName)) { AnnotationNode namedAnnotation = new AnnotationNode(NAMED_TYPE); namedAnnotation.addMember("value", new ConstantExpression(qualifierName)); fieldNode.addAnnotation(namedAnnotation); } return new FieldExpression(fieldNode); }
@Nonnull public static FieldExpression injectedField(@Nonnull ClassNode owner, @Nonnull ClassNode type, @Nonnull String name, @Nullable String qualifierName) { FieldNode fieldNode = GriffonASTUtils.injectField(owner, name, Modifier.PRIVATE, type, null, false); if (fieldNode.getAnnotations(INJECT_TYPE) == null) { fieldNode.addAnnotation(new AnnotationNode(INJECT_TYPE)); } if (isNotBlank(qualifierName) && fieldNode.getAnnotations(NAMED_TYPE) == null) { AnnotationNode namedAnnotation = new AnnotationNode(NAMED_TYPE); namedAnnotation.addMember("value", new ConstantExpression(qualifierName)); fieldNode.addAnnotation(namedAnnotation); } return new FieldExpression(fieldNode); } }
@Override public void apply(GroovyClassLoader loader, GroovyCompilerConfiguration configuration, GeneratorContext generatorContext, SourceUnit source, ClassNode classNode) throws CompilationFailedException { if (!AstUtils.hasAtLeastOneAnnotation(classNode, "RunWith")) { AnnotationNode runWith = new AnnotationNode(ClassHelper.make("RunWith")); runWith.addMember("value", new ClassExpression(ClassHelper.make("SpringRunner"))); classNode.addAnnotation(runWith); } }
@Override public void call(SourceUnit source, GeneratorContext context, ClassNode classNode) throws CompilationFailedException { if (staticCompile) { classNode.addAnnotation(new AnnotationNode(new ClassNode(CompileStatic.class))); } classNode.addAnnotation(new AnnotationNode(new ClassNode(InheritConstructors.class))); if (scriptPath != null) { AnnotationNode scriptPathAnnotation = new AnnotationNode(new ClassNode(ScriptPath.class)); scriptPathAnnotation.addMember("value", new ConstantExpression(scriptPath.toUri().toString())); classNode.addAnnotation(scriptPathAnnotation); } } });
/** * Captures the parameter names as annotations on the class. */ private void write(MethodNode c) { ListExpression v = new ListExpression(); for( Parameter p : c.getParameters() ) v.addExpression(new ConstantExpression(p.getName())); AnnotationNode a = new AnnotationNode(new ClassNode(CapturedParameterNames.class)); a.addMember("value",v); c.addAnnotation(a); } }
/** * Captures the parameter names as annotations on the class. */ private void write(MethodNode c) { ListExpression v = new ListExpression(); for( Parameter p : c.getParameters() ) v.addExpression(new ConstantExpression(p.getName())); AnnotationNode a = new AnnotationNode(new ClassNode(CapturedParameterNames.class)); a.addMember("value",v); c.addAnnotation(a); } }
/** * Captures the parameter names as annotations on the class. */ private void write(MethodNode c) { ListExpression v = new ListExpression(); for( Parameter p : c.getParameters() ) v.addExpression(new ConstantExpression(p.getName())); AnnotationNode a = new AnnotationNode(new ClassNode(CapturedParameterNames.class)); a.addMember("value",v); c.addAnnotation(a); } }
private void visitModule(ModuleNode module) { for (ClassNode classNode : module.getClasses()) { AnnotationNode annotation = new AnnotationNode(new ClassNode(Grab.class)); annotation.addMember("value", new ConstantExpression("groovy")); classNode.addAnnotation(annotation); // We only need to do it at most once break; } // Disable the addition of a static initializer that calls Grape.addResolver // because all the dependencies are local now disableGrabResolvers(module.getClasses()); disableGrabResolvers(module.getImports()); }