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


Java ImportDeclaration类代码示例

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


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

示例1: tryResolveFullName

import com.github.javaparser.ast.ImportDeclaration; //导入依赖的package包/类
/**
 * If the name is dotted this just returns immediately because it's already qualified. If
 * not this walks all imports trying to find the import that gets this class. When found
 * it will return the qualified name; if not the name is returned unaltered.
 */
String tryResolveFullName(String className) {
	if(className.contains("."))
		return className;

	for(ImportDeclaration id : getUnit().getImports()) {
		String name = id.getName().asString();
		int pos = name.lastIndexOf('.');
		if(pos > 0) {
			if(className.equals(name.substring(pos + 1))) {
				return name;
			}
		}
	}
	return className;
}
 
开发者ID:fjalvingh,项目名称:domui,代码行数:21,代码来源:ClassWrapper.java

示例2: parseFields

import com.github.javaparser.ast.ImportDeclaration; //导入依赖的package包/类
private void parseFields(NodeList<ImportDeclaration> imports, List<FieldDeclaration> fields) {
	fields.forEach(f -> {
		// Map field type
		String type = trimType(f.getElementType().asString());
		int typeStart = toIndex(f.getElementType().getBegin().get());
		String full = getQuantified(imports, type);
		ClassMapping cm = jremap.getJarReader().getMapping().getMapping(full);
		if (cm != null) {
			fill(typeStart - 1, type, cm);
		}
		// Map field name
		VariableDeclarator var = f.getVariable(0);
		String name = var.getNameAsString();
		String desc = getArr(f.getElementType()) + (full.length() == 1 ? full : "L" + full + ";");
		int start = toIndex(var.getBegin().get()) - 1;
		MemberMapping mm = jremap.getCurrentClass().getMemberMappingWithRenaming(name, desc);
		if (mm != null) {
			fill(start, name, mm);
		}
	});
}
 
开发者ID:Col-E,项目名称:JRemapper,代码行数:22,代码来源:Context.java

示例3: getPrelude

import com.github.javaparser.ast.ImportDeclaration; //导入依赖的package包/类
public String getPrelude() {

        for (ImportDeclaration node : nodes) {

            try {
                if (node.isStatic()) {
                    if (node.isAsterisk()) {
                        importStatic(node.getName().toString());
                    } else {
                        QualifiedNameExpr fqn = (QualifiedNameExpr) node.getChildrenNodes().get(0);
                        importMethod(fqn.getQualifier().toString(), fqn.getName());
                    }
                } else if (node.isAsterisk()) {
                    importPackage(node.getName().toString());
                } else {
                    importClass(node.getName().toString());
                }
            } catch (ClassNotFoundException | NoSuchMethodException ex) {
                LOG.log(Level.WARNING, null, ex);
            }

        }

        return prelude.toString();

    }
 
开发者ID:Nosorog,项目名称:nosorog-core,代码行数:27,代码来源:Importer.java

示例4: visit

import com.github.javaparser.ast.ImportDeclaration; //导入依赖的package包/类
@Override
public void visit(final ImportDeclaration n, final Object arg) {
    printer.printLn("ImportDeclaration");
    printJavaComment(n.getComment(), arg);
    printer.print("import ");
    if (n.isStatic()) {
        printer.print("static ");
    }
    n.getName().accept(this, arg);
    if (n.isAsterisk()) {
        printer.print(".*");
    }
    printer.printLn(";");

    printOrphanCommentsEnding(n);
}
 
开发者ID:pcgomes,项目名称:javaparser2jctree,代码行数:17,代码来源:ASTDumpVisitor.java

示例5: visit

import com.github.javaparser.ast.ImportDeclaration; //导入依赖的package包/类
@Override
public JCTree visit(final ImportDeclaration n, final Object arg) {
    //ARG0: JCTree qualid
    JCTree arg0;

    JCExpression packagename = (JCExpression) n.getName().accept(this, arg);
    // JavaParser remove asterisk from name. Adding it back;
    if (n.isAsterisk()) {
        arg0 = new AJCFieldAccess(make.Select(packagename, names.fromString("*")), null);
    } else {
        arg0 = packagename;
    }

    //ARG1: boolean importStatic
    boolean arg1 = n.isStatic();

    return new AJCImport(make.Import(arg0, arg1), ((n.getComment() != null) ? n.getComment().getContent() : null));
}
 
开发者ID:pcgomes,项目名称:javaparser2jctree,代码行数:19,代码来源:JavaParser2JCTree.java

示例6: mergeContent

import com.github.javaparser.ast.ImportDeclaration; //导入依赖的package包/类
public static String mergeContent(CompilationUnit one, CompilationUnit two) throws Exception {

        // 包声明不同,返回null
        if (!one.getPackage().equals(two.getPackage())) return null;

        CompilationUnit cu = new CompilationUnit();

        // add package declaration to the compilation unit
        PackageDeclaration pd = new PackageDeclaration();
        pd.setName(one.getPackage().getName());
        cu.setPackage(pd);

        // check and merge file comment;
        Comment fileComment = mergeSelective(one.getComment(), two.getComment());
        cu.setComment(fileComment);

        // check and merge imports
        List<ImportDeclaration> ids = mergeListNoDuplicate(one.getImports(), two.getImports());
        cu.setImports(ids);

        // check and merge Types
        List<TypeDeclaration> types = mergeTypes(one.getTypes(), two.getTypes());
        cu.setTypes(types);

        return cu.toString();
    }
 
开发者ID:beihaifeiwu,项目名称:dolphin,代码行数:27,代码来源:JavaSourceUtils.java

示例7: visit

import com.github.javaparser.ast.ImportDeclaration; //导入依赖的package包/类
@Override public void visit(final CompilationUnit n, final Object arg) {
printJavaComment(n.getComment(), arg);

if (n.getPackage() != null) {
    n.getPackage().accept(this, arg);
}

if (!isNullOrEmpty(n.getImports())) {
    for (final ImportDeclaration i : n.getImports()) {
	i.accept(this, arg);
    }
    printer.printLn();
}

if (!isNullOrEmpty(n.getTypes())) {
    for (final Iterator<TypeDeclaration> i = n.getTypes().iterator(); i.hasNext();) {
	i.next().accept(this, arg);
	printer.printLn();
	if (i.hasNext()) {
	    printer.printLn();
	}
    }
}

       printOrphanCommentsEnding(n);
   }
 
开发者ID:plum-umd,项目名称:java-sketch,代码行数:27,代码来源:DumpVisitor.java

示例8: visit

import com.github.javaparser.ast.ImportDeclaration; //导入依赖的package包/类
@Override public void visit(final CompilationUnit n, final A arg) {
	visitComment(n.getComment(), arg);
	if (n.getPackage() != null) {
		n.getPackage().accept(this, arg);
	}
	if (n.getImports() != null) {
		for (final ImportDeclaration i : n.getImports()) {
			i.accept(this, arg);
		}
	}
	if (n.getTypes() != null) {
		for (final TypeDeclaration typeDeclaration : n.getTypes()) {
			typeDeclaration.accept(this, arg);
		}
	}
}
 
开发者ID:plum-umd,项目名称:java-sketch,代码行数:17,代码来源:VoidVisitorAdapter.java

示例9: visit

import com.github.javaparser.ast.ImportDeclaration; //导入依赖的package包/类
@Override public void visit(final CompilationUnit n, final A arg) {
    visitComment(n.getComment(), arg);
    if (n.getPackage() != null) {
        n.getPackage().accept(this, arg);
    }
    if (n.getImports() != null) {
        for (final ImportDeclaration i : n.getImports()) {
            i.accept(this, arg);
        }
    }
    if (n.getTypes() != null) {
        for (final TypeDeclaration typeDeclaration : n.getTypes()) {
            typeDeclaration.accept(this, arg);
        }
    }
}
 
开发者ID:plum-umd,项目名称:java-sketch,代码行数:17,代码来源:JsonVisitorAdapter.java

示例10: visit

import com.github.javaparser.ast.ImportDeclaration; //导入依赖的package包/类
@Override public Node visit(final CompilationUnit n, final A arg) {
	if (n.getPackage() != null) {
		n.setPackage((PackageDeclaration) n.getPackage().accept(this, arg));
	}
	final List<ImportDeclaration> imports = n.getImports();
	if (imports != null) {
		for (int i = 0; i < imports.size(); i++) {
			imports.set(i, (ImportDeclaration) imports.get(i).accept(this, arg));
		}
		removeNulls(imports);
	}
	final List<TypeDeclaration> types = n.getTypes();
	if (types != null) {
		for (int i = 0; i < types.size(); i++) {
			types.set(i, (TypeDeclaration) types.get(i).accept(this, arg));
		}
		removeNulls(types);
	}
	return n;
}
 
开发者ID:plum-umd,项目名称:java-sketch,代码行数:21,代码来源:ModifierVisitorAdapter.java

示例11: importParametersForType

import com.github.javaparser.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);
}
 
开发者ID:BenDol,项目名称:Databind,代码行数:24,代码来源:JavaParserUtils.java

示例12: determineQualifiedName

import com.github.javaparser.ast.ImportDeclaration; //导入依赖的package包/类
public static String determineQualifiedName(final CompilationUnit compilationUnit,
                                           final NameExpr nameExpr) {
    final ImportDeclaration importDeclaration = getImportDeclarationFor(
        compilationUnit, nameExpr);

    if (importDeclaration == null) {
        if (JdkJavaType.isPartOfJavaLang(nameExpr.getName())) {
            return "java.lang." + nameExpr.getName();
        }

        String unitPackage = compilationUnit.getPackage().getName().toString();
        return unitPackage.equals("") ? nameExpr.getName()
            : unitPackage + "." + nameExpr.getName();
    }
    return null;
}
 
开发者ID:BenDol,项目名称:Databind,代码行数:17,代码来源:TypeUtil.java

示例13: visit

import com.github.javaparser.ast.ImportDeclaration; //导入依赖的package包/类
@Override
public void visit(CompilationUnit node, Object arg) {
    if (node == null || node.getPackage() == null || node.getPackage().getName() == null) {
        return;
    }
    Log.d(TAG, "visit CompilationUnit, packageName: %s", node.getPackage().getName());
    sourceInfo.setPackageName(node.getPackage().getName().toString());
    if (node.getImports() != null && node.getImports().size() > 0) {
        for (ImportDeclaration importDeclaration : node.getImports()) {
            Log.d(TAG, "visit CompilationUnit, import: %s", importDeclaration.getName());
            sourceInfo.addImports(importDeclaration.isAsterisk() ? importDeclaration.getName().toString() + ".*" :
                importDeclaration.getName().toString());
        }
    }
    super.visit(node, arg);
}
 
开发者ID:ragnraok,项目名称:JParserUtil,代码行数:17,代码来源:SourceTreeVisitor.java

示例14: solve

import com.github.javaparser.ast.ImportDeclaration; //导入依赖的package包/类
private void solve(Node node) {
    if (node instanceof ClassOrInterfaceDeclaration) {
        solveTypeDecl((ClassOrInterfaceDeclaration) node);
    } else if (node instanceof Expression) {
        if ((getParentNode(node) instanceof ImportDeclaration) || (getParentNode(node) instanceof Expression)
                || (getParentNode(node) instanceof MethodDeclaration)
                || (getParentNode(node) instanceof PackageDeclaration)) {
            // skip
        } else if ((getParentNode(node) instanceof Statement) || (getParentNode(node) instanceof VariableDeclarator)) {
            try {
                Type ref = JavaParserFacade.get(typeSolver).getType(node);
                out.println("  Line " + node.getRange().get().begin.line + ") " + node + " ==> " + ref.describe());
                ok++;
            } catch (UnsupportedOperationException upe) {
                unsupported++;
                err.println(upe.getMessage());
                throw upe;
            } catch (RuntimeException re) {
                ko++;
                err.println(re.getMessage());
                throw re;
            }
        }
    }
}
 
开发者ID:javaparser,项目名称:javasymbolsolver,代码行数:26,代码来源:SourceFileInfoExtractor.java

示例15: visit

import com.github.javaparser.ast.ImportDeclaration; //导入依赖的package包/类
@Override public void visit(final CompilationUnit n, final Object arg) {
	printJavaComment(n.getComment(), arg);

	if (n.getPackage() != null) {
		n.getPackage().accept(this, arg);
	}

	if (n.getImports() != null) {
		for (final ImportDeclaration i : n.getImports()) {
			i.accept(this, arg);
		}
		printer.printLn();
	}

	if (n.getTypes() != null) {
		for (final Iterator<TypeDeclaration> i = n.getTypes().iterator(); i.hasNext();) {
			i.next().accept(this, arg);
			printer.printLn();
			if (i.hasNext()) {
				printer.printLn();
			}
		}
	}

       printOrphanCommentsEnding(n);
}
 
开发者ID:javaparser,项目名称:javasymbolsolver,代码行数:27,代码来源:DumpVisitor.java


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