@Override public R visit(final TypeDeclarationStmt n, final A arg) { { R result = n.getTypeDeclaration().accept(this, arg); if (result != null) { return result; } } return null; }
/** * Adds the given declaration to the specified type. The list of members * will be initialized if it is <code>null</code>. * * @param type * type declaration * @param decl * member declaration */ public static void addMember(TypeDeclaration type, BodyDeclaration decl) { List<BodyDeclaration> members = type.getMembers(); if (members == null) { members = new ArrayList<BodyDeclaration>(); type.setMembers(members); } members.add(decl); }
public String getName() { return typeDeclaration.getName(); }
public TypeDeclaration(List<AnnotationExpr> annotations, int modifiers, String name, List<BodyDeclaration> members) { super(annotations); setName(name); setModifiers(modifiers); setMembers(members); }
@Override public final NodeData resolve(Node node, String mappedClass) { if (!(node instanceof FieldDeclaration)) { throw new IllegalArgumentException("this annotation belongs only on FieldDeclaration"); } final FieldDeclaration field = (FieldDeclaration) node; if (ResolverUtil.canFieldBeAnnotated(field)) { final TypeDeclaration dclr = (TypeDeclaration) node.getParentNode(); final String name = dclr.getName(); final String pckg = ((CompilationUnit) dclr.getParentNode()).getPackage().getName().toString(); final String fullyQualifiedClass = pckg + "." + name; final boolean mappedColumn = OjbUtil.isMappedColumn(mappedClass, ParserUtil.getFieldName(field), descriptorRepositories); if (mappedColumn) { return getAnnotationNodes(fullyQualifiedClass, ParserUtil.getFieldName(field), mappedClass); } } return null; }
final TypeDeclaration parent = unit.getTypes().get(0); final List<BodyDeclaration> members = parent.getMembers() != null ? parent.getMembers() : new ArrayList<BodyDeclaration>(); final TypeDeclaration existingNestedDeclaration = findTypeDeclaration(members, nodes.nestedDeclaration.getName()); LOG.info("removing existing nested declaration " + existingNestedDeclaration.getName() + " from " + getTypeOrFieldNameForMsg(n) + "."); members.remove(existingNestedDeclaration); members.add(nodes.nestedDeclaration); parent.setMembers(members);
if(line==-1){line = tn.getBeginLine(); column = tn.getBeginColumn();} types = add(types, tn);
private void initializeFieldDetails(CompilationUnit cu) { List<TypeDeclaration> types = cu.getTypes(); for (TypeDeclaration type : types) { List<BodyDeclaration> members = type.getMembers(); for (BodyDeclaration member : members) { if (member instanceof FieldDeclaration) { FieldDeclaration field = (FieldDeclaration) member; fields.add(field); } } } }
Clip typeClip = Clip.get(declaration.getBeginLine() - 1, 0, declaration.getEndLine() - 1, declaration.getEndColumn());
@Override public NodeData resolve(Node node, String mappedClass) { if (!(node instanceof ClassOrInterfaceDeclaration)) { throw new IllegalArgumentException("this annotation belongs only on ClassOrInterfaceDeclaration"); } final TypeDeclaration dclr = (TypeDeclaration) node; if (!(dclr.getParentNode() instanceof CompilationUnit)) { //handling nested classes return null; } final String name = dclr.getName(); final String pckg = ((CompilationUnit) dclr.getParentNode()).getPackage().getName().toString(); final String enclosingClass = pckg + "." + name; if (!enclosingClass.equals(mappedClass)) { return new NodeData(new MarkerAnnotationExpr(new NameExpr(SIMPLE_NAME)), new ImportDeclaration(new QualifiedNameExpr(new NameExpr(PACKAGE), SIMPLE_NAME), false, false)); } return null; } }
if(line==-1){line = tn.getBeginLine(); column = tn.getBeginColumn();} types = add(types, tn);
private Collection<String> getFieldsOnNode(TypeDeclaration node, Collection<String> fields) { final Collection<String> fieldsOnNode = new ArrayList<String>(); final Collection<FieldDeclaration> fds = ParserUtil.getFieldMembers(node.getMembers()); if (fields != null) { for (FieldDeclaration f : fds) { final String name = ParserUtil.getFieldName(f); if (fields.contains(name)) { fieldsOnNode.add(name); } } } return fieldsOnNode; } }
public TypeDeclaration(int beginLine, int beginColumn, int endLine, int endColumn, List<AnnotationExpr> annotations, int modifiers, String name, List<BodyDeclaration> members) { super(beginLine, beginColumn, endLine, endColumn, annotations); setName(name); setModifiers(modifiers); setMembers(members); }
public void visit(TypeDeclarationStmt n, Object arg) { n.getTypeDeclaration().accept(this, arg); }
@Override public NodeData resolve(Node node, String mappedClass) { if (!(node instanceof ClassOrInterfaceDeclaration)) { throw new IllegalArgumentException("this annotation belongs only on ClassOrInterfaceDeclaration"); } final TypeDeclaration dclr = (TypeDeclaration) node; if (!(dclr.getParentNode() instanceof CompilationUnit)) { //handling nested classes return null; } final String name = dclr.getName(); final String pckg = ((CompilationUnit) dclr.getParentNode()).getPackage().getName().toString(); final String enclosingClass = pckg + "." + name; final Collection<String> customizedFieldsOnNode = getFieldsOnNode(dclr, getCustomizedFields(mappedClass)); if (customizedFieldsOnNode == null || customizedFieldsOnNode.isEmpty()) { LOG.info(ResolverUtil.logMsgForClass(enclosingClass, mappedClass) + " has no customized fields"); return null; } return new NodeData(new SingleMemberAnnotationExpr(new NameExpr(SIMPLE_NAME), new NameExpr("CreateCustomizerFor" + customizedFieldsOnNode.toString())), new ImportDeclaration(new QualifiedNameExpr(new NameExpr(PACKAGE), SIMPLE_NAME), false, false)); }
private TypeDeclaration findTypeDeclaration(List<BodyDeclaration> members, String name) { if (members != null) { for (BodyDeclaration bd : members) { if (bd instanceof TypeDeclaration) { if (((TypeDeclaration) bd).getName().equals(name)) { return (TypeDeclaration) bd; } } } } return null; }
private void initializeMethodDetails(CompilationUnit cu) { String className = file.getName(); className = className.substring(0, className.indexOf(".")); List<TypeDeclaration> types = cu.getTypes(); for (TypeDeclaration type : types) { List<BodyDeclaration> members = type.getMembers(); for (BodyDeclaration member : members) { if (member instanceof MethodDeclaration) { MethodDeclaration method = (MethodDeclaration) member; method.setJavaDoc(new JavadocComment("@deprecated This method is moved to the class {@link " + className + "}")); methods.add(method); } } } }
public List<JavaMethod> getMethods() { MethodCollector collector = new MethodCollector(); typeDeclaration.accept(collector, null); return collector.javaMethods(); }
@Override public NodeData resolve(Node node, String mappedClass) { if (!(node instanceof ClassOrInterfaceDeclaration)) { throw new IllegalArgumentException("this annotation belongs only on ClassOrInterfaceDeclaration"); } final TypeDeclaration dclr = (TypeDeclaration) node; if (!(dclr.getParentNode() instanceof CompilationUnit)) { //handling nested classes return null; } final String name = dclr.getName(); final String pckg = ((CompilationUnit) dclr.getParentNode()).getPackage().getName().toString(); final String enclosingClass = pckg + "." + name; final ClassDescriptor cd = OjbUtil.findClassDescriptor(enclosingClass, descriptorRepositories); if (cd != null) { return new NodeData(new MarkerAnnotationExpr(new NameExpr(SIMPLE_NAME)), new ImportDeclaration(new QualifiedNameExpr(new NameExpr(PACKAGE), SIMPLE_NAME), false, false)); } return null; } }