public String createFullQualifiedSignature(MethodDecl method) { StringBuffer buffer = new StringBuffer(); buffer.append(method.getModifiers()).append(' '); getFullQualifiedNameInt(buffer, method.type()); buffer.append(' '); getFullQualifiedNameInt(buffer, method.hostType()); buffer.append('.'); buffer.append(method.signature()); return buffer.toString(); }
private LayerMemberSets collectPartialMethods() { Set<MethodDecl> partialMethods = new HashSet<MethodDecl>(); Set<BodyDecl> otherMembers = new HashSet<BodyDecl>(); for (BodyDecl decl : this.layerDecl.getBodyDeclList()) { if ((decl instanceof MethodDecl)) { MethodDecl layerMethod = (MethodDecl) decl; if (layerMethod.isPartialMethod()) { partialMethods.add(layerMethod); } else { layerMethod.setModifiers(this.gen.createPublicModifierFor(layerMethod)); otherMembers.add(decl); } } else otherMembers.add(decl); } return new LayerMemberSets(partialMethods, otherMembers); }
private void transformPartialMethod(MethodDecl partialMethod) { PartialMethodTransformer pmdTransformer; try { if (isSourceFile(partialMethod)) { pmdTransformer = new PartialMethodSourceTransformer(layerDecl, partialMethod); } else pmdTransformer = new PartialMethodClassTransformer(layerDecl, partialMethod); MethodDecl m = pmdTransformer.transform(); TypeDecl host = partialMethod.hostType(); host.addBodyDecl(m); host.resetCache(); } catch (Exception e) { System.out.println("error in layer decl"); } }
@Override public void visit(MethodDecl method) { System.out.print("public "); if (method.getReturnType() != null) method.getReturnType().accept(this); System.out.print(" "); if (method.getId() != null) method.getId().accept(this); System.out.print(" ("); if (method.getParams() != null) { for (int i = 0; i < method.getParams().size(); i++) { if (method.getParams().elementAt(i) == null) continue; method.getParams().elementAt(i).accept(this); if (i < method.getParams().size() - 1) System.out.print(", "); } } System.out.println(") {"); if (method.getVars() != null) { for (int i = 0; i < method.getVars().size(); i++) { if (method.getVars().elementAt(i) == null) continue; System.out.print("\t\t"); method.getVars().elementAt(i).accept(this); System.out.println(); } } if (method.getStms() != null) { for (int i = 0; i < method.getStms().size(); i++) { if (method.getStms().elementAt(i) == null) continue; System.out.print("\t\t"); method.getStms().elementAt(i).accept(this); System.out.println(); } } System.out.print("\t\treturn "); if (method.getReturnExp() != null) method.getReturnExp().accept(this); System.out.println(";"); System.out.println("\t}"); }
/** * generate {@link AST.Stmt Stmt} for {@link AST.MethodDecl MethodDecl}. if return value of {@code * <decl>} is void, generate {@link AST.ExprStmt ExprStmt}, otherwise, generate {@link * AST.ReturnStmt ReturnStmt} * * @param decl * @param expr * @return */ public Stmt maybeGenerateReturnStmt(MethodDecl decl, Expr expr) { if (decl.isVoid()) return new ExprStmt(expr); else return new ReturnStmt(expr); }
private boolean isSourceFile(MethodDecl partialMethod) { return partialMethod.hostType().compilationUnit().fromSource(); }