當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。