本文整理汇总了Java中japa.parser.ast.ImportDeclaration类的典型用法代码示例。如果您正苦于以下问题:Java ImportDeclaration类的具体用法?Java ImportDeclaration怎么用?Java ImportDeclaration使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ImportDeclaration类属于japa.parser.ast包,在下文中一共展示了ImportDeclaration类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: Fact
import japa.parser.ast.ImportDeclaration; //导入依赖的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));
}
}
示例2: importParametersForType
import japa.parser.ast.ImportDeclaration; //导入依赖的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);
}
示例3: getCompilationUnitContents
import japa.parser.ast.ImportDeclaration; //导入依赖的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();
}
示例4: getDefaultCompilationUnitServices
import japa.parser.ast.ImportDeclaration; //导入依赖的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;
}
};
}
示例5: getAnnotationNodes
import japa.parser.ast.ImportDeclaration; //导入依赖的package包/类
@Override
protected NodeData getAnnotationNodes(String enclosingClass, String fieldName, String mappedClass) {
final FieldDescriptor fd = OjbUtil.findFieldDescriptor(mappedClass, fieldName, descriptorRepositories);
if (fd != null) {
final Class<?> fc = ResolverUtil.getType(enclosingClass, fieldName);
final String columnType = fd.getColumnType();
if (isLob(columnType)) {
if (isValidFieldType(fc)) {
return new NodeData(new MarkerAnnotationExpr(new NameExpr(SIMPLE_NAME)),
new ImportDeclaration(new QualifiedNameExpr(new NameExpr(PACKAGE), SIMPLE_NAME), false, false));
} else {
LOG.error(ResolverUtil.logMsgForField(enclosingClass, fieldName, mappedClass) + " is not a valid field type for the @Lob annotation, must be one of " + VALID_TYPES_STR);
}
}
return null;
}
return null;
}
示例6: getAnnotationNodes
import japa.parser.ast.ImportDeclaration; //导入依赖的package包/类
@Override
protected NodeData getAnnotationNodes(String enclosingClass, String fieldName, String mappedClass) {
final FieldDescriptor fd = OjbUtil.findFieldDescriptor(mappedClass, fieldName, descriptorRepositories);
if (fd != null) {
final Class<?> fc = ResolverUtil.getType(enclosingClass, fieldName);
if (isEnum(fc)) {
final Comment fixme = new BlockComment("\nFIXME:\n" +
"Enums must be annotated with the @Enumerated annotation.\n " +
"The @Enumerated annotation should set the EnumType.\n" +
"If the EnumType is not set, then the Enumerated annotation is defaulted to EnumType.ORDINAL.\n" +
"This conversion program cannot tell whether EnumType.ORDINAL is the appropriate EnumType.");
AnnotationExpr enumerated = new NormalAnnotationExpr(new NameExpr(SIMPLE_NAME), Collections.singletonList(new MemberValuePair("value", new NameExpr("EnumType."))));
enumerated.setComment(fixme);
return new NodeData(enumerated, new ImportDeclaration(new QualifiedNameExpr(new NameExpr(PACKAGE), SIMPLE_NAME), false, false),
Collections.singletonList(new ImportDeclaration(new QualifiedNameExpr(new NameExpr(PACKAGE), "TemporalType"), false, false)));
}
}
return null;
}
示例7: resolve
import japa.parser.ast.ImportDeclaration; //导入依赖的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;
}
示例8: getAnnotationNodes
import japa.parser.ast.ImportDeclaration; //导入依赖的package包/类
@Override
protected NodeData getAnnotationNodes(String enclosingClass, String fieldName, String mappedClass) {
final FieldDescriptor fd = OjbUtil.findFieldDescriptor(mappedClass, fieldName, descriptorRepositories);
if (fd != null) {
final boolean autoInc = fd.isAutoIncrement();
final String seqName = fd.getSequenceName();
if (autoInc && StringUtils.isBlank(seqName)) {
LOG.error(ResolverUtil.logMsgForField(enclosingClass, fieldName, mappedClass) + " field has autoincrement set to true but sequenceName is blank.");
}
if (!autoInc && StringUtils.isNotBlank(seqName)) {
LOG.error(ResolverUtil.logMsgForField(enclosingClass, fieldName, mappedClass) + " field has autoincrement set to false but sequenceName is " + seqName + ".");
}
if (autoInc || StringUtils.isNotBlank(seqName)) {
return new NodeData(new NormalAnnotationExpr(new NameExpr(SIMPLE_NAME), Collections.singletonList(new MemberValuePair("name", new StringLiteralExpr(upperCaseTableName ? seqName.toUpperCase() : seqName)))),
new ImportDeclaration(new QualifiedNameExpr(new NameExpr(PACKAGE), SIMPLE_NAME), false, false));
}
}
return null;
}
示例9: resolve
import japa.parser.ast.ImportDeclaration; //导入依赖的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;
}
示例10: resolve
import japa.parser.ast.ImportDeclaration; //导入依赖的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;
}
示例11: getAnnotationNodes
import japa.parser.ast.ImportDeclaration; //导入依赖的package包/类
/** gets the annotation but also adds an import in the process if a Convert annotation is required. */
@Override
protected NodeData getAnnotationNodes(String enclosingClass, String fieldName, String mappedClass) {
final CollectionDescriptor cld = OjbUtil.findCollectionDescriptor(mappedClass, fieldName, descriptorRepositories);
if (cld != null) {
Collection<FieldHelper> orderBy = cld.getOrderBy();
if (orderBy != null && !orderBy.isEmpty()) {
String orderByStr = "";
for (FieldHelper fh : orderBy) {
orderByStr += fh.name + (fh.isAscending ? "" : " DESC") + ", ";
}
orderByStr = orderByStr.replaceAll(", $", "");
return new NodeData(new SingleMemberAnnotationExpr(new NameExpr(SIMPLE_NAME), new StringLiteralExpr(orderByStr)),
new ImportDeclaration(new QualifiedNameExpr(new NameExpr(PACKAGE), SIMPLE_NAME), false, false));
}
}
return null;
}
示例12: getAnnotationNodes
import japa.parser.ast.ImportDeclaration; //导入依赖的package包/类
@Override
protected NodeData getAnnotationNodes(String enclosingClass, String fieldName, String mappedClass) {
final FieldDescriptor fd = OjbUtil.findFieldDescriptor(mappedClass, fieldName, descriptorRepositories);
if (fd != null) {
final boolean autoInc = fd.isAutoIncrement();
final String seqName = fd.getSequenceName();
if (autoInc && StringUtils.isBlank(seqName)) {
LOG.error(ResolverUtil.logMsgForField(enclosingClass, fieldName, mappedClass) + " field has autoincrement set to true but sequenceName is blank.");
}
if (!autoInc && StringUtils.isNotBlank(seqName)) {
LOG.error(ResolverUtil.logMsgForField(enclosingClass, fieldName, mappedClass) + " field has autoincrement set to false but sequenceName is " + seqName + ".");
}
if (autoInc || StringUtils.isNotBlank(seqName)) {
return new NodeData(new NormalAnnotationExpr(new NameExpr(SIMPLE_NAME), Collections.singletonList(new MemberValuePair("generator", new StringLiteralExpr(upperCaseTableName ? seqName.toUpperCase() : seqName)))),
new ImportDeclaration(new QualifiedNameExpr(new NameExpr(PACKAGE), SIMPLE_NAME), false, false));
}
}
return null;
}
示例13: resolve
import japa.parser.ast.ImportDeclaration; //导入依赖的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));
}
示例14: resolve
import japa.parser.ast.ImportDeclaration; //导入依赖的package包/类
@Override
public 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 boolean mappedColumn = OjbUtil.isMappedColumn(mappedClass, ParserUtil.getFieldName(field),
descriptorRepositories);
if (!mappedColumn) {
return new NodeData(new MarkerAnnotationExpr(new NameExpr(SIMPLE_NAME)),
new ImportDeclaration(new QualifiedNameExpr(new NameExpr(PACKAGE), SIMPLE_NAME), false, false));
}
}
return null;
}
示例15: getAnnotationNodes
import japa.parser.ast.ImportDeclaration; //导入依赖的package包/类
@Override
protected NodeData getAnnotationNodes(String enclosingClass, String fieldName, String mappedClass) {
final List<Expression> joinColumns = getJoinColumns(enclosingClass, fieldName, mappedClass);
if (joinColumns != null && joinColumns.size() > 1) {
final Comment fixme = new BlockComment("\nFIXME: JPA_CONVERSION\n"
+ "For compound primary keys, make sure the join columns are in the correct order.\n");
AnnotationExpr
annotation = new SingleMemberAnnotationExpr(new NameExpr(SIMPLE_NAME), new ArrayInitializerExpr(joinColumns));
annotation.setComment(fixme);
return new NodeData(annotation,
new ImportDeclaration(new QualifiedNameExpr(new NameExpr(PACKAGE), SIMPLE_NAME), false, false),
Arrays.asList(
new ImportDeclaration(new QualifiedNameExpr(new NameExpr(PrimaryKeyJoinColumnResolver.PACKAGE),PrimaryKeyJoinColumnResolver.SIMPLE_NAME), false, false)
, new ImportDeclaration(new QualifiedNameExpr(new NameExpr(JoinColumnResolver.PACKAGE),JoinColumnResolver.SIMPLE_NAME), false, false)
));
}
return null;
}