• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Type类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: testParse

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


示例17: introduce

import japa.parser.ast.type.Type; //导入依赖的package包/类
String introduce(VariableDeclarator d, Type t, Map<String, TypedVariableDeclarator> s) {
    String prefix = this.block.getScopePrefix();
    if (this.block.findScopeForVariable(d.getId().getName()) != null) {
        throw new TransformException(d.getId().getName() + " already exists in scope");
    }
    // We introduce the typed variable in two places: the full name in
    // map we're carrying around, and the scoped name in the block.
    TypedVariableDeclarator tv = new TypedVariableDeclarator(t, d);
    s.put(prefix + d.getId().getName(), tv);
    this.block.vars.put(d.getId().getName(), tv);

    return prefix + d.getId().getName();
}
 
开发者ID:rfw,项目名称:genja,代码行数:14,代码来源:ScopeMangleTransform.java


示例18: ExplicitConstructorInvocationStmt

import japa.parser.ast.type.Type; //导入依赖的package包/类
public ExplicitConstructorInvocationStmt(int beginLine, int beginColumn, int endLine, int endColumn, List<Type> typeArgs, boolean isThis, Expression expr, List<Expression> args) {
    super(beginLine, beginColumn, endLine, endColumn);
    this.typeArgs = typeArgs;
    this.isThis = isThis;
    this.expr = expr;
    this.args = args;
}
 
开发者ID:rfw,项目名称:genja,代码行数:8,代码来源:ExplicitConstructorInvocationStmt.java


示例19: MethodDeclaration

import japa.parser.ast.type.Type; //导入依赖的package包/类
public MethodDeclaration(JavadocComment javaDoc, int modifiers, List<AnnotationExpr> annotations, List<TypeParameter> typeParameters, Type type, String name, List<Parameter> parameters, int arrayCount, List<NameExpr> throws_, boolean generator, BlockStmt block) {
    super(annotations, javaDoc);
    this.modifiers = modifiers;
    this.typeParameters = typeParameters;
    this.type = type;
    this.name = name;
    this.parameters = parameters;
    this.arrayCount = arrayCount;
    this.throws_ = throws_;
    this.generator = generator;
    this.body = block;
}
 
开发者ID:rfw,项目名称:genja,代码行数:13,代码来源:MethodDeclaration.java


示例20: Parameter

import japa.parser.ast.type.Type; //导入依赖的package包/类
public Parameter(int beginLine, int beginColumn, int endLine, int endColumn, int modifiers, List<AnnotationExpr> annotations, Type type, boolean isVarArgs, VariableDeclaratorId id) {
    super(beginLine, beginColumn, endLine, endColumn);
    this.modifiers = modifiers;
    this.annotations = annotations;
    this.type = type;
    this.isVarArgs = isVarArgs;
    this.id = id;
}
 
开发者ID:rfw,项目名称:genja,代码行数:9,代码来源:Parameter.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java EditorActionManager类代码示例发布时间:2022-05-22
下一篇:
Java DavPropertySet类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap