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


Java TypeDeclaration类代码示例

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


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

示例1: Fact

import japa.parser.ast.body.TypeDeclaration; //导入依赖的package包/类
public Fact(File file, CompilationUnit compilationUnit) throws FileNotFoundException {
    if (compilationUnit.getPackage() != null)
        packageName = compilationUnit.getPackage().getName().toString().replace("package", "");
    
    comment = extractTopComment(file);

    imports = new HashSet<String>();
    if (compilationUnit.getImports() != null)
        for (ImportDeclaration imp : compilationUnit.getImports()) {
            String str = imp.getName().toString();
            if (!imp.isAsterisk())
                str = str.substring(0, str.lastIndexOf("."));
            imports.add(str);
        }
        
    declarations = new ArrayList<Declaration>();
    if (compilationUnit.getTypes() != null)
        for (TypeDeclaration decl : compilationUnit.getTypes()) {
            if (decl instanceof ClassOrInterfaceDeclaration)
                declarations.add(new Declaration(decl));
        }
}
 
开发者ID:amritbhat786,项目名称:DocIT,代码行数:23,代码来源:Fact.java

示例2: locateTypeDeclaration

import japa.parser.ast.body.TypeDeclaration; //导入依赖的package包/类
/**
 * Searches a compilation unit and locates the declaration with the given
 * type's simple name.
 * 
 * @param compilationUnit to scan (required)
 * @param javaType the target to locate (required)
 * @return the located type declaration or null if it could not be found
 */
public static TypeDeclaration locateTypeDeclaration(
        final CompilationUnit compilationUnit, final JavaType javaType) {
    Validate.notNull(compilationUnit, "Compilation unit required");
    Validate.notNull(javaType, "Java type to search for required");
    if (compilationUnit.getTypes() == null) {
        return null;
    }
    for (final TypeDeclaration candidate : compilationUnit.getTypes()) {
        if (javaType.getSimpleTypeName().equals(candidate.getName())) {
            // We have the required type declaration
            return candidate;
        }
    }
    return null;
}
 
开发者ID:gvSIGAssociation,项目名称:gvnix1,代码行数:24,代码来源:JavaParserUtils.java

示例3: getCompilationUnitContents

import japa.parser.ast.body.TypeDeclaration; //导入依赖的package包/类
public final String getCompilationUnitContents(
        final ClassOrInterfaceTypeDetails cid) {
    Validate.notNull(cid, "Class or interface type details are required");
    // Create a compilation unit to store the type to be created
    final CompilationUnit compilationUnit = new CompilationUnit();

    // NB: this import list is replaced at the end of this method by a
    // sorted version
    compilationUnit.setImports(new ArrayList<ImportDeclaration>());

    if (!cid.getName().isDefaultPackage()) {
        compilationUnit.setPackage(new PackageDeclaration(ASTHelper
                .createNameExpr(cid.getName().getPackage()
                        .getFullyQualifiedPackageName())));
    }

    // Add the class of interface declaration to the compilation unit
    final List<TypeDeclaration> types = new ArrayList<TypeDeclaration>();
    compilationUnit.setTypes(types);

    updateOutput(compilationUnit, null, cid, null);

    return compilationUnit.toString();
}
 
开发者ID:gvSIGAssociation,项目名称:gvnix1,代码行数:25,代码来源:JavaParserTypeParsingService.java

示例4: JavaParserClassOrInterfaceTypeDetailsBuilder

import japa.parser.ast.body.TypeDeclaration; //导入依赖的package包/类
/**
 * Constructor
 * 
 * @param compilationUnit
 * @param enclosingCompilationUnitServices
 * @param typeDeclaration
 * @param declaredByMetadataId
 * @param typeName
 * @param metadataService
 * @param typeLocationService
 */
private JavaParserClassOrInterfaceTypeDetailsBuilder(
        final CompilationUnit compilationUnit,
        final CompilationUnitServices enclosingCompilationUnitServices,
        final TypeDeclaration typeDeclaration,
        final String declaredByMetadataId, final JavaType typeName,
        final MetadataService metadataService,
        final TypeLocationService typeLocationService) {
    // Check
    Validate.notNull(compilationUnit, "Compilation unit required");
    Validate.notBlank(declaredByMetadataId,
            "Declared by metadata ID required");
    Validate.notNull(typeDeclaration,
            "Unable to locate the class or interface declaration");
    Validate.notNull(typeName, "Name required");

    // Assign
    this.compilationUnit = compilationUnit;
    compilationUnitServices = enclosingCompilationUnitServices == null ? getDefaultCompilationUnitServices()
            : enclosingCompilationUnitServices;
    this.declaredByMetadataId = declaredByMetadataId;
    this.metadataService = metadataService;
    name = typeName;
    this.typeDeclaration = typeDeclaration;
    this.typeLocationService = typeLocationService;
}
 
开发者ID:gvSIGAssociation,项目名称:gvnix1,代码行数:37,代码来源:JavaParserClassOrInterfaceTypeDetailsBuilder.java

示例5: getDefaultCompilationUnitServices

import japa.parser.ast.body.TypeDeclaration; //导入依赖的package包/类
private CompilationUnitServices getDefaultCompilationUnitServices() {
    return new CompilationUnitServices() {
        public JavaPackage getCompilationUnitPackage() {
            return compilationUnitPackage;
        }

        public JavaType getEnclosingTypeName() {
            return name;
        }

        public List<ImportDeclaration> getImports() {
            return imports;
        }

        public List<TypeDeclaration> getInnerTypes() {
            return innerTypes;
        }

        public PhysicalTypeCategory getPhysicalTypeCategory() {
            return physicalTypeCategory;
        }
    };
}
 
开发者ID:gvSIGAssociation,项目名称:gvnix1,代码行数:24,代码来源:JavaParserClassOrInterfaceTypeDetailsBuilder.java

示例6: resolve

import japa.parser.ast.body.TypeDeclaration; //导入依赖的package包/类
@Override
public NodeData resolve(Node node, String mappedClass) {
    if (!(node instanceof ClassOrInterfaceDeclaration)) {
        throw new IllegalArgumentException("this annotation belongs only on ClassOrInterfaceDeclaration");
    }

    final TypeDeclaration dclr = (TypeDeclaration) node;
    if (!(dclr.getParentNode() instanceof CompilationUnit)) {
        //handling nested classes
        return null;
    }
    final String name = dclr.getName();

    final Collection<FieldDescriptor> primaryKeyDescriptors = getPrimaryKeyDescriptors(mappedClass);

    if (primaryKeyDescriptors != null && primaryKeyDescriptors.size() > 1  && nodeContainsPkFields(dclr,
            primaryKeyDescriptors)) {
        final NodeAndImports<ClassOrInterfaceDeclaration> primaryKeyClass = createPrimaryKeyClass(name, primaryKeyDescriptors);
        final String pkClassName = primaryKeyClass.node.getName();
        return new NodeData(new SingleMemberAnnotationExpr(new NameExpr(SIMPLE_NAME), new NameExpr(name + "." + pkClassName + ".class")),
                new ImportDeclaration(new QualifiedNameExpr(new NameExpr(PACKAGE), SIMPLE_NAME), false, false), primaryKeyClass.imprts, primaryKeyClass.node);

    }
    return null;
}
 
开发者ID:kuali,项目名称:kc-rice,代码行数:26,代码来源:IdClassResolver.java

示例7: nodeContainsPkFields

import japa.parser.ast.body.TypeDeclaration; //导入依赖的package包/类
private boolean nodeContainsPkFields(TypeDeclaration dclr, Collection<FieldDescriptor> pks) {
    for (FieldDescriptor pk : pks) {
        boolean contains = false;
        for (FieldDeclaration field : ParserUtil.getFieldMembers(dclr.getMembers())) {
            if (field.getVariables().get(0).getId().getName().equals(pk.getAttributeName())) {
                contains =  true;
                break;
            }
        }

        if (!contains) {
            return false;
        }
    }

    return true;
}
 
开发者ID:kuali,项目名称:kc-rice,代码行数:18,代码来源:IdClassResolver.java

示例8: resolve

import japa.parser.ast.body.TypeDeclaration; //导入依赖的package包/类
@Override
public NodeData resolve(Node node, String mappedClass) {
    if (!(node instanceof ClassOrInterfaceDeclaration)) {
        throw new IllegalArgumentException("this annotation belongs only on ClassOrInterfaceDeclaration");
    }

    final TypeDeclaration dclr = (TypeDeclaration) node;
    if (!(dclr.getParentNode() instanceof CompilationUnit)) {
        //handling nested classes
        return null;
    }

    final String name = dclr.getName();
    final String pckg = ((CompilationUnit) dclr.getParentNode()).getPackage().getName().toString();
    final String enclosingClass = pckg + "." + name;

    final ClassDescriptor cd = OjbUtil.findClassDescriptor(enclosingClass, descriptorRepositories);
    if (cd != null) {
        return new NodeData(new MarkerAnnotationExpr(new NameExpr(SIMPLE_NAME)),
                new ImportDeclaration(new QualifiedNameExpr(new NameExpr(PACKAGE), SIMPLE_NAME), false, false));
    }

    return null;
}
 
开发者ID:kuali,项目名称:kc-rice,代码行数:25,代码来源:EntityResolver.java

示例9: resolve

import japa.parser.ast.body.TypeDeclaration; //导入依赖的package包/类
@Override
public final NodeData resolve(Node node, String mappedClass) {
    if (!(node instanceof FieldDeclaration)) {
        throw new IllegalArgumentException("this annotation belongs only on FieldDeclaration");
    }

    final FieldDeclaration field = (FieldDeclaration) node;

    if (ResolverUtil.canFieldBeAnnotated(field)) {
        final TypeDeclaration dclr = (TypeDeclaration) node.getParentNode();

        final String name = dclr.getName();
        final String pckg = ((CompilationUnit) dclr.getParentNode()).getPackage().getName().toString();
        final String fullyQualifiedClass = pckg + "." + name;
        final boolean mappedColumn = OjbUtil.isMappedColumn(mappedClass, ParserUtil.getFieldName(field),
                descriptorRepositories);
        if (mappedColumn) {
            return getAnnotationNodes(fullyQualifiedClass, ParserUtil.getFieldName(field), mappedClass);
        }
    }
    return null;
}
 
开发者ID:kuali,项目名称:kc-rice,代码行数:23,代码来源:AbstractMappedFieldResolver.java

示例10: resolve

import japa.parser.ast.body.TypeDeclaration; //导入依赖的package包/类
@Override
public NodeData resolve(Node node, String mappedClass) {
    if (!(node instanceof ClassOrInterfaceDeclaration)) {
        throw new IllegalArgumentException("this annotation belongs only on ClassOrInterfaceDeclaration");
    }

    final TypeDeclaration dclr = (TypeDeclaration) node;
    if (!(dclr.getParentNode() instanceof CompilationUnit)) {
        //handling nested classes
        return null;
    }

    final String name = dclr.getName();
    final String pckg = ((CompilationUnit) dclr.getParentNode()).getPackage().getName().toString();
    final String enclosingClass = pckg + "." + name;
    if (!enclosingClass.equals(mappedClass)) {
        return new NodeData(new MarkerAnnotationExpr(new NameExpr(SIMPLE_NAME)),
            new ImportDeclaration(new QualifiedNameExpr(new NameExpr(PACKAGE), SIMPLE_NAME), false, false));
    }
    return null;
}
 
开发者ID:kuali,项目名称:kc-rice,代码行数:22,代码来源:MappedSuperClassResolver.java

示例11: resolve

import japa.parser.ast.body.TypeDeclaration; //导入依赖的package包/类
@Override
public NodeData resolve(Node node, String mappedClass) {
    if (!(node instanceof ClassOrInterfaceDeclaration)) {
        throw new IllegalArgumentException("this annotation belongs only on ClassOrInterfaceDeclaration");
    }

    final TypeDeclaration dclr = (TypeDeclaration) node;
    if (!(dclr.getParentNode() instanceof CompilationUnit)) {
        //handling nested classes
        return null;
    }
    final String name = dclr.getName();
    final String pckg = ((CompilationUnit) dclr.getParentNode()).getPackage().getName().toString();
    final String enclosingClass = pckg + "." + name;
    final Collection<String> customizedFieldsOnNode = getFieldsOnNode(dclr, getCustomizedFields(mappedClass));
    if (customizedFieldsOnNode == null || customizedFieldsOnNode.isEmpty()) {
        LOG.info(ResolverUtil.logMsgForClass(enclosingClass, mappedClass) + " has no customized fields");
        return null;
    }
    return new NodeData(new SingleMemberAnnotationExpr(new NameExpr(SIMPLE_NAME), new NameExpr("CreateCustomizerFor" + customizedFieldsOnNode.toString())),
            new ImportDeclaration(new QualifiedNameExpr(new NameExpr(PACKAGE), SIMPLE_NAME), false, false));
}
 
开发者ID:kuali,项目名称:kc-rice,代码行数:23,代码来源:CustomizerResolver.java

示例12: getTypeOrFieldNameForMsg

import japa.parser.ast.body.TypeDeclaration; //导入依赖的package包/类
private String getTypeOrFieldNameForMsg(final BodyDeclaration n) {
    if (n instanceof TypeDeclaration) {
        return ((TypeDeclaration) n).getName();
    } else if (n instanceof FieldDeclaration) {
        final FieldDeclaration fd = (FieldDeclaration) n;
        //this wont work for nested classes but we should be in nexted classes at this point
        final CompilationUnit unit = getCompilationUnit(n);
        final TypeDeclaration parent = unit.getTypes().get(0);
        Collection<String> variableNames = new ArrayList<String>();
        if (fd.getVariables() != null) {
            for (VariableDeclarator vd : fd.getVariables()) {
                variableNames.add(vd.getId().getName());
            }
        }
        return variableNames.size() == 1 ?
                parent.getName() + "." + variableNames.iterator().next() :
                parent.getName() + "." + variableNames.toString();

    }
    return null;
}
 
开发者ID:kuali,项目名称:kc-rice,代码行数:22,代码来源:AnnotationHelper.java

示例13: parseType

import japa.parser.ast.body.TypeDeclaration; //导入依赖的package包/类
private JType parseType(String type, JCodeModel codeModel) {
	final String text = "public class Ignored extends " + type + " {}";
	try {
		CompilationUnit compilationUnit = JavaParser.parse(
				new ByteArrayInputStream(text.getBytes("UTF-8")), "UTF-8");
		final List<TypeDeclaration> typeDeclarations = compilationUnit
				.getTypes();
		final TypeDeclaration typeDeclaration = typeDeclarations.get(0);
		final ClassOrInterfaceDeclaration classDeclaration = (ClassOrInterfaceDeclaration) typeDeclaration;
		final List<ClassOrInterfaceType> _extended = classDeclaration
				.getExtends();
		final ClassOrInterfaceType classOrInterfaceType = _extended.get(0);

		return classOrInterfaceType.accept(
				this.typeToJTypeConvertingVisitor, codeModel);
	} catch (ParseException pex) {
		throw new IllegalArgumentException(
				"Could not parse the type definition [" + type + "].", pex);
	} catch (UnsupportedEncodingException uex) {
		throw new UnsupportedOperationException(uex);
	}
}
 
开发者ID:highsource,项目名称:jaxb2-basics,代码行数:23,代码来源:JavaTypeParser.java

示例14: getJavaMethods

import japa.parser.ast.body.TypeDeclaration; //导入依赖的package包/类
private void getJavaMethods (ArrayList<JavaMethod> methods, TypeDeclaration type) {
	classStack.push(type);
	if (type.getMembers() != null) {
		for (BodyDeclaration member : type.getMembers()) {
			if (member instanceof ClassOrInterfaceDeclaration || member instanceof EnumDeclaration) {
				getJavaMethods(methods, (TypeDeclaration)member);
			} else {
				if (member instanceof MethodDeclaration) {
					MethodDeclaration method = (MethodDeclaration)member;
					if (!ModifierSet.hasModifier(((MethodDeclaration)member).getModifiers(), ModifierSet.NATIVE)) continue;
					methods.add(createMethod(method));
				}
			}
		}
	}
	classStack.pop();
}
 
开发者ID:basherone,项目名称:libgdxcn,代码行数:18,代码来源:RobustJavaMethodParser.java

示例15: getNode

import japa.parser.ast.body.TypeDeclaration; //导入依赖的package包/类
public static Node getNode(CompilationUnit unit, String fqName) {
	String pkg = getQualifiedName(unit.getPackage().getName());
	if (!fqName.startsWith(pkg)) {
		return null;
	}
	if (fqName.equals(pkg)) {
		return unit.getPackage();
	}

	String name = fqName.substring(pkg.length() + 1);

	for (TypeDeclaration typeDecl : unit.getTypes()) {
		if (name.startsWith(typeDecl.getName())) {
			if (name.length() == typeDecl.getName().length()) {
				return typeDecl;
			} else {
				return getNode(typeDecl, name.substring(typeDecl.getName().length() + 1));
			}
		}
	}

	return null;
}
 
开发者ID:jedwards1211,项目名称:breakout,代码行数:24,代码来源:JavaParserUtils.java


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