Package org.eclipse.jdt.core.dom

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


        List imports = astRoot.imports();
        List importsToBeRemoved = new ArrayList();

        for (Iterator j = imports.iterator(); j.hasNext();) {

          ImportDeclaration anImportDecl = (ImportDeclaration) j.next();
          String importName = anImportDecl.getName().getFullyQualifiedName();
          if (importName.endsWith("Exception") || //$NON-NLS-1$
              importName.equals("com.google.gwt.core.client.GWT") || //$NON-NLS-1$
              importName.equals("com.google.gwt.user.client.rpc.ServiceDefTarget") || //$NON-NLS-1$
              importName.equals("com.google.gwt.user.client.rpc.RemoteService")//$NON-NLS-1$
          )
            importsToBeRemoved.add(anImportDecl);
        }

        imports.removeAll(importsToBeRemoved);

        ImportDeclaration importDecl = ast.newImportDeclaration();
        importDecl.setName(ast.newName("com.google.gwt.user.client.rpc.AsyncCallback")); //$NON-NLS-1$
        astRoot.imports().add(importDecl);

        // Add Async to the name
        TypeDeclaration aRemoteService = (TypeDeclaration) astRoot.types().get(0);
        String remoteServiceAsyncName = aRemoteService.getName().getFullyQualifiedName() + "Async"; //$NON-NLS-1$
View Full Code Here


        List imports = astRoot.imports();
        List importsToBeRemoved = new ArrayList();
       
        for (Iterator j = imports.iterator(); j.hasNext();) {

          ImportDeclaration anImportDecl = (ImportDeclaration) j.next();
          String importName = anImportDecl.getName().getFullyQualifiedName();
          if(importName.equals("com.google.gwt.user.client.rpc.RemoteService") || importName.endsWith("Exception")) //$NON-NLS-1$ //$NON-NLS-2$
            importsToBeRemoved.add(anImportDecl);
         
        }
       
        imports.removeAll(importsToBeRemoved);

        ImportDeclaration importDecl = ast.newImportDeclaration();
        importDecl.setName(ast.newName("com.google.gwt.user.client.rpc.AsyncCallback")); //$NON-NLS-1$
        astRoot.imports().add(importDecl);

        // Add Async to the name
        TypeDeclaration aRemoteService = (TypeDeclaration) astRoot.types().get(0);
        String remoteServiceAsyncName = aRemoteService.getName().getFullyQualifiedName()+"Async"; //$NON-NLS-1$
View Full Code Here

        List imports = astRoot.imports();
        List importsToBeRemoved = new ArrayList();
       
        for (Iterator j = imports.iterator(); j.hasNext();) {

          ImportDeclaration anImportDecl = (ImportDeclaration) j.next();
          String importName = anImportDecl.getName().getFullyQualifiedName();
          if(importName.endsWith("Exception") || //$NON-NLS-1$
              importName.equals("com.google.gwt.core.client.GWT") ||//$NON-NLS-1$
              importName.equals("com.google.gwt.user.client.rpc.ServiceDefTarget") || //$NON-NLS-1$
              importName.equals("com.google.gwt.user.client.rpc.RemoteService")//$NON-NLS-1$
             
            importsToBeRemoved.add(anImportDecl);
        }
       
        imports.removeAll(importsToBeRemoved);

        ImportDeclaration importDecl = ast.newImportDeclaration();
        importDecl.setName(ast.newName("com.google.gwt.user.client.rpc.AsyncCallback")); //$NON-NLS-1$
        astRoot.imports().add(importDecl);

        // Add Async to the name
        TypeDeclaration aRemoteService = (TypeDeclaration) astRoot.types().get(0);
        String remoteServiceAsyncName = aRemoteService.getName().getFullyQualifiedName()+"Async"; //$NON-NLS-1$
View Full Code Here

    List imports = astRoot.imports();
    List importsToBeRemoved = new ArrayList();

    for (Iterator j = imports.iterator(); j.hasNext();) {

      ImportDeclaration anImportDecl = (ImportDeclaration) j.next();
      String importName = anImportDecl.getName().getFullyQualifiedName();
      if (importName.endsWith("Exception") || //$NON-NLS-1$
          importName.equals("com.google.gwt.core.client.GWT") || //$NON-NLS-1$
          importName.equals("com.google.gwt.user.client.rpc.ServiceDefTarget") || //$NON-NLS-1$
          importName.equals("com.google.gwt.user.client.rpc.RemoteService") || //$NON-NLS-1$
          importName.equals("com.google.gwt.user.client.rpc.RemoteServiceRelativePath") //$NON-NLS-1$
      )
        importsToBeRemoved.add(anImportDecl);
    }

    imports.removeAll(importsToBeRemoved);

    ImportDeclaration importDecl = ast.newImportDeclaration();
    importDecl.setName(ast.newName("com.google.gwt.user.client.rpc.AsyncCallback")); //$NON-NLS-1$
    astRoot.imports().add(importDecl);
  }
View Full Code Here

                    break;
                }
            }

            if (transform) {
                ImportDeclaration importDeclaration = ast
                        .newImportDeclaration();
                importDeclaration.setName(AbstractTransformer.createName(ast,
                        fullName));
                root.imports().add(importDeclaration);
                loader.importClass(fullName);
            }
        }
View Full Code Here

        int length = imports.size();
        AST ast = node.getAST();

        for (int i = 0; i < (length - 1); i++) {
            for (int j = i + 1; j < length; j++) {
                ImportDeclaration import1 = (ImportDeclaration) imports.get(i);
                ImportDeclaration import2 = (ImportDeclaration) imports.get(j);

                if (import1.toString().compareTo(import2.toString()) > 0) {
                    // Swap.
                    imports.remove(j);
                    imports.remove(i);
                    imports.add(i, ASTNode.copySubtree(ast, import2));
                    imports.add(j, ASTNode.copySubtree(ast, import1));
                }
            }
        }

        if (node.getPackage() != null) {
            node.getPackage().accept(this);
        }

        for (Iterator it = node.imports().iterator(); it.hasNext();) {
            ImportDeclaration d = (ImportDeclaration) it.next();
            d.accept(this);
        }

        _output("\n");

        for (Iterator it = node.types().iterator(); it.hasNext();) {
            AbstractTypeDeclaration d = (AbstractTypeDeclaration) it.next();
            d.accept(this);
        }

        return false;
    }
View Full Code Here

                }
            }
        }

        AST ast = root.getAST();
        ImportDeclaration declaration = ast.newImportDeclaration();
        declaration.setName(createName(ast, name));
        root.imports().add(declaration);
        loader.importClass(name);
        return simpleName;
    }
View Full Code Here

    ASTParser newParser = ASTParser.newParser(AST.JLS3);
    newParser.setSource(snippet.toCharArray());
    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()) {
        results.add(name + ".*");
      } else {
        results.add(name);
      }
    }
View Full Code Here

  void addImportToCompilationUnit(String classToImport, CompilationUnit compilationUnit) {
    if (!isClassImported(classToImport, compilationUnit)) {
      AST ast = compilationUnit.getAST();

      Name name = createQualifiedName(ast, classToImport);
      ImportDeclaration importDeclaration = ast.newImportDeclaration();
      importDeclaration.setName(name);
      importDeclaration.setOnDemand(false);
      importDeclaration.setStatic(false);

      compilationUnit.imports().add(importDeclaration);
    }
  }
View Full Code Here

  private boolean isClassImported(String importedClass, CompilationUnit compilationUnit) {
    Iterator<ImportDeclaration> iterator = compilationUnit.imports().iterator();
    String packageName = importedClass.substring(0, importedClass.lastIndexOf(".")); //$NON-NLS-1$

    while (iterator.hasNext()) {
      ImportDeclaration importDeclaration = iterator.next();
      String importedName = importDeclaration.getName().toString();
      if (importedName.equals(packageName) || importedName.equals(importedClass)) {
        return true;
      }
    }
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.