public void setField(final String field) { this.field = new NameExpr(field); }
public void setName(final String name) { this.name = new NameExpr(name); }
public final void setName(String name) { this.name = new NameExpr(name); }
public void setName(String name) { this.name = new NameExpr(name); }
public void setName(final String name) { this.name = new NameExpr(name); }
final public NameExpr SimpleName() throws ParseException { NameExpr ret; jj_consume_token(IDENTIFIER); ret = new NameExpr(token.beginLine, token.beginColumn, token.endLine, token.endColumn, token.image); {if (true) return ret;} throw new Error("Missing return statement in function"); }
/** * Creates a new {@link NameExpr} from a qualified name.<br> * The qualified name can contains "." (dot) characters. * * @param qualifiedName * qualified name * @return instanceof {@link NameExpr} */ public static NameExpr createNameExpr(String qualifiedName) { String[] split = qualifiedName.split("\\."); NameExpr ret = new NameExpr(split[0]); for (int i = 1; i < split.length; i++) { ret = new QualifiedNameExpr(ret, split[i]); } return ret; }
@Override protected NodeData getAnnotationNodes(String enclosingClass, String fieldName, String mappedClass) { final boolean pk = isPrimaryKeyColumn(mappedClass, fieldName); if (pk) { return new NodeData(new MarkerAnnotationExpr(new NameExpr(SIMPLE_NAME)), new ImportDeclaration(new QualifiedNameExpr(new NameExpr(PACKAGE), SIMPLE_NAME), false, false)); } return null; }
@Override protected NodeData getAnnotationNodes(String enclosingClass, String fieldName, String mappedClass) { final FieldDescriptor fd = OjbUtil.findFieldDescriptor(mappedClass, fieldName, descriptorRepositories); if (fd != null) { if (fd.isLocking()) { return new NodeData(new MarkerAnnotationExpr(new NameExpr(SIMPLE_NAME)), new ImportDeclaration(new QualifiedNameExpr(new NameExpr(PACKAGE), SIMPLE_NAME), false, false)); } } return null; } }
@Override protected NodeData getAnnotationNodes(String enclosingClass, String fieldName, String mappedClass) { final List<Expression> joinColumns = getJoinColumns(enclosingClass, fieldName, mappedClass); if (joinColumns != null && joinColumns.size() == 1) { return new NodeData((AnnotationExpr) joinColumns.get(0), new ImportDeclaration(new QualifiedNameExpr(new NameExpr(PACKAGE), SIMPLE_NAME), false, false)); } return null; } }
@Override protected NodeData getAnnotationNodes(String enclosingClass, String fieldName, String mappedClass) { final List<Expression> joinColumns = getJoinColumns(enclosingClass, fieldName, mappedClass); if (joinColumns != null && joinColumns.size() == 1) { return new NodeData((AnnotationExpr) joinColumns.get(0), 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 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; } }
@Override public 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 boolean mappedColumn = OjbUtil.isMappedColumn(mappedClass, ParserUtil.getFieldName(field), descriptorRepositories); if (!mappedColumn) { 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; 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; } }
private NodeAndImports<MethodDeclaration> createPrimaryKeyToString(Collection<FieldDescriptor> primaryKeyDescriptors) { final MethodDeclaration toString = new MethodDeclaration(ModifierSet.PUBLIC, new ClassOrInterfaceType("String"), "toString"); toString.setAnnotations(Collections.<AnnotationExpr>singletonList(new MarkerAnnotationExpr(new NameExpr("Override")))); Expression toStringBuilderExpr = new ObjectCreationExpr(null, new ClassOrInterfaceType("ToStringBuilder"), Collections.<Expression>singletonList(new ThisExpr())); for (FieldDescriptor f : primaryKeyDescriptors) { final List<Expression> args = new ArrayList<Expression>(); args.add(new StringLiteralExpr(f.getAttributeName())); args.add(new FieldAccessExpr(new ThisExpr(), f.getAttributeName())); toStringBuilderExpr = new MethodCallExpr(toStringBuilderExpr, "append", args); } toStringBuilderExpr = new MethodCallExpr(toStringBuilderExpr, "toString"); final BlockStmt toStringBody = new BlockStmt(Collections.<Statement>singletonList(new ReturnStmt(toStringBuilderExpr))); toString.setBody(toStringBody); return new NodeAndImports<MethodDeclaration>(toString, Collections.singleton(new ImportDeclaration(new QualifiedNameExpr(new NameExpr("org.apache.commons.lang.builder"), "ToStringBuilder"), false, false))); }
private AnnotationExpr createJoinColumn(FieldDescriptor thisField, FieldDescriptor itemField) { final List<MemberValuePair> pairs = new ArrayList<MemberValuePair>(); pairs.add(new MemberValuePair("name", new StringLiteralExpr(thisField.getColumnName()))); pairs.add(new MemberValuePair("referencedColumnName", new StringLiteralExpr(itemField.getColumnName()))); if (!isAnonymousFk(thisField)) { pairs.add(new MemberValuePair("insertable", new BooleanLiteralExpr(false))); pairs.add(new MemberValuePair("updatable", new BooleanLiteralExpr(false))); } // Per this page: https://forums.oracle.com/message/3923913 // the nullable attribute is a hint to the DDL generation, especially on fields like this. // Commenting this flag out for now as it's just "noise" in the annotation definitions // if (!isNullableFk(thisField)) { // pairs.add(new MemberValuePair("nullable", new BooleanLiteralExpr(false))); // } return new NormalAnnotationExpr(new NameExpr("JoinColumn"), pairs); }
@Override public Node visit(NameExpr _n, Object _arg) { Comment comment = cloneNodes(_n.getComment(), _arg); NameExpr r = new NameExpr( _n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn(), _n.getName() ); r.setComment(comment); return r; }
final public NameExpr Name() throws ParseException { NameExpr ret; jj_consume_token(IDENTIFIER); ret = new NameExpr(token.beginLine, token.beginColumn, token.endLine, token.endColumn, token.image); label_23: while (true) { if (jj_2_17(2)) { ; } else { break label_23; } jj_consume_token(DOT); jj_consume_token(IDENTIFIER); ret = new QualifiedNameExpr(ret.getBeginLine(), ret.getBeginColumn(), token.endLine, token.endColumn, ret, token.image); } {if (true) return ret;} throw new Error("Missing return statement in function"); }
final public NameExpr Name() throws ParseException { NameExpr ret; jj_consume_token(IDENTIFIER); ret = new NameExpr(token.beginLine, token.beginColumn, token.endLine, token.endColumn, token.image); label_23: while (true) { if (jj_2_17(2)) { ; } else { break label_23; } jj_consume_token(DOT); jj_consume_token(IDENTIFIER); ret = new QualifiedNameExpr(ret.getBeginLine(), ret.getBeginColumn(), token.endLine, token.endColumn, ret, token.image); } {if (true) return ret;} throw new Error("Missing return statement in function"); }