Package com.google.gwt.dev.javac.typemodel

Examples of com.google.gwt.dev.javac.typemodel.JClassType


  public void testLookup() throws NotFoundException {
    JavaSourceParser parser = new JavaSourceParser();
    addGeneratedUnits(FOO);
    addGeneratedUnits(BAR);
    addGeneratedUnits(BAZ);
    JClassType string = state.getTypeOracle().getType("java.lang.String");
    JClassType foo = state.getTypeOracle().getType("test.Foo");
    parser.addSourceForType(foo, FOO);
    JClassType bar = state.getTypeOracle().getType("test.Bar");
    parser.addSourceForType(bar, BAR);
    JClassType baz = state.getTypeOracle().getType("test.Baz");
    parser.addSourceForType(baz, BAZ);
    JClassType baz1 = state.getTypeOracle().getType("test.Baz.Baz1");
    JClassType baz2 = state.getTypeOracle().getType("test.Baz.Baz2");
    JMethod method = foo.getMethod("value", new JType[]{
        string, JPrimitiveType.INT});
    String[] arguments = parser.getArguments(method);
    assertNotNull(arguments);
    assertEquals(2, arguments.length);
    assertEquals("a", arguments[0]);
    assertEquals("val", arguments[1]);
    method = bar.getMethod("value", new JType[]{string, JPrimitiveType.INT});
    arguments = parser.getArguments(method);
    assertNotNull(arguments);
    assertEquals(2, arguments.length);
    assertEquals("a", arguments[0]);
    assertEquals("val", arguments[1]);
    method = bar.getMethod("value", new JType[]{JPrimitiveType.INT});
    arguments = parser.getArguments(method);
    assertNotNull(arguments);
    assertEquals(1, arguments.length);
    assertEquals("val", arguments[0]);
    method = bar.getMethod("value", new JType[]{string});
    arguments = parser.getArguments(method);
    assertNotNull(arguments);
    assertEquals(1, arguments.length);
    assertEquals("a", arguments[0]);
    method = baz1.getMethod("value", new JType[]{JPrimitiveType.INT});
    arguments = parser.getArguments(method);
    assertNotNull(arguments);
    assertEquals(1, arguments.length);
    assertEquals("val", arguments[0]);
    method = baz1.getMethod("value", new JType[]{string});
    arguments = parser.getArguments(method);
    assertNotNull(arguments);
    assertEquals(1, arguments.length);
    assertEquals("a", arguments[0]);
    method = baz2.getMethod("value", new JType[]{JPrimitiveType.INT});
    arguments = parser.getArguments(method);
    assertNotNull(arguments);
    assertEquals(1, arguments.length);
    assertEquals("val", arguments[0]);
    method = baz2.getMethod("value", new JType[]{string});
    arguments = parser.getArguments(method);
    assertNotNull(arguments);
    assertEquals(1, arguments.length);
    assertEquals("a", arguments[0]);
  }
View Full Code Here


  }

  public void testParamNames() throws NotFoundException {
    JavaSourceParser parser = new JavaSourceParser();
    addGeneratedUnits(FOO_INT);
    JClassType string = state.getTypeOracle().getType("java.lang.String");
    JClassType fooInt = state.getTypeOracle().getType("test.FooInt");
    parser.addSourceForType(fooInt, FOO_INT);
    JMethod method = fooInt.getMethod("value", new JType[]{
        string, JPrimitiveType.INT});
    String[] arguments = parser.getArguments(method);
    assertNotNull(arguments);
    assertEquals(2, arguments.length);
    assertEquals("a", arguments[0]);
View Full Code Here

    // TODO(jat): meaningful tests besides no errors?
  }

  public void testOuter1Class() {
    resolveClassSignature(testOuter1, OUTER1_CLASS_SIG);
    JClassType superClass = testOuter1.getSuperclass();
    assertNotNull(superClass);
    assertNotNull(superClass.isParameterized());
    // TODO(jat): additional checks?
  }
View Full Code Here

    // TODO(jat): meaningful tests besides no errors?
  }

  public void testOuter2Class() {
    resolveClassSignature(testOuter2, OUTER2_CLASS_SIG);
    JClassType superClass = testOuter2.getSuperclass();
    assertNotNull(superClass);
    assertNotNull(superClass.isParameterized());
    // TODO(jat): additional checks?
  }
View Full Code Here

    // Called after visitClass has already been called, and we will
    // successively refine the class by going into its inner classes.
    assert returnTypeRef[0] != null;
    resolveGenerics();
    outerClass = (JClassType) returnTypeRef[0];
    JClassType searchClass = outerClass;
    try {
      JParameterizedType pt = searchClass.isParameterized();
      if (pt != null) {
        searchClass = pt.getBaseType();
      }
      returnTypeRef[0] = searchClass.getNestedType(innerName);
    } catch (NotFoundException e) {
      logger.log(TreeLogger.ERROR, "Unable to resolve inner class " + innerName
          + " in " + searchClass, e);
    }
  }
View Full Code Here

        if (actual != expected) {
          throw new IllegalStateException("Incorrect # of type parameters to "
              + genericType.getQualifiedBinaryName() + ": expected " + expected
              + ", actual=" + actual);
        }
        JClassType genericEnc = genericType.getEnclosingType();
        if (outer == null && genericEnc != null) {
          // Sometimes the signature is like Foo$Bar<H> even if Foo is a
          // generic class. The cases I have seen are where Foo's type
          // parameter is also named H and has the same bounds. That
          // manifests itself as getting visitClassType("Foo$Bar") and
          // then VisitTypeArgument/etc, rather than the usual
          // visitClassType("Foo"), visitTypeArgument/etc,
          // visitInnerClass("Bar"), visitTypeArgument/etc.
          //
          // So, in this case we have to build our own chain of enclosing
          // classes here, properly parameterizing any generics along the
          // way.
          // TODO(jat): more testing to validate this assumption
          JClassType[] outerArgs = null;
          JGenericType genericEncGeneric = genericEnc.isGenericType();
          if (genericEncGeneric != null) {
            JTypeParameter[] encTypeParams = genericEncGeneric.getTypeParameters();
            int n = encTypeParams.length;
            outerArgs = new JClassType[n];
            for (int i = 0; i < n; ++i) {
View Full Code Here

   *
   * @param method method to lookup parameter names for
   * @return array of argument names or null if no source is available
   */
  public synchronized String[] getArguments(JAbstractMethod method) {
    JClassType type = method.getEnclosingType();
    JClassType topType = getTopmostType(type);
    CompilationUnitDeclaration cud = getCudForTopLevelType(topType);
    if (cud == null) {
      return null;
    }
    TypeDeclaration jdtType = findType(cud, type.getQualifiedBinaryName());
View Full Code Here

      // Set the super type for non-interfaces
      if ((access & Opcodes.ACC_INTERFACE) == 0) {
        String superInternalName = classData.getSuperInternalName();
        assert Name.isInternalName(superInternalName);
        if (superInternalName != null) {
          JClassType superType = findByInternalName(superInternalName);
          if (superType == null || !resolveClass(logger, superType, context)) {
            logger.log(TreeLogger.WARN, "Unable to resolve supertype " + superInternalName);
            return false;
          }
          setSuperClass(unresolvedType, (JClassType) possiblySubstituteRawType(superType));
        }
      }

      // Set interfaces
      for (String interfaceInternalName : classData.getInterfaceInternalNames()) {
        JClassType interfaceType = findByInternalName(interfaceInternalName);
        if (interfaceType == null || !resolveClass(logger, interfaceType, context)) {
          logger.log(TreeLogger.WARN, "Unable to resolve interface " + interfaceInternalName);
          return false;
        }
        addImplementedInterface(
View Full Code Here

    } else {
      // Set the super type for non-interfaces
      if ((access & Opcodes.ACC_INTERFACE) == 0) {
        String superName = classData.getSuperName();
        if (superName != null) {
          JClassType superType = binaryMapper.get(superName);
          if (superType == null || !resolveClass(logger, superType, context)) {
            logger.log(TreeLogger.WARN, "Unable to resolve supertype "
                + superName);
            return false;
          }
          setSuperClass(type, (JClassType) possiblySubstituteRawType(superType));
        }
      }

      // Set interfaces
      for (String intfName : classData.getInterfaces()) {
        JClassType intf = binaryMapper.get(intfName);
        if (intf == null || !resolveClass(logger, intf, context)) {
          logger.log(TreeLogger.WARN, "Unable to resolve interface " + intfName);
          return false;
        }
        addImplementedInterface(type,
View Full Code Here

    // Called after visitClass has already been called, and we will
    // successively refine the class by going into its inner classes.
    assert returnTypeRef[0] != null;
    resolveGenerics();
    outerClass = (JClassType) returnTypeRef[0];
    JClassType searchClass = outerClass;
    try {
      JParameterizedType pt = searchClass.isParameterized();
      if (pt != null) {
        searchClass = pt.getBaseType();
      }
      returnTypeRef[0] = searchClass.getNestedType(innerName);
    } catch (NotFoundException e) {
      logger.log(TreeLogger.ERROR, "Unable to resolve inner class " + innerName
          + " in " + searchClass, e);
    }
  }
View Full Code Here

TOP

Related Classes of com.google.gwt.dev.javac.typemodel.JClassType

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.