Package org.eclipse.jdt.core.dom

Examples of org.eclipse.jdt.core.dom.ImportDeclaration


    PackageDeclaration packageDeclaration = ast.newPackageDeclaration();
    packageDeclaration.setName(ast.newName("org.kissmda.test.junit"));
    cu.setPackage(packageDeclaration);

    ImportDeclaration importDeclaration = ast.newImportDeclaration();
    importDeclaration
        .setName(ast.newName("org.junit.Assert.assertNotNull"));
    importDeclaration.setStatic(true);
    cu.imports().add(importDeclaration);

    logger.info(cu.toString());
    new ImportPacker(cu).pack();
View Full Code Here


        .equals(name.getQualifier().getFullyQualifiedName());
  }

  @SuppressWarnings("unchecked")
  private void addImport(AST ast, QualifiedName qualifiedName) {
    ImportDeclaration impDecl = ast.newImportDeclaration();
    impDecl.setName(ast.newName(qualifiedName.getFullyQualifiedName()));
    compilationUnit.imports().add(impDecl);
  }
View Full Code Here

    PackageDeclaration p1 = ast.newPackageDeclaration();
    p1.setName(ast.newSimpleName("foo"));
    cu.setPackage(p1);

    ImportDeclaration id = ast.newImportDeclaration();
    id.setName(ast.newName(new String[] {
        "java", "util", "Set" }));
    cu.imports().add(id);

    TypeDeclaration td = ast.newTypeDeclaration();
    td.setName(ast.newSimpleName("Foo"));
View Full Code Here

    @SuppressWarnings("unchecked")
    List<ImportDeclaration> imports = astRoot.imports();
    String lineDelim = src.findRecommendedLineSeparator();
    MultiTextEdit edit = new MultiTextEdit();
    ImportDeclaration next = null;
    for (int i = imports.size() - 1; i >= 0; i--){
      ImportDeclaration imprt = imports.get(i);
      int end = imprt.getStartPosition() + imprt.getLength() + lineDelim.length();
      if (next != null &&
          end == next.getStartPosition() &&
          !ImportUtils.importsInSameGroup(separationLevel, imprt, next))
      {
        edit.addChild(new InsertEdit(end, lineDelim));
View Full Code Here

    CompilationUnit astRoot = SharedASTProvider
      .getAST(src, SharedASTProvider.WAIT_YES, null);
    ASTNode node = NodeFinder.perform(astRoot, offset, 1);
    MultiTextEdit edit = new MultiTextEdit();
    if (node != null && node.getNodeType() == ASTNode.IMPORT_DECLARATION){
      ImportDeclaration imprt = (ImportDeclaration)node;

      ASTNode next = getNext(astRoot, node, lineDelim);
      while (next != null && next.getNodeType() == ASTNode.IMPORT_DECLARATION){
        ImportDeclaration nextImprt = (ImportDeclaration)next;
        if (!ImportUtils.importsInSameGroup(separationLevel, imprt, nextImprt)){
          int end =
            imprt.getStartPosition() +
            imprt.getLength() +
            lineDelim.length();
          addLineDelim(astRoot, edit, end, lineDelim);
        }
        next = getNext(astRoot, next, lineDelim);
        imprt = nextImprt;
      }

      // reset imprt ref back to the one we are importing.
      imprt = (ImportDeclaration)node;
      ASTNode prev = getPrev(astRoot, node, lineDelim);
      if (prev != null && prev.getNodeType() == ASTNode.IMPORT_DECLARATION){
        ImportDeclaration prevImprt = (ImportDeclaration)prev;
        if (!ImportUtils.importsInSameGroup(separationLevel, imprt, prevImprt)){
          int end = prev.getStartPosition() + prev.getLength() + lineDelim.length();
          addLineDelim(astRoot, edit, end, lineDelim);
        }
      }
View Full Code Here

  public boolean visit(CompilationUnit node) {
    if (node.getPackage() != null) {
      node.getPackage().accept(this);
    }
    for (Iterator it = node.imports().iterator(); it.hasNext(); ) {
      ImportDeclaration d = (ImportDeclaration) it.next();
      d.accept(this);
    }
    for (Iterator it = node.types().iterator(); it.hasNext(); ) {
      AbstractTypeDeclaration d = (AbstractTypeDeclaration) it.next();
      d.accept(this);
    }
    return false;
  }
View Full Code Here

  String importActualName = this.importName;
  if (onDemand) {
    importActualName = this.importName.substring(0, this.importName.length() - 2);
  }
  while (imports.hasNext()) {
    ImportDeclaration importDeclaration = (ImportDeclaration) imports.next();
    if (importActualName.equals(importDeclaration.getName().getFullyQualifiedName())
        && (onDemand == importDeclaration.isOnDemand())
        && (Flags.isStatic(this.flags) == importDeclaration.isStatic())) {
      this.creationOccurred = false;
      return null;
    }
  }

  AST ast = this.cuAST.getAST();
  ImportDeclaration importDeclaration = ast.newImportDeclaration();
  importDeclaration.setStatic(Flags.isStatic(this.flags));
  // split import name into individual fragments, checking for on demand imports
  char[][] charFragments = CharOperation.splitOn('.', importActualName.toCharArray(), 0, importActualName.length());
  int length = charFragments.length;
  String[] strFragments = new String[length];
  for (int i = 0; i < length; i++) {
    strFragments[i] = String.valueOf(charFragments[i]);
  }
  Name name = ast.newName(strFragments);
  importDeclaration.setName(name);
  if (onDemand) importDeclaration.setOnDemand(true);
  return importDeclaration;
}
View Full Code Here

    if (decls.isEmpty()) {
      return;
    }
    PackageEntry currPackage= null;

    ImportDeclaration curr= (ImportDeclaration) decls.get(0);
    int currOffset= curr.getStartPosition();
    int currLength= curr.getLength();
    int currEndLine= root.getLineNumber(currOffset + currLength);

    for (int i= 1; i < decls.size(); i++) {
      boolean isStatic= curr.isStatic();
      String name= getFullName(curr);
      String packName= getQualifier(curr);
      if (currPackage == null || currPackage.compareTo(packName, isStatic) != 0) {
        currPackage= new PackageEntry(packName, null, isStatic);
        this.packageEntries.add(currPackage);
      }

      ImportDeclaration next= (ImportDeclaration) decls.get(i);
      int nextOffset= next.getStartPosition();
      int nextLength= next.getLength();
      int nextOffsetLine= root.getLineNumber(nextOffset);

      int extendedStart = root.getExtendedStartPosition(curr);
      int extendedLength = root.getExtendedLength(curr);
      if (extendedStart < this.replaceRange.getOffset()) {
View Full Code Here

    /* for the first comment, we only take the trailing comment if any and the replace range doesn't
     * include the preceding comment
     */
    for (int i= 0; i < decls.size(); i++) {
      ImportDeclaration next= (ImportDeclaration) decls.get(i);
      int nextOffset= next.getStartPosition();
      int nextLength= next.getLength();

      int extendedStart = root.getExtendedStartPosition(next);
      int extendedLength = root.getExtendedLength(next);
      int nextOffsetLine= root.getLineNumber(nextOffset);

View Full Code Here

    IRegion precedingCommentRange = null;
    IRegion trailingCommentRange = null;
    int prevOffset = this.replaceRange.getOffset()// will store offset of the previous import's extended end
    int numOfImports = decls.size();
    for (int i= 0; i < numOfImports; i++) {
      ImportDeclaration curr= (ImportDeclaration) decls.get(i);
      int currOffset= curr.getStartPosition();
      int currLength= curr.getLength();
      int currExtendedStart = root.getExtendedStartPosition(curr);
      int currExtendedLen = root.getExtendedLength(curr);
      String name= getFullName(curr);
      String packName= getQualifier(curr);
      if (packName.equals(containerName) && (name.equals(fullTypeName) || name.endsWith("*"))) {//$NON-NLS-1$
View Full Code Here

TOP

Related Classes of org.eclipse.jdt.core.dom.ImportDeclaration

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.