mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-31 12:55:40 +02:00
Bug 328522. Fixed NPE.
This commit is contained in:
parent
0bdbe7ce95
commit
2a8a5ec51a
1 changed files with 23 additions and 24 deletions
|
@ -56,6 +56,7 @@ public class CContentAssistProcessor extends ContentAssistProcessor {
|
||||||
|
|
||||||
private static class ActivationSet {
|
private static class ActivationSet {
|
||||||
private final String theSet;
|
private final String theSet;
|
||||||
|
|
||||||
ActivationSet(String s) {
|
ActivationSet(String s) {
|
||||||
theSet = s;
|
theSet = s;
|
||||||
}
|
}
|
||||||
|
@ -64,14 +65,11 @@ public class CContentAssistProcessor extends ContentAssistProcessor {
|
||||||
return -1 != theSet.indexOf(c);
|
return -1 != theSet.indexOf(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private ActivationSet fReplacementAutoActivationCharacters;
|
|
||||||
private ActivationSet fCContentAutoActivationCharacters;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A wrapper for {@link ICompetionProposal}s.
|
* A wrapper for {@link ICompetionProposal}s.
|
||||||
*/
|
*/
|
||||||
private static class CCompletionProposalWrapper implements ICCompletionProposal {
|
private static class CCompletionProposalWrapper implements ICCompletionProposal {
|
||||||
|
|
||||||
private ICompletionProposal fWrappedProposal;
|
private ICompletionProposal fWrappedProposal;
|
||||||
|
|
||||||
public CCompletionProposalWrapper(ICompletionProposal proposal) {
|
public CCompletionProposalWrapper(ICompletionProposal proposal) {
|
||||||
|
@ -140,10 +138,10 @@ public class CContentAssistProcessor extends ContentAssistProcessor {
|
||||||
public ICompletionProposal unwrap() {
|
public ICompletionProposal unwrap() {
|
||||||
return fWrappedProposal;
|
return fWrappedProposal;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ActivationSet fReplacementAutoActivationCharacters;
|
||||||
|
private ActivationSet fCContentAutoActivationCharacters;
|
||||||
private IContextInformationValidator fValidator;
|
private IContextInformationValidator fValidator;
|
||||||
private final IEditorPart fEditor;
|
private final IEditorPart fEditor;
|
||||||
|
|
||||||
|
@ -164,15 +162,16 @@ public class CContentAssistProcessor extends ContentAssistProcessor {
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @see org.eclipse.cdt.internal.ui.text.contentassist.ContentAssistProcessor#filterAndSort(java.util.List, org.eclipse.core.runtime.IProgressMonitor)
|
* @see org.eclipse.cdt.internal.ui.text.contentassist.ContentAssistProcessor#filterAndSort(List, IProgressMonitor)
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected List<ICompletionProposal> filterAndSortProposals(List<ICompletionProposal> proposals, IProgressMonitor monitor, ContentAssistInvocationContext context) {
|
protected List<ICompletionProposal> filterAndSortProposals(List<ICompletionProposal> proposals,
|
||||||
|
IProgressMonitor monitor, ContentAssistInvocationContext context) {
|
||||||
IProposalFilter filter = getCompletionFilter();
|
IProposalFilter filter = getCompletionFilter();
|
||||||
ICCompletionProposal[] proposalsInput= new ICCompletionProposal[proposals.size()];
|
ICCompletionProposal[] proposalsInput= new ICCompletionProposal[proposals.size()];
|
||||||
// wrap proposals which are no ICCompletionProposals
|
// wrap proposals which are no ICCompletionProposals
|
||||||
boolean wrapped= false;
|
boolean wrapped= false;
|
||||||
int i=0;
|
int i= 0;
|
||||||
for (ICompletionProposal proposal : proposals) {
|
for (ICompletionProposal proposal : proposals) {
|
||||||
if (proposal instanceof ICCompletionProposal) {
|
if (proposal instanceof ICCompletionProposal) {
|
||||||
proposalsInput[i++]= (ICCompletionProposal)proposal;
|
proposalsInput[i++]= (ICCompletionProposal)proposal;
|
||||||
|
@ -218,8 +217,7 @@ public class CContentAssistProcessor extends ContentAssistProcessor {
|
||||||
try {
|
try {
|
||||||
IConfigurationElement filterElement = ProposalFilterPreferencesUtil.getPreferredFilterElement();
|
IConfigurationElement filterElement = ProposalFilterPreferencesUtil.getPreferredFilterElement();
|
||||||
if (null != filterElement) {
|
if (null != filterElement) {
|
||||||
Object contribObject = filterElement
|
Object contribObject = filterElement.createExecutableExtension("class"); //$NON-NLS-1$
|
||||||
.createExecutableExtension("class"); //$NON-NLS-1$
|
|
||||||
if ((contribObject instanceof IProposalFilter)) {
|
if ((contribObject instanceof IProposalFilter)) {
|
||||||
filter = (IProposalFilter) contribObject;
|
filter = (IProposalFilter) contribObject;
|
||||||
}
|
}
|
||||||
|
@ -232,7 +230,7 @@ public class CContentAssistProcessor extends ContentAssistProcessor {
|
||||||
CUIPlugin.log(e);
|
CUIPlugin.log(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (null == filter) {
|
if (filter == null) {
|
||||||
// fail-safe default implementation
|
// fail-safe default implementation
|
||||||
filter = new DefaultProposalFilter();
|
filter = new DefaultProposalFilter();
|
||||||
}
|
}
|
||||||
|
@ -287,9 +285,10 @@ public class CContentAssistProcessor extends ContentAssistProcessor {
|
||||||
@Override
|
@Override
|
||||||
protected ContentAssistInvocationContext createContext(ITextViewer viewer, int offset, boolean isCompletion) {
|
protected ContentAssistInvocationContext createContext(ITextViewer viewer, int offset, boolean isCompletion) {
|
||||||
char activationChar = getActivationChar(viewer, offset);
|
char activationChar = getActivationChar(viewer, offset);
|
||||||
CContentAssistInvocationContext context
|
CContentAssistInvocationContext context =
|
||||||
= new CContentAssistInvocationContext(viewer, offset, fEditor, isCompletion, isAutoActivated());
|
new CContentAssistInvocationContext(viewer, offset, fEditor, isCompletion, isAutoActivated());
|
||||||
if (isCompletion && activationChar == '.' && fReplacementAutoActivationCharacters.contains('.')) {
|
if (isCompletion && activationChar == '.' && fReplacementAutoActivationCharacters != null &&
|
||||||
|
fReplacementAutoActivationCharacters.contains('.')) {
|
||||||
IASTCompletionNode node = context.getCompletionNode();
|
IASTCompletionNode node = context.getCompletionNode();
|
||||||
if (node != null) {
|
if (node != null) {
|
||||||
IASTName[] names = node.getNames();
|
IASTName[] names = node.getNames();
|
||||||
|
@ -310,16 +309,17 @@ public class CContentAssistProcessor extends ContentAssistProcessor {
|
||||||
boolean isCompletion, CContentAssistInvocationContext context, char activationChar) {
|
boolean isCompletion, CContentAssistInvocationContext context, char activationChar) {
|
||||||
IDocument doc = viewer.getDocument();
|
IDocument doc = viewer.getDocument();
|
||||||
try {
|
try {
|
||||||
doc.replace(offset-1, 1, "->"); //$NON-NLS-1$
|
doc.replace(offset - 1, 1, "->"); //$NON-NLS-1$
|
||||||
context.dispose();
|
context.dispose();
|
||||||
// if user turned on activation only for replacement characters,
|
// if user turned on activation only for replacement characters,
|
||||||
// setting the context to null will skip the proposals popup later
|
// setting the context to null will skip the proposals popup later
|
||||||
if (!isAutoActivated() || fCContentAutoActivationCharacters.contains(activationChar))
|
if (!isAutoActivated() || fCContentAutoActivationCharacters.contains(activationChar)) {
|
||||||
context = new CContentAssistInvocationContext(viewer, offset+1, fEditor,
|
context = new CContentAssistInvocationContext(viewer, offset + 1, fEditor,
|
||||||
isCompletion, isAutoActivated());
|
isCompletion, isAutoActivated());
|
||||||
else
|
} else {
|
||||||
context = null;
|
context = null;
|
||||||
} catch (BadLocationException exc) {
|
}
|
||||||
|
} catch (BadLocationException e) {
|
||||||
if (isAutoActivated() && !fCContentAutoActivationCharacters.contains(activationChar)) {
|
if (isAutoActivated() && !fCContentAutoActivationCharacters.contains(activationChar)) {
|
||||||
if (context != null) {
|
if (context != null) {
|
||||||
context.dispose(); // XXX dang false positives null deref warnings
|
context.dispose(); // XXX dang false positives null deref warnings
|
||||||
|
@ -345,8 +345,8 @@ public class CContentAssistProcessor extends ContentAssistProcessor {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
return doc.getChar(offset-1);
|
return doc.getChar(offset - 1);
|
||||||
} catch (BadLocationException exc) {
|
} catch (BadLocationException e) {
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -381,9 +381,8 @@ public class CContentAssistProcessor extends ContentAssistProcessor {
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} catch (BadLocationException exc) {
|
} catch (BadLocationException e) {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue