private AnnotationExpr findAnnotation(final BodyDeclaration n, String fullyQualifiedName, boolean foundAnnImport) { final String simpleName = ClassUtils.getShortClassName(fullyQualifiedName); final List<AnnotationExpr> annotations = n.getAnnotations() != null ? n.getAnnotations() : new ArrayList<AnnotationExpr>(); for (AnnotationExpr ae : annotations) { final String name = ae.getName().toString(); if ((simpleName.equals(name) && foundAnnImport)) { LOG.info("found " + ae + " on " + getTypeOrFieldNameForMsg(n) + "."); return ae; } if (fullyQualifiedName.equals(name)) { LOG.info("found " + ae + " on " + getTypeOrFieldNameForMsg(n) + "."); return ae; } } return null; }
private void printAnnotations(final List<AnnotationExpr> annotations, final Object arg) { if (annotations != null) { for (final AnnotationExpr a : annotations) { a.accept(this, arg); printer.print(" "); } } }
public void setName(NameExpr name) { this.name = name; setAsParentNodeOf(name); } }
annotations = add(annotations, ann); if(line==-1){line=ann.getBeginLine(); column=ann.getBeginColumn();}
@Override protected NodeData getAnnotationNodes(String enclosingClass, String fieldName, String mappedClass) { final List<Expression> joinColumns = getJoinColumns(enclosingClass, fieldName, mappedClass); if (joinColumns != null && joinColumns.size() > 1) { final Comment fixme = new BlockComment("\nFIXME: JPA_CONVERSION\n" + "For compound primary keys, make sure the join columns are in the correct order.\n"); AnnotationExpr annotation = new SingleMemberAnnotationExpr(new NameExpr(SIMPLE_NAME), new ArrayInitializerExpr(joinColumns)); annotation.setComment(fixme); return new NodeData(annotation, new ImportDeclaration(new QualifiedNameExpr(new NameExpr(PACKAGE), SIMPLE_NAME), false, false), Collections.singletonList(new ImportDeclaration(new QualifiedNameExpr(new NameExpr(PACKAGE), "PrimaryKeyJoinColumn"), false, false))); } return null; } }
ClassOrInterfaceDeclaration a = file.assertDeclaration(); MethodDeclaration decl = (MethodDeclaration)a.getMembers().get(0); decl.getAnnotations().get(0).setName(ASTHelper.createNameExpr(Action.class.getName())); file.assertSave();
annotations = add(annotations, ann); if(line==-1){line=ann.getBeginLine(); column=ann.getBeginColumn();}
@Override protected NodeData getAnnotationNodes(String enclosingClass, String fieldName, String mappedClass) { final FieldDescriptor fd = OjbUtil.findFieldDescriptor(mappedClass, fieldName, descriptorRepositories); if (fd != null) { final Class<?> fc = ResolverUtil.getType(enclosingClass, fieldName); if (isEnum(fc)) { final Comment fixme = new BlockComment("\nFIXME:\n" + "Enums must be annotated with the @Enumerated annotation.\n " + "The @Enumerated annotation should set the EnumType.\n" + "If the EnumType is not set, then the Enumerated annotation is defaulted to EnumType.ORDINAL.\n" + "This conversion program cannot tell whether EnumType.ORDINAL is the appropriate EnumType."); AnnotationExpr enumerated = new NormalAnnotationExpr(new NameExpr(SIMPLE_NAME), Collections.singletonList(new MemberValuePair("value", new NameExpr("EnumType.")))); enumerated.setComment(fixme); return new NodeData(enumerated, new ImportDeclaration(new QualifiedNameExpr(new NameExpr(PACKAGE), SIMPLE_NAME), false, false), Collections.singletonList(new ImportDeclaration(new QualifiedNameExpr(new NameExpr(PACKAGE), "TemporalType"), false, false))); } } return null; }
ClassOrInterfaceDeclaration a = file.assertDeclaration(); MethodDeclaration decl = (MethodDeclaration)a.getMembers().get(0); decl.getAnnotations().get(0).setName(ASTHelper.createNameExpr(Action.class.getName())); file.assertSave();
private void printMemberAnnotations(final List<AnnotationExpr> annotations, final Object arg) { if (annotations != null) { for (final AnnotationExpr a : annotations) { a.accept(this, arg); printer.printLn(); } } }
@Override public void visit(MethodDeclaration n, Object arg) { // here you can access the attributes of the method. // this method will be called for all methods in this // CompilationUnit, including inner class methods currentMethod = new CGEntry(TYPE.METHOD, currentClass, currentMethod, n.getName()); if (isDebug()) System.out.println("M:" + currentMethod); list.add(currentMethod); List<AnnotationExpr> annos = n.getAnnotations(); if (annos != null) { for (AnnotationExpr anno : annos) { if (isDebug()) System.out.println("A:" + anno.getName()); currentMethod.addAnnotation(new CGEntry(TYPE.ANNOTATION, currentClass, currentMethod, anno.getName().getName())); } } super.visit(n, arg); if (currentMethod != null) currentMethod = currentMethod.getMethod(); }
case AT: ann = Annotation(); annotations = add(annotations, ann); if(beginLine==-1) {beginLine=ann.getBeginLine(); beginColumn=ann.getBeginColumn();} break; default:
@Override protected NodeData getAnnotationNodes(String enclosingClass, String fieldName, String mappedClass) { final List<Expression> joinColumns = getJoinColumns(enclosingClass, fieldName, mappedClass); if (joinColumns != null && joinColumns.size() > 1) { final Comment fixme = new BlockComment("\nFIXME: JPA_CONVERSION\n" + "For compound primary keys, make sure the join columns are in the correct order.\n"); AnnotationExpr annotation = new SingleMemberAnnotationExpr(new NameExpr(SIMPLE_NAME), new ArrayInitializerExpr(joinColumns)); annotation.setComment(fixme); return new NodeData(annotation, new ImportDeclaration(new QualifiedNameExpr(new NameExpr(PACKAGE), SIMPLE_NAME), false, false), Arrays.asList( new ImportDeclaration(new QualifiedNameExpr(new NameExpr(PrimaryKeyJoinColumnResolver.PACKAGE),PrimaryKeyJoinColumnResolver.SIMPLE_NAME), false, false) , new ImportDeclaration(new QualifiedNameExpr(new NameExpr(JoinColumnResolver.PACKAGE),JoinColumnResolver.SIMPLE_NAME), false, false) )); } return null; } }
private void printAnnotations(List<AnnotationExpr> annotations, Object arg) { if (annotations != null) { for (AnnotationExpr a : annotations) { a.accept(this, arg); printer.print(" "); } } }
@Override public void visit(FieldDeclaration n, Object arg) { for (VariableDeclarator var : n.getVariables()) { CGEntry currentVariable = new CGEntry(TYPE.VARIABLE, currentClass, currentMethod, var.getId().getName()); if (isDebug()) System.out.println("V:" + currentVariable); list.add(currentVariable); List<AnnotationExpr> annos = n.getAnnotations(); if (annos != null) { for (AnnotationExpr anno : annos) { if (isDebug()) System.out.println("A:" + anno.getName()); currentVariable.addAnnotation(new CGEntry(TYPE.ANNOTATION, currentClass, currentMethod, anno.getName().getName())); } } } super.visit(n, arg); }
case AT: ann = Annotation(); annotations = add(annotations, ann); if(beginLine==-1) {beginLine=ann.getBeginLine(); beginColumn=ann.getBeginColumn();} break; default:
private void printMemberAnnotations(List<AnnotationExpr> annotations, Object arg) { if (annotations != null) { for (AnnotationExpr a : annotations) { a.accept(this, arg); printer.printLn(); } } }
@SuppressWarnings("unchecked") public XAnnotation<?> parse(final AnnotationExpr annotationElement) throws AnnotationExpressionParseException { Validate.notNull(annotationElement, "Annotation expression must not be null."); final String className = annotationElement.getName().toString(); try { final Class<?> draftClass = ClassUtils.getClass(classLoader, className); if (!Annotation.class.isAssignableFrom(draftClass)) throw new AnnotationExpressionParseException(annotationElement, new IllegalArgumentException(MessageFormat.format( "The class [{0}] is not an annotation class.", draftClass.getName()))); final Class<? extends Annotation> annotationClass = (Class<? extends Annotation>) draftClass; final XAnnotationField<?>[] fields = parseFields(annotationElement, annotationClass); @SuppressWarnings("rawtypes") final XAnnotation<?> xannotation = new XAnnotation(annotationClass, fields); return xannotation; } catch (ClassNotFoundException cnfex) { throw new AnnotationExpressionParseException(annotationElement, new AnnotationClassNotFoundException(className, cnfex)); } }
@Override public Node visit(final PackageDeclaration n, final A arg) { final List<AnnotationExpr> annotations = n.getAnnotations(); if (annotations != null) { for (int i = 0; i < annotations.size(); i++) { annotations.set(i, (AnnotationExpr) annotations.get(i).accept(this, arg)); } removeNulls(annotations); } n.setName((NameExpr) n.getName().accept(this, arg)); return n; }
@Override public void visit(ClassOrInterfaceDeclaration n, Object arg) { currentClass = new CGEntry(CGEntry.TYPE.CLASS, currentClass, null, n.getName()); if (mainClass == null) { mainClass = currentClass; mainClass.setMainClass(true); mainClass.setPackage(pack); } if (isDebug()) System.out.println("C:" + currentClass); list.add(currentClass); List<AnnotationExpr> annos = n.getAnnotations(); if (annos != null) { for (AnnotationExpr anno : annos) { if (isDebug()) System.out.println("A:" + anno.getName()); currentClass.addAnnotation(new CGEntry(TYPE.ANNOTATION, currentClass, currentMethod, anno.getName().getName())); } } super.visit(n, arg); if (currentClass != null ) currentClass = currentClass.getClazz(); }