@Override public void visit(SynchronizedStmt n, Object arg) { printer.print("synchronized ("); n.getExpr().accept(this, arg); printer.print(") "); n.getBlock().accept(this, arg); }
@Override public void visit(ArrayAccessExpr n, Object arg) { n.getName().accept(this, arg); printer.print("["); n.getIndex().accept(this, arg); printer.print("]"); }
@Override public void visit(CatchClause n, Object arg) { printer.print(" catch ("); n.getExcept().accept(this, arg); printer.print(") "); n.getCatchBlock().accept(this, arg); }
@Override public void visit(CastExpr n, Object arg) { printer.print("("); n.getType().accept(this, arg); printer.print(") "); n.getExpr().accept(this, arg); }
@Override public void visit(VariableDeclaratorId n, Object arg) { printer.print(n.getName()); for (int i = 0; i < n.getArrayCount(); i++) { printer.print("[]"); } }
@Override public void visit(WhileStmt n, Object arg) { printer.print("while ("); n.getCondition().accept(this, arg); printer.print(") "); n.getBody().accept(this, arg); }
@Override public void visit(ConditionalExpr n, Object arg) { n.getCondition().accept(this, arg); printer.print(" ? "); n.getThenExpr().accept(this, arg); printer.print(" : "); n.getElseExpr().accept(this, arg); }
@Override public void visit(SingleMemberAnnotationExpr n, Object arg) { printer.print("@"); n.getName().accept(this, arg); printer.print("("); n.getMemberValue().accept(this, arg); printer.print(")"); }
@Override public void visit(SuperExpr n, Object arg) { if (n.getClassExpr() != null) { n.getClassExpr().accept(this, arg); printer.print("."); } printer.print("super"); }
@Override public void visit(ForeachStmt n, Object arg) { printer.print("for ("); n.getVariable().accept(this, arg); printer.print(" : "); n.getIterable().accept(this, arg); printer.print(") "); n.getBody().accept(this, arg); }
@Override public void visit(ContinueStmt n, Object arg) { printer.print("continue"); if (n.getId() != null) { printer.print(" "); printer.print(n.getId()); } printer.print(";"); }
@Override public void visit(ReturnStmt n, Object arg) { printer.print("return"); if (n.getExpr() != null) { printer.print(" "); n.getExpr().accept(this, arg); } printer.print(";"); }
@Override public void visit(BreakStmt n, Object arg) { printer.print("break"); if (n.getId() != null) { printer.print(" "); printer.print(n.getId()); } printer.print(";"); }
@Override public void visit(ClassOrInterfaceType n, Object arg) { printAnnotations(n.getAnnotations(), arg); if (n.getScope() != null) { n.getScope().accept(this, arg); printer.print("."); } printer.print(n.getName()); printTypeArgs(n.getTypeArgs(), arg); }
@Override public void visit(AssertStmt n, Object arg) { printer.print("assert "); n.getCheck().accept(this, arg); if (n.getMessage() != null) { printer.print(" : "); n.getMessage().accept(this, arg); } printer.print(";"); }
@Override public void visit(MethodCallExpr n, Object arg) { if (n.getScope() != null) { n.getScope().accept(this, arg); printer.print("."); } printTypeArgs(n.getTypeArgs(), arg); printer.print(n.getName()); printArguments(n.getArgs(), arg); }
@Override public void visit(IfStmt n, Object arg) { printer.print("if ("); n.getCondition().accept(this, arg); printer.print(") "); n.getThenStmt().accept(this, arg); if (n.getElseStmt() != null) { printer.print(" else "); n.getElseStmt().accept(this, arg); } }
@Override public void visit(ImportDeclaration n, Object arg) { printer.print("import "); if (n.isStatic()) { printer.print("static "); } n.getName().accept(this, arg); if (n.isAsterisk()) { printer.print(".*"); } printer.printLn(";"); }
@Override public void visit(Parameter n, Object arg) { printAnnotations(n.getAnnotations(), arg); printModifiers(n.getModifiers()); n.getType().accept(this, arg); if (n.isVarArgs()) { printer.print("..."); } printer.print(" "); n.getId().accept(this, arg); }
/** * Print a list of method arguments in between parentheses. * * @param args method arguments * @param arg argument provided to the calling visitor method */ private void printArguments(List<Expression> args, Object arg) { printer.print("("); if (args != null) { for (Iterator<Expression> i = args.iterator(); i.hasNext(); ) { Expression e = i.next(); e.accept(this, arg); if (i.hasNext()) { printer.print(", "); } } } printer.print(")"); }
/** * Print a list of type parameters in between angle brackets. * * @param args type parameters * @param arg argument provided to the calling visitor method */ private void printTypeParameters(List<TypeParameter> args, Object arg) { if (args != null) { printer.print("<"); for (Iterator<TypeParameter> i = args.iterator(); i.hasNext(); ) { TypeParameter t = i.next(); t.accept(this, arg); if (i.hasNext()) { printer.print(", "); } } printer.print(">"); } }
@Override public void visit(WildcardType n, Object arg) { printAnnotations(n.getAnnotations(), arg); printer.print("?"); if (n.getExtends() != null) { printer.print(" extends "); n.getExtends().accept(this, arg); } if (n.getSuper() != null) { printer.print(" super "); n.getSuper().accept(this, arg); } }
@Override public void visit(ReferenceType n, Object arg) { printAnnotations(n.getAnnotations(), arg); n.getType().accept(this, arg); for (int i = 0; i < n.getArrayCount(); i++) { if (!n.getAnnotationsAtLevel(i).isEmpty()) { printer.print(" "); printAnnotations(n.getAnnotationsAtLevel(i), arg); } printer.print("[]"); } }
/** * @param srcWriter * @param type * @param parentVariable * @param added * @param iocContainerVariable * @param configurations */ private static void injectMethods( SourcePrinter srcWriter, JClassType type, String parentVariable, Set<String> added, String iocContainerVariable, Map<String, IocConfig<?>> configurations) { for (JMethod method : type.getMethods()) { Inject inject = method.getAnnotation(Inject.class); if (inject != null && !method.isStatic()) { String methodName = method.getName(); if (!added.contains(methodName + "()")) { added.add(methodName + "()"); JParameter[] parameters = method.getParameters(); List<String> params = new ArrayList<String>(); for (JParameter parameter : parameters) { JType parameterType = parameter.getType(); if ((parameterType.isPrimitive() != null)) { throw new IoCException( "IoC Error Method [" + methodName + "] from class [" + type.getQualifiedSourceName() + "] declares an invalid parameter. Primitive types are not allowed here"); } String variableName = "parameter_" + methodName + "_" + parameter.getName(); params.add(variableName); String injectionExpression = getParameterInjectionExpression(parameter, iocContainerVariable, configurations); srcWriter.println( parameterType.getQualifiedSourceName() + " " + variableName + " = " + injectionExpression + ";"); } srcWriter.print(parentVariable + "." + methodName + "("); boolean first = true; for (String param : params) { if (!first) { srcWriter.print(", "); } first = false; srcWriter.print(param); } srcWriter.println(");"); } } } }
@Override public void visit(UnaryExpr n, Object arg) { switch (n.getOperator()) { case positive: printer.print("+"); break; case negative: printer.print("-"); break; case inverse: printer.print("~"); break; case not: printer.print("!"); break; case preIncrement: printer.print("++"); break; case preDecrement: printer.print("--"); break; } n.getExpr().accept(this, arg); switch (n.getOperator()) { case posIncrement: printer.print("++"); break; case posDecrement: printer.print("--"); break; } }
@Override public void visit(SwitchStmt n, Object arg) { printer.print("switch("); n.getSelector().accept(this, arg); printer.printLn(") {"); if (n.getEntries() != null) { printer.indent(); for (SwitchEntryStmt e : n.getEntries()) { e.accept(this, arg); } printer.unindent(); } printer.print("}"); }
@Override public void visit(TryStmt n, Object arg) { printer.print("try "); n.getTryBlock().accept(this, arg); if (n.getCatchs() != null) { for (CatchClause c : n.getCatchs()) { c.accept(this, arg); } } if (n.getFinallyBlock() != null) { printer.print(" finally "); n.getFinallyBlock().accept(this, arg); } }
@Override public void visit(PrimitiveType n, Object arg) { printAnnotations(n.getAnnotations(), arg); switch (n.getType()) { case Boolean: printer.print("boolean"); break; case Byte: printer.print("byte"); break; case Char: printer.print("char"); break; case Double: printer.print("double"); break; case Float: printer.print("float"); break; case Int: printer.print("int"); break; case Long: printer.print("long"); break; case Short: printer.print("short"); break; } }
@Override public void visit(TypeParameter n, Object arg) { printAnnotations(n.getAnnotations(), arg); printer.print(n.getName()); if (n.getTypeBound() != null) { printer.print(" extends "); for (Iterator<ClassOrInterfaceType> i = n.getTypeBound().iterator(); i.hasNext(); ) { ClassOrInterfaceType c = i.next(); c.accept(this, arg); if (i.hasNext()) { printer.print(" & "); } } } }
@Override public void visit(ArrayInitializerExpr n, Object arg) { printer.print("{"); if (n.getValues() != null) { printer.print(" "); for (Iterator<Expression> i = n.getValues().iterator(); i.hasNext(); ) { Expression expr = i.next(); expr.accept(this, arg); if (i.hasNext()) { printer.print(", "); } } printer.print(" "); } printer.print("}"); }