Java Code Examples for com.google.gwt.core.ext.typeinfo.JClassType#getSuperclass()

The following examples show how to use com.google.gwt.core.ext.typeinfo.JClassType#getSuperclass() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InjectCreatorUtil.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static Collection<JField> listFields(JClassType type, Class<? extends Annotation> annotationClass) {
	Collection<JField> methodAnnoted = Lists.newArrayList();
	JField[] fields = type.getFields();
	for (JField field : fields) {
		Annotation annotation = field.getAnnotation(annotationClass);
		if (annotation != null) {
			methodAnnoted.add(field);
		}
	}
	// Recurse to superclass
	JClassType superclass = type.getSuperclass();
	if (superclass != null) {
		methodAnnoted.addAll(InjectCreatorUtil.listFields(superclass, annotationClass));
	}

	return methodAnnoted;
}
 
Example 2
Source File: TextBinderGenerator.java    From EasyML with Apache License 2.0 5 votes vote down vote up
/**
 * Generate method bind
 */
private void composeBindMethod(TreeLogger logger, SourceWriter sourceWriter) {

	logger.log(TreeLogger.INFO, "");
	String line = "public void bind("
			+ parameterizedType1.getQualifiedSourceName() + " text, "
			+ parameterizedType2.getQualifiedSourceName() + " obj){";
	sourceWriter.println(line);
	logger.log(TreeLogger.INFO, line);

	line = "  System.out.println(\"Implement it now:)\");";
	sourceWriter.println(line);
	logger.log(TreeLogger.INFO, line);

	ArrayList<JField> fields = new ArrayList<JField>();

	JClassType curtype = parameterizedType2;
	do {

		for (JField filed : curtype.getFields()) {
			fields.add(filed);
		}
		curtype = curtype.getSuperclass();
	} while (!curtype.getName().equals("Object"));

	for (JField field : fields) {
		String name = field.getName();
		String Name = name.substring(0, 1).toUpperCase() + name.substring(1);
		line = " text.setText(\"" + name + "\", obj.get" + Name
				+ "().toString() );";
		sourceWriter.println(line);
		logger.log(TreeLogger.INFO, line);

	}
	line = "}";

	sourceWriter.println(line);
	logger.log(TreeLogger.INFO, line);

}
 
Example 3
Source File: DecoratorPresenterCreatorFactory.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 5 votes vote down vote up
private boolean isAssignableFrom(JClassType type, Class<?> clazz) {
	if (type.getQualifiedSourceName().equals(clazz.getName())) {
		return true;
	}
	if (type.getSuperclass() == null) {
		return false;
	}
	return this.isAssignableFrom(type.getSuperclass(), clazz);
}
 
Example 4
Source File: CreatorUtils.java    From gwt-jackson with Apache License 2.0 5 votes vote down vote up
/**
 * Browse all the hierarchy of the type and return the first corresponding annotation it found
 *
 * @param type type
 * @param annotation annotation to find
 * @param <T> type of the annotation
 * @param ignoreType type to ignore when browsing the hierarchy
 *
 * @return the annotation if found, null otherwise
 */
private static <T extends Annotation> Optional<T> findFirstEncounteredAnnotationsOnAllHierarchy( RebindConfiguration configuration,
                                                                                                JClassType type, Class<T> annotation,
                                                                                                Optional<JClassType> ignoreType ) {
    JClassType currentType = type;
    while ( null != currentType ) {
        Optional<JClassType> mixin = configuration.getMixInAnnotations( currentType );
        if ( mixin.isPresent() && mixin.get().isAnnotationPresent( annotation ) ) {
            return Optional.of( mixin.get().getAnnotation( annotation ) );
        }
        if ( currentType.isAnnotationPresent( annotation ) ) {
            return Optional.of( currentType.getAnnotation( annotation ) );
        }
        for ( JClassType interf : currentType.getImplementedInterfaces() ) {
            if (!ignoreType.isPresent() || !ignoreType.get().equals( interf )) {
                Optional<T> annot = findFirstEncounteredAnnotationsOnAllHierarchy( configuration, interf, annotation );
                if ( annot.isPresent() ) {
                    return annot;
                }
            }
        }
        currentType = currentType.getSuperclass();
        if ( ignoreType.isPresent() && ignoreType.get().equals( currentType ) ) {
            currentType = null;
        }
    }
    return Optional.absent();
}
 
Example 5
Source File: BeanProcessor.java    From gwt-jackson with Apache License 2.0 5 votes vote down vote up
private static String findNameOnJsonSubTypes( JClassType baseType, JClassType subtype, ImmutableList<JClassType> allSubtypes,
                                              Optional<JsonSubTypes> propertySubTypes, Optional<JsonSubTypes> baseSubTypes ) {
    JsonSubTypes.Type typeFound = findTypeOnSubTypes( subtype, propertySubTypes );
    if ( null != typeFound ) {
        return typeFound.name();
    }

    typeFound = findTypeOnSubTypes( subtype, baseSubTypes );
    if ( null != typeFound ) {
        return typeFound.name();
    }

    if ( baseType != subtype ) {
        // we look in all the hierarchy
        JClassType type = subtype;
        while ( null != type ) {
            if ( allSubtypes.contains( type ) ) {
                JsonSubTypes.Type found = findTypeOnSubTypes( subtype, Optional.fromNullable( type
                        .getAnnotation( JsonSubTypes.class ) ) );
                if ( null != found ) {
                    typeFound = found;
                }
            }
            type = type.getSuperclass();
        }

        if ( null != typeFound ) {
            return typeFound.name();
        }
    }

    return null;
}
 
Example 6
Source File: TextBinderGenerator.java    From EasyML with Apache License 2.0 4 votes vote down vote up
/**
 * Generate method sync
 */
private void composeSyncMethod(TreeLogger logger, SourceWriter sourceWriter) {

	logger.log(TreeLogger.INFO, "");
	String line = "public void sync("
			+ parameterizedType1.getQualifiedSourceName() + " text, "
			+ parameterizedType2.getQualifiedSourceName() + " obj){";
	sourceWriter.println(line);
	logger.log(TreeLogger.INFO, line);

	line = "  System.out.println(\"Implement it now:)\");";
	sourceWriter.println(line);
	logger.log(TreeLogger.INFO, line);

	ArrayList<JField> fields = new ArrayList<JField>();

	JClassType curtype = parameterizedType2;
	do {

		for (JField filed : curtype.getFields()) {
			fields.add(filed);
		}
		curtype = curtype.getSuperclass();
	} while (!curtype.getName().equals("Object"));

	for (JField field : fields) {
		String name = field.getName();
		String Name = name.substring(0, 1).toUpperCase() + name.substring(1);
		String type = field.getType().getQualifiedSourceName();
		String simType = field.getType().getSimpleSourceName();
		if ("java.lang.String".equals(type))
			line = " if( text.getText(\"" + name + "\") != null )obj.set" + Name
			+ "( text.getText(\"" + name + "\") );";
		else
			line = " if( text.getText(\"" + name + "\") != null )obj.set" + Name
			+ "( " + type + ".parse" + simType + "( text.getText(\"" + name
			+ "\")) );";

		sourceWriter.println(line);
		logger.log(TreeLogger.INFO, line);

	}
	line = "}";

	sourceWriter.println(line);
	logger.log(TreeLogger.INFO, line);

}