Package org.eclipse.jdt.core.dom

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


       
        // add all imports to source
        List imports = m_importsTracker.freeze(m_name);
        for (Iterator iter = imports.iterator(); iter.hasNext();) {
            String type = (String)iter.next();
            ImportDeclaration imp = m_ast.newImportDeclaration();
            imp.setName(m_ast.newName(type));
            m_compilationUnit.imports().add(imp);
        }
       
        // convert generated AST to text document
        Map options = new HashMap();
View Full Code Here


      return null;
    }
    ArrayList importDecl = new ArrayList();
    ListIterator iter = imports.listIterator();
    while (iter.hasNext()) {
      ImportDeclaration decl = (ImportDeclaration) iter.next();
      importDecl.add(decl.getName().toString());
    }
    return importDecl;
  }
View Full Code Here

            if (curr.getSourceEnd() < importsEnd) {
                int id = curr.getID();
                if (id == IProblem.UnusedImport || id == IProblem.NotVisibleType) { // not visible problems hide unused -> remove both
                    int pos = curr.getSourceStart();
                    for (int k = 0; k < importsDecls.size(); k++) {
                        ImportDeclaration decl = importsDecls.get(k);
                        if (decl.getStartPosition() <= pos && pos < decl.getStartPosition() + decl.getLength()) {
                            if (existingImports.isEmpty() || !existingImports.contains(ASTNodes.asString(decl))) {
                                String name = decl.getName().getFullyQualifiedName();
                                if (decl.isOnDemand()) {
                                    name += ".*"; //$NON-NLS-1$
                                }
                                if (decl.isStatic()) {
                                    imports.removeStaticImport(name);
                                } else {
                                    imports.removeImport(name);
                                }
                            }
View Full Code Here

            if (curr.getSourceEnd() < importsEnd) {
                int id = curr.getID();
                if (id == IProblem.UnusedImport || id == IProblem.NotVisibleType) { // not visible problems hide unused -> remove both
                    int pos = curr.getSourceStart();
                    for (int k = 0; k < importsDecls.size(); k++) {
                        ImportDeclaration decl = importsDecls.get(k);
                        if (decl.getStartPosition() <= pos && pos < decl.getStartPosition() + decl.getLength()) {
                            if (existingImports.isEmpty() || !existingImports.contains(ASTNodes.asString(decl))) {
                                String name = decl.getName().getFullyQualifiedName();
                                if (decl.isOnDemand()) {
                                    name += ".*"; //$NON-NLS-1$
                                }
                                if (decl.isStatic()) {
                                    imports.removeStaticImport(name);
                                } else {
                                    imports.removeImport(name);
                                }
                            }
View Full Code Here

  public boolean visit(CompilationUnit node) {
    IValue packageOfUnit = node.getPackage() == null ? null : visitChild(node.getPackage());
   
    IValueList imports = new IValueList(values);
    for (Iterator it = node.imports().iterator(); it.hasNext();) {
      ImportDeclaration d = (ImportDeclaration) it.next();
      imports.add(visitChild(d));
    }
 
    IValueList typeDeclarations = new IValueList(values);
    for (Iterator it = node.types().iterator(); it.hasNext();) {
View Full Code Here

    private String[] readPackage(ASTNode selectedNode, IProblemLocation location)
    {
        ArrayList<String> packages = new ArrayList<String>();

        ImportDeclaration id = (ImportDeclaration) ASTNodes.getParent(selectedNode,
            ASTNode.IMPORT_DECLARATION);

        if (id == null)
        {
            MethodInvocation m = (MethodInvocation) ASTNodes.getParent(selectedNode,
                ASTNode.METHOD_INVOCATION);

            if (m != null)
            {
                packages.add(readPackage(m));
                while (m.getExpression() != null
                    && m.getExpression() instanceof MethodInvocation)
                {
                    m = (MethodInvocation) m.getExpression();
                    packages.add(readPackage(m));
                }
            }
        }
        else
        {
            if (id.isOnDemand())
            {
                packages.add(id.getName().toString());
            }
            else
            {
                String iStr = id.getName().toString();
                packages.add(iStr.substring(0, iStr.lastIndexOf(".")));
            }
        }

        return packages.toArray(new String[packages.size()]);
View Full Code Here

      newParser.setSource(str.toCharArray());
      StringBuilder bls=new StringBuilder(str);
      CompilationUnit createAST = (CompilationUnit) newParser.createAST(null);
      //ArrayList<String> results = new ArrayList<String>();
      for (Object n : createAST.imports()) {
        ImportDeclaration decl = (ImportDeclaration) n;
        String name = decl.getName().getFullyQualifiedName();
        if (decl.isOnDemand()) {
          bs.append("import "+name+".*;");
         
        } else {
          bs.append("import "+name+";");
        }
        int i = decl.getStartPosition()+decl.getLength();
        for (int a=decl.getStartPosition();a<i;a++){
          bls.setCharAt(a, ' ');
        }
      }
     
      bs
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);

      // if next import is on a different line, modify the end position to the next line begin offset
      if (currEndLine < nextOffsetLine) {
        currEndLine++;
View Full Code Here

  }

  private IRegion evaluateReplaceRange(CompilationUnit root) {
    List imports= root.imports();
    if (!imports.isEmpty()) {
      ImportDeclaration first= (ImportDeclaration) imports.get(0);
      ImportDeclaration last= (ImportDeclaration) imports.get(imports.size() - 1);

      int startPos= first.getStartPosition(); // no extended range for first: bug 121428
      int endPos= root.getExtendedStartPosition(last) + root.getExtendedLength(last);
      int endLine= root.getLineNumber(endPos);
      if (endLine > 0) {
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

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.