Package org.eclipse.jdt.core.dom.rewrite

Examples of org.eclipse.jdt.core.dom.rewrite.ImportRewrite


    private void addSourceImport()
    {
        // add import
        try
        {
            ImportRewrite rewrite = CodeStyleConfiguration.createImportRewrite(
                fCompilationUnit, true);
            rewrite.addImport(result.getClassName());
            JavaModelUtil.applyEdit(fCompilationUnit, rewrite.rewriteImports(null),
                false, null);
        }
        catch (CoreException e)
        {
            SigilCore.error("Failed to add import", e);
View Full Code Here


        return null;
      ICompilationUnit unit = root.getCompilationUnit();
      ICompilationUnit copy = unit.getWorkingCopy(monitor);
      IType type = getUnitMainType(copy);
      if (type != null) {
        ImportRewrite imports = createImportRewrite(copy);
        boolean success = parser.generateCode(type, imports, monitor);
        if (!success)
          return null;
        removeRemovedComponent(root, monitor, unit, type);
        createPreferredLnf(root, monitor, type, imports);
        if (success) {
          TextEdit edit = imports.rewriteImports(monitor);
          JavaUtil.applyEdit(copy, edit, true, monitor);
        }
        if (copy.isWorkingCopy()) {
          copy.commitWorkingCopy(true, monitor);
          copy.discardWorkingCopy();
View Full Code Here

      final IType newEnumType = page.getCreatedType();
      final CompilationUnit node = (CompilationUnit) Util.getASTNode(
          newEnumType, monitor);

      final ASTRewrite astRewrite = ASTRewrite.create(node.getAST());
      final ImportRewrite importRewrite = ImportRewrite
          .create(node, true);

      final EnumDeclaration oldEnumDeclaration = (EnumDeclaration) node
          .types().get(0);

      // Add imports for annotations to the enum constants.
      for (final Iterator eit = newEnumDeclaration.enumConstants()
          .iterator(); eit.hasNext();) {
        final Object obj = eit.next();
        final EnumConstantDeclaration ecd = (EnumConstantDeclaration) obj;
        for (final Iterator emit = ecd.modifiers().iterator(); emit
            .hasNext();) {
          final Object o = emit.next();
          if (o instanceof Annotation) {
            final Annotation anno = (Annotation) o;
            final String newName = importRewrite
                .addImport((String) annotationToQualifiedNameMap
                    .get(anno));
            anno.setTypeName(ast.newName(newName));
          }
        }
View Full Code Here

  protected void rewriteCompilationUnit(ICompilationUnit unit,
      Collection matches, CompilationUnit node, RefactoringStatus status,
      IProgressMonitor monitor) throws CoreException {
    final ASTRewrite astRewrite = ASTRewrite.create(node.getAST());
    final ImportRewrite importRewrite = ImportRewrite.create(node, true);

    for (final Iterator it = matches.iterator(); it.hasNext();) {
      final SearchMatch match = (SearchMatch) it.next();
      if (match.getAccuracy() == SearchMatch.A_ACCURATE
          && !match.isInsideDocComment())
View Full Code Here

    ListRewrite listRewrite = rewrite.getListRewrite(declaration, modifiersProperty);
    listRewrite.insertFirst(annotation, null);
   
    TextEdit importEdits = null;
    if (importDeclaration != null) {
      ImportRewrite importRewrite = ImportRewrite.create(compilationUnit, true);
      importRewrite.addImport(importDeclaration.getName().getFullyQualifiedName());
      importEdits = importRewrite.rewriteImports(null);
    }
   
    Map options = compilationUnit.getJavaProject().getOptions(true);
    TextEdit edits = rewrite.rewriteAST(document, options);
   
View Full Code Here

    ListRewrite listRewrite = rewrite.getListRewrite(declaration, SingleVariableDeclaration.MODIFIERS2_PROPERTY);
    listRewrite.insertFirst(annotation, null);
   
    TextEdit importEdits = null;
    if (importDeclaration != null) {
      ImportRewrite importRewrite = ImportRewrite.create(compilationUnit, true);
      importRewrite.addImport(importDeclaration.getName().getFullyQualifiedName());
      importEdits = importRewrite.rewriteImports(null);
    }
   
    Map options = compilationUnit.getJavaProject().getOptions(true);
    TextEdit edits = rewrite.rewriteAST(document, options);
   
View Full Code Here

    listRewrite.insertFirst(normalAnnotation, null);

    maintainValuesProperty(normalAnnotation, memberValues, ast, rewrite);

    TextEdit importEdits = null;
    ImportRewrite importRewrite = ImportRewrite.create(compilationUnit, true);
    importRewrite.addImport(importDeclaration.getName().getFullyQualifiedName());
    importEdits = importRewrite.rewriteImports(null);
   
    Map options = compilationUnit.getJavaProject().getOptions(true);
    TextEdit edits = rewrite.rewriteAST(document, options);
   
    // computation of the new source code
View Full Code Here

    listRewrite.insertFirst(normalAnnotation, null);

    maintainValuesProperty(normalAnnotation, memberValues, ast, rewrite);

    TextEdit importEdits = null;
    ImportRewrite importRewrite = ImportRewrite.create(compilationUnit, true);
    importRewrite.addImport(importDeclaration.getName().getFullyQualifiedName());
    importEdits = importRewrite.rewriteImports(null);
   
    Map options = compilationUnit.getJavaProject().getOptions(true);
    TextEdit edits = rewrite.rewriteAST(document, options);
   
    // computation of the new source code
View Full Code Here

      try{
        ICompilationUnit src = (ICompilationUnit)cu.getJavaElement();
        IJavaProject javaProject = src.getJavaProject();

        MultiTextEdit edit = new MultiTextEdit();
        ImportRewrite imports = StubUtility.createImportRewrite(cu, true);
        imports.addStaticImport("org.junit.Assert", "*", false);
        imports.addImport(JUnitCorePlugin.JUNIT4_ANNOTATION_NAME);
        edit.addChild(imports.rewriteImports(null));

        AST ast = cu.getAST();
        ASTRewrite astRewrite = ASTRewrite.create(ast);
        ASTNode node = cu.findDeclaringNode(typeBinding);
        ChildListPropertyDescriptor property = ((AbstractTypeDeclaration)node)
View Full Code Here

              continue;
            }

            // honor the user's import exclusions
            if (proposal instanceof ASTRewriteCorrectionProposal){
              ImportRewrite rewrite =
                ((ASTRewriteCorrectionProposal)proposal).getImportRewrite();
              if (rewrite != null && (
                    rewrite.getAddedImports().length != 0 ||
                    rewrite.getAddedStaticImports().length != 0))
              {
                boolean exclude = true;
                for(String fqn : rewrite.getAddedImports()){
                  if (!ImportUtils.isImportExcluded(project, fqn)){
                    exclude = false;
                    break;
                  }
                }
                for(String fqn : rewrite.getAddedStaticImports()){
                  if (!ImportUtils.isImportExcluded(project, fqn)){
                    exclude = false;
                    break;
                  }
                }
View Full Code Here

TOP

Related Classes of org.eclipse.jdt.core.dom.rewrite.ImportRewrite

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.