Tabnine Logo
CompilationUnit
Code IndexAdd Tabnine to your IDE (free)

How to use
CompilationUnit
in
japa.parser.ast

Best Java code snippets using japa.parser.ast.CompilationUnit (Showing top 20 results out of 315)

origin: com.google.code.javaparser/javaparser

@Override
public Node visit(CompilationUnit _n, Object _arg) {
  PackageDeclaration package_ = cloneNodes(_n.getPackage(), _arg);
  List<ImportDeclaration> imports = visit(_n.getImports(), _arg);
  List<TypeDeclaration> types = visit(_n.getTypes(), _arg);
  return new CompilationUnit(
      _n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn(),
      package_, imports, types
  );
}
origin: paypal/SeLion

/**
 * This method will add methods, fields and import statement to existing java file
 * 
 * @throws IOException
 * @throws ParseException
 */
public void insertCode() throws IOException, ParseException {
  CompilationUnit cuResult = JavaParser.parse(baseFile);
  if (cuResult.getImports() != null) {
    List<ImportDeclaration> importsFromBaseFile = cuResult.getImports();
    for (ImportDeclaration eachImport : importsFromExtendedFile) {
      if (!importAlreadyPresent(importsFromBaseFile, eachImport)) {
        importsFromBaseFile.add(eachImport);
      }
    }
    cuResult.setImports(importsFromBaseFile);
  }
  String code = cuResult.toString();
  BufferedWriter b = new BufferedWriter(new FileWriter(baseFile));
  b.write(code);
  b.close();
}
origin: com.google.code.javaparser/javaparser

public CompilationUnit(PackageDeclaration pakage, List<ImportDeclaration> imports, List<TypeDeclaration> types) {
  setPackage(pakage);
  setImports(imports);
  setTypes(types);
}
origin: com.google.code.javaparser/javaparser

/**
 * 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);
}
origin: com.google.code.javaparser/javaparser

@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);
    }
  }
}
origin: com.google.code.javaparser/javaparser

@Override public Boolean visit(final CompilationUnit n1, final Node arg) {
  final CompilationUnit n2 = (CompilationUnit) arg;
  if (!nodeEquals(n1.getPackage(), n2.getPackage())) {
    return Boolean.FALSE;
  }
  if (!nodesEquals(n1.getImports(), n2.getImports())) {
    return Boolean.FALSE;
  }
  if (!nodesEquals(n1.getTypes(), n2.getTypes())) {
    return Boolean.FALSE;
  }
  if (!nodesEquals(n1.getComments(), n2.getComments())) {
    return Boolean.FALSE;
  }
  return Boolean.TRUE;
}
origin: com.google.code.javaparser/javaparser

@Override
public R visit(final CompilationUnit n, final A arg) {
  if (n.getPackage() != null) {
      R result = n.getPackage().accept(this, arg);
      if (result != null) {
        return result;
  if (n.getImports() != null) {
    for (final ImportDeclaration i : n.getImports()) {
  if (n.getTypes() != null) {
    for (final TypeDeclaration typeDeclaration : n.getTypes()) {
origin: com.google.code.javaparser/javaparser

@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;
}
origin: org.mule.tools/mule-cloud-connector-generator

private TypeDeclaration typeDeclarationFromCompilationUnit()
{
  List<TypeDeclaration> typeDeclarations = compilationUnit.getTypes();
  if (typeDeclarations == null)
  {
    throw new IllegalArgumentException("Source file does not contain a Java class");
  }
  if (typeDeclarations.size() > 1)
  {
    throw new IllegalArgumentException("Source file contains more than one Java class");
  }
  return typeDeclarations.get(0);
}
origin: org.mule.tools/mule-cloud-connector-generator

  private String packageNameFromCompilationUnit()
  {
    PackageDeclaration packageDeclaration = compilationUnit.getPackage();
    if (packageDeclaration == null)
    {
      throw new IllegalArgumentException("Source file does not declare a package. Default package is unsupported.");
    }
    return packageDeclaration.getName().toString();
  }
}
origin: org.kuali.rice/rice-development-tools

final List<ImportDeclaration> imports = unit.getImports() != null ? unit.getImports() : new ArrayList<ImportDeclaration>();
final boolean foundAnnImport = imported(imports, fullyQualifiedName);
    unit.setImports(imports);
      final TypeDeclaration parent = unit.getTypes().get(0);
origin: org.kuali.rice/rice-development-tools

final String enclosingName = n.getPackage().getName() + "." + n.getTypes().get(0).getName();
origin: org.chromattic/chromattic.testgenerator

public void build() {
 UnitChromatticVisitor unitChromatticVisitor = new UnitChromatticVisitor();
 compilationUnit.getPackage().getName().setName(compilationUnit.getPackage().getName().getName() + ".groovy");
 unitChromatticVisitor.visit(compilationUnit, null);
 sb.append(compilationUnit.toString(new GroovyCompatibilityFactory()));
}
origin: org.chromattic/chromattic.testgenerator

public void build(DumpVisitorFactory factory, List<String> excludedMethods) {
 UnitTestVisitor unitTestVisitor = new UnitTestVisitor(name);
 //
 Iterator<ImportDeclaration> itImports = compilationUnit.getImports().iterator();
 while (itImports.hasNext()) {
  if (GroovyTestGeneration.class.getName().equals(itImports.next().getName().toString())) {
   itImports.remove();
  }
 }
 //
 for (String dep : deps)
 {
  int i = dep.lastIndexOf(".");
  String depPackage = dep.substring(0, i) + ".groovy";
  String depImport = depPackage + dep.substring(i);
  compilationUnit.getImports().add(new ImportDeclaration(new NameExpr(depImport), false, false));
 }
 //
 unitTestVisitor.visit(compilationUnit, excludedMethods);
 sb.append(compilationUnit.toString(factory));
}
origin: com.google.code.javaparser/javaparser

/**
 * Comments are attributed to the thing the comment and are removed from
 * allComments.
 */
private static void insertCommentsInCu(CompilationUnit cu, CommentsCollection commentsCollection){
  if (commentsCollection.size()==0) return;
  // I should sort all the direct children and the comments, if a comment is the first thing then it
  // a comment to the CompilationUnit
  // FIXME if there is no package it could be also a comment to the following class...
  // so I could use some heuristics in these cases to distinguish the two cases
  List<Comment> comments = commentsCollection.getAll();
  sortByBeginPosition(comments);
  List<Node> children = cu.getChildrenNodes();
  sortByBeginPosition(children);
  if (cu.getPackage()!=null && (children.size()==0 || areInOrder(comments.get(0), children.get(0)))){
    cu.setComment(comments.get(0));
    comments.remove(0);
  }
  insertCommentsInNode(cu,comments);
}
origin: paypal/SeLion

private void initialize() throws IOException, ParseException {
  CompilationUnit cu = JavaParser.parse(file);
  if (cu.getImports() != null) {
    imports = cu.getImports();
  }
  initializeFieldDetails(cu);
  initializeMethodDetails(cu);
}
origin: juzu/juzu

public void assertSave() {
 assertSave(cu.toString());
}
origin: com.google.code.javaparser/javaparser

throw new ParseException();
CompilationUnit tmp = new CompilationUnit(line == -1 ? 0 : line, column, token.endLine, token.endColumn,pakage, imports, types);
origin: com.google.code.javaparser/javaparser

@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);
}
origin: org.chromattic/chromattic.testgenerator

public void visit(CompilationUnit n, Object arg) {
  if (n.getPackage() != null) {
    n.getPackage().accept(this, arg);
  }
  if (n.getImports() != null) {
    for (ImportDeclaration i : n.getImports()) {
      i.accept(this, arg);
    }
    printer.printLn();
  }
  if (n.getTypes() != null) {
    for (Iterator<TypeDeclaration> i = n.getTypes().iterator(); i.hasNext();) {
      i.next().accept(this, arg);
      printer.printLn();
      if (i.hasNext()) {
        printer.printLn();
      }
    }
  }
}
japa.parser.astCompilationUnit

Javadoc

This class represents the entire compilation unit. Each java file denotes a compilation unit.

The CompilationUnit is constructed following the syntax:
CompilationUnit ::= ( PackageDeclaration )?
( ImportDeclaration )*
( TypeDeclaration )*

Most used methods

  • getTypes
    Return the list of types declared in this compilation unit. If there is no types declared, null is r
  • getPackage
    Retrieves the package declaration of this compilation unit. If this compilation unit has no package
  • getImports
    Retrieves the list of imports declared in this compilation unit ornull if there is no import.
  • setImports
    Sets the list of imports of this compilation unit. The list is initiallynull.
  • toString
  • <init>
  • accept
  • equals
  • getAllContainedComments
  • getBeginColumn
  • getBeginLine
  • getChildrenNodes
  • getBeginLine,
  • getChildrenNodes,
  • getComment,
  • getComments,
  • getEndColumn,
  • getEndLine,
  • setAsParentNodeOf,
  • setComment,
  • setPackage,
  • setTypes

Popular in Java

  • Making http requests using okhttp
  • onRequestPermissionsResult (Fragment)
  • getResourceAsStream (ClassLoader)
  • getSharedPreferences (Context)
  • URL (java.net)
    A Uniform Resource Locator that identifies the location of an Internet resource as specified by RFC
  • SQLException (java.sql)
    An exception that indicates a failed JDBC operation. It provides the following information about pro
  • Queue (java.util)
    A collection designed for holding elements prior to processing. Besides basic java.util.Collection o
  • SortedMap (java.util)
    A map that has its keys ordered. The sorting is according to either the natural ordering of its keys
  • UUID (java.util)
    UUID is an immutable representation of a 128-bit universally unique identifier (UUID). There are mul
  • Option (scala)
  • Top plugins for Android Studio
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now