Example usage for org.eclipse.jdt.core IJavaElement COMPILATION_UNIT

List of usage examples for org.eclipse.jdt.core IJavaElement COMPILATION_UNIT

Introduction

In this page you can find the example usage for org.eclipse.jdt.core IJavaElement COMPILATION_UNIT.

Prototype

int COMPILATION_UNIT

To view the source code for org.eclipse.jdt.core IJavaElement COMPILATION_UNIT.

Click Source Link

Document

Constant representing a Java compilation unit.

Usage

From source file:org.eclipse.objectteams.otdt.ui.tests.refactoring.reorg.OTCopyToClipboardTests.java

License:Open Source License

private static int countResources(IJavaElement[] javaElementsCopied) {
    int count = 0;
    for (int i = 0; i < javaElementsCopied.length; i++) {
        IJavaElement element = javaElementsCopied[i];
        switch (element.getElementType()) {
        case IJavaElement.JAVA_PROJECT:
        case IJavaElement.PACKAGE_FRAGMENT_ROOT:
        case IJavaElement.PACKAGE_FRAGMENT:
        case IJavaElement.COMPILATION_UNIT:
        case IJavaElement.CLASS_FILE:
            count++;//from  www  . jav  a2s. c o  m
        }
    }
    return count;
}

From source file:org.eclipse.objectteams.otdt.ui.tests.refactoring.reorg.OTCopyToClipboardTests.java

License:Open Source License

private static IJavaElement[] getCompilationUnits(IJavaElement[] javaElements) {
    List cus = ReorgUtils.getElementsOfType(javaElements, IJavaElement.COMPILATION_UNIT);
    return (ICompilationUnit[]) cus.toArray(new ICompilationUnit[cus.size()]);
}

From source file:org.eclipse.osee.framework.ui.skynet.FindInWorkspaceOperation.java

License:Open Source License

@Override
protected void doWork(final IProgressMonitor monitor) throws Exception {
    final Map<String, Artifact> guids = getGuidMap();
    monitor.beginTask("Searching Java Files", guids.size());
    findByName(guids, monitor);/* w  w  w .java 2  s.com*/

    if (guids.isEmpty()) {
        return;
    }

    final NullProgressMonitor subMonitor = new NullProgressMonitor();

    SearchPattern searchPattern = SearchPattern.createPattern("ObjectId", IJavaSearchConstants.ANNOTATION_TYPE,
            IJavaSearchConstants.ANNOTATION_TYPE_REFERENCE, SearchPattern.R_PATTERN_MATCH);

    IJavaSearchScope workspaceScope = SearchEngine.createWorkspaceScope();
    SearchRequestor requestor = new SearchRequestor() {

        @Override
        public void acceptSearchMatch(SearchMatch match) throws CoreException {
            ICompilationUnit unit = null;
            IJavaElement jElement = JavaCore.create(match.getResource());
            if (jElement != null && jElement.exists()
                    && jElement.getElementType() == IJavaElement.COMPILATION_UNIT) {
                unit = (ICompilationUnit) jElement;
            }

            String uuid = getGuid(unit.getSource());
            if (guids.containsKey(uuid)) {
                monitor.worked(1);
                collector.onResource(unit.getResource());
                guids.remove(uuid);
                if (guids.isEmpty()) {
                    subMonitor.setCanceled(true);
                }
            }
        }
    };

    SearchEngine engine = new SearchEngine();
    try {
        engine.search(searchPattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() },
                workspaceScope, requestor, subMonitor);
    } catch (OperationCanceledException ex) {
        //do nothings
    }

    for (Artifact artifact : guids.values()) {
        collector.onNotFound(artifact);
    }
}

From source file:org.eclipse.pde.api.tools.internal.ApiDescriptionManager.java

License:Open Source License

/**
 * Flushes the changed element from the model cache
 * //w  ww  .  j a  va 2 s .  c  om
 * @param element
 */
void flushElementCache(IJavaElement element) {
    switch (element.getElementType()) {
    case IJavaElement.COMPILATION_UNIT: {
        ICompilationUnit unit = (ICompilationUnit) element;
        IType type = unit.findPrimaryType();
        if (type != null) {
            ApiModelCache.getCache().removeElementInfo(ApiBaselineManager.WORKSPACE_API_BASELINE_ID,
                    element.getJavaProject().getElementName(), type.getFullyQualifiedName(), IApiElement.TYPE);
        }
        break;
    }
    case IJavaElement.JAVA_PROJECT: {
        ApiModelCache.getCache().removeElementInfo(ApiBaselineManager.WORKSPACE_API_BASELINE_ID,
                element.getElementName(), null, IApiElement.COMPONENT);
        break;
    }
    default:
        break;
    }
}

From source file:org.eclipse.pde.api.tools.internal.builder.BaseApiAnalyzer.java

License:Open Source License

/**
 * Recursively finds all source in the given project and scans it for
 * invalid tags// www .  j  a  v a 2s.  c  o m
 * 
 * @param element
 * @param monitor
 * @throws JavaModelException
 */
private void scanSource(IJavaElement element, boolean tags, boolean annotations, IProgressMonitor monitor)
        throws JavaModelException {
    try {
        switch (element.getElementType()) {
        case IJavaElement.PACKAGE_FRAGMENT_ROOT:
        case IJavaElement.PACKAGE_FRAGMENT: {
            IParent parent = (IParent) element;
            IJavaElement[] children = parent.getChildren();
            for (int i = 0; i < children.length; i++) {
                scanSource(children[i], tags, annotations, monitor);
                Util.updateMonitor(monitor, 0);
            }
            break;
        }
        case IJavaElement.COMPILATION_UNIT: {
            ICompilationUnit unit = (ICompilationUnit) element;
            processType(unit, tags, annotations);
            Util.updateMonitor(monitor, 0);
            break;
        }
        default:
            break;
        }
    } finally {
        if (monitor != null) {
            Util.updateMonitor(monitor);
            monitor.done();
        }
    }
}

From source file:org.eclipse.pde.api.tools.internal.WorkspaceDeltaProcessor.java

License:Open Source License

/**
 * Processes the java element deltas of interest
 * /*from  www  . j ava 2s  .c om*/
 * @param deltas
 */
void processJavaElementDeltas(IJavaElementDelta[] deltas, IJavaProject project) {
    for (int i = 0; i < deltas.length; i++) {
        IJavaElementDelta delta = deltas[i];
        switch (delta.getElement().getElementType()) {
        case IJavaElement.JAVA_PROJECT: {
            IJavaProject proj = (IJavaProject) delta.getElement();
            int flags = delta.getFlags();
            switch (delta.getKind()) {
            case IJavaElementDelta.CHANGED: {
                if (!Util.isApiProject(proj)) {
                    if (ApiPlugin.DEBUG_WORKSPACE_DELTA_PROCESSOR) {
                        System.out.println(
                                "--> skipped processing CHANGED delta for project: " + proj.getElementName()); //$NON-NLS-1$
                    }
                    continue;
                }
                if ((flags & IJavaElementDelta.F_OPENED) != 0) {
                    if (ApiPlugin.DEBUG_WORKSPACE_DELTA_PROCESSOR) {
                        System.out.println("--> processing OPEN project: [" + proj.getElementName() + "]"); //$NON-NLS-1$ //$NON-NLS-2$
                    }
                    bmanager.disposeWorkspaceBaseline();
                } else if ((flags & IJavaElementDelta.F_RESOLVED_CLASSPATH_CHANGED) != 0
                        || (flags & IJavaElementDelta.F_CLASSPATH_CHANGED) != 0) {
                    if (ApiPlugin.DEBUG_WORKSPACE_DELTA_PROCESSOR) {
                        System.out.println(
                                "--> processing CLASSPATH CHANGE project: [" + proj.getElementName() + "]"); //$NON-NLS-1$ //$NON-NLS-2$
                    }
                    bmanager.disposeWorkspaceBaseline();
                    dmanager.projectClasspathChanged(proj);
                    try {
                        BuildState.setLastBuiltState(proj.getProject(), null);
                    } catch (CoreException e) {
                    }
                    dmanager.flushElementCache(delta.getElement());
                } else if ((flags & IJavaElementDelta.F_CHILDREN) != 0) {
                    if (ApiPlugin.DEBUG_WORKSPACE_DELTA_PROCESSOR) {
                        System.out.println(
                                "--> processing CHILDREN delta of project: [" + proj.getElementName() + "]"); //$NON-NLS-1$ //$NON-NLS-2$
                    }
                    processJavaElementDeltas(delta.getAffectedChildren(), proj);
                } else if ((flags & IJavaElementDelta.F_CONTENT) != 0) {
                    if (proj != null) {
                        if (ApiPlugin.DEBUG_WORKSPACE_DELTA_PROCESSOR) {
                            System.out.println(
                                    "--> processing child CONTENT of project: [" + proj.getElementName() + "]"); //$NON-NLS-1$ //$NON-NLS-2$
                        }
                        IResourceDelta[] resourcedeltas = delta.getResourceDeltas();
                        if (resourcedeltas != null) {
                            IResourceDelta rdelta = null;
                            for (int j = 0; j < resourcedeltas.length; j++) {
                                rdelta = resourcedeltas[j].findMember(new Path(Util.MANIFEST_NAME));
                                if (rdelta != null && rdelta.getKind() == IResourceDelta.CHANGED
                                        && (rdelta.getFlags() & IResourceDelta.CONTENT) > 0) {
                                    if (ApiPlugin.DEBUG_WORKSPACE_DELTA_PROCESSOR) {
                                        System.out.println("--> processing manifest delta"); //$NON-NLS-1$
                                    }
                                    bmanager.disposeWorkspaceBaseline();
                                    break;
                                }
                            }
                        }
                    } else {
                        if (ApiPlugin.DEBUG_WORKSPACE_DELTA_PROCESSOR) {
                            System.out.println("--> ignoring child CONTENT project context is null"); //$NON-NLS-1$
                        }
                    }
                }
                break;
            }
            case IJavaElementDelta.ADDED: {
                if (!Util.isApiProject(proj)) {
                    if (ApiPlugin.DEBUG_WORKSPACE_DELTA_PROCESSOR) {
                        System.out.println(
                                "--> skipped processing ADDED delta for project: " + proj.getElementName()); //$NON-NLS-1$
                    }
                    continue;
                }
                if ((flags & IJavaElementDelta.F_MOVED_FROM) != 0) {
                    if (ApiPlugin.DEBUG_WORKSPACE_DELTA_PROCESSOR) {
                        System.out.println("--> processing PROJECT RENAME from: [" //$NON-NLS-1$
                                + delta.getMovedFromElement().getJavaProject().getElementName() + "] to: [" //$NON-NLS-1$
                                + proj.getElementName() + "]"); //$NON-NLS-1$
                    }
                    bmanager.disposeWorkspaceBaseline();
                }
                break;
            }
            default:
                break;
            }
            break;
        }
        case IJavaElement.PACKAGE_FRAGMENT_ROOT: {
            IPackageFragmentRoot root = (IPackageFragmentRoot) delta.getElement();
            int flags = delta.getFlags();
            if ((flags & (IJavaElementDelta.F_ARCHIVE_CONTENT_CHANGED | IJavaElementDelta.F_ADDED_TO_CLASSPATH
                    | IJavaElementDelta.F_REMOVED_FROM_CLASSPATH)) != 0) {
                if (ApiPlugin.DEBUG_WORKSPACE_DELTA_PROCESSOR) {
                    System.out.println("processed CLASSPATH CHANGED for package fragment root: [" //$NON-NLS-1$
                            + root.getElementName() + "]"); //$NON-NLS-1$
                }
                dmanager.projectClasspathChanged(project);
            }
            if ((flags & IJavaElementDelta.F_CHILDREN) != 0) {
                if (ApiPlugin.DEBUG_WORKSPACE_DELTA_PROCESSOR) {
                    System.out.println(
                            "processed CHILDREN for package fragment root: [" + root.getElementName() + "]"); //$NON-NLS-1$ //$NON-NLS-2$
                }
                processJavaElementDeltas(delta.getAffectedChildren(), project);
            }
            break;
        }
        case IJavaElement.PACKAGE_FRAGMENT: {
            IPackageFragment fragment = (IPackageFragment) delta.getElement();
            if (delta.getKind() == IJavaElementDelta.REMOVED) {
                if (ApiPlugin.DEBUG_WORKSPACE_DELTA_PROCESSOR) {
                    System.out.println("processed REMOVED delta for package fragment: [" //$NON-NLS-1$
                            + fragment.getElementName() + "]"); //$NON-NLS-1$
                }
                ((ApiBaseline) bmanager.getWorkspaceBaseline()).clearPackage(fragment.getElementName());
            }
            int flags = delta.getFlags();
            if ((flags & IJavaElementDelta.F_CHILDREN) != 0) {
                if (ApiPlugin.DEBUG_WORKSPACE_DELTA_PROCESSOR) {
                    System.out.println("processed CHILDREN delta for package fragment: [" //$NON-NLS-1$
                            + fragment.getElementName() + "]"); //$NON-NLS-1$
                }
                processJavaElementDeltas(delta.getAffectedChildren(), project);
            }
            break;
        }
        case IJavaElement.COMPILATION_UNIT: {
            int flags = delta.getFlags();
            switch (delta.getKind()) {
            case IJavaElementDelta.CHANGED: {
                if ((flags & (IJavaElementDelta.F_CONTENT | IJavaElementDelta.F_FINE_GRAINED
                        | IJavaElementDelta.F_PRIMARY_RESOURCE)) != 0) {
                    if (project != null) {
                        if (ApiPlugin.DEBUG_WORKSPACE_DELTA_PROCESSOR) {
                            System.out
                                    .println("processed CONTENT / FINE_GRAINED / PRIMARY_RESOURCE delta for: [" //$NON-NLS-1$
                                            + delta.getElement().getElementName() + "]"); //$NON-NLS-1$
                        }
                        dmanager.projectChanged(project);
                        dmanager.flushElementCache(delta.getElement());
                        continue;
                    }
                }
                break;
            }
            case IJavaElementDelta.ADDED:
            case IJavaElementDelta.REMOVED: {
                if (project != null) {
                    if (ApiPlugin.DEBUG_WORKSPACE_DELTA_PROCESSOR) {
                        if (delta.getKind() == IJavaElementDelta.ADDED) {
                            System.out.println(
                                    "processed ADDED delta for: [" + delta.getElement().getElementName() + "]"); //$NON-NLS-1$//$NON-NLS-2$
                        } else {
                            System.out.println("processed REMOVED delta for: [" //$NON-NLS-1$
                                    + delta.getElement().getElementName() + "]"); //$NON-NLS-1$
                        }
                    }
                    dmanager.projectChanged(project);
                    dmanager.flushElementCache(delta.getElement());
                    continue;
                }
                break;
            }
            default:
                break;
            }
            break;
        }
        default:
            break;
        }
    }
}

From source file:org.eclipse.pde.api.tools.ui.internal.JavaElementActionFilter.java

License:Open Source License

/**
 * @see org.eclipse.ui.IActionFilter#testAttribute(Object, String, String)
 *///  w  ww . ja  v a  2s  .  co  m
@Override
public boolean testAttribute(Object target, String name, String value) {
    if (name.equals("JavaElementActionFilter")) { //$NON-NLS-1$
        if (target instanceof IJavaElement) {
            IJavaElement javaElement = (IJavaElement) target;
            if (value.equals("isEnabled")) { //$NON-NLS-1$
                while (javaElement != null) {
                    switch (javaElement.getElementType()) {
                    case IJavaElement.PACKAGE_FRAGMENT_ROOT:
                        IPackageFragmentRoot root = (IPackageFragmentRoot) javaElement;
                        return !root.isArchive();
                    case IJavaElement.PACKAGE_FRAGMENT:
                    case IJavaElement.COMPILATION_UNIT:
                    case IJavaElement.CLASS_FILE:
                    case IJavaElement.TYPE:
                        javaElement = javaElement.getParent();
                        break;
                    case IJavaElement.ANNOTATION:
                    case IJavaElement.FIELD:
                    case IJavaElement.IMPORT_CONTAINER:
                    case IJavaElement.IMPORT_DECLARATION:
                    case IJavaElement.INITIALIZER:
                    case IJavaElement.JAVA_MODEL:
                    case IJavaElement.LOCAL_VARIABLE:
                    case IJavaElement.METHOD:
                    case IJavaElement.PACKAGE_DECLARATION:
                    case IJavaElement.TYPE_PARAMETER:
                        return false;
                    case IJavaElement.JAVA_PROJECT:
                        return true;
                    default:
                        break;
                    }
                }
                return true;
            }
        }
    }
    return false;
}

From source file:org.eclipse.pde.api.tools.ui.internal.markers.RemoveUnsupportedAnnotationOperation.java

License:Open Source License

@Override
public IStatus runInUIThread(IProgressMonitor monitor) {
    SubMonitor localMonitor = SubMonitor.convert(monitor,
            MarkerMessages.RemoveUnsupportedTagOperation_removeing_unsupported_tag, fMarkers.length + 6);
    HashMap<ICompilationUnit, Boolean> seen = new HashMap<ICompilationUnit, Boolean>();
    for (int i = 0; i < fMarkers.length; i++) {
        // retrieve the AST node compilation unit
        IResource resource = fMarkers[i].getResource();
        IJavaElement javaElement = JavaCore.create(resource);
        try {/*from w ww .  j  a v a2 s .c  o m*/
            if (javaElement != null && javaElement.getElementType() == IJavaElement.COMPILATION_UNIT) {
                ICompilationUnit compilationUnit = (ICompilationUnit) javaElement;
                if (!seen.containsKey(compilationUnit)) {
                    seen.put(compilationUnit, Boolean.valueOf(compilationUnit.hasUnsavedChanges()));
                }
                if (!compilationUnit.isWorkingCopy()) {
                    // open an editor of the corresponding unit to "show"
                    // the quick-fix change
                    JavaUI.openInEditor(compilationUnit);
                }
                if (!compilationUnit.isConsistent()) {
                    compilationUnit.reconcile(ICompilationUnit.NO_AST, false, null, null);
                    Util.updateMonitor(localMonitor, 1);
                }
                Util.updateMonitor(localMonitor, 1);
                ASTParser parser = ASTParser.newParser(AST.JLS8);
                parser.setSource(compilationUnit);
                Integer charStartAttribute = null;
                charStartAttribute = (Integer) fMarkers[i].getAttribute(IMarker.CHAR_START);
                int intValue = charStartAttribute.intValue();
                parser.setFocalPosition(intValue);
                final CompilationUnit unit = (CompilationUnit) parser.createAST(new NullProgressMonitor());
                AnnotationFinder finder = new AnnotationFinder(intValue);
                unit.accept(finder);
                Util.updateMonitor(localMonitor, 1);
                if (finder.fNode != null) {
                    unit.recordModifications();
                    AST ast = unit.getAST();
                    ASTRewrite rewrite = ASTRewrite.create(ast);
                    TextEditGroup group = new TextEditGroup("Removing API tools annotations"); //$NON-NLS-1$
                    rewrite.remove(finder.fNode, group);
                    Util.updateMonitor(localMonitor, 1);
                    TextEdit edit = rewrite.rewriteAST();
                    compilationUnit.applyTextEdit(edit, monitor);
                    Util.updateMonitor(localMonitor, 1);
                }
            }
        } catch (JavaModelException jme) {
        } catch (PartInitException e) {
        } catch (CoreException e) {
        }
    }
    // try saving the compilation units if they were in a saved state when
    // the quick-fix started
    for (Entry<ICompilationUnit, Boolean> entry : seen.entrySet()) {
        if (!entry.getValue().booleanValue()) {
            try {
                entry.getKey().commitWorkingCopy(true, null);
            } catch (JavaModelException jme) {
            }
        }
    }
    return Status.OK_STATUS;
}

From source file:org.eclipse.pde.api.tools.ui.internal.markers.RemoveUnsupportedTagOperation.java

License:Open Source License

@Override
public IStatus runInUIThread(IProgressMonitor monitor) {
    SubMonitor localMonitor = SubMonitor.convert(monitor,
            MarkerMessages.RemoveUnsupportedTagOperation_removeing_unsupported_tag, this.markers.length + 6);
    HashMap<ICompilationUnit, Boolean> seen = new HashMap<ICompilationUnit, Boolean>();
    for (int i = 0; i < this.markers.length; i++) {
        // retrieve the AST node compilation unit
        IResource resource = this.markers[i].getResource();
        IJavaElement javaElement = JavaCore.create(resource);
        try {/* ww w . ja  v  a2s  .co  m*/
            if (javaElement != null && javaElement.getElementType() == IJavaElement.COMPILATION_UNIT) {
                ICompilationUnit compilationUnit = (ICompilationUnit) javaElement;
                if (!seen.containsKey(compilationUnit)) {
                    seen.put(compilationUnit, Boolean.valueOf(compilationUnit.hasUnsavedChanges()));
                }
                if (!compilationUnit.isWorkingCopy()) {
                    // open an editor of the corresponding unit to "show"
                    // the quick-fix change
                    JavaUI.openInEditor(compilationUnit);
                }
                if (!compilationUnit.isConsistent()) {
                    compilationUnit.reconcile(ICompilationUnit.NO_AST, false, null, null);
                    Util.updateMonitor(localMonitor, 1);
                }
                Util.updateMonitor(localMonitor, 1);
                ASTParser parser = ASTParser.newParser(AST.JLS8);
                parser.setSource(compilationUnit);
                Integer charStartAttribute = null;
                charStartAttribute = (Integer) this.markers[i].getAttribute(IMarker.CHAR_START);
                int intValue = charStartAttribute.intValue();
                parser.setFocalPosition(intValue);
                Map<String, String> options = compilationUnit.getJavaProject().getOptions(true);
                options.put(JavaCore.COMPILER_DOC_COMMENT_SUPPORT, JavaCore.ENABLED);
                parser.setCompilerOptions(options);
                final CompilationUnit unit = (CompilationUnit) parser.createAST(new NullProgressMonitor());
                NodeFinder finder = new NodeFinder(intValue);
                unit.accept(finder);
                Util.updateMonitor(localMonitor, 1);
                BodyDeclaration node = finder.getNode();
                if (node != null) {
                    unit.recordModifications();
                    AST ast = unit.getAST();
                    ASTRewrite rewrite = ASTRewrite.create(ast);
                    Javadoc docnode = node.getJavadoc();
                    if (docnode == null) {
                        return Status.CANCEL_STATUS;
                    } else {
                        List<TagElement> tags = docnode.tags();
                        String arg = (String) this.markers[i]
                                .getAttribute(IApiMarkerConstants.MARKER_ATTR_MESSAGE_ARGUMENTS);
                        String[] args = arg.split("#"); //$NON-NLS-1$
                        TagElement tag = null;
                        for (Iterator<TagElement> iterator = tags.iterator(); iterator.hasNext();) {
                            tag = iterator.next();
                            if (args[0].equals(tag.getTagName()) && tag.getStartPosition() == intValue) {
                                break;
                            }
                        }
                        if (tag == null) {
                            return Status.CANCEL_STATUS;
                        }
                        ListRewrite lrewrite = rewrite.getListRewrite(docnode, Javadoc.TAGS_PROPERTY);
                        lrewrite.remove(tag, null);
                        Util.updateMonitor(localMonitor, 1);
                    }
                    TextEdit edit = rewrite.rewriteAST();
                    compilationUnit.applyTextEdit(edit, monitor);
                    Util.updateMonitor(localMonitor, 1);
                }
            }
        } catch (JavaModelException jme) {
        } catch (PartInitException e) {
        } catch (CoreException e) {
        }
    }
    // try saving the compilation units if they were in a saved state when
    // the quick-fix started
    for (Entry<ICompilationUnit, Boolean> entry : seen.entrySet()) {
        if (!entry.getValue().booleanValue()) {
            try {
                entry.getKey().commitWorkingCopy(true, null);
            } catch (JavaModelException jme) {
            }
        }
    }
    return Status.OK_STATUS;
}

From source file:org.eclipse.pde.api.tools.ui.internal.markers.UpdateSinceTagOperation.java

License:Open Source License

public void run(IProgressMonitor monitor) {
    if (monitor != null && monitor.isCanceled()) {
        return;/*  www .j a  v  a 2s  . c  o  m*/
    }
    if (monitor != null) {
        monitor.beginTask(MarkerMessages.UpdateSinceTagOperation_title, 3);
    }
    // retrieve the AST node compilation unit
    try {
        Integer charStartAttribute = (Integer) this.fMarker.getAttribute(IMarker.CHAR_START);
        int intValue = charStartAttribute.intValue();
        IJavaElement javaElement = null;
        IJavaElement handleElement = null;
        if (intValue > 0) {
            IResource resource = this.fMarker.getResource();
            javaElement = JavaCore.create(resource);
        } else {
            // this is a case where the marker is reported against the
            // MANIFEST.MF file
            String handle = (String) fMarker.getAttribute(IApiMarkerConstants.MARKER_ATTR_HANDLE_ID);
            if (handle != null) {
                handleElement = JavaCore.create(handle);
            }
            if (handleElement != null && handleElement.exists()) {
                javaElement = handleElement.getAncestor(IJavaElement.COMPILATION_UNIT);
            }
        }
        if (javaElement != null && javaElement.getElementType() == IJavaElement.COMPILATION_UNIT) {
            ICompilationUnit compilationUnit = (ICompilationUnit) javaElement;
            if (!compilationUnit.isWorkingCopy()) {
                // open an editor of the corresponding unit to "show" the
                // quickfix change
                JavaUI.openInEditor(compilationUnit);
            }
            ASTParser parser = ASTParser.newParser(AST.JLS8);
            parser.setSource(compilationUnit);
            if (intValue <= 0) {
                // try to use the name range of the corresponding element
                if (handleElement instanceof IMember) {
                    IMember member = (IMember) handleElement;
                    ISourceRange range = member.getNameRange();
                    if (range != null) {
                        intValue = range.getOffset();
                    } else {
                        range = member.getSourceRange();
                        if (range != null && range.getOffset() > 0) {
                            intValue = range.getOffset();
                        } else {
                            return;
                        }
                    }
                } else {
                    return;
                }
            }
            parser.setFocalPosition(intValue);
            parser.setResolveBindings(true);
            Map<String, String> options = compilationUnit.getJavaProject().getOptions(true);
            options.put(JavaCore.COMPILER_DOC_COMMENT_SUPPORT, JavaCore.ENABLED);
            parser.setCompilerOptions(options);
            final CompilationUnit unit = (CompilationUnit) parser.createAST(new NullProgressMonitor());
            BodyDeclaration node = null;
            NodeFinder nodeFinder = new NodeFinder(intValue);
            unit.accept(nodeFinder);
            if (monitor != null) {
                monitor.worked(1);
            }
            node = nodeFinder.getNode();
            if (node != null) {
                unit.recordModifications();
                AST ast = unit.getAST();
                ASTRewrite rewrite = ASTRewrite.create(ast);
                if (IApiProblem.SINCE_TAG_MISSING == this.sinceTagType) {
                    Javadoc docnode = node.getJavadoc();
                    if (docnode == null) {
                        docnode = ast.newJavadoc();
                        // we do not want to create a new empty Javadoc node
                        // in
                        // the AST if there are no missing tags
                        rewrite.set(node, node.getJavadocProperty(), docnode, null);
                    } else {
                        List<TagElement> tags = docnode.tags();
                        boolean found = false;
                        loop: for (Iterator<TagElement> iterator = tags.iterator(); iterator.hasNext();) {
                            TagElement element = iterator.next();
                            String tagName = element.getTagName();
                            if (TagElement.TAG_SINCE.equals(tagName)) {
                                found = true;
                                break loop;
                            }
                        }
                        if (found) {
                            return;
                        }
                    }
                    ListRewrite lrewrite = rewrite.getListRewrite(docnode, Javadoc.TAGS_PROPERTY);
                    // check the existing tags list
                    TagElement newtag = ast.newTagElement();
                    newtag.setTagName(TagElement.TAG_SINCE);
                    TextElement textElement = ast.newTextElement();
                    textElement.setText(this.sinceTagVersion);
                    newtag.fragments().add(textElement);
                    lrewrite.insertLast(newtag, null);
                } else {
                    Javadoc docnode = node.getJavadoc();
                    List<TagElement> tags = docnode.tags();
                    TagElement sinceTag = null;
                    for (Iterator<TagElement> iterator = tags.iterator(); iterator.hasNext();) {
                        TagElement tagElement = iterator.next();
                        if (TagElement.TAG_SINCE.equals(tagElement.getTagName())) {
                            sinceTag = tagElement;
                            break;
                        }
                    }
                    if (sinceTag != null) {
                        List<TextElement> fragments = sinceTag.fragments();
                        if (fragments.size() >= 1) {
                            TextElement textElement = fragments.get(0);
                            StringBuffer buffer = new StringBuffer();
                            buffer.append(' ').append(this.sinceTagVersion);
                            rewrite.set(textElement, TextElement.TEXT_PROPERTY, String.valueOf(buffer), null);
                        } else {
                            ListRewrite lrewrite = rewrite.getListRewrite(docnode, Javadoc.TAGS_PROPERTY);
                            // check the existing tags list
                            TagElement newtag = ast.newTagElement();
                            newtag.setTagName(TagElement.TAG_SINCE);
                            TextElement textElement = ast.newTextElement();
                            textElement.setText(this.sinceTagVersion);
                            newtag.fragments().add(textElement);
                            lrewrite.replace(sinceTag, newtag, null);
                        }
                    }
                }
                try {
                    if (monitor != null) {
                        monitor.worked(1);
                    }
                    TextEdit edit = rewrite.rewriteAST();
                    compilationUnit.applyTextEdit(edit, monitor);
                    if (monitor != null) {
                        monitor.worked(1);
                    }
                } finally {
                    compilationUnit.reconcile(ICompilationUnit.NO_AST, false /*
                                                                             * don
                                                                             * 't
                                                                             * force
                                                                             * problem
                                                                             * detection
                                                                             */, null /*
                                                                                       * use
                                                                                       * primary
                                                                                       * owner
                                                                                       */, null /*
                                                                                                 * no
                                                                                                 * progress
                                                                                                 * monitor
                                                                                                 */);
                }
            }
        }
    } catch (CoreException e) {
        ApiUIPlugin.log(e);
    } finally {
        if (monitor != null) {
            monitor.done();
        }
    }
}