当前位置: 首页>>代码示例>>Java>>正文


Java ClassOrInterfaceType.getTypeArgs方法代码示例

本文整理汇总了Java中japa.parser.ast.type.ClassOrInterfaceType.getTypeArgs方法的典型用法代码示例。如果您正苦于以下问题:Java ClassOrInterfaceType.getTypeArgs方法的具体用法?Java ClassOrInterfaceType.getTypeArgs怎么用?Java ClassOrInterfaceType.getTypeArgs使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在japa.parser.ast.type.ClassOrInterfaceType的用法示例。


在下文中一共展示了ClassOrInterfaceType.getTypeArgs方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: visit

import japa.parser.ast.type.ClassOrInterfaceType; //导入方法依赖的package包/类
@Override
public JType visit(ClassOrInterfaceType type, JCodeModel codeModel) {
	final String name = getName(type);
	final JClass knownClass = this.knownClasses.get(name);
	final JClass jclass = knownClass != null ? knownClass : codeModel
			.ref(name);
	final List<Type> typeArgs = type.getTypeArgs();
	if (typeArgs == null || typeArgs.isEmpty()) {
		return jclass;
	} else {
		final List<JClass> jtypeArgs = new ArrayList<JClass>(
				typeArgs.size());
		for (Type typeArg : typeArgs) {
			final JType jtype = typeArg.accept(this, codeModel);
			if (!(jtype instanceof JClass)) {
				throw new IllegalArgumentException("Type argument ["
						+ typeArg.toString() + "] is not a class.");
			} else {
				jtypeArgs.add((JClass) jtype);
			}
		}
		return jclass.narrow(jtypeArgs);
	}
}
 
开发者ID:highsource,项目名称:jaxb2-basics,代码行数:25,代码来源:TypeToJTypeConvertingVisitor.java

示例2: buildClass

import japa.parser.ast.type.ClassOrInterfaceType; //导入方法依赖的package包/类
private static JClass buildClass(JClassContainer _package, ClassOrInterfaceType c, int arrayCount) {
    final String packagePrefix = (c.getScope() != null) ? c.getScope().toString() + "." : "";

    JClass _class;
    try {
        _class = _package.owner().ref(Thread.currentThread().getContextClassLoader().loadClass(packagePrefix + c.getName()));
    } catch (ClassNotFoundException e) {
        _class = _package.owner().ref(packagePrefix + c.getName());
    }

    for (int i=0; i<arrayCount; i++) {
        _class = _class.array();
    }

    List<Type> typeArgs = c.getTypeArgs();
    if (typeArgs != null && typeArgs.size() > 0) {
        JClass[] genericArgumentClasses = new JClass[typeArgs.size()];

        for (int i=0; i<typeArgs.size(); i++) {
            genericArgumentClasses[i] = buildClass(_package, (ClassOrInterfaceType) ((ReferenceType) typeArgs.get(i)).getType(), ((ReferenceType) typeArgs.get(i)).getArrayCount());
        }

        _class = _class.narrow(genericArgumentClasses);
    }

    return _class;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:28,代码来源:TypeUtil.java

示例3: getJavaTypeNow

import japa.parser.ast.type.ClassOrInterfaceType; //导入方法依赖的package包/类
/**
 * Resolves the effective {@link JavaType} a {@link ClassOrInterfaceType}
 * represents, including any type arguments.
 * 
 * @param compilationUnitServices for package management (required)
 * @param cit the class or interface type to resolve (required)
 * @return the effective Java type (never null)
 */
public static JavaType getJavaTypeNow(
        final CompilationUnitServices compilationUnitServices,
        final ClassOrInterfaceType cit,
        final Set<JavaSymbolName> typeParameters) {
    Validate.notNull(compilationUnitServices,
            "Compilation unit services required");
    Validate.notNull(cit, "ClassOrInterfaceType required");

    final JavaPackage compilationUnitPackage = compilationUnitServices
            .getCompilationUnitPackage();
    Validate.notNull(compilationUnitPackage,
            "Compilation unit package required");

    String typeName = cit.getName();
    ClassOrInterfaceType scope = cit.getScope();
    while (scope != null) {
        typeName = scope.getName() + "." + typeName;
        scope = scope.getScope();
    }
    final NameExpr nameExpr = getNameExpr(typeName);

    final JavaType effectiveType = getJavaType(compilationUnitServices,
            nameExpr, typeParameters);

    // Handle any type arguments
    final List<JavaType> parameterTypes = new ArrayList<JavaType>();
    if (cit.getTypeArgs() != null) {
        for (final Type ta : cit.getTypeArgs()) {
            parameterTypes.add(getJavaType(compilationUnitServices, ta,
                    typeParameters));
        }
    }

    return new JavaType(effectiveType.getFullyQualifiedTypeName(),
            effectiveType.getArray(), effectiveType.getDataType(), null,
            parameterTypes);
}
 
开发者ID:gvSIGAssociation,项目名称:gvnix1,代码行数:46,代码来源:JavaParserUtils.java

示例4: testParse

import japa.parser.ast.type.ClassOrInterfaceType; //导入方法依赖的package包/类
public void testParse() throws Exception {

		final String text = "public class Dummy implements java.util.Comparator<java.lang.Integer>{}";

		final CompilationUnit compilationUnit = JavaParser.parse(
				new ByteArrayInputStream(text.getBytes("UTF-8")), "UTF-8");
		final List<TypeDeclaration> typeDeclarations = compilationUnit
				.getTypes();
		assertEquals(1, typeDeclarations.size());
		final TypeDeclaration typeDeclaration = typeDeclarations.get(0);
		assertTrue(typeDeclaration instanceof ClassOrInterfaceDeclaration);
		final ClassOrInterfaceDeclaration classDeclaration = (ClassOrInterfaceDeclaration) typeDeclaration;
		assertEquals("Dummy", classDeclaration.getName());
		final List<ClassOrInterfaceType> implementedInterfaces = classDeclaration
				.getImplements();
		assertEquals(1, implementedInterfaces.size());
		final ClassOrInterfaceType implementedInterface = implementedInterfaces
				.get(0);
		assertEquals("Comparator", implementedInterface.getName());
		final List<Type> typeArgs = implementedInterface.getTypeArgs();
		assertEquals(1, typeArgs.size());
		final Type typeArg = typeArgs.get(0);
		assertTrue(typeArg instanceof ReferenceType);
		final ReferenceType referenceTypeArg = (ReferenceType) typeArg;
		final Type referencedType = referenceTypeArg.getType();
		assertTrue(referencedType instanceof ClassOrInterfaceType);
		final ClassOrInterfaceType typeArgType = (ClassOrInterfaceType) referencedType;
		assertEquals("Integer", typeArgType.getName());

	}
 
开发者ID:highsource,项目名称:jaxb2-basics,代码行数:31,代码来源:JavaTypeParserTest.java

示例5: visit

import japa.parser.ast.type.ClassOrInterfaceType; //导入方法依赖的package包/类
public R visit(ClassOrInterfaceType n, A arg) {
    if (n.getScope() != null) {
        n.getScope().accept(this, arg);
    }
    if (n.getTypeArgs() != null) {
        for (Type t : n.getTypeArgs()) {
            t.accept(this, arg);
        }
    }
    return null;
}
 
开发者ID:rfw,项目名称:genja,代码行数:12,代码来源:GenericVisitorAdapter.java

示例6: visit

import japa.parser.ast.type.ClassOrInterfaceType; //导入方法依赖的package包/类
public void visit(ClassOrInterfaceType n, A arg) {
    if (n.getScope() != null) {
        n.getScope().accept(this, arg);
    }
    if (n.getTypeArgs() != null) {
        for (Type t : n.getTypeArgs()) {
            t.accept(this, arg);
        }
    }
}
 
开发者ID:rfw,项目名称:genja,代码行数:11,代码来源:VoidVisitorAdapter.java

示例7: visit

import japa.parser.ast.type.ClassOrInterfaceType; //导入方法依赖的package包/类
public Node visit(ClassOrInterfaceType n, A arg) {
    if (n.getScope() != null) {
        n.setScope((ClassOrInterfaceType) n.getScope().accept(this, arg));
    }
    List<Type> typeArgs = n.getTypeArgs();
    if (typeArgs != null) {
        for (int i = 0; i < typeArgs.size(); i++) {
            typeArgs.set(i, (Type) typeArgs.get(i).accept(this, arg));
        }
        removeNulls(typeArgs);
    }
    return n;
}
 
开发者ID:rfw,项目名称:genja,代码行数:14,代码来源:ModifierVisitorAdapter.java


注:本文中的japa.parser.ast.type.ClassOrInterfaceType.getTypeArgs方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。