Skip to content

Commit

Permalink
APIToolsJavadocCompletionProposalComputer: MT hardening #312
Browse files Browse the repository at this point in the history
collectExistingTags() is running in background while sessionEnded() is
running in UI Thread.

#312
  • Loading branch information
EcljpseB0T authored and jukzi committed Feb 15, 2024
1 parent 72fa789 commit f13bc87
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@
*/
public class APIToolsJavadocCompletionProposal implements IJavaCompletionProposal, ICompletionProposalExtension2, ICompletionProposalExtension3 {

private String fReplaceText = null;
private String fDisplayText = null;
private Image fImage = null;
private CompletionContext fContext = null;
private final String fReplaceText;
private final String fDisplayText;
private final Image fImage;
private final CompletionContext fContext;

/**
* Constructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jdt.core.CompletionContext;
Expand Down Expand Up @@ -71,10 +71,10 @@
*/
public class APIToolsJavadocCompletionProposalComputer implements IJavaCompletionProposalComputer {

private String fErrorMessage = null;
private Image fImageHandle = null;
private ASTParser fParser = null;
HashMap<String, Boolean> fExistingTags = null;
private volatile String fErrorMessage = null;
private volatile Image fImageHandle = null;
private volatile ASTParser fParser = null;
private final Map<String, Boolean> fExistingTags = new ConcurrentHashMap<>();

/**
* Collects all of the existing API Tools Javadoc tags form a given Javadoc
Expand All @@ -85,9 +85,6 @@ class TagCollector extends ASTVisitor {
public boolean visit(Javadoc node) {
Set<String> tagnames = ApiPlugin.getJavadocTagManager().getAllTagNames();
List<TagElement> tags = node.tags();
if (fExistingTags == null) {
fExistingTags = new HashMap<>(tags.size());
}
String name = null;
for (TagElement tag : tags) {
name = tag.getTagName();
Expand Down Expand Up @@ -135,8 +132,12 @@ List<ICompletionProposal> computeJavadocProposals(JavaContentAssistInvocationCon
if (!isVisible(element)) {
return Collections.emptyList();
}
ImageDescriptor imagedesc = jcontext.getLabelProvider().createImageDescriptor(org.eclipse.jdt.core.CompletionProposal.create(org.eclipse.jdt.core.CompletionProposal.JAVADOC_BLOCK_TAG, offset));
fImageHandle = (imagedesc == null ? null : imagedesc.createImage());
if (fImageHandle == null) {
ImageDescriptor imagedesc = jcontext.getLabelProvider()
.createImageDescriptor(org.eclipse.jdt.core.CompletionProposal
.create(org.eclipse.jdt.core.CompletionProposal.JAVADOC_BLOCK_TAG, offset));
fImageHandle = (imagedesc == null ? null : imagedesc.createImage());
}
int type = getType(element);
int member = IApiJavadocTag.MEMBER_NONE;
switch (element.getElementType()) {
Expand Down Expand Up @@ -377,11 +378,11 @@ public String getErrorMessage() {
public void sessionEnded() {
if (fImageHandle != null) {
fImageHandle.dispose();
fImageHandle = null;
}
fParser = null;
if (fExistingTags != null) {
fExistingTags.clear();
fExistingTags = null;
}
fErrorMessage = null;
}
Expand Down

0 comments on commit f13bc87

Please sign in to comment.