1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-08 18:26:01 +02:00

Cosmetics.

This commit is contained in:
Sergey Prigogin 2012-02-22 20:12:37 -08:00
parent 948494892a
commit d7ed01e939
4 changed files with 101 additions and 100 deletions

View file

@ -6,8 +6,8 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* Doug Schaefer (IBM) - Initial API and implementation * Doug Schaefer (IBM) - Initial API and implementation
* Markus Schorn (Wind River Systems) * Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.core.dom.ast; package org.eclipse.cdt.core.dom.ast;
@ -30,7 +30,6 @@ import org.eclipse.core.runtime.IAdaptable;
* @noimplement This interface is not intended to be implemented by clients. * @noimplement This interface is not intended to be implemented by clients.
*/ */
public interface IASTTranslationUnit extends IASTDeclarationListOwner, IFileNomination, IAdaptable { public interface IASTTranslationUnit extends IASTDeclarationListOwner, IFileNomination, IAdaptable {
/** /**
* <code>OWNED_DECLARATION</code> represents the relationship between an <code>IASTTranslationUnit</code> and * <code>OWNED_DECLARATION</code> represents the relationship between an <code>IASTTranslationUnit</code> and
* it's nested <code>IASTDeclaration</code>'s. * it's nested <code>IASTDeclaration</code>'s.
@ -107,7 +106,7 @@ public interface IASTTranslationUnit extends IASTDeclarationListOwner, IFileNomi
/** /**
* Returns the array of definitions in this translation unit for the given binding. * Returns the array of definitions in this translation unit for the given binding.
* The array contains the IASTName nodes that define the binding. * The array contains the IASTName nodes that define the binding.
* These are part of the AST no definitions are pulled in from the index. * These are part of the AST, no definitions are pulled in from the index.
* *
* @param binding * @param binding
* @return Array of IASTName nodes for the binding's declaration * @return Array of IASTName nodes for the binding's declaration
@ -117,7 +116,7 @@ public interface IASTTranslationUnit extends IASTDeclarationListOwner, IFileNomi
/** /**
* Returns the list of references in this translation unit to the given * Returns the list of references in this translation unit to the given
* binding. This list contains the IASTName nodes that represent a use of * binding. This list contains the IASTName nodes that represent a use of
* the binding. These are part of the AST no definitions are pulled in from * the binding. These are part of the AST, no definitions are pulled in from
* the index. * the index.
* *
* @param binding * @param binding

View file

@ -6,7 +6,7 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* Markus Schorn - initial API and implementation * Markus Schorn - initial API and implementation
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser; package org.eclipse.cdt.internal.core.dom.parser;
@ -31,22 +31,27 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor;
public class ASTQueries { public class ASTQueries {
private static class NameSearch extends ASTVisitor { private static class NameSearch extends ASTVisitor {
private boolean fFound; private boolean fFound;
NameSearch() { NameSearch() {
super(false); super(false);
shouldVisitAmbiguousNodes= true; shouldVisitAmbiguousNodes= true;
shouldVisitNames= true; shouldVisitNames= true;
} }
public void reset() { public void reset() {
fFound= false; fFound= false;
} }
public boolean foundName() { public boolean foundName() {
return fFound; return fFound;
} }
@Override @Override
public int visit(IASTName name) { public int visit(IASTName name) {
fFound= true; fFound= true;
return PROCESS_ABORT; return PROCESS_ABORT;
} }
@Override @Override
public int visit(ASTAmbiguousNode node) { public int visit(ASTAmbiguousNode node) {
IASTNode[] alternatives= node.getNodes(); IASTNode[] alternatives= node.getNodes();

View file

@ -6,8 +6,8 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* John Camelon (IBM Rational Software) - Initial API and implementation * John Camelon (IBM Rational Software) - Initial API and implementation
* Markus Schorn (Wind River Systems) * Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.c; package org.eclipse.cdt.internal.core.dom.parser.c;
@ -24,15 +24,14 @@ import org.eclipse.cdt.core.parser.util.ArrayUtil;
import org.eclipse.cdt.internal.core.dom.parser.ASTQueries; import org.eclipse.cdt.internal.core.dom.parser.ASTQueries;
/** /**
* Models function declarators for plain c. * A function declarator for plain C.
*/ */
public class CASTFunctionDeclarator extends CASTDeclarator implements IASTStandardFunctionDeclarator { public class CASTFunctionDeclarator extends CASTDeclarator implements IASTStandardFunctionDeclarator {
private IASTParameterDeclaration[] parameters;
private IASTParameterDeclaration [] parameters = null; private int parametersPos= -1;
private int parametersPos=-1;
private boolean varArgs; private boolean varArgs;
private IScope scope; private IScope scope;
public CASTFunctionDeclarator() { public CASTFunctionDeclarator() {
} }
@ -50,20 +49,22 @@ public class CASTFunctionDeclarator extends CASTDeclarator implements IASTStanda
CASTFunctionDeclarator copy = new CASTFunctionDeclarator(); CASTFunctionDeclarator copy = new CASTFunctionDeclarator();
copyBaseDeclarator(copy, style); copyBaseDeclarator(copy, style);
copy.varArgs = varArgs; copy.varArgs = varArgs;
for(IASTParameterDeclaration param : getParameters()) for (IASTParameterDeclaration param : getParameters()) {
copy.addParameterDeclaration(param == null ? null : param.copy(style)); copy.addParameterDeclaration(param == null ? null : param.copy(style));
}
if (style == CopyStyle.withLocations) { if (style == CopyStyle.withLocations) {
copy.setCopyLocation(this); copy.setCopyLocation(this);
} }
return copy; return copy;
} }
@Override @Override
public IASTParameterDeclaration[] getParameters() { public IASTParameterDeclaration[] getParameters() {
if( parameters == null ) return IASTParameterDeclaration.EMPTY_PARAMETERDECLARATION_ARRAY; if (parameters == null)
parameters = ArrayUtil.trimAt( IASTParameterDeclaration.class, parameters, parametersPos ); return IASTParameterDeclaration.EMPTY_PARAMETERDECLARATION_ARRAY;
parameters = ArrayUtil.trimAt(IASTParameterDeclaration.class, parameters, parametersPos);
return parameters; return parameters;
} }
@ -73,8 +74,8 @@ public class CASTFunctionDeclarator extends CASTDeclarator implements IASTStanda
if (parameter != null) { if (parameter != null) {
parameter.setParent(this); parameter.setParent(this);
parameter.setPropertyInParent(FUNCTION_PARAMETER); parameter.setPropertyInParent(FUNCTION_PARAMETER);
parameters = ArrayUtil.appendAt( IASTParameterDeclaration.class, parameters, ++parametersPos, parameter ); parameters = ArrayUtil.appendAt(IASTParameterDeclaration.class, parameters, ++parametersPos, parameter);
} }
} }
@Override @Override
@ -100,7 +101,7 @@ public class CASTFunctionDeclarator extends CASTDeclarator implements IASTStanda
@Override @Override
public void replace(IASTNode child, IASTNode other) { public void replace(IASTNode child, IASTNode other) {
if( parameters != null ) { if (parameters != null) {
for (int i = 0; i < parameters.length; ++i) { for (int i = 0; i < parameters.length; ++i) {
if (child == parameters[i]) { if (child == parameters[i]) {
other.setPropertyInParent(child.getPropertyInParent()); other.setPropertyInParent(child.getPropertyInParent());
@ -112,22 +113,22 @@ public class CASTFunctionDeclarator extends CASTDeclarator implements IASTStanda
} }
super.replace(child, other); super.replace(child, other);
} }
@Override @Override
public IScope getFunctionScope() { public IScope getFunctionScope() {
if (scope != null) if (scope != null)
return scope; return scope;
// introduce a scope for function declarations and definitions, only. // introduce a scope for function declarations and definitions, only.
IASTNode node= getParent(); IASTNode node= getParent();
while(!(node instanceof IASTDeclaration)) { while (!(node instanceof IASTDeclaration)) {
if (node==null) if (node==null)
return null; return null;
node= node.getParent(); node= node.getParent();
} }
if (node instanceof IASTParameterDeclaration) if (node instanceof IASTParameterDeclaration)
return null; return null;
if (node instanceof IASTFunctionDefinition) { if (node instanceof IASTFunctionDefinition) {
scope= ((IASTFunctionDefinition) node).getScope(); scope= ((IASTFunctionDefinition) node).getScope();
} else if (ASTQueries.findTypeRelevantDeclarator(this) == this) { } else if (ASTQueries.findTypeRelevantDeclarator(this) == this) {

View file

@ -6,11 +6,11 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* QNX - Initial API and implementation * QNX - Initial API and implementation
* Markus Schorn (Wind River Systems) * Markus Schorn (Wind River Systems)
* Anton Leherbauer (Wind River Systems) * Anton Leherbauer (Wind River Systems)
* Sergey Prigogin (Google) * Sergey Prigogin (Google)
* Jens Elmenthaler - http://bugs.eclipse.org/173458 (camel case completion) * Jens Elmenthaler - http://bugs.eclipse.org/173458 (camel case completion)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.ui.text.contentassist; package org.eclipse.cdt.internal.ui.text.contentassist;
@ -85,7 +85,7 @@ import org.eclipse.cdt.internal.ui.viewsupport.CElementImageProvider;
/** /**
* Searches the DOM (both the AST and the index) for completion proposals. * Searches the DOM (both the AST and the index) for completion proposals.
* *
* @author Bryan Wilkinson * @author Bryan Wilkinson
*/ */
public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer { public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer {
@ -95,14 +95,13 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
*/ */
public DOMCompletionProposalComputer() { public DOMCompletionProposalComputer() {
} }
@Override @Override
protected List<ICompletionProposal> computeCompletionProposals( protected List<ICompletionProposal> computeCompletionProposals(
CContentAssistInvocationContext context, CContentAssistInvocationContext context,
IASTCompletionNode completionNode, String prefix) { IASTCompletionNode completionNode, String prefix) {
List<ICompletionProposal> proposals = new ArrayList<ICompletionProposal>(); List<ICompletionProposal> proposals = new ArrayList<ICompletionProposal>();
if (inPreprocessorDirective(context)) { if (inPreprocessorDirective(context)) {
if (!inPreprocessorKeyword(context)) { if (!inPreprocessorKeyword(context)) {
// add only macros // add only macros
@ -123,7 +122,7 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
if (name.getTranslationUnit() == null) if (name.getTranslationUnit() == null)
// The node isn't properly hooked up, must have backtracked out of this node // The node isn't properly hooked up, must have backtracked out of this node
continue; continue;
IASTCompletionContext astContext = name.getCompletionContext(); IASTCompletionContext astContext = name.getCompletionContext();
if (astContext == null) { if (astContext == null) {
continue; continue;
@ -132,9 +131,9 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
// handle macros only if there is a prefix // handle macros only if there is a prefix
handleMacros = prefix.length() > 0; handleMacros = prefix.length() > 0;
} }
IBinding[] bindings = astContext.findBindings(name, !context.isContextInformationStyle()); IBinding[] bindings = astContext.findBindings(name, !context.isContextInformationStyle());
if (bindings != null) { if (bindings != null) {
AccessContext accessibilityContext = new AccessContext(name); AccessContext accessibilityContext = new AccessContext(name);
for (IBinding binding : bindings) { for (IBinding binding : bindings) {
@ -147,20 +146,20 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
if (handleMacros) if (handleMacros)
addMacroProposals(context, prefix, proposals); addMacroProposals(context, prefix, proposals);
} }
return proposals; return proposals;
} }
/** /**
* Test whether the invocation offset is inside or before the preprocessor directive keyword. * Test whether the invocation offset is inside or before the preprocessor directive keyword.
* *
* @param context the invocation context * @param context the invocation context
* @return <code>true</code> if the invocation offset is inside or before the directive keyword * @return <code>true</code> if the invocation offset is inside or before the directive keyword
*/ */
private boolean inPreprocessorKeyword(CContentAssistInvocationContext context) { private boolean inPreprocessorKeyword(CContentAssistInvocationContext context) {
IDocument doc = context.getDocument(); IDocument doc = context.getDocument();
int offset = context.getInvocationOffset(); int offset = context.getInvocationOffset();
try { try {
final ITypedRegion partition= final ITypedRegion partition=
TextUtilities.getPartition(doc, ICPartitions.C_PARTITIONING, offset, true); TextUtilities.getPartition(doc, ICPartitions.C_PARTITIONING, offset, true);
@ -171,7 +170,7 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
return true; return true;
} }
} }
} catch (BadLocationException exc) { } catch (BadLocationException exc) {
} }
return false; return false;
@ -179,21 +178,21 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
/** /**
* Check if the invocation offset is inside a preprocessor directive. * Check if the invocation offset is inside a preprocessor directive.
* *
* @param context the content asist invocation context * @param context the content asist invocation context
* @return <code>true</code> if invocation offset is inside a preprocessor directive * @return <code>true</code> if invocation offset is inside a preprocessor directive
*/ */
private boolean inPreprocessorDirective(CContentAssistInvocationContext context) { private boolean inPreprocessorDirective(CContentAssistInvocationContext context) {
IDocument doc = context.getDocument(); IDocument doc = context.getDocument();
int offset = context.getInvocationOffset(); int offset = context.getInvocationOffset();
try { try {
final ITypedRegion partition= final ITypedRegion partition=
TextUtilities.getPartition(doc, ICPartitions.C_PARTITIONING, offset, true); TextUtilities.getPartition(doc, ICPartitions.C_PARTITIONING, offset, true);
if (ICPartitions.C_PREPROCESSOR.equals(partition.getType())) { if (ICPartitions.C_PREPROCESSOR.equals(partition.getType())) {
return true; return true;
} }
} catch (BadLocationException exc) { } catch (BadLocationException exc) {
} }
return false; return false;
@ -202,10 +201,10 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
private void addMacroProposals(CContentAssistInvocationContext context, String prefix, private void addMacroProposals(CContentAssistInvocationContext context, String prefix,
List<ICompletionProposal> proposals) { List<ICompletionProposal> proposals) {
IASTCompletionNode completionNode = context.getCompletionNode(); IASTCompletionNode completionNode = context.getCompletionNode();
addMacroProposals(context, prefix, proposals, completionNode.getTranslationUnit() addMacroProposals(context, prefix, proposals,
.getMacroDefinitions()); completionNode.getTranslationUnit().getMacroDefinitions());
addMacroProposals(context, prefix, proposals, completionNode.getTranslationUnit() addMacroProposals(context, prefix, proposals,
.getBuiltinMacroDefinitions()); completionNode.getTranslationUnit().getBuiltinMacroDefinitions());
} }
private void addMacroProposals(CContentAssistInvocationContext context, String prefix, private void addMacroProposals(CContentAssistInvocationContext context, String prefix,
@ -231,22 +230,22 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
} }
} }
} }
private void handleMacro(IASTPreprocessorMacroDefinition macro, CContentAssistInvocationContext context, private void handleMacro(IASTPreprocessorMacroDefinition macro, CContentAssistInvocationContext context,
String prefix, List<ICompletionProposal> proposals) { String prefix, List<ICompletionProposal> proposals) {
final String macroName = macro.getName().toString(); final String macroName = macro.getName().toString();
final int baseRelevance= computeBaseRelevance(prefix, macroName); final int baseRelevance= computeBaseRelevance(prefix, macroName);
Image image = getImage(CElementImageProvider.getMacroImageDescriptor()); Image image = getImage(CElementImageProvider.getMacroImageDescriptor());
if (macro instanceof IASTPreprocessorFunctionStyleMacroDefinition) { if (macro instanceof IASTPreprocessorFunctionStyleMacroDefinition) {
IASTPreprocessorFunctionStyleMacroDefinition functionMacro = IASTPreprocessorFunctionStyleMacroDefinition functionMacro =
(IASTPreprocessorFunctionStyleMacroDefinition) macro; (IASTPreprocessorFunctionStyleMacroDefinition) macro;
StringBuilder repStringBuff = new StringBuilder(); StringBuilder repStringBuff = new StringBuilder();
repStringBuff.append(macroName); repStringBuff.append(macroName);
repStringBuff.append('('); repStringBuff.append('(');
StringBuilder args = new StringBuilder(); StringBuilder args = new StringBuilder();
IASTFunctionStyleMacroParameter[] params = functionMacro.getParameters(); IASTFunctionStyleMacroParameter[] params = functionMacro.getParameters();
@ -258,15 +257,15 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
} }
} }
String argString = args.toString(); String argString = args.toString();
StringBuilder descStringBuff = new StringBuilder(repStringBuff.toString()); StringBuilder descStringBuff = new StringBuilder(repStringBuff.toString());
descStringBuff.append(argString); descStringBuff.append(argString);
descStringBuff.append(')'); descStringBuff.append(')');
repStringBuff.append(')'); repStringBuff.append(')');
String repString = repStringBuff.toString(); String repString = repStringBuff.toString();
String descString = descStringBuff.toString(); String descString = descStringBuff.toString();
CCompletionProposal proposal = createProposal(repString, descString, prefix.length(), image, CCompletionProposal proposal = createProposal(repString, descString, prefix.length(), image,
baseRelevance + RelevanceConstants.MACRO_TYPE_RELEVANCE, context); baseRelevance + RelevanceConstants.MACRO_TYPE_RELEVANCE, context);
if (!context.isContextInformationStyle()) { if (!context.isContextInformationStyle()) {
@ -276,13 +275,13 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
proposal.setCursorPosition(repString.length()); proposal.setCursorPosition(repString.length());
} }
} }
if (argString.length() > 0) { if (argString.length() > 0) {
CProposalContextInformation info = new CProposalContextInformation(image, descString, argString); CProposalContextInformation info = new CProposalContextInformation(image, descString, argString);
info.setContextInformationPosition(context.getContextInformationOffset()); info.setContextInformationPosition(context.getContextInformationOffset());
proposal.setContextInformation(info); proposal.setContextInformation(info);
} }
proposals.add(proposal); proposals.add(proposal);
} else { } else {
proposals.add(createProposal(macroName, macroName, prefix.length(), image, proposals.add(createProposal(macroName, macroName, prefix.length(), image,
@ -290,7 +289,7 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
} }
} }
protected void handleBinding(IBinding binding, CContentAssistInvocationContext cContext, String prefix, protected void handleBinding(IBinding binding, CContentAssistInvocationContext cContext, String prefix,
IASTCompletionContext astContext, List<ICompletionProposal> proposals) { IASTCompletionContext astContext, List<ICompletionProposal> proposals) {
if ((binding instanceof CPPImplicitFunction if ((binding instanceof CPPImplicitFunction
|| binding instanceof CPPImplicitTypedef || binding instanceof CPPImplicitTypedef
@ -332,7 +331,7 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
} }
} }
} }
private boolean isAnonymousBinding(IBinding binding) { private boolean isAnonymousBinding(IBinding binding) {
char[] name= binding.getNameCharArray(); char[] name= binding.getNameCharArray();
return name.length == 0 || name[0] == '{'; return name.length == 0 || name[0] == '{';
@ -369,15 +368,15 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
baseRelevance + RelevanceConstants.CLASS_TYPE_RELEVANCE, context)); baseRelevance + RelevanceConstants.CLASS_TYPE_RELEVANCE, context));
} }
} }
private void handleFunction(IFunction function, CContentAssistInvocationContext context, private void handleFunction(IFunction function, CContentAssistInvocationContext context,
int baseRelevance, List<ICompletionProposal> proposals) { int baseRelevance, List<ICompletionProposal> proposals) {
Image image = getImage(function); Image image = getImage(function);
StringBuilder repStringBuff = new StringBuilder(); StringBuilder repStringBuff = new StringBuilder();
repStringBuff.append(function.getName()); repStringBuff.append(function.getName());
repStringBuff.append('('); repStringBuff.append('(');
StringBuilder dispargs = new StringBuilder(); // for the dispargString StringBuilder dispargs = new StringBuilder(); // for the dispargString
StringBuilder idargs = new StringBuilder(); // for the idargString StringBuilder idargs = new StringBuilder(); // for the idargString
boolean hasArgs = true; boolean hasArgs = true;
@ -399,7 +398,7 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
dispargs.append(paramName); dispargs.append(paramName);
} }
} }
if (function.takesVarArgs()) { if (function.takesVarArgs()) {
if (params.length > 0) { if (params.length > 0) {
dispargs.append(','); dispargs.append(',');
@ -420,7 +419,7 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
} }
hasArgs = ASTTypeUtil.functionTakesParameters(function); hasArgs = ASTTypeUtil.functionTakesParameters(function);
String dispargString = dispargs.toString(); String dispargString = dispargs.toString();
String idargString = idargs.toString(); String idargString = idargs.toString();
String contextDispargString = hasArgs ? dispargString : null; String contextDispargString = hasArgs ? dispargString : null;
@ -437,7 +436,7 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
idStringBuff.append(idargString); idStringBuff.append(idargString);
idStringBuff.append(')'); idStringBuff.append(')');
String idString = idStringBuff.toString(); String idString = idStringBuff.toString();
repStringBuff.append(')'); repStringBuff.append(')');
String repString = repStringBuff.toString(); String repString = repStringBuff.toString();
@ -449,17 +448,17 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
int cursorPosition = hasArgs ? (repString.length() - 1) : repString.length(); int cursorPosition = hasArgs ? (repString.length() - 1) : repString.length();
proposal.setCursorPosition(cursorPosition); proposal.setCursorPosition(cursorPosition);
} }
if (contextDispargString != null) { if (contextDispargString != null) {
CProposalContextInformation info = CProposalContextInformation info =
new CProposalContextInformation(image, dispString, contextDispargString); new CProposalContextInformation(image, dispString, contextDispargString);
info.setContextInformationPosition(context.getContextInformationOffset()); info.setContextInformationPosition(context.getContextInformationOffset());
proposal.setContextInformation(info); proposal.setContextInformation(info);
} }
proposals.add(proposal); proposals.add(proposal);
} }
private void handleVariable(IVariable variable, CContentAssistInvocationContext context, private void handleVariable(IVariable variable, CContentAssistInvocationContext context,
int baseRelevance, List<ICompletionProposal> proposals) { int baseRelevance, List<ICompletionProposal> proposals) {
if (context.isContextInformationStyle()) { if (context.isContextInformationStyle()) {
@ -473,16 +472,16 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
} }
} }
return; return;
} }
StringBuilder repStringBuff = new StringBuilder(); StringBuilder repStringBuff = new StringBuilder();
repStringBuff.append(variable.getName()); repStringBuff.append(variable.getName());
String returnTypeStr = "<unknown>"; //$NON-NLS-1$ String returnTypeStr = "<unknown>"; //$NON-NLS-1$
IType varType = variable.getType(); IType varType = variable.getType();
if (varType != null) if (varType != null)
returnTypeStr = ASTTypeUtil.getType(varType, false); returnTypeStr = ASTTypeUtil.getType(varType, false);
StringBuilder dispStringBuff = new StringBuilder(repStringBuff.toString()); StringBuilder dispStringBuff = new StringBuilder(repStringBuff.toString());
if (returnTypeStr != null) { if (returnTypeStr != null) {
dispStringBuff.append(" : "); //$NON-NLS-1$ dispStringBuff.append(" : "); //$NON-NLS-1$
@ -492,24 +491,25 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
StringBuilder idStringBuff = new StringBuilder(repStringBuff.toString()); StringBuilder idStringBuff = new StringBuilder(repStringBuff.toString());
String idString = idStringBuff.toString(); String idString = idStringBuff.toString();
String repString = repStringBuff.toString(); String repString = repStringBuff.toString();
Image image = getImage(variable); Image image = getImage(variable);
final int relevance = isLocalVariable(variable) final int relevance = isLocalVariable(variable) ?
? RelevanceConstants.LOCAL_VARIABLE_TYPE_RELEVANCE RelevanceConstants.LOCAL_VARIABLE_TYPE_RELEVANCE :
: isField(variable) isField(variable) ?
? RelevanceConstants.FIELD_TYPE_RELEVANCE RelevanceConstants.FIELD_TYPE_RELEVANCE :
: RelevanceConstants.VARIABLE_TYPE_RELEVANCE; RelevanceConstants.VARIABLE_TYPE_RELEVANCE;
CCompletionProposal proposal = createProposal(repString, dispString, idString, CCompletionProposal proposal = createProposal(repString, dispString, idString,
context.getCompletionNode().getLength(), image, baseRelevance + relevance, context); context.getCompletionNode().getLength(), image, baseRelevance + relevance, context);
proposals.add(proposal); proposals.add(proposal);
} }
private IType unwindTypedefs(final IType t) { private IType unwindTypedefs(final IType t) {
IType r= t; IType r= t;
while (r instanceof ITypedef) while (r instanceof ITypedef) {
r= ((ITypedef) r).getType(); r= ((ITypedef) r).getType();
}
return r != null ? r : t; return r != null ? r : t;
} }
@ -541,38 +541,35 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
return false; return false;
} }
private void handleNamespace(ICPPNamespace namespace, private void handleNamespace(ICPPNamespace namespace, IASTCompletionContext astContext,
IASTCompletionContext astContext, CContentAssistInvocationContext cContext, int baseRelevance,
CContentAssistInvocationContext cContext,
int baseRelevance,
List<ICompletionProposal> proposals) { List<ICompletionProposal> proposals) {
if (astContext instanceof ICPPASTQualifiedName) { if (astContext instanceof ICPPASTQualifiedName) {
IASTCompletionContext parent = ((ICPPASTQualifiedName) astContext) IASTCompletionContext parent = ((ICPPASTQualifiedName) astContext)
.getCompletionContext(); .getCompletionContext();
handleNamespace(namespace, parent, cContext, baseRelevance, proposals); handleNamespace(namespace, parent, cContext, baseRelevance, proposals);
return; return;
} }
StringBuilder repStringBuff = new StringBuilder(); StringBuilder repStringBuff = new StringBuilder();
repStringBuff.append(namespace.getName()); repStringBuff.append(namespace.getName());
if (!(astContext instanceof ICPPASTUsingDeclaration) if (!(astContext instanceof ICPPASTUsingDeclaration)
&& !(astContext instanceof ICPPASTUsingDirective)) { && !(astContext instanceof ICPPASTUsingDirective)) {
repStringBuff.append("::"); //$NON-NLS-1$ repStringBuff.append("::"); //$NON-NLS-1$
} }
String repString = repStringBuff.toString(); String repString = repStringBuff.toString();
proposals.add(createProposal(repString, namespace.getName(), getImage(namespace), proposals.add(createProposal(repString, namespace.getName(), getImage(namespace),
baseRelevance + RelevanceConstants.NAMESPACE_TYPE_RELEVANCE, cContext)); baseRelevance + RelevanceConstants.NAMESPACE_TYPE_RELEVANCE, cContext));
} }
private CCompletionProposal createProposal(String repString, String dispString, Image image, private CCompletionProposal createProposal(String repString, String dispString, Image image,
int relevance, CContentAssistInvocationContext context) { int relevance, CContentAssistInvocationContext context) {
return createProposal(repString, dispString, null, context.getCompletionNode().getLength(), image, return createProposal(repString, dispString, null, context.getCompletionNode().getLength(), image,
relevance, context); relevance, context);
} }
private CCompletionProposal createProposal(String repString, String dispString, int prefixLength, private CCompletionProposal createProposal(String repString, String dispString, int prefixLength,
Image image, int relevance, CContentAssistInvocationContext context) { Image image, int relevance, CContentAssistInvocationContext context) {
return createProposal(repString, dispString, null, prefixLength, image, relevance, context); return createProposal(repString, dispString, null, prefixLength, image, relevance, context);
@ -583,11 +580,11 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
int parseOffset = context.getParseOffset(); int parseOffset = context.getParseOffset();
int invocationOffset = context.getInvocationOffset(); int invocationOffset = context.getInvocationOffset();
boolean doReplacement = !context.isContextInformationStyle(); boolean doReplacement = !context.isContextInformationStyle();
int repLength = doReplacement ? prefixLength : 0; int repLength = doReplacement ? prefixLength : 0;
int repOffset = doReplacement ? parseOffset - repLength : invocationOffset; int repOffset = doReplacement ? parseOffset - repLength : invocationOffset;
repString = doReplacement ? repString : ""; //$NON-NLS-1$ repString = doReplacement ? repString : ""; //$NON-NLS-1$
return new CCompletionProposal(repString, repOffset, repLength, image, dispString, idString, return new CCompletionProposal(repString, repOffset, repLength, image, dispString, idString,
relevance, context.getViewer()); relevance, context.getViewer());
} }
@ -595,10 +592,10 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
private Image getImage(ImageDescriptor desc) { private Image getImage(ImageDescriptor desc) {
return desc != null ? CUIPlugin.getImageDescriptorRegistry().get(desc) : null; return desc != null ? CUIPlugin.getImageDescriptorRegistry().get(desc) : null;
} }
private Image getImage(IBinding binding) { private Image getImage(IBinding binding) {
ImageDescriptor imageDescriptor = null; ImageDescriptor imageDescriptor = null;
if (binding instanceof ITypedef) { if (binding instanceof ITypedef) {
imageDescriptor = CElementImageProvider.getTypedefImageDescriptor(); imageDescriptor = CElementImageProvider.getTypedefImageDescriptor();
} else if (binding instanceof ICompositeType) { } else if (binding instanceof ICompositeType) {
@ -651,9 +648,8 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
if (delegates.length > 0) if (delegates.length > 0)
return getImage(delegates[0]); return getImage(delegates[0]);
} }
return imageDescriptor != null return imageDescriptor != null ?
? CUIPlugin.getImageDescriptorRegistry().get(imageDescriptor) CUIPlugin.getImageDescriptorRegistry().get(imageDescriptor) : null;
: null;
} }
} }