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


Java Type类代码示例

本文整理汇总了Java中japa.parser.ast.type.Type的典型用法代码示例。如果您正苦于以下问题:Java Type类的具体用法?Java Type怎么用?Java Type使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: getResolvedName

import japa.parser.ast.type.Type; //导入依赖的package包/类
public static ClassOrInterfaceType getResolvedName(final JavaType target,
        final JavaType current, final CompilationUnit compilationUnit) {
    final NameExpr nameExpr = JavaParserUtils.importTypeIfRequired(target,
            compilationUnit.getImports(), current);
    final ClassOrInterfaceType resolvedName = JavaParserUtils
            .getClassOrInterfaceType(nameExpr);
    if (current.getParameters() != null
            && current.getParameters().size() > 0) {
        resolvedName.setTypeArgs(new ArrayList<Type>());
        for (final JavaType param : current.getParameters()) {
            resolvedName.getTypeArgs().add(
                    getResolvedName(target, param, compilationUnit));
        }
    }

    return resolvedName;
}
 
开发者ID:gvSIGAssociation,项目名称:gvnix1,代码行数:18,代码来源:JavaParserUtils.java

示例2: importParametersForType

import japa.parser.ast.type.Type; //导入依赖的package包/类
public static ReferenceType importParametersForType(
        final JavaType targetType, final List<ImportDeclaration> imports,
        final JavaType typeToImport) {
    Validate.notNull(targetType, "Target type is required");
    Validate.notNull(imports, "Compilation unit imports required");
    Validate.notNull(typeToImport, "Java type to import is required");

    final ClassOrInterfaceType cit = getClassOrInterfaceType(importTypeIfRequired(
            targetType, imports, typeToImport));
    
    // Add any type arguments presented for the return type
    if (typeToImport.getParameters().size() > 0) {
        final List<Type> typeArgs = new ArrayList<Type>();
        cit.setTypeArgs(typeArgs);
        for (final JavaType parameter : typeToImport
                .getParameters()) {
            typeArgs.add(JavaParserUtils.importParametersForType(
                    targetType,
                    imports, parameter));
        }
    }
    return  new ReferenceType(cit);
}
 
开发者ID:gvSIGAssociation,项目名称:gvnix1,代码行数:24,代码来源:JavaParserUtils.java

示例3: visit

import japa.parser.ast.type.Type; //导入依赖的package包/类
@Override
 public void visit(CatchClause n, Object arg)
 {	int line = n.getBeginLine();
 	Parameter e = n.getExcept();
 	if(!IGNORED_METHODS.contains(currentMethod))
 	{	Type t = e.getType();
  	if(t instanceof ReferenceType)
{	Type t2 = ((ReferenceType)t).getType();
	if(t2 instanceof ClassOrInterfaceType)
	{	String exceptionName = ((ClassOrInterfaceType)t2).getName();
		if(FORBIDDEN_EXCEPTIONS.contains(exceptionName))
		{	printErr("Erreur ligne "+line+" : le catch("+exceptionName+") masque l'appel à "+CHECK_INTERRUPTION_METHOD+"()");
			errorCount++;
		}
	}
	else
	{	System.err.print(">>11111111111 problème : exception non conforme ("+t2.getClass()+")");
	}
}
  	else
{	System.err.print(">>222222222 problème : exception non conforme ("+t.getClass()+")");
  	}
 	}
 	e.accept(this, arg);
     n.getCatchBlock().accept(this, arg);
 }
 
开发者ID:vlabatut,项目名称:totalboumboum,代码行数:27,代码来源:AiVisitor.java

示例4: visit

import japa.parser.ast.type.Type; //导入依赖的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

示例5: getRawTypeName

import japa.parser.ast.type.Type; //导入依赖的package包/类
private static String getRawTypeName(Type type) {
	if (type instanceof ClassOrInterfaceType) {
		return getQualifiedName((ClassOrInterfaceType) type);
	}
	if (type instanceof ReferenceType) {
		ReferenceType refType = (ReferenceType) type;
		return getRawTypeName(refType.getType()) + StringUtils.multiply("[]", refType.getArrayCount());
	}
	if (type instanceof PrimitiveType) {
		return ((PrimitiveType) type).getType().name().toLowerCase();
	}
	if (type instanceof VoidType) {
		return "void";
	}
	if (type instanceof WildcardType) {
		return "java.lang.Object";
	}
	return type.toString();
}
 
开发者ID:jedwards1211,项目名称:breakout,代码行数:20,代码来源:JavaParserUtils.java

示例6: visit

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

示例7: visit

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

示例8: visit

import japa.parser.ast.type.Type; //导入依赖的package包/类
public Node visit(AnnotationMemberDeclaration n, A arg) {
    if (n.getJavaDoc() != null) {
        n.setJavaDoc((JavadocComment) n.getJavaDoc().accept(this, arg));
    }
    List<AnnotationExpr> annotations = n.getAnnotations();
    if (annotations != null) {
        for (int i = 0; i < annotations.size(); i++) {
            annotations.set(i, (AnnotationExpr) annotations.get(i).accept(this, arg));
        }
        removeNulls(annotations);
    }
    n.setType((Type) n.getType().accept(this, arg));
    if (n.getDefaultValue() != null) {
        n.setDefaultValue((Expression) n.getDefaultValue().accept(this, arg));
    }
    return n;
}
 
开发者ID:rfw,项目名称:genja,代码行数:18,代码来源:ModifierVisitorAdapter.java

示例9: buildClass

import japa.parser.ast.type.Type; //导入依赖的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

示例10: getJavaTypeNow

import japa.parser.ast.type.Type; //导入依赖的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

示例11: getType

import japa.parser.ast.type.Type; //导入依赖的package包/类
/**
 * Given a primitive type, computes the corresponding Java Parser type.
 * <p>
 * Presenting a non-primitive type to this method will throw an exception.
 * If you have a non-primitive type, use
 * {@link #importTypeIfRequired(JavaType, List, JavaType)} and then present
 * the {@link NameExpr} it returns to
 * {@link #getClassOrInterfaceType(NameExpr)}.
 * 
 * @param javaType a primitive type (required, and must be primitive)
 * @return the equivalent Java Parser {@link Type}
 */
public static Type getType(final JavaType javaType) {
    Validate.notNull(javaType, "Java type required");
    Validate.isTrue(javaType.isPrimitive(),
            "Java type must be primitive to be presented to this method");
    if (javaType.equals(JavaType.VOID_PRIMITIVE)) {
        return new VoidType();
    }
    else if (javaType.equals(JavaType.BOOLEAN_PRIMITIVE)) {
        return new PrimitiveType(Primitive.Boolean);
    }
    else if (javaType.equals(JavaType.BYTE_PRIMITIVE)) {
        return new PrimitiveType(Primitive.Byte);
    }
    else if (javaType.equals(JavaType.CHAR_PRIMITIVE)) {
        return new PrimitiveType(Primitive.Char);
    }
    else if (javaType.equals(JavaType.DOUBLE_PRIMITIVE)) {
        return new PrimitiveType(Primitive.Double);
    }
    else if (javaType.equals(JavaType.FLOAT_PRIMITIVE)) {
        return new PrimitiveType(Primitive.Float);
    }
    else if (javaType.equals(JavaType.INT_PRIMITIVE)) {
        return new PrimitiveType(Primitive.Int);
    }
    else if (javaType.equals(JavaType.LONG_PRIMITIVE)) {
        return new PrimitiveType(Primitive.Long);
    }
    else if (javaType.equals(JavaType.SHORT_PRIMITIVE)) {
        return new PrimitiveType(Primitive.Short);
    }
    throw new IllegalStateException("Unknown primitive " + javaType);
}
 
开发者ID:gvSIGAssociation,项目名称:gvnix1,代码行数:46,代码来源:JavaParserUtils.java

示例12: getClassOrInterfaceType

import japa.parser.ast.type.Type; //导入依赖的package包/类
/**
 * Returns the final {@link ClassOrInterfaceType} from a {@link Type}
 * 
 * @param initType
 * @return the final {@link ClassOrInterfaceType} or null if no {@link ClassOrInterfaceType} found
 * 
 */
public static ClassOrInterfaceType getClassOrInterfaceType(Type type) {
    Type tmp = type;
    while (tmp instanceof ReferenceType) {
           tmp = ((ReferenceType) tmp).getType();
    };
    if (tmp instanceof ClassOrInterfaceType){
    	return (ClassOrInterfaceType) tmp;
    }
    return null;
}
 
开发者ID:gvSIGAssociation,项目名称:gvnix1,代码行数:18,代码来源:JavaParserUtils.java

示例13: visit

import japa.parser.ast.type.Type; //导入依赖的package包/类
@Override
 public void visit(CatchClause n, Object arg)
 {	int line = n.getBeginLine();
 	Parameter e = n.getExcept();
 	if(!IGNORED_METHODS.contains(currentMethod))
 	{	Type t = e.getType();
  	if(t instanceof ReferenceType)
{	Type t2 = ((ReferenceType)t).getType();
	if(t2 instanceof ClassOrInterfaceType)
	{	String exceptionName = ((ClassOrInterfaceType)t2).getName();
		if(FORBIDDEN_EXCEPTIONS.contains(exceptionName))
		{	for(int i=0;i<indentLevel;i++)
				System.out.print(">>");
	       	System.out.println("Erreur ligne "+line+" : le catch("+exceptionName+") masque l'appel à "+CHECK_INTERRUPTION_METHOD+"()");
			errorCount++;
			// à compléter par la création d'un commentaire dans le code source
		}
	}
	else
	{	System.out.print(">>11111111111 problème : exception non conforme ("+t2.getClass()+")");
	}
}
  	else
{	System.out.print(">>222222222 problème : exception non conforme ("+t.getClass()+")");
  	}
 	}
 	e.accept(this, arg);
     n.getCatchBlock().accept(this, arg);
 }
 
开发者ID:vlabatut,项目名称:totalboumboum,代码行数:30,代码来源:AiVisitor.java

示例14: visit

import japa.parser.ast.type.Type; //导入依赖的package包/类
@Override
 public void visit(CatchClause n, Object arg)
 {	int line = n.getBeginLine();
 	Parameter e = n.getExcept();
 	if(!IGNORED_METHODS.contains(currentMethod))
 	{	Type t = e.getType();
  	if(t instanceof ReferenceType)
{	Type t2 = ((ReferenceType)t).getType();
	if(t2 instanceof ClassOrInterfaceType)
	{	String exceptionName = ((ClassOrInterfaceType)t2).getName();
		if(FORBIDDEN_EXCEPTIONS.contains(exceptionName))
		{	printErr("Erreur ligne "+line+" : le catch("+exceptionName+") masque l'appel à "+CHECK_INTERRUPTION_METHOD+"()");
			errorCount++;
			//
		}
	}
	else
	{	System.err.print(">>11111111111 problème : exception non conforme ("+t2.getClass()+")");
	}
}
  	else
{	System.err.print(">>222222222 problème : exception non conforme ("+t.getClass()+")");
  	}
 	}
 	e.accept(this, arg);
     n.getCatchBlock().accept(this, arg);
 }
 
开发者ID:vlabatut,项目名称:totalboumboum,代码行数:28,代码来源:AiVisitor.java

示例15: visit

import japa.parser.ast.type.Type; //导入依赖的package包/类
@Override
 public void visit(CatchClause n, Object arg)
 {	int line = n.getBeginLine();
 	Parameter e = n.getExcept();
 	if(!IGNORED_METHODS.contains(currentMethod))
 	{	Type t = e.getType();
  	if(t instanceof ReferenceType)
{	Type t2 = ((ReferenceType)t).getType();
	if(t2 instanceof ClassOrInterfaceType)
	{	String exceptionName = ((ClassOrInterfaceType)t2).getName();
		if(FORBIDDEN_EXCEPTIONS.contains(exceptionName))
		{	for(int i=0;i<indentLevel;i++)
				System.out.print(">>");
	       	System.out.println("Erreur ligne "+line+" : le catch("+exceptionName+") masque l'appel à "+CHECK_INTERRUPTION_METHOD+"()");
			errorCount++;
		}
	}
	else
	{	System.out.print(">>11111111111 problème : exception non conforme ("+t2.getClass()+")");
	}
}
  	else
{	System.out.print(">>222222222 problème : exception non conforme ("+t.getClass()+")");
  	}
 	}
 	e.accept(this, arg);
     n.getCatchBlock().accept(this, arg);
 }
 
开发者ID:vlabatut,项目名称:totalboumboum,代码行数:29,代码来源:AiVisitor.java


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