Example usage for com.google.gwt.core.ext.typeinfo JClassType isPrivate

List of usage examples for com.google.gwt.core.ext.typeinfo JClassType isPrivate

Introduction

In this page you can find the example usage for com.google.gwt.core.ext.typeinfo JClassType isPrivate.

Prototype

boolean isPrivate();

Source Link

Usage

From source file:com.gwtent.gen.reflection.ReflectAllInOneCreator.java

License:Apache License

private boolean addClassIfNotExists(JClassType classType, Reflectable setting) {
    //Add next line we can make sure we just append normal class type, always get from TypeOracle
    //not JParameterizedType or JTypeParameter etc...
    //RC2 we support ParameterizedType now.
    if (classType != null && classType.isParameterized() == null) {
        //         System.out.println("addClassIfNotExists: " + classType.getQualifiedSourceName());
        classType = this.typeOracle.findType(classType.getQualifiedSourceName());

    }/*  ww  w  .  j a  v  a 2s .c om*/

    //we just process public classes
    if ((classType == null) || (classType.isPrivate()) || (classType.isProtected())
            || (GeneratorHelper.isSystemClass(classType) && !classType.isPublic()))
        return false;

    //no need java.lang.class
    if (classType.getQualifiedSourceName().equals("java.lang.Class"))
        return false;

    if (candidateList.indexOf(classType.getErasedType()) < 0) {
        candidateList.add(classType.getErasedType());
        candidates.put(classType.getErasedType(), setting);
        return true;
    }

    return false;
}

From source file:com.smartgwt.rebind.CanvasMetaBeanFactoryGenerator.java

License:Open Source License

private boolean isEligibleForGeneration(JClassType classType) {
    // Abstract classses will probably be generated as superclasses anyway, but
    // we don't need to generate them from here.
    if (classType.isAbstract())
        return false;

    // Don't try to generate for classes declared private, since it won't work
    if (classType.isPrivate())
        return false;

    // We only generate factories for classes that have a no-arg constructor
    JConstructor constructor = classType.findConstructor(new JType[] {});
    if (constructor == null)
        return false;

    return true;//from   w w  w.j  a va  2s . co m
}

From source file:fr.onevu.gwt.uibinder.rebind.JClassTypeAdapter.java

License:Apache License

/**
 * Creates a mock GWT class type for the given Java class.
 *
 * @param clazz the java class//ww  w  . j a  v a2 s.  c o m
 * @return the gwt class
 */
public JClassType adaptJavaClass(final Class<?> clazz) {
    if (clazz.isPrimitive()) {
        throw new RuntimeException("Only classes can be passed to adaptJavaClass");
    }

    // First try the cache (also avoids infinite recursion if a type references
    // itself).
    JClassType type = adaptedClasses.get(clazz);
    if (type != null) {
        return type;
    }

    // Create and put in the cache
    type = createMock(JClassType.class);
    final JClassType finalType = type;
    adaptedClasses.put(clazz, type);

    // Adds behaviour for annotations and generics
    addAnnotationBehaviour(clazz, type);

    // TODO(rdamazio): Add generics behaviour

    // Add behaviour for getting methods
    expect(type.getMethods()).andStubAnswer(new IAnswer<JMethod[]>() {
        public JMethod[] answer() throws Throwable {
            // TODO(rdamazio): Check behaviour for parent methods
            Method[] realMethods = clazz.getDeclaredMethods();
            JMethod[] methods = new JMethod[realMethods.length];
            for (int i = 0; i < realMethods.length; i++) {
                methods[i] = adaptMethod(realMethods[i], finalType);
            }
            return methods;
        }
    });

    // Add behaviour for getting constructors
    expect(type.getConstructors()).andStubAnswer(new IAnswer<JConstructor[]>() {
        public JConstructor[] answer() throws Throwable {
            Constructor<?>[] realConstructors = clazz.getDeclaredConstructors();
            JConstructor[] constructors = new JConstructor[realConstructors.length];
            for (int i = 0; i < realConstructors.length; i++) {
                constructors[i] = adaptConstructor(realConstructors[i], finalType);
            }
            return constructors;
        }
    });

    // Add behaviour for getting fields
    expect(type.getFields()).andStubAnswer(new IAnswer<JField[]>() {
        public JField[] answer() throws Throwable {
            Field[] realFields = clazz.getDeclaredFields();
            JField[] fields = new JField[realFields.length];
            for (int i = 0; i < realFields.length; i++) {
                fields[i] = adaptField(realFields[i], finalType);
            }
            return fields;
        }
    });

    // Add behaviour for getting names
    expect(type.getName()).andStubReturn(clazz.getName());
    expect(type.getQualifiedSourceName()).andStubReturn(clazz.getCanonicalName());
    expect(type.getSimpleSourceName()).andStubReturn(clazz.getSimpleName());

    // Add modifier behaviour
    int modifiers = clazz.getModifiers();
    expect(type.isAbstract()).andStubReturn(Modifier.isAbstract(modifiers));
    expect(type.isFinal()).andStubReturn(Modifier.isFinal(modifiers));
    expect(type.isPublic()).andStubReturn(Modifier.isPublic(modifiers));
    expect(type.isProtected()).andStubReturn(Modifier.isProtected(modifiers));
    expect(type.isPrivate()).andStubReturn(Modifier.isPrivate(modifiers));

    // Add conversion behaviours
    expect(type.isArray()).andStubReturn(null);
    expect(type.isEnum()).andStubReturn(null);
    expect(type.isPrimitive()).andStubReturn(null);
    expect(type.isClassOrInterface()).andStubReturn(type);
    if (clazz.isInterface()) {
        expect(type.isClass()).andStubReturn(null);
        expect(type.isInterface()).andStubReturn(type);
    } else {
        expect(type.isClass()).andStubReturn(type);
        expect(type.isInterface()).andStubReturn(null);
    }
    expect(type.getEnclosingType()).andStubAnswer(new IAnswer<JClassType>() {
        public JClassType answer() throws Throwable {
            Class<?> enclosingClass = clazz.getEnclosingClass();
            if (enclosingClass == null) {
                return null;
            }

            return adaptJavaClass(enclosingClass);
        }
    });
    expect(type.getSuperclass()).andStubAnswer(new IAnswer<JClassType>() {
        public JClassType answer() throws Throwable {
            Class<?> superclass = clazz.getSuperclass();
            if (superclass == null) {
                return null;
            }

            return adaptJavaClass(superclass);
        }
    });

    // TODO(rdamazio): Mock out other methods as needed
    // TODO(rdamazio): Figure out what to do with reflections that GWT allows
    //                 but Java doesn't

    EasyMock.replay(type);
    return type;
}

From source file:org.lirazs.gbackbone.gen.reflection.ReflectAllInOneCreator.java

License:Apache License

private boolean addClassIfNotExists(JClassType classType, Reflectable setting) {
    //Add next line we can make sure we just append normal class type, always get from TypeOracle
    //not JParameterizedType or JTypeParameter etc...
    //RC2 we support ParameterizedType now.

    if (classType != null && classType.isParameterized() == null) {
        //         System.out.println("addClassIfNotExists: " + classType.getQualifiedSourceName());
        classType = this.typeOracle.findType(classType.getQualifiedSourceName());
    }//from   w  ww. j  av a2s . c  o  m

    //we just process public classes
    if ((classType == null) || (classType.isPrivate()) || (classType.isProtected())
            || (GeneratorHelper.isSystemClass(classType) && !classType.isPublic()))
        return false;

    String qualifiedSourceName = classType.getQualifiedSourceName();

    //no need java.lang.class
    if (qualifiedSourceName.equals("java.lang.Class"))
        return false;

    //no need for system or gwt core classes
    if (qualifiedSourceName.contains("java.lang") || qualifiedSourceName.contains("java.util")
            || qualifiedSourceName.contains("java.io") || qualifiedSourceName.contains("com.google.gwt"))
        return false;

    // if class is extending javascript object we cannot create reflection for it.
    if ((javascriptClassType != null && classType.isAssignableTo(javascriptClassType)))
        return false;

    if (candidateList.indexOf(classType.getErasedType()) < 0) {
        candidateList.add(classType.getErasedType());
        candidates.put(classType.getErasedType(), setting);
        return true;
    }

    return false;
}

From source file:rocket.generator.rebind.gwt.JRealClassOrJRawClassTypeTypeAdapter.java

License:Apache License

public Visibility getVisibility() {
    Visibility visibility = null;

    while (true) {
        final JClassType type = this.getJClassType();
        if (type.isPrivate()) {
            visibility = Visibility.PRIVATE;
            break;
        }//  w  w  w .  ja v a  2s .c  o  m
        if (type.isProtected()) {
            visibility = Visibility.PROTECTED;
            break;
        }
        if (type.isPublic()) {
            visibility = Visibility.PUBLIC;
            break;
        }
        visibility = Visibility.PACKAGE_PRIVATE;
        break;
    }

    return visibility;
}