예제 #1
0
 @Override
 public void visit(SynchronizedStmt n, Object arg) {
   printer.print("synchronized (");
   n.getExpr().accept(this, arg);
   printer.print(") ");
   n.getBlock().accept(this, arg);
 }
예제 #2
0
 @Override
 public void visit(ArrayAccessExpr n, Object arg) {
   n.getName().accept(this, arg);
   printer.print("[");
   n.getIndex().accept(this, arg);
   printer.print("]");
 }
예제 #3
0
 @Override
 public void visit(CatchClause n, Object arg) {
   printer.print(" catch (");
   n.getExcept().accept(this, arg);
   printer.print(") ");
   n.getCatchBlock().accept(this, arg);
 }
예제 #4
0
 @Override
 public void visit(CastExpr n, Object arg) {
   printer.print("(");
   n.getType().accept(this, arg);
   printer.print(") ");
   n.getExpr().accept(this, arg);
 }
예제 #5
0
 @Override
 public void visit(VariableDeclaratorId n, Object arg) {
   printer.print(n.getName());
   for (int i = 0; i < n.getArrayCount(); i++) {
     printer.print("[]");
   }
 }
예제 #6
0
 @Override
 public void visit(WhileStmt n, Object arg) {
   printer.print("while (");
   n.getCondition().accept(this, arg);
   printer.print(") ");
   n.getBody().accept(this, arg);
 }
예제 #7
0
 @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);
 }
예제 #8
0
 @Override
 public void visit(SingleMemberAnnotationExpr n, Object arg) {
   printer.print("@");
   n.getName().accept(this, arg);
   printer.print("(");
   n.getMemberValue().accept(this, arg);
   printer.print(")");
 }
예제 #9
0
 @Override
 public void visit(SuperExpr n, Object arg) {
   if (n.getClassExpr() != null) {
     n.getClassExpr().accept(this, arg);
     printer.print(".");
   }
   printer.print("super");
 }
예제 #10
0
 @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);
 }
예제 #11
0
 @Override
 public void visit(ContinueStmt n, Object arg) {
   printer.print("continue");
   if (n.getId() != null) {
     printer.print(" ");
     printer.print(n.getId());
   }
   printer.print(";");
 }
예제 #12
0
 @Override
 public void visit(ReturnStmt n, Object arg) {
   printer.print("return");
   if (n.getExpr() != null) {
     printer.print(" ");
     n.getExpr().accept(this, arg);
   }
   printer.print(";");
 }
예제 #13
0
 @Override
 public void visit(BreakStmt n, Object arg) {
   printer.print("break");
   if (n.getId() != null) {
     printer.print(" ");
     printer.print(n.getId());
   }
   printer.print(";");
 }
예제 #14
0
 @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);
 }
예제 #15
0
 @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(";");
 }
예제 #16
0
 @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);
 }
예제 #17
0
 @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);
   }
 }
예제 #18
0
 @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(";");
 }
예제 #19
0
  @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);
  }
예제 #20
0
 /**
  * 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(")");
 }
예제 #21
0
 /**
  * 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(">");
   }
 }
예제 #22
0
 @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);
   }
 }
예제 #23
0
  @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("[]");
    }
  }
예제 #24
0
 /**
  * @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(");");
       }
     }
   }
 }
예제 #25
0
  @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;
    }
  }
예제 #26
0
 @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("}");
 }
예제 #27
0
 @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);
   }
 }
예제 #28
0
  @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;
    }
  }
예제 #29
0
 @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(" & ");
       }
     }
   }
 }
예제 #30
0
 @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("}");
 }