public String getName() { return typeDeclaration.getName(); }
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; }
@Override void appendPathPrefix(StringBuilder path) { parent.appendPathPrefix(path); path.append(decl.getName()); path.append('$'); }
String getFQN() { StringBuilder fqn = new StringBuilder(); parent.appendFQNPrefix(fqn); fqn.append(decl.getName()); return fqn.toString(); }
String getPath() { StringBuilder path = new StringBuilder(); parent.appendPathPrefix(path); path.append(decl.getName()); path.append(".class"); return path.toString(); }
@Override void appendFQNPrefix(StringBuilder path) { parent.appendFQNPrefix(path); path.append(decl.getName()); path.append('.'); }
private String getTypeNameForMsg(final Node n) { final CompilationUnit unit = getCompilationUnit(n); final TypeDeclaration parent = unit.getTypes().get(0); return parent.getName(); } }
private String getTypeOrFieldNameForMsg(final BodyDeclaration n) { if (n instanceof TypeDeclaration) { return ((TypeDeclaration) n).getName(); } else if (n instanceof FieldDeclaration) { final FieldDeclaration fd = (FieldDeclaration) n; //this wont work for nested classes but we should be in nexted classes at this point final CompilationUnit unit = getCompilationUnit(n); final TypeDeclaration parent = unit.getTypes().get(0); Collection<String> variableNames = new ArrayList<String>(); if (fd.getVariables() != null) { for (VariableDeclarator vd : fd.getVariables()) { variableNames.add(vd.getId().getName()); } } return variableNames.size() == 1 ? parent.getName() + "." + variableNames.iterator().next() : parent.getName() + "." + variableNames.toString(); } return null; }
final String enclosingName = n.getPackage().getName() + "." + n.getTypes().get(0).getName();
@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; }
LOG.info("removing existing nested declaration " + existingNestedDeclaration.getName() + " from " + getTypeOrFieldNameForMsg(n) + "."); members.remove(existingNestedDeclaration);
@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)); }
@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; } }
@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) { final String tableName = getMappedTable(enclosingClass); if (tableName == null) { LOG.error(ResolverUtil.logMsgForClass(enclosingClass, mappedClass) + " table could not be found"); return null; } return new NodeData(new NormalAnnotationExpr(new NameExpr(SIMPLE_NAME), Collections.singletonList(new MemberValuePair("name", new StringLiteralExpr(upperCaseTableName ? tableName.toUpperCase() : tableName)))), new ImportDeclaration(new QualifiedNameExpr(new NameExpr(PACKAGE), SIMPLE_NAME), false, false)); } return null; }
@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 Collection<FieldDescriptor> primaryKeyDescriptors = getPrimaryKeyDescriptors(mappedClass); if (primaryKeyDescriptors != null && primaryKeyDescriptors.size() > 1 && nodeContainsPkFields(dclr, primaryKeyDescriptors)) { final NodeAndImports<ClassOrInterfaceDeclaration> primaryKeyClass = createPrimaryKeyClass(name, primaryKeyDescriptors); final String pkClassName = primaryKeyClass.node.getName(); return new NodeData(new SingleMemberAnnotationExpr(new NameExpr(SIMPLE_NAME), new NameExpr(name + "." + pkClassName + ".class")), new ImportDeclaration(new QualifiedNameExpr(new NameExpr(PACKAGE), SIMPLE_NAME), false, false), primaryKeyClass.imprts, primaryKeyClass.node); } return null; }
@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; } }