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


Java CompilationUnit.setTypes方法代码示例

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


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

示例1: mergeContent

import com.github.javaparser.ast.CompilationUnit; //导入方法依赖的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

示例2: addTypeDeclaration

import com.github.javaparser.ast.CompilationUnit; //导入方法依赖的package包/类
/**
 * Adds the given type declaration to the compilation unit. The list of
 * types will be initialized if it is <code>null</code>.
 * 
 * @param cu
 *            compilation unit
 * @param type
 *            type declaration
 */
public static void addTypeDeclaration(CompilationUnit cu, TypeDeclaration type) {
    List<TypeDeclaration> types = cu.getTypes();
    if (isNullOrEmpty(types)) {
        types = new ArrayList<TypeDeclaration>();
        cu.setTypes(types);
    }
    types.add(type);

}
 
开发者ID:plum-umd,项目名称:java-sketch,代码行数:19,代码来源:ASTHelper.java

示例3: whenAClassCalledIsAddedToTheCompilationUnit

import com.github.javaparser.ast.CompilationUnit; //导入方法依赖的package包/类
@When("a public class called \"$className\" is added to the CompilationUnit")
public void whenAClassCalledIsAddedToTheCompilationUnit(String className) {
    CompilationUnit compilationUnit = (CompilationUnit) state.get("cu1");
    TypeDeclaration type = new ClassOrInterfaceDeclaration(ModifierSet.PUBLIC, false, "CreateClass");
    compilationUnit.setTypes(Arrays.asList(type));
    state.put("cu1", compilationUnit);
}
 
开发者ID:plum-umd,项目名称:java-sketch,代码行数:8,代码来源:ManipulationSteps.java

示例4: addTypeDeclaration

import com.github.javaparser.ast.CompilationUnit; //导入方法依赖的package包/类
/**
 * Adds the given type declaration to the compilation unit. The list of
 * types will be initialized if it is <code>null</code>.
 * 
 * @param cu
 *            compilation unit
 * @param type
 *            type declaration
 */
public static void addTypeDeclaration(CompilationUnit cu, TypeDeclaration type) {
    List<TypeDeclaration> types = cu.getTypes();
    if (types == null) {
        types = new ArrayList<TypeDeclaration>();
        cu.setTypes(types);
    }
    types.add(type);

}
 
开发者ID:javaparser,项目名称:javasymbolsolver,代码行数:19,代码来源:ASTHelper.java

示例5: doMerge

import com.github.javaparser.ast.CompilationUnit; //导入方法依赖的package包/类
@Override
public CompilationUnit doMerge(CompilationUnit first, CompilationUnit second) {

  CompilationUnit unit = new CompilationUnit();

  unit.setPackage(mergeSingle(first.getPackage(), second.getPackage()));

  unit.setImports(mergeCollections(first.getImports(), second.getImports()));

  unit.setTypes(mergeCollections(first.getTypes(), second.getTypes()));

  return unit;
}
 
开发者ID:beihaifeiwu,项目名称:dolphin,代码行数:14,代码来源:CompilationUnitMerger.java


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