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

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


  public static JMethod findQualifiedMethod(JProgram program, String methodName) {
    int pos = methodName.lastIndexOf('.');
    assertTrue(pos > 0);
    String typeName = methodName.substring(0, pos);
    String unqualMethodName = methodName.substring(pos + 1);
    JDeclaredType type = findDeclaredType(program, typeName);
    return findMethod(type, unqualMethodName);
  }
View Full Code Here


   * Finds a declared type by name. The type name may be short, e.g. <code>"Foo"</code>,
   * or fully-qualified, e.g. <code>"com.google.example.Foo"</code>. If a short
   * name is used, it must be unambiguous.
   */
  public static JDeclaredType findDeclaredType(JProgram program, String typeName) {
    JDeclaredType type = program.getFromTypeMap(typeName);
    if (type != null || typeName.indexOf('.') != -1) {
      return type;
    }
    // Do a slow lookup by short name.
    for (JDeclaredType checkType : program.getDeclaredTypes()) {
      if (!checkType.getShortName().equals(typeName)) {
        continue;
      }
      if (type != null) {
        fail("Ambiguous type reference '" + typeName + "' might be '"
            + type.getName() + "' or '" + checkType.getName()
            + "' (possibly more matches)");
      }
      type = checkType;
    }
    return type;
View Full Code Here

  }

  public void testBasic() throws UnableToCompleteException {
    JProgram program = compileSnippet("void", "test.Simple.FOO.toString();");

    JDeclaredType simple = findDeclaredType(program, "test.Simple");
    Set<JEnumField> enumFields = new HashSet<JEnumField>();
    for (JField field : simple.getFields()) {
      if (field instanceof JEnumField) {
        enumFields.add((JEnumField) field);
      }
    }
    assertEquals(3, enumFields.size());
View Full Code Here

    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[]",
View Full Code Here

  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");
    assertNotNull("Unknown type InsertedClass", insertedClassType);
  }
View Full Code Here

  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");
    assertNotNull("Unknown type InsertedClass", insertedClassType);
  }
View Full Code Here

  }

  // 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

      this.originalCode = originalCode;
      this.madeChanges = madeChanges;
    }

    public void classHasMethodSnippets(String className, List<String> expectedMethodSnippets) {
      JDeclaredType targetClass = findClass(className);

      Set<String> actualMethodSnippets = Sets.newHashSet();
      for (JMethod method : targetClass.getMethods()) {
        actualMethodSnippets.add(method.toString().trim());
      }

      assertTrue(actualMethodSnippets.containsAll(expectedMethodSnippets));
    }
View Full Code Here

    options.setEnableAssertions(true);
    JProgram jprogram = AstConstructor.construct(logger, state, options, config);

    // Add entry methods for entry points.
    for (String entryPoint : entryPoints) {
      JDeclaredType entryType = jprogram.getFromTypeMap(entryPoint);
      for (JMethod method : entryType.getMethods()) {
        if (method.isStatic() && JProgram.isClinit(method)) {
          jprogram.addEntryMethod(method);
        }
      }
    }
View Full Code Here

TOP

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

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.