Package com.google.gwt.core.ext.typeinfo

Examples of com.google.gwt.core.ext.typeinfo.JClassType


    }

    JClassType[] typeArgs = paramType.getTypeArgs();

    assert typeArgs.length == 1;
    JClassType toReturn = typeArgs[0].isClassOrInterface();
    if (toReturn == null) {
      logger.log(TreeLogger.ERROR,
          "A Gadget's UserPreferences type must be an interface", null);
      throw new UnableToCompleteException();
    }
View Full Code Here


    Content content = gadgetSourceType.getAnnotation(Content.class);
    if (content != null) {
      for (Class<? extends ContentSection<?>> contentSectionClass : content.contents()) {
        String viewTypeName = contentSectionClass.getName().replaceAll("\\$",
            ".");
        JClassType viewType = typeOracle.findType(viewTypeName);
        if (viewType != null) {
          ContentType contentType = viewType.getAnnotation(ContentType.class);
          result.add(new GadgetViewType(contentType.views(), viewType));
        } else {
          logger.log(TreeLogger.ERROR, "Unable to find view type: "
              + viewTypeName);
          throw new UnableToCompleteException();
View Full Code Here

            }
        };

        stubPassingField(field, mock(JClassType.class), "field");

        JClassType ownerTypeParent = mock(JClassType.class);
        Set<? extends JClassType> ownerTypeFlattenedSupertypeHierarchy = new HashSet<JClassType>(
                Arrays.asList(ownerType, ownerTypeParent));
        doReturn(ownerTypeFlattenedSupertypeHierarchy).when(ownerType).getFlattenedSupertypeHierarchy();
        when(ownerType.getFields()).thenReturn(new JField[] { ownerTypeField1, ownerTypeField2 });
        when(ownerTypeParent.getFields()).thenReturn(new JField[] { ownerTypeParentField });
        when(ownerType.getName()).thenReturn("OwnerTypeName");

        JClassType ownerTypeParentFieldType = mock(JClassType.class, "ownerTypeParentFieldType");
        stubPassingField(ownerTypeField1, mock(JClassType.class), "ownerTypeField1");
        stubPassingField(ownerTypeField2, mock(JClassType.class), "ownerTypeField2");
        stubPassingField(ownerTypeParentField, ownerTypeParentFieldType, "ownerTypeParentField");

        Set<? extends JClassType> ownerTypeParentFieldTypeFlattenedSupertypeHierarchy = new HashSet<JClassType>(
                Arrays.asList(ownerTypeParentFieldType));
        doReturn(ownerTypeParentFieldTypeFlattenedSupertypeHierarchy).when(ownerTypeParentFieldType)
                .getFlattenedSupertypeHierarchy();
        when(ownerTypeParentFieldType.getFields()).thenReturn(new JField[] {
                ownerTypeParentFieldTypeSubField1, ownerTypeParentFieldTypeSubField2 });

        stubPassingField(ownerTypeParentFieldTypeSubField1, ownerTypeParentFieldTypeSubField1Type,
                "ownerTypeParentFieldTypeSubField1");
        stubPassingField(ownerTypeParentFieldTypeSubField2, mock(JClassType.class),
View Full Code Here

        verifyProcessFieldReturns(true);
    }

    @Test
    public void processFieldPrimitiveType() {
        JClassType fieldType = mock(JClassType.class);
        when(field.getType()).thenReturn(fieldType);
        when(fieldType.isClass()).thenReturn(null);
        verifyProcessFieldReturns(false);
    }
View Full Code Here

public class XsrfRpcProxyGeneratorTest {

    /** Test createProxyCreator() for an annotated class. */
    @Test public void testCreateProxyCreatorAnnotated() {
        XsrfRpcProxyGenerator generator = new XsrfRpcProxyGenerator();
        JClassType remoteService = mock(JClassType.class);
        when(remoteService.isAnnotationPresent(XsrfProtect.class)).thenReturn(true);
        ProxyCreator creator = generator.createProxyCreator(remoteService);
        assertTrue(creator instanceof XsrfRpcProxyCreator);
    }
View Full Code Here

    }

    /** Test createProxyCreator() for a class that's not annotated. */
    @Test public void testCreateProxyCreatorNotAnnotated() {
        XsrfRpcProxyGenerator generator = new XsrfRpcProxyGenerator();
        JClassType remoteService = mock(JClassType.class);
        when(remoteService.isAnnotationPresent(XsrfProtect.class)).thenReturn(false);
        ProxyCreator creator = generator.createProxyCreator(remoteService);
        assertTrue(creator instanceof XsrfRpcProxyCreator)// decision is down in creator itself
    }
View Full Code Here

*/
public class XsrfRpcProxyCreatorTest {

    /** Test getProxySupertype(). */
    @Test public void testGetProxySuperType() {
        JClassType type = mock(JClassType.class);
        XsrfRpcProxyCreator creator = new XsrfRpcProxyCreator(type);
        assertEquals(XsrfRpcProxy.class, creator.getProxySupertype());
        assertSame(type, creator.getType());
    }
View Full Code Here

    }

    /** Test isMethodXsrfProtected(). */
    @Test public void testIsMethodXsrfProtected() {
        // Declare some standard classes
        JClassType protectedType = mock(JClassType.class);
        when(protectedType.isAnnotationPresent(XsrfProtect.class)).thenReturn(true);
        when(protectedType.isAnnotationPresent(NoXsrfProtect.class)).thenReturn(false);

        JClassType notProtectedType = mock(JClassType.class);
        when(notProtectedType.isAnnotationPresent(XsrfProtect.class)).thenReturn(false);
        when(notProtectedType.isAnnotationPresent(NoXsrfProtect.class)).thenReturn(true);

        JClassType noAnnotationType = mock(JClassType.class);
        when(noAnnotationType.isAnnotationPresent(XsrfProtect.class)).thenReturn(false);
        when(noAnnotationType.isAnnotationPresent(NoXsrfProtect.class)).thenReturn(false);

        JClassType bothAnnotationType = mock(JClassType.class);
        when(bothAnnotationType.isAnnotationPresent(XsrfProtect.class)).thenReturn(true);
        when(bothAnnotationType.isAnnotationPresent(NoXsrfProtect.class)).thenReturn(true);

        // Declare some standard methods
        JMethod protectedMethod = mock(JMethod.class);
        when(protectedMethod.isAnnotationPresent(XsrfProtect.class)).thenReturn(true);
        when(protectedMethod.isAnnotationPresent(NoXsrfProtect.class)).thenReturn(false);
View Full Code Here

        assertEquals(expected, actual);
    }

    /** Create a fully mocked XsrfRpcProxyCreator that will work for tests. */
    private static XsrfRpcProxyCreator createMockedCreator() {
        JClassType classOrInterface = mock(JClassType.class, Mockito.RETURNS_DEEP_STUBS);
        when(classOrInterface.getName()).thenReturn("IExchangeRpc");
        when(classOrInterface.getPackage().getName()).thenReturn("com.cedarsolutions.santa.client.rpc");

        JType leafType = mock(JType.class);
        when(leafType.isPrimitive()).thenReturn(null);
        when(leafType.isClassOrInterface()).thenReturn(classOrInterface);

        JClassType type = mock(JClassType.class);
        when(type.getLeafType()).thenReturn(leafType);
        when(type.getQualifiedSourceName()).thenReturn("IExchangeRpc");

        return new XsrfRpcProxyCreator(type);
    }
View Full Code Here

    @Override
    public String generate(TreeLogger logger, GeneratorContext context,
            String typeName) throws UnableToCompleteException {
        TypeOracle oracle = context.getTypeOracle();
        JClassType toGenerate = oracle.findType(typeName).isInterface();
        if (toGenerate == null) {
            logger.log(TreeLogger.ERROR, typeName + " is not an interface type");
            throw new UnableToCompleteException();
        }

        ElementIdTypeParser parser = new ElementIdTypeParser(logger, toGenerate);
        ElementIdStatement[] statements = parser.parseStatements();

        String packageName = toGenerate.getPackage().getName();
        String simpleSourceName = toGenerate.getName().replace('.', '_')
                + "Impl";
        PrintWriter pw = context.tryCreate(logger, packageName,
                simpleSourceName);
        if (pw == null) {
            return packageName + "." + simpleSourceName;
        }

        JClassType superclass = oracle.findType(
                BaseElementIdHandler.class.getName()).isClass();
        assert superclass != null : "No BaseElementIdHandler type";

        ClassSourceFileComposerFactory factory = new ClassSourceFileComposerFactory(
                packageName, simpleSourceName);
        factory.setSuperclass(superclass.getQualifiedSourceName() + "<"
                + parser.getOwnerType().getParameterizedQualifiedSourceName()
                + ">");
        factory.addImplementedInterface(typeName);

        SourceWriter sw = factory.createSourceWriter(context, pw);
View Full Code Here

TOP

Related Classes of com.google.gwt.core.ext.typeinfo.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.