private static void mergeParameters(AnnotationNode to, AnnotationNode from) { for (String name : from.getMembers().keySet()) { if (to.getMember(name) == null) { to.setMember(name, from.getMember(name)); } } }
private void extractGrab(Expression init, ConstantExpression ce) { if (ce.getValue() instanceof AnnotationNode) { AnnotationNode annotation = (AnnotationNode) ce.getValue(); if ((init != null) && (annotation.getMember("initClass") != null)) { annotation.setMember("initClass", init); } String name = annotation.getClassNode().getName(); if ((GRAB_CLASS_NAME.equals(name)) || (allowShortGrab && GRAB_SHORT_NAME.equals(name)) || (grabAliases.contains(name))) { grabAnnotations.add(annotation); } if ((GRABEXCLUDE_CLASS_NAME.equals(name)) || (allowShortGrabExcludes && GRABEXCLUDE_SHORT_NAME.equals(name)) || (grabExcludeAliases.contains(name))) { grabExcludeAnnotations.add(annotation); } if ((GRABCONFIG_CLASS_NAME.equals(name)) || (allowShortGrabConfig && GRABCONFIG_SHORT_NAME.equals(name)) || (grabConfigAliases.contains(name))) { grabConfigAnnotations.add(annotation); } if ((GRABRESOLVER_CLASS_NAME.equals(name)) || (allowShortGrabResolver && GRABRESOLVER_SHORT_NAME.equals(name)) || (grabResolverAliases.contains(name))) { grabResolverAnnotations.add(annotation); } } }
private void addFieldMetadata(Field field) { AnnotationNode ann = new AnnotationNode(nodeCache.FieldMetadata); ann.setMember(FieldMetadata.NAME, new ConstantExpression(field.getName())); ann.setMember(FieldMetadata.ORDINAL, new ConstantExpression(field.getOrdinal())); ann.setMember(FieldMetadata.LINE, new ConstantExpression(field.getAst().getLineNumber())); ann.setMember(FieldMetadata.INITIALIZER, new ConstantExpression(field.hasInitialExpression())); field.getAst().addAnnotation(ann); }
private void addFeatureMetadata(FeatureMethod feature) { AnnotationNode ann = new AnnotationNode(nodeCache.FeatureMetadata); ann.setMember(FeatureMetadata.NAME, new ConstantExpression(feature.getName())); ann.setMember(FeatureMetadata.ORDINAL, new ConstantExpression(feature.getOrdinal())); ann.setMember(FeatureMetadata.LINE, new ConstantExpression(feature.getAst().getLineNumber())); ann.setMember(FeatureMetadata.BLOCKS, blockAnnElems = new ListExpression()); ListExpression paramNames = new ListExpression(); for (Parameter param : feature.getAst().getParameters()) paramNames.addExpression(new ConstantExpression(param.getName())); ann.setMember(FeatureMetadata.PARAMETER_NAMES, paramNames); feature.getAst().addAnnotation(ann); }
private void addSpecMetadata(Spec spec) { AnnotationNode ann = new AnnotationNode(nodeCache.SpecMetadata); String pathname = spec.getAst().getModule().getContext().getName(); String filename = new File(pathname).getName(); ann.setMember(SpecMetadata.FILENAME, new ConstantExpression(filename)); ann.setMember(SpecMetadata.LINE, new ConstantExpression(spec.getAst().getLineNumber())); spec.getAst().addAnnotation(ann); }
if (an.getClassNode().hasMethod(name, Parameter.EMPTY_ARRAY)) { unusedNames.remove(name); an.setMember(name, aliasAnnotationUsage.getMember(name));
private void addBlockMetadata(Block block, BlockKind kind) { AnnotationNode blockAnn = new AnnotationNode(nodeCache.BlockMetadata); blockAnn.setMember(BlockMetadata.KIND, new PropertyExpression( new ClassExpression(nodeCache.BlockKind), kind.name())); ListExpression textExprs = new ListExpression(); for (String text : block.getDescriptions()) textExprs.addExpression(new ConstantExpression(text)); blockAnn.setMember(BlockMetadata.TEXTS, textExprs); blockAnnElems.addExpression(new AnnotationConstantExpression(blockAnn)); }
protected void addTypeCheckingInfoAnnotation(final MethodNode node) { // TypeChecked$TypeCheckingInfo can not be applied on constructors if (node instanceof ConstructorNode) return; // if a returned inferred type is available and no @TypeCheckingInfo is on node, then add an // annotation to the method node ClassNode rtype = getInferredReturnType(node); if (rtype != null && node.getAnnotations(TYPECHECKING_INFO_NODE).isEmpty()) { AnnotationNode anno = new AnnotationNode(TYPECHECKING_INFO_NODE); anno.setMember("version", CURRENT_SIGNATURE_PROTOCOL); SignatureCodec codec = SignatureCodecFactory.getCodec(CURRENT_SIGNATURE_PROTOCOL_VERSION, getTransformLoader()); String genericsSignature = codec.encode(rtype); if (genericsSignature != null) { ConstantExpression signature = new ConstantExpression(genericsSignature); signature.setType(STRING_TYPE); anno.setMember("inferredType", signature); node.addAnnotation(anno); } } }
RetentionPolicy value = r.value(); setRetentionPolicy(value, node); node.setMember("value", new PropertyExpression( new ClassExpression(ClassHelper.makeWithoutCaching(RetentionPolicy.class, false)), value.toString())); new ClassExpression(ClassHelper.ELEMENT_TYPE_TYPE), element.name())); node.setMember("value", elementExprs); } else { Method[] declaredMethods; if (valueExpression == null) continue; node.setMember(declaredMethod.getName(), valueExpression); } catch (IllegalAccessException | InvocationTargetException e) {
helper.addAnnotation(new AnnotationNode(COMPILESTATIC_CLASSNODE)); MethodNode serializeClass = collector.getClassNode().getMethod("serializeClass", Parameter.EMPTY_ARRAY); collector.setMember("serializeClass", new ClassExpression(helper.getPlainNodeReference()));
public void visit(ASTNode[] nodes, SourceUnit source) { init(nodes, source); AnnotatedNode parent = (AnnotatedNode) nodes[1]; AnnotationNode anno = (AnnotationNode) nodes[0]; if (!MY_TYPE.equals(anno.getClassNode())) return; if (parent instanceof ClassNode) { ClassNode cNode = (ClassNode) parent; if (!checkNotInterface(cNode, MY_TYPE_NAME)) return; ClassNode exception = getMemberClassValue(anno, "exception"); if (exception != null && Undefined.isUndefinedException(exception)) { exception = null; } String message = getMemberStringValue(anno, "message"); Expression code = anno.getMember("code"); if (code != null && !(code instanceof ClosureExpression)) { addError("Expected closure value for annotation parameter 'code'. Found " + code, cNode); return; } createMethods(cNode, exception, message, (ClosureExpression) code); if (code != null) { anno.setMember("code", new ClosureExpression(Parameter.EMPTY_ARRAY, EmptyStatement.INSTANCE)); } } }
protected AnnotationNode annotation(AST annotationNode) { annotationBeingDef = true; AST node = annotationNode.getFirstChild(); String name = qualifiedName(node); AnnotationNode annotatedNode = new AnnotationNode(ClassHelper.make(name)); configureAST(annotatedNode, annotationNode); while (true) { node = node.getNextSibling(); if (isType(ANNOTATION_MEMBER_VALUE_PAIR, node)) { AST memberNode = node.getFirstChild(); String param = identifier(memberNode); Expression expression = expression(memberNode.getNextSibling()); if (annotatedNode.getMember(param) != null) { throw new ASTRuntimeException(memberNode, "Annotation member '" + param + "' has already been associated with a value"); } annotatedNode.setMember(param, expression); } else { break; } } annotationBeingDef = false; return annotatedNode; }
private void handle(String name, AnnotatedNode annotated) { for (AnnotationNode ann : (List<AnnotationNode>)annotated.getAnnotations()) { if (ann.getClassNode().getName().endsWith(Argument.class.getName())) { Expression expr = ann.getMember("name"); if (expr == null) { expr = new ConstantExpression(name); ann.setMember("name", expr); } } } } }
listExp.addExpression(attrExp); if (annotation != null) { annotation.setMember(attrName, listExp);
private void disableGrabResolvers(List<? extends AnnotatedNode> nodes) { for (AnnotatedNode classNode : nodes) { List<AnnotationNode> annotations = classNode.getAnnotations(); for (AnnotationNode node : new ArrayList<>(annotations)) { if (node.getClassNode().getNameWithoutPackage() .equals("GrabResolver")) { node.setMember("initClass", new ConstantExpression(false)); } } } }
private void handle(String name, AnnotatedNode annotated) { for (AnnotationNode ann : (List<AnnotationNode>)annotated.getAnnotations()) { if (ann.getClassNode().getName().endsWith(Argument.class.getName())) { Expression expr = ann.getMember("name"); if (expr == null) { expr = new ConstantExpression(name); ann.setMember("name", expr); } } } } }
private void handle(String name, AnnotatedNode annotated) { for (AnnotationNode ann : (List<AnnotationNode>)annotated.getAnnotations()) { if (ann.getClassNode().getName().endsWith(Argument.class.getName())) { Expression expr = ann.getMember("name"); if (expr == null) { expr = new ConstantExpression(name); ann.setMember("name", expr); } } } } }
private void addDependencyManagementBom(ModuleNode node, String module) { AnnotatedNode annotated = getAnnotatedNode(node); if (annotated != null) { AnnotationNode bom = getAnnotation(annotated); List<Expression> expressions = new ArrayList<>( getConstantExpressions(bom.getMember("value"))); expressions.add(new ConstantExpression(module)); bom.setMember("value", new ListExpression(expressions)); } }