本文整理汇总了Java中com.google.gwt.core.ext.typeinfo.JType.isClassOrInterface方法的典型用法代码示例。如果您正苦于以下问题:Java JType.isClassOrInterface方法的具体用法?Java JType.isClassOrInterface怎么用?Java JType.isClassOrInterface使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.gwt.core.ext.typeinfo.JType
的用法示例。
在下文中一共展示了JType.isClassOrInterface方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: implementsInterface
import com.google.gwt.core.ext.typeinfo.JType; //导入方法依赖的package包/类
private boolean implementsInterface( JType type, String interfaceName )
{
if( type.getQualifiedSourceName().equals( interfaceName ) )
return true;
JClassType c = type.isClassOrInterface();
if( c != null )
{
JType[] interfaces = c.getImplementedInterfaces();
for( int i = 0; i < interfaces.length; i++ )
if( interfaces[i].getSimpleSourceName().equals( interfaceName ) || interfaces[i].getQualifiedSourceName().equals( interfaceName ) )
return true;
return false;
}
return false;
}
示例2: isPropertyIgnored
import com.google.gwt.core.ext.typeinfo.JType; //导入方法依赖的package包/类
private static boolean isPropertyIgnored( RebindConfiguration configuration, PropertyAccessors propertyAccessors, BeanInfo beanInfo,
JType type, String propertyName ) {
// we first check if the property is ignored
Optional<JsonIgnore> jsonIgnore = propertyAccessors.getAnnotation( JsonIgnore.class );
if ( jsonIgnore.isPresent() && jsonIgnore.get().value() ) {
return true;
}
// if type is ignored, we ignore the property
if ( null != type.isClassOrInterface() ) {
Optional<JsonIgnoreType> jsonIgnoreType = findFirstEncounteredAnnotationsOnAllHierarchy( configuration, type
.isClassOrInterface(), JsonIgnoreType.class );
if ( jsonIgnoreType.isPresent() && jsonIgnoreType.get().value() ) {
return true;
}
}
// we check if it's not in the ignored properties
return beanInfo.getIgnoredFields().contains( propertyName );
}
示例3: isIntrospectable
import com.google.gwt.core.ext.typeinfo.JType; //导入方法依赖的package包/类
private boolean isIntrospectable(TreeLogger logger, JType type) {
if (type == null) {
return false;
}
JClassType ct = type.isClassOrInterface();
if (ct != null) {
if (ct.getAnnotation(Introspectable.class) != null) {
return true;
}
for (JClassType iface : ct.getImplementedInterfaces()) {
if (isIntrospectable(logger, iface)) {
return true;
}
}
if (isIntrospectable(logger, ct.getSuperclass())) {
return true;
}
}
return false;
}
示例4: generateDependenciesForExtension
import com.google.gwt.core.ext.typeinfo.JType; //导入方法依赖的package包/类
/**
* Writes dependency gathering code, like:
*
* <p>Array<DependencyDescription> deps = Collections.<DependencyDescription> createArray();
* deps.add(new DependencyDescription("ide.api.ui.menu", "")); deps.add(new
* DependencyDescription("extension.demo", "1.0.0-alpha"));
*
* @param sw
* @param extension
* @throws UnableToCompleteException
*/
private void generateDependenciesForExtension(SourceWriter sw, JClassType extension)
throws UnableToCompleteException {
// expected code
/*
Array<DependencyDescription> deps = Collections.<DependencyDescription> createArray();
deps.add(new DependencyDescription("ide.api.ui.menu", ""));
*/
if (extension.getConstructors().length == 0) {
throw new UnableToCompleteException();
}
sw.println("List<DependencyDescription> deps = new ArrayList<>();");
JConstructor jConstructor = extension.getConstructors()[0];
JType[] parameterTypes = jConstructor.getParameterTypes();
for (JType jType : parameterTypes) {
JClassType argType = jType.isClassOrInterface();
if (argType != null
&& (argType.isAnnotationPresent(SDK.class)
|| argType.isAnnotationPresent(Extension.class))) {
String id = "";
String version = "";
if (argType.isAnnotationPresent(SDK.class)) {
id = argType.getAnnotation(SDK.class).title();
} else if (argType.isAnnotationPresent(Extension.class)) {
id = argType.getQualifiedSourceName();
version = argType.getAnnotation(Extension.class).version();
}
sw.println(
"deps.add(new DependencyDescription(\"%s\", \"%s\"));", escape(id), escape(version));
}
}
}
示例5: isInteresting
import com.google.gwt.core.ext.typeinfo.JType; //导入方法依赖的package包/类
/**
* @param returnType
* @param modelInterface
* @return
*/
private boolean isInteresting(final JType returnType, final JClassType modelInterface) {
if (returnType.isArray() != null) {
// All arrays are interesting, as we must prime java.lang.reflect.Array for runtime support
return true;
}
final JClassType asClass = returnType.isClassOrInterface();
if (asClass == null) {
return false;
}
// All model classes are interesting.
return asClass.isAssignableTo(modelInterface);
}
示例6: isCollectionOrMapType
import com.google.gwt.core.ext.typeinfo.JType; //导入方法依赖的package包/类
private boolean isCollectionOrMapType(JType jType){
if(jType == null) return false;
JClassType jClassType = jType.isClassOrInterface();
if(jClassType == null) return false;
for(JClassType possibleSuperType : collectionOrMap){
if(jClassType.isAssignableTo(possibleSuperType)){
return true;
}
}
return false;
}
示例7: implementInterestingTypes
import com.google.gwt.core.ext.typeinfo.JType; //导入方法依赖的package包/类
/**
* Print magic method initialization for all interesting types;
* <p>
* Currently, this will call Array.newInstance(Component.class, 0) for all array types,
* thus initializing the model Class's ability to instantiate the arrays it requires,
* plus calls X_Model.register(DependentModel.class) on all model types used as fields of
* the current model type; thus ensuring all children will be fully de/serializable.
*
*/
private void implementInterestingTypes(final JClassType type, final ClassBuffer out, final JClassType modelInterface,
final Set<JType> interestingTypes) {
interestingTypes.remove(type);
if (interestingTypes.isEmpty()) {
return;
}
out
.outdent()
.println("// Initialize our referenced array / model types")
.println("static {")
.indent();
for (JType interestingType : interestingTypes) {
if (interestingType.isArray() != null) {
// Print a primer for runtime array reflection.
final JType componentType = interestingType.isArray().getComponentType();
final String array = out.addImport(Array.class);
String component = out.addImport(componentType.getQualifiedSourceName());
interestingType = componentType;
while (interestingType.isArray() != null) {
interestingType = interestingType.isArray().getComponentType();
component += "[]";
}
out.println(array+".newInstance("+component+".class, 0);");
}
final JClassType asClass = interestingType.isClassOrInterface();
if (asClass != null) {
if (asClass.isAssignableTo(modelInterface)) {
// We have a model type; so long as it is not the same type that we are currently generating,
// we want to print X_Model.register() for the given type, so we can inherit all model types
// that are referenced as fields of the current model type.
if (!type.getName().equals(asClass.getName())) {
final String referencedModel = out.addImport(asClass.getQualifiedSourceName());
final String X_Model = out.addImport(X_Model.class);
out.println(X_Model+".register("+referencedModel+".class);");
}
}
}
}
out.outdent().println("}");
}
示例8: extractBeanType
import com.google.gwt.core.ext.typeinfo.JType; //导入方法依赖的package包/类
/**
* Extract the bean type from the type given in parameter. For {@link java.util.Collection}, it gives the bounded type. For {@link
* java.util.Map}, it gives the second bounded type. Otherwise, it gives the type given in parameter.
*
* @param type type to extract the bean type
* @param propertyName name of the property
*
* @return the extracted type
*/
private static Optional<JClassType> extractBeanType( TreeLogger logger, JacksonTypeOracle typeOracle, JType type, String propertyName
) {
if ( null != type.isWildcard() ) {
// we use the base type to find the serializer to use
type = type.isWildcard().getBaseType();
}
if ( null != type.isRawType() ) {
type = type.isRawType().getBaseType();
}
JArrayType arrayType = type.isArray();
if ( null != arrayType ) {
return extractBeanType( logger, typeOracle, arrayType.getComponentType(), propertyName );
}
JClassType classType = type.isClassOrInterface();
if ( null == classType ) {
return Optional.absent();
} else if ( typeOracle.isIterable( classType ) ) {
if ( (null == classType.isParameterized() || classType.isParameterized().getTypeArgs().length != 1) && (null == classType
.isGenericType() || classType.isGenericType().getTypeParameters().length != 1) ) {
logger.log( Type.INFO, "Expected one argument for the java.lang.Iterable '" + propertyName + "'. Applying annotations to " +
"type " + classType.getParameterizedQualifiedSourceName() );
return Optional.of( classType );
}
if ( null != classType.isParameterized() ) {
return extractBeanType( logger, typeOracle, classType.isParameterized().getTypeArgs()[0], propertyName );
} else {
return extractBeanType( logger, typeOracle, classType.isGenericType().getTypeParameters()[0].getBaseType(), propertyName );
}
} else if ( typeOracle.isMap( classType ) ) {
if ( (null == classType.isParameterized() || classType.isParameterized().getTypeArgs().length != 2) && (null == classType
.isGenericType() || classType.isGenericType().getTypeParameters().length != 2) ) {
logger.log( Type.INFO, "Expected two arguments for the java.util.Map '" + propertyName + "'. Applying annotations to " +
"type " + classType.getParameterizedQualifiedSourceName() );
return Optional.of( classType );
}
if ( null != classType.isParameterized() ) {
return extractBeanType( logger, typeOracle, classType.isParameterized().getTypeArgs()[1], propertyName );
} else {
return extractBeanType( logger, typeOracle, classType.isGenericType().getTypeParameters()[1].getBaseType(), propertyName );
}
} else {
return Optional.of( classType );
}
}
示例9: replaceType
import com.google.gwt.core.ext.typeinfo.JType; //导入方法依赖的package包/类
/**
* <p>replaceType</p>
*
* @param logger a {@link com.google.gwt.core.ext.TreeLogger} object.
* @param type a {@link com.google.gwt.core.ext.typeinfo.JType} object.
* @param deserializeAs a {@link java.lang.annotation.Annotation} object.
* @return a {@link com.google.gwt.core.ext.typeinfo.JType} object.
* @throws com.google.gwt.core.ext.UnableToCompleteException if any.
*/
public JType replaceType( TreeLogger logger, JType type, Annotation deserializeAs ) throws UnableToCompleteException {
JClassType classType = type.isClassOrInterface();
if ( null == classType ) {
return type;
}
Optional<JClassType> typeAs = getClassFromJsonDeserializeAnnotation( logger, deserializeAs, "as" );
Optional<JClassType> keyAs = getClassFromJsonDeserializeAnnotation( logger, deserializeAs, "keyAs" );
Optional<JClassType> contentAs = getClassFromJsonDeserializeAnnotation( logger, deserializeAs, "contentAs" );
if ( !typeAs.isPresent() && !keyAs.isPresent() && !contentAs.isPresent() ) {
return type;
}
JArrayType arrayType = type.isArray();
if ( null != arrayType ) {
if ( contentAs.isPresent() ) {
return typeOracle.getArrayType( contentAs.get() );
} else if ( typeAs.isPresent() ) {
return typeOracle.getArrayType( typeAs.get() );
} else {
return classType;
}
}
JParameterizedType parameterizedType = type.isParameterized();
if ( null != parameterizedType ) {
JGenericType genericType;
if ( typeAs.isPresent() ) {
genericType = typeAs.get().isGenericType();
} else {
genericType = parameterizedType.getBaseType();
}
if ( !keyAs.isPresent() && !contentAs.isPresent() ) {
return typeOracle.getParameterizedType( genericType, parameterizedType.getTypeArgs() );
} else if ( contentAs.isPresent() && isIterable( parameterizedType ) ) {
return typeOracle.getParameterizedType( genericType, new JClassType[]{contentAs.get()} );
} else if ( isMap( parameterizedType ) ) {
JClassType key;
if ( keyAs.isPresent() ) {
key = keyAs.get();
} else {
key = parameterizedType.getTypeArgs()[0];
}
JClassType content;
if ( contentAs.isPresent() ) {
content = contentAs.get();
} else {
content = parameterizedType.getTypeArgs()[1];
}
return typeOracle.getParameterizedType( genericType, new JClassType[]{key, content} );
}
}
if ( typeAs.isPresent() ) {
return typeAs.get();
}
return type;
}
示例10: toType
import com.google.gwt.core.ext.typeinfo.JType; //导入方法依赖的package包/类
private String toType(JType type, String innerExpression) {
//System.out.println("toType " + type);
if ((type.isPrimitive() == JPrimitiveType.DOUBLE) ||
(type.isPrimitive() == JPrimitiveType.FLOAT) ||
(type.isPrimitive() == JPrimitiveType.LONG) ||
(type.isPrimitive() == JPrimitiveType.INT) ||
(type.isPrimitive() == JPrimitiveType.SHORT)) {
return " new JSONNumber( (double) " + innerExpression + ")";
} else if (type.isPrimitive() == JPrimitiveType.BOOLEAN) {
return " JSONBoolean.getInstance( " + innerExpression + " ) ";
} else if (type.isPrimitive() == JPrimitiveType.CHAR ){
return " new JSONString( Character.toString("+ innerExpression +") )";
}
StringBuilder sb = new StringBuilder(innerExpression +
" == null ? JSONNull.getInstance() : ");
if(type.isEnum() != null){
sb = sb.append(" new JSONString(( (Enum) "+innerExpression+").name()) ");
} else if (type.getQualifiedSourceName().equals("java.lang.String")) {
sb = sb.append(" new JSONString( " + innerExpression + " ) ");
} else if(type.getQualifiedSourceName().equals("java.lang.Character")){
sb = sb.append(" new JSONString( Character.toString(" + innerExpression + ") ) ");
}else if (type.isClassOrInterface() != null && type.isClassOrInterface().isAssignableTo(this.numberType)) {
sb = sb.append("new JSONNumber( ((Number) " + innerExpression +
").doubleValue())");
} else if (type.getQualifiedSourceName().equals("java.lang.Boolean")) {
sb.append(" JSONBoolean.getInstance( " + innerExpression + " ) ");
} else if(type.getQualifiedSourceName().equals(Serializable.class.getCanonicalName())){
sb.append(" dynamicType("+innerExpression+" )");
} else {
BeanResolver child = findType(type);
if (child == null) {
if(type.isTypeParameter() != null){
boolean found = false;
for(JClassType bound : type.isTypeParameter().getBounds()){
if(bound.getQualifiedSourceName().equals(Serializable.class.getCanonicalName())){
sb.append(" dynamicType("+innerExpression+" ) ");
found = true;
break;
}
}
if(!found){
throw new RuntimeException(type+" could not be mapped to JSON.");
}
}else {
throw new RuntimeException(type+" is not introspectable!");
}
} else {
this.children.add(child);
sb = sb.append("CODEC_" +
type.getQualifiedSourceName().replaceAll("\\.", "_") +
".serializeToJSONObject( " + innerExpression + " ) ");
}
}
return sb.toString();
}