Skip to content

Commit

Permalink
autocomplete for build.properties: follow-up (#529)
Browse files Browse the repository at this point in the history
a few review comments are included in this follow-up PR:
 - removed inheriting from ICompletionListener
 - hence removed completion listener registration
(ICompletionListener.addCompletionListener)
 - usage of array creation shortcut
 - better string initialization
 - localization of fContentAssistantProcessor variable

Refs: #508
  • Loading branch information
gireeshpunathil committed Mar 24, 2023
1 parent 1c3e809 commit 91ab862
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ public class BuildSourceViewerConfiguration extends ChangeAwareSourceViewerConfi
private BasePDEScanner fPropertyValueScanner;

private ContentAssistant fContentAssistant;
private BuildPropertiesContentAssistProcessor fContentAssistantProcessor;

private abstract class AbstractJavaScanner extends BasePDEScanner {

Expand Down Expand Up @@ -247,10 +246,9 @@ public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) {
PDEPluginImages.get(null);
fContentAssistant = new ContentAssistant(true);
fContentAssistant.setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer));
fContentAssistantProcessor = new BuildPropertiesContentAssistProcessor(fSourcePage);
var fContentAssistantProcessor = new BuildPropertiesContentAssistProcessor(fSourcePage);
fContentAssistant.setContentAssistProcessor(fContentAssistantProcessor, IDocument.DEFAULT_CONTENT_TYPE);
fContentAssistant.setContentAssistProcessor(fContentAssistantProcessor, PROPERTY_VALUE);
fContentAssistant.addCompletionListener(fContentAssistantProcessor);
fContentAssistant.enableAutoInsert(true);
fContentAssistant.setInformationControlCreator(parent -> new DefaultInformationControl(parent, false));
fContentAssistant.setContextInformationPopupOrientation(IContentAssistant.CONTEXT_INFO_ABOVE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,36 +15,17 @@
import java.lang.reflect.Field;
import java.util.ArrayList;
import org.eclipse.jface.text.*;
import org.eclipse.jface.text.contentassist.*;
import org.eclipse.jface.text.contentassist.ICompletionProposal;
import org.eclipse.pde.internal.build.IBuildPropertiesConstants;
import org.eclipse.pde.internal.ui.editor.PDESourcePage;

public class BuildPropertiesContentAssistProcessor extends TypePackageCompletionProcessor
implements ICompletionListener {
public class BuildPropertiesContentAssistProcessor extends TypePackageCompletionProcessor {

protected PDESourcePage fSourcePage;
public BuildPropertiesContentAssistProcessor(PDESourcePage sourcePage) {
fSourcePage = sourcePage;
}

@Override
public void assistSessionStarted(ContentAssistEvent event) {
// TODO Auto-generated method stub

}

@Override
public void assistSessionEnded(ContentAssistEvent event) {
// TODO Auto-generated method stub

}

@Override
public void selectionChanged(ICompletionProposal proposal, boolean smartToggle) {
// TODO Auto-generated method stub

}

@Override
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) {
IDocument doc = fSourcePage.getDocumentProvider().getDocument(fSourcePage.getInputContext().getInput());
Expand All @@ -56,7 +37,7 @@ public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int
Field[] properties = IBuildPropertiesConstants.class.getFields();
for (Field f : properties) {
String key = f.getName();
String element = "";
String element;
try {
element = (String) f.get(key);
} catch (IllegalAccessException e) {
Expand All @@ -68,7 +49,7 @@ public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int
completions.add(proposal);
}
}
return completions.toArray(new ICompletionProposal[completions.size()]);
return completions.toArray(ICompletionProposal[]::new);
} catch (BadLocationException e) {
}
return null;
Expand Down

0 comments on commit 91ab862

Please sign in to comment.