Package com.google.gwt.dev.jjs.ast

Examples of com.google.gwt.dev.jjs.ast.JProgram


  public void testArrayClassCastabilityIsExhaustive() throws UnableToCompleteException {
    registerCompilableResources();

    // Compiles and gets a reference to the String[] type.
    JProgram program = compileSnippet("void", "", "", false);
    ComputeExhaustiveCastabilityInformation.exec(program, false);
    JDeclaredType stringType = program.getIndexedType("String");
    JArrayType stringArrayType = program.getTypeArray(stringType);

    // Verifies that String[] casts to the exhaustive list of related array types and Object.
    assertSourceCastsToTargets(program, stringArrayType, Sets.newHashSet("java.lang.String[]",
        "java.lang.CharSequence[]", "java.lang.Comparable[]", "java.lang.Object[]",
        "java.io.Serializable[]", "java.lang.Object", "java.io.Serializable",
View Full Code Here


    assertEquals(expectedTargetTypeNames, actualTargetTypeNames);
  }

  private void assertSourceCastsToTargets(String sourceTypeName,
      Set<String> expectedTargetTypeNames) throws UnableToCompleteException {
    JProgram program = compileSnippet("void", "", "", false);
    ComputeExhaustiveCastabilityInformation.exec(program, false);
    JDeclaredType sourceType = program.getIndexedType(sourceTypeName);
    assertSourceCastsToTargets(program, sourceType, expectedTargetTypeNames);
  }
View Full Code Here

       }
     });
  }

  public void testInsertedClass() throws UnableToCompleteException {
    JProgram program = compileSnippet("void", "new test.B().func();");

    // Make sure the compiled classes appeared.
    JDeclaredType bType = findDeclaredType(program, "test.B");
    assertNotNull("Unknown type B", bType);
    JDeclaredType insertedClassType = findDeclaredType(program, "myPackage.InsertedClass");
View Full Code Here

    JDeclaredType insertedClassType = findDeclaredType(program, "myPackage.InsertedClass");
    assertNotNull("Unknown type InsertedClass", insertedClassType);
  }

  public void testInsertedClass2() throws UnableToCompleteException {
    JProgram program = compileSnippet("void", "new test.B1().func();");

    // Make sure the compiled classes appeared.
    JDeclaredType bType = findDeclaredType(program, "test.B1");
    assertNotNull("Unknown type B1", bType);
    JDeclaredType insertedClassType = findDeclaredType(program, "myPackage.InsertedClass");
View Full Code Here

    assertNotNull("Unknown type InsertedClass", insertedClassType);
  }

  // Make sure regular code not using the AdditionalTypeProviderDelegate still works.
  public void testSimpleParse() throws UnableToCompleteException {
    JProgram program = compileSnippet("void", "new test.A();");
    JDeclaredType goodClassType = findDeclaredType(program, "test.A");
    assertNotNull("Unknown class A", goodClassType);
  }
View Full Code Here

    analyzeExpression("float[]", "new float[3]").createsObject().check();
  }

  private Result analyzeExpression(String type, String expression)
      throws UnableToCompleteException {
    JProgram program = compileSnippet(type, "return " + expression + ";");
    ExpressionAnalyzer ea = new ExpressionAnalyzer();
    JMethod mainMethod = findMainMethod(program);
    JMethodBody body = (JMethodBody) mainMethod.getBody();
    JReturnStatement returnStmt = (JReturnStatement) body.getStatements().get(0);
    ea.accept(returnStmt.getExpr());
View Full Code Here

    assertEquals(expected, testExpresssion.toSource());
  }

  private JExpression getExpression(String type, String expression)
      throws UnableToCompleteException {
    JProgram program = compileSnippet(type, "return " + expression + ";");
    JMethod mainMethod = findMainMethod(program);
    JMethodBody body = (JMethodBody) mainMethod.getBody();
    JReturnStatement returnStmt = (JReturnStatement) body.getStatements().get(0);
    return returnStmt.getExpr();
  }
View Full Code Here

      .replaceAll("([\\p{Punct}&&[^$]])\\s", "$1"); // removes whitespace succeeding symbols.
  }

  private JBlock getStatement(String statement)
      throws UnableToCompleteException {
    JProgram program = compileSnippet("void", statement);
    JMethod mainMethod = findMainMethod(program);
    JMethodBody body = (JMethodBody) mainMethod.getBody();
    return body.getBlock();
  }
View Full Code Here

    if (!returnType.equals("void")) {
      expressionSnippets[expressionSnippets.length - 1] =
          "return " + expressionSnippets[expressionSnippets.length - 1];
    }
    String snippet = Joiner.on(";\n").join(expressionSnippets) + ";\n";
    final JProgram program = compileSnippet(returnType, snippet);
    JMethod method = findMethod(program, MAIN_METHOD_NAME);
    JMethodBody body = (JMethodBody) method.getBody();
    JMultiExpression multi = new JMultiExpression(body.getSourceInfo());

    // Transform statement sequence into a JMultiExpression
View Full Code Here

  protected final Result optimizeMethod(final String methodName,
      final String mainMethodReturnType, final String... mainMethodSnippet)
      throws UnableToCompleteException {
    String snippet = Joiner.on("\n").join(mainMethodSnippet);
    JProgram program = compileSnippet(mainMethodReturnType, snippet);
    JMethod method = findMethod(program, methodName);
    boolean madeChanges = optimizeMethod(program, method);
    if (madeChanges && runDeadCodeElimination) {
      DeadCodeElimination.exec(program);
    }
View Full Code Here

TOP

Related Classes of com.google.gwt.dev.jjs.ast.JProgram

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.