diff options
9 files changed, 128 insertions, 111 deletions
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java index 718482429ff..fc8f9fdbea3 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/AbstractGNUSourceCodeParser.java @@ -399,8 +399,9 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { return; try { fActiveCode= true; - while (t != null && t.getType() != IToken.tINACTIVE_CODE_END) + while (t != null && t.getType() != IToken.tINACTIVE_CODE_END) { t= t.getNext(); + } if (t != null) { nextToken= t.getNext(); @@ -524,7 +525,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { protected final boolean isOnSameLine(int offset1, int offset2) { ILocationResolver lr= getTranslationUnit().getAdapter(ILocationResolver.class); - IASTFileLocation floc= lr.getMappedFileLocation(offset1, offset2-offset1+1); + IASTFileLocation floc= lr.getMappedFileLocation(offset1, offset2 - offset1 + 1); return floc.getFileName().equals(lr.getContainingFilePath(offset1)) && floc.getStartingLineNumber() == floc.getEndingLineNumber(); } @@ -541,12 +542,12 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { protected final <T extends IASTNode> T setRange(T n, IASTNode from, int endOffset) { final int offset = ((ASTNode) from).getOffset(); - ((ASTNode) n).setOffsetAndLength(offset, endOffset-offset); + ((ASTNode) n).setOffsetAndLength(offset, endOffset - offset); return n; } protected final <T extends IASTNode> T setRange(T n, int offset, int endOffset) { - ((ASTNode) n).setOffsetAndLength(offset, endOffset-offset); + ((ASTNode) n).setOffsetAndLength(offset, endOffset - offset); return n; } @@ -557,7 +558,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser { protected final <T extends IASTNode> T adjustEndOffset(T n, final int endOffset) { final ASTNode node = (ASTNode) n; - node.setLength(endOffset-node.getOffset()); + node.setLength(endOffset - node.getOffset()); return n; } diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/AbstractContentAssistTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/AbstractContentAssistTest.java index e6c78ba6d80..ce1f485d98c 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/AbstractContentAssistTest.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/AbstractContentAssistTest.java @@ -16,6 +16,9 @@ *******************************************************************************/ package org.eclipse.cdt.ui.tests.text.contentassist2; +import static org.eclipse.cdt.core.formatter.DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_COMMA_IN_METHOD_DECLARATION_PARAMETERS; +import static org.eclipse.cdt.core.formatter.DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_COMMA_IN_TEMPLATE_PARAMETERS; + import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; @@ -36,7 +39,6 @@ import org.eclipse.ui.texteditor.AbstractTextEditor; import org.eclipse.ui.texteditor.ITextEditor; import org.eclipse.cdt.core.dom.IPDOMManager; -import org.eclipse.cdt.core.formatter.DefaultCodeFormatterConstants; import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.testplugin.CProjectHelper; import org.eclipse.cdt.ui.CUIPlugin; @@ -56,9 +58,7 @@ import org.eclipse.cdt.internal.ui.text.contentassist.ParameterGuessingProposal; import org.eclipse.cdt.internal.ui.text.contentassist.RelevanceConstants; public abstract class AbstractContentAssistTest extends BaseUITestCase { - public static enum CompareType { - ID, DISPLAY, REPLACEMENT, CONTEXT, INFORMATION - } + public static enum CompareType { ID, DISPLAY, REPLACEMENT, CONTEXT, INFORMATION } private class ContentAssistResult { long startTime; @@ -102,7 +102,7 @@ public abstract class AbstractContentAssistTest extends BaseUITestCase { } /** - * Setup the project's content. + * Sets up the project's content. * @param project * @return the file to be opened in the editor */ @@ -123,9 +123,8 @@ public abstract class AbstractContentAssistTest extends BaseUITestCase { return CUIPlugin.getDefault().getPreferenceStore(); } - private ContentAssistResult invokeContentAssist(int offset, int length, - boolean isCompletion, boolean isTemplate, boolean filterResults) - throws Exception { + private ContentAssistResult invokeContentAssist(int offset, int length, boolean isCompletion, + boolean isTemplate, boolean filterResults) throws Exception { if (CTestPlugin.getDefault().isDebugging()) { System.out.println("\n\n\n\n\nTesting " + this.getClass().getName()); } @@ -158,9 +157,8 @@ public abstract class AbstractContentAssistTest extends BaseUITestCase { return new ContentAssistResult(startTime, endTime, results); } - protected void assertContentAssistResults(int offset, int length, - String[] expected, boolean isCompletion, boolean isTemplate, - boolean filterResults, CompareType compareType) throws Exception { + protected void assertContentAssistResults(int offset, int length, String[] expected, boolean isCompletion, + boolean isTemplate, boolean filterResults, CompareType compareType) throws Exception { ContentAssistResult r = invokeContentAssist(offset, length, isCompletion, isTemplate, filterResults); String[] resultStrings= toStringArray(r.results, compareType); @@ -204,7 +202,7 @@ public abstract class AbstractContentAssistTest extends BaseUITestCase { protected void assertContentAssistResults(int offset, int length, Map<String, String[][]> expected, boolean isCompletion, boolean isTemplate, boolean filterResults, CompareType compareType) - throws Exception { + throws Exception { ContentAssistResult r = invokeContentAssist(offset, length, isCompletion, isTemplate, filterResults); Map<String, String[][]> resultMap = toMap(r.results, compareType); @@ -242,8 +240,7 @@ public abstract class AbstractContentAssistTest extends BaseUITestCase { } } - private Map<String, String[][]> toMap(Object[] results, - CompareType compareType) { + private Map<String, String[][]> toMap(Object[] results, CompareType compareType) { Map<String, String[][]> resultsMap = new HashMap<>(); for (Object result : results) { switch (compareType) { @@ -273,16 +270,19 @@ public abstract class AbstractContentAssistTest extends BaseUITestCase { return resultsMap; } - protected void assertContentAssistResults(int offset, int length, String[] expected, boolean isCompletion, boolean isTemplate, CompareType compareType) throws Exception { + protected void assertContentAssistResults(int offset, int length, String[] expected, boolean isCompletion, + boolean isTemplate, CompareType compareType) throws Exception { assertContentAssistResults(offset, length, expected, isCompletion, isTemplate, true, compareType); } - protected void assertContentAssistResults(int offset, String[] expected, boolean isCompletion, CompareType compareType) throws Exception { + protected void assertContentAssistResults(int offset, String[] expected, boolean isCompletion, + CompareType compareType) throws Exception { assertContentAssistResults(offset, 0, expected, isCompletion, false, compareType); } /** * Filter out template and keyword proposals. + * * @param results * @param isCodeCompletion completion is in code, not preprocessor, etc. * @return filtered proposals @@ -386,14 +386,14 @@ public abstract class AbstractContentAssistTest extends BaseUITestCase { } /** - * @return the content of the editor buffer + * Returns the content of the editor buffer */ protected String getBuffer() { return getDocument().get(); } /** - * @return the editor document + * Returns the editor document */ protected IDocument getDocument() { return EditorTestHelper.getDocument(fEditor); @@ -401,11 +401,10 @@ public abstract class AbstractContentAssistTest extends BaseUITestCase { protected void setCommaAfterFunctionParameter(String value) { fCProject.setOption( - DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_COMMA_IN_METHOD_DECLARATION_PARAMETERS, value); + FORMATTER_INSERT_SPACE_AFTER_COMMA_IN_METHOD_DECLARATION_PARAMETERS, value); } protected void setCommaAfterTemplateParameter(String value) { - fCProject.setOption( - DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_COMMA_IN_TEMPLATE_PARAMETERS, value); + fCProject.setOption(FORMATTER_INSERT_SPACE_AFTER_COMMA_IN_TEMPLATE_PARAMETERS, value); } } diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/CParameterGuessingTests.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/CParameterGuessingTests.java index 5c9b94d6345..c85a1c1d010 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/CParameterGuessingTests.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/CParameterGuessingTests.java @@ -13,13 +13,13 @@ package org.eclipse.cdt.ui.tests.text.contentassist2; import java.util.HashMap; import java.util.Map; -import junit.framework.Test; - import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; import org.eclipse.cdt.core.testplugin.util.BaseTestCase; +import junit.framework.Test; + public class CParameterGuessingTests extends AbstractContentAssistTest { private static final String HEADER_FILE_NAME = "PGTest_C.h"; private static final String SOURCE_FILE_NAME = "PGTest_C.c"; @@ -52,8 +52,8 @@ public class CParameterGuessingTests extends AbstractContentAssistTest { } protected void assertParametersGuesses(Map<String, String[][]> expected) throws Exception { - assertContentAssistResults(getBuffer().length() - 1, 0, expected, true, - false, false, CompareType.REPLACEMENT); + assertContentAssistResults(getBuffer().length() - 1, 0, expected, true, false, false, + CompareType.REPLACEMENT); } // void foo(){ diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/CompletionProposalCategory.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/CompletionProposalCategory.java index e0af8e27962..677a8a110b5 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/CompletionProposalCategory.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/CompletionProposalCategory.java @@ -19,11 +19,11 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.FileLocator; import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.IExtension; +import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.SubProgressMonitor; import org.eclipse.jface.action.LegacyActionTools; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.text.contentassist.ICompletionProposal; @@ -252,7 +252,8 @@ public final class CompletionProposalCategory { * @return the list of computed completion proposals (element type: * {@link org.eclipse.jface.text.contentassist.ICompletionProposal}) */ - public List<ICompletionProposal> computeCompletionProposals(ContentAssistInvocationContext context, String partition, SubProgressMonitor monitor) { + public List<ICompletionProposal> computeCompletionProposals(ContentAssistInvocationContext context, + String partition, IProgressMonitor monitor) { fLastError= null; List<ICompletionProposal> result= new ArrayList<>(); List<CompletionProposalComputerDescriptor> descriptors= new ArrayList<>(fRegistry.getProposalComputerDescriptors(partition)); @@ -276,10 +277,12 @@ public final class CompletionProposalCategory { * @return the list of computed context information objects (element type: * {@link org.eclipse.jface.text.contentassist.IContextInformation}) */ - public List<IContextInformation> computeContextInformation(ContentAssistInvocationContext context, String partition, SubProgressMonitor monitor) { + public List<IContextInformation> computeContextInformation(ContentAssistInvocationContext context, + String partition, IProgressMonitor monitor) { fLastError= null; List<IContextInformation> result= new ArrayList<>(); - List<CompletionProposalComputerDescriptor> descriptors= new ArrayList<>(fRegistry.getProposalComputerDescriptors(partition)); + List<CompletionProposalComputerDescriptor> descriptors= + new ArrayList<>(fRegistry.getProposalComputerDescriptors(partition)); for (CompletionProposalComputerDescriptor desc : descriptors) { if (desc.getCategory() == this) result.addAll(desc.computeContextInformation(context, monitor)); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/ContentAssistProcessor.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/ContentAssistProcessor.java index 60b508fc4b8..00063fcb142 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/ContentAssistProcessor.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/ContentAssistProcessor.java @@ -23,7 +23,7 @@ import org.eclipse.core.runtime.Assert; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.Platform; -import org.eclipse.core.runtime.SubProgressMonitor; +import org.eclipse.core.runtime.SubMonitor; import org.eclipse.jface.action.LegacyActionTools; import org.eclipse.jface.bindings.TriggerSequence; import org.eclipse.jface.bindings.keys.KeySequence; @@ -251,11 +251,13 @@ public class ContentAssistProcessor implements IContentAssistProcessor { fNumberOfComputedResults= 0; } - private List<ICompletionProposal> collectProposals(ITextViewer viewer, int offset, IProgressMonitor monitor, ContentAssistInvocationContext context) { + private List<ICompletionProposal> collectProposals(ITextViewer viewer, int offset, + IProgressMonitor monitor, ContentAssistInvocationContext context) { List<ICompletionProposal> proposals= new ArrayList<>(); List<CompletionProposalCategory> providers= getCategories(); + SubMonitor progress = SubMonitor.convert(monitor, providers.size()); for (CompletionProposalCategory cat : providers) { - List<ICompletionProposal> computed= cat.computeCompletionProposals(context, fPartition, new SubProgressMonitor(monitor, 1)); + List<ICompletionProposal> computed= cat.computeCompletionProposals(context, fPartition, progress.split(1)); proposals.addAll(computed); if (fErrorMessage == null) fErrorMessage= cat.getErrorMessage(); @@ -298,14 +300,17 @@ public class ContentAssistProcessor implements IContentAssistProcessor { return result; } - private List<IContextInformation> collectContextInformation(ITextViewer viewer, int offset, IProgressMonitor monitor) { + private List<IContextInformation> collectContextInformation(ITextViewer viewer, int offset, + IProgressMonitor monitor) { List<IContextInformation> proposals= new ArrayList<>(); ContentAssistInvocationContext context= createContext(viewer, offset, false); try { List<CompletionProposalCategory> providers= getCategories(); + SubMonitor progress = SubMonitor.convert(monitor, providers.size()); for (CompletionProposalCategory cat : providers) { - List<IContextInformation> computed= cat.computeContextInformation(context, fPartition, new SubProgressMonitor(monitor, 1)); + List<IContextInformation> computed= + cat.computeContextInformation(context, fPartition, progress.split(1)); proposals.addAll(computed); if (fErrorMessage == null) fErrorMessage= cat.getErrorMessage(); @@ -326,7 +331,8 @@ public class ContentAssistProcessor implements IContentAssistProcessor { * @return the list of filtered and sorted proposals, ready for * display (element type: {@link IContextInformation}) */ - protected List<IContextInformation> filterAndSortContextInformation(List<IContextInformation> contexts, IProgressMonitor monitor) { + protected List<IContextInformation> filterAndSortContextInformation(List<IContextInformation> contexts, + IProgressMonitor monitor) { return contexts; } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/DOMCompletionProposalComputer.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/DOMCompletionProposalComputer.java index dde9f3fc2fe..1685b257aec 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/DOMCompletionProposalComputer.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/DOMCompletionProposalComputer.java @@ -111,7 +111,7 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer private static final String TYPENAME = "typename"; //$NON-NLS-1$; private static final String ELLIPSIS = "..."; //$NON-NLS-1$; private String fPrefix; - private ArrayList<IBinding> fAvailableElements; + private List<IBinding> fAvailableElements; /** * Default constructor is required (executable extension). @@ -121,8 +121,7 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer } @Override - protected List<ICompletionProposal> computeCompletionProposals( - CContentAssistInvocationContext context, + protected List<ICompletionProposal> computeCompletionProposals(CContentAssistInvocationContext context, IASTCompletionNode completionNode, String prefix) { fPrefix = prefix; initializeDefinedElements(context); @@ -130,7 +129,7 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer if (inPreprocessorDirective(context)) { if (!inPreprocessorKeyword(context)) { - // add only macros + // Add only macros. if (prefix.length() == 0) { try { prefix= context.computeIdentifierPrefix().toString(); @@ -146,7 +145,7 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer for (IASTName name : names) { 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; IASTCompletionContext astContext = name.getCompletionContext(); @@ -154,7 +153,7 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer continue; } else if (astContext instanceof IASTIdExpression || astContext instanceof IASTNamedTypeSpecifier) { - // handle macros only if there is a prefix + // Handle macros only if there is a prefix. handleMacros = prefix.length() > 0; } @@ -192,12 +191,12 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer if (ICPartitions.C_PREPROCESSOR.equals(partition.getType())) { String ppPrefix= doc.get(partition.getOffset(), offset - partition.getOffset()); if (ppPrefix.matches("\\s*#\\s*\\w*")) { //$NON-NLS-1$ - // we are inside the directive keyword + // We are inside the directive keyword. return true; } } - } catch (BadLocationException exc) { + } catch (BadLocationException e) { } return false; } @@ -205,7 +204,7 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer /** * Check if the invocation offset is inside a preprocessor directive. * - * @param context the content asist invocation context + * @param context the content assist invocation context * @return <code>true</code> if invocation offset is inside a preprocessor directive */ private boolean inPreprocessorDirective(CContentAssistInvocationContext context) { @@ -239,7 +238,8 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer char[] prefixChars= prefix.toCharArray(); final boolean matchPrefix= !context.isContextInformationStyle(); if (matchPrefix) { - IContentAssistMatcher matcher = ContentAssistMatcherFactory.getInstance().createMatcher(prefixChars); + IContentAssistMatcher matcher = + ContentAssistMatcherFactory.getInstance().createMatcher(prefixChars); for (int i = 0; i < macros.length; ++i) { final char[] macroName= macros[i].getName().toCharArray(); if (matcher.match(macroName)) { @@ -304,8 +304,9 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer } } - if (argString.length() > 0) { - CProposalContextInformation info = new CProposalContextInformation(image, descString, argString); + if (!argString.isEmpty()) { + CProposalContextInformation info = + new CProposalContextInformation(image, descString, argString); info.setContextInformationPosition(context.getContextInformationOffset()); proposal.setContextInformation(info); } @@ -366,8 +367,8 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer return name.length == 0 || name[0] == '{'; } - private void addProposalForClassTemplate(ICPPClassTemplate templateType, CContentAssistInvocationContext context, - int baseRelevance, List<ICompletionProposal> proposals) { + private void addProposalForClassTemplate(ICPPClassTemplate templateType, + CContentAssistInvocationContext context, int baseRelevance, List<ICompletionProposal> proposals) { int relevance = getClassTypeRelevance(templateType); StringBuilder representation = new StringBuilder(templateType.getName()); boolean inUsingDeclaration = context.isInUsingDirective(); @@ -384,8 +385,8 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer baseRelevance + relevance, context); if (!inUsingDeclaration) { - CProposalContextInformation info = - new CProposalContextInformation(getImage(templateType), displayString, templateParameterRepresentation); + CProposalContextInformation info = new CProposalContextInformation( + getImage(templateType), displayString, templateParameterRepresentation); info.setContextInformationPosition(context.getContextInformationOffset()); proposal.setContextInformation(info); if (!context.isContextInformationStyle()) { @@ -418,8 +419,10 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer } else if (parameter instanceof ICPPTemplateTypeParameter) { representation.append(TYPENAME); } else if (parameter instanceof ICPPTemplateTemplateParameter) { - String templateParameterParameters = buildTemplateParameters((ICPPTemplateTemplateParameter) parameter, context); - representation.append(MessageFormat.format(TEMPLATE_PARAMETER_PATTERN, templateParameterParameters)); + String templateParameterParameters = + buildTemplateParameters((ICPPTemplateTemplateParameter) parameter, context); + representation.append( + MessageFormat.format(TEMPLATE_PARAMETER_PATTERN, templateParameterParameters)); representation.append(templateParameterParameters); } if (parameter.isParameterPack()) { @@ -428,11 +431,13 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer representation.append(' '); representation.append(parameter.getName()); if (addDefaultArguments && defaultValue != null) { - String defaultArgumentRepresentation = MessageFormat.format(DEFAULT_ARGUMENT_PATTERN, defaultValue); + String defaultArgumentRepresentation = + MessageFormat.format(DEFAULT_ARGUMENT_PATTERN, defaultValue); for (int parameterIndex = 0; parameterIndex < i; parameterIndex++) { String templateArgumentID = HASH + parameterIndex; String templateArgumentValue = parameters[parameterIndex].getName(); - defaultArgumentRepresentation = defaultArgumentRepresentation.replaceAll(templateArgumentID, templateArgumentValue); + defaultArgumentRepresentation = + defaultArgumentRepresentation.replaceAll(templateArgumentID, templateArgumentValue); } representation.append(defaultArgumentRepresentation); } @@ -493,8 +498,8 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer repStringBuff.append('('); - StringBuilder dispargs = new StringBuilder(); // for the dispargString - StringBuilder idargs = new StringBuilder(); // for the idargString + StringBuilder dispArgs = new StringBuilder(); // for the dispargString + StringBuilder idArgs = new StringBuilder(); // for the idargString boolean hasArgs = true; String returnTypeStr = null; IParameter[] params = function.getParameters(); @@ -507,35 +512,36 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer } IType paramType = param.getType(); if (i > 0) { - dispargs.append(parameterDelimiter); - idargs.append(parameterDelimiter); + dispArgs.append(parameterDelimiter); + idArgs.append(parameterDelimiter); } - dispargs.append(ASTTypeUtil.getType(paramType, false)); - idargs.append(ASTTypeUtil.getType(paramType, false)); + dispArgs.append(ASTTypeUtil.getType(paramType, false)); + idArgs.append(ASTTypeUtil.getType(paramType, false)); String paramName = param.getName(); if (paramName != null && paramName.length() > 0) { - dispargs.append(' '); - dispargs.append(paramName); + dispArgs.append(' '); + dispArgs.append(paramName); } if (param instanceof ICPPParameter) { ICPPParameter cppParam = (ICPPParameter) param; if (cppParam.hasDefaultValue() && isDisplayDefaultArguments()) { - dispargs.append(MessageFormat.format(DEFAULT_ARGUMENT_PATTERN, cppParam.getDefaultValue())); + dispArgs.append( + MessageFormat.format(DEFAULT_ARGUMENT_PATTERN, cppParam.getDefaultValue())); } } } if (function.takesVarArgs()) { - if (params.length > 0) { - dispargs.append(parameterDelimiter); - idargs.append(parameterDelimiter); + if (params.length != 0) { + dispArgs.append(parameterDelimiter); + idArgs.append(parameterDelimiter); } - dispargs.append("..."); //$NON-NLS-1$ - idargs.append("..."); //$NON-NLS-1$ + dispArgs.append("..."); //$NON-NLS-1$ + idArgs.append("..."); //$NON-NLS-1$ } else if (params.length == 0) { // force the void in - dispargs.append("void"); //$NON-NLS-1$ - idargs.append("void"); //$NON-NLS-1$ + dispArgs.append("void"); //$NON-NLS-1$ + idArgs.append("void"); //$NON-NLS-1$ } } IFunctionType functionType = function.getType(); @@ -547,20 +553,20 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer hasArgs = ASTTypeUtil.functionTakesParameters(function); - String dispargString = dispargs.toString(); - String idargString = idargs.toString(); - String contextDispargString = hasArgs ? dispargString : null; + String dispArgString = dispArgs.toString(); + String idArgString = idArgs.toString(); + String contextDispargString = hasArgs ? dispArgString : null; StringBuilder dispStringBuff = new StringBuilder(repStringBuff); - dispStringBuff.append(dispargString); + dispStringBuff.append(dispArgString); dispStringBuff.append(')'); - if (returnTypeStr != null && returnTypeStr.length() > 0) { + if (returnTypeStr != null && !returnTypeStr.isEmpty()) { dispStringBuff.append(" : "); //$NON-NLS-1$ dispStringBuff.append(returnTypeStr); } String dispString = dispStringBuff.toString(); StringBuilder idStringBuff = new StringBuilder(repStringBuff); - idStringBuff.append(idargString); + idStringBuff.append(idArgString); idStringBuff.append(')'); String idString = idStringBuff.toString(); @@ -584,7 +590,8 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer CCompletionProposal proposal = createProposal(repString, dispString, idString, context.getCompletionNode().getLength(), image, baseRelevance + relevance, context); if (!context.isContextInformationStyle()) { - int cursorPosition = (!inUsingDeclaration && hasArgs) ? (repString.length() - 1) : repString.length(); + int cursorPosition = !inUsingDeclaration && hasArgs ? + repString.length() - 1 : repString.length(); proposal.setCursorPosition(cursorPosition); } @@ -596,18 +603,21 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer } /* - * The ParameterGuessingProposal will be active if the function accepts parameters and the content assist is - * invoked before typing any parameters. Otherwise, the normal Parameter Hint Proposal will be added. + * The ParameterGuessingProposal will be active if the function accepts parameters and the content + * assist is invoked before typing any parameters. Otherwise, the normal parameter hint proposal will + * be added. */ - if (function.getParameters() != null && function.getParameters().length > 0 && isBeforeParameters(context)) { - proposals.add(ParameterGuessingProposal.createProposal(context, fAvailableElements, proposal, function, fPrefix)); + if (function.getParameters() != null && function.getParameters().length != 0 + && isBeforeParameters(context)) { + proposals.add(ParameterGuessingProposal.createProposal(context, fAvailableElements, proposal, + function, fPrefix)); } else { proposals.add(proposal); } } /** - * Returns true if the invocation is at the function name or before typing any parameters + * Returns true if the invocation is at the function name or before typing any parameters. */ private boolean isBeforeParameters(CContentAssistInvocationContext context) { /* @@ -637,7 +647,7 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer } /** - * Initializes the list of defined elements at the start of the current statement. + * Initializes the list of variables accessible at the start of the current statement. */ private void initializeDefinedElements(CContentAssistInvocationContext context) { /* @@ -804,8 +814,7 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer CContentAssistInvocationContext cContext, int baseRelevance, List<ICompletionProposal> proposals) { if (astContext instanceof ICPPASTQualifiedName) { - IASTCompletionContext parent = ((ICPPASTQualifiedName) astContext) - .getCompletionContext(); + IASTCompletionContext parent = ((ICPPASTQualifiedName) astContext).getCompletionContext(); handleNamespace(namespace, parent, cContext, baseRelevance, proposals); return; } @@ -904,7 +913,7 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer imageDescriptor = CElementImageProvider.getFunctionImageDescriptor(); } else if (binding instanceof ICPPUsingDeclaration) { IBinding[] delegates = ((ICPPUsingDeclaration) binding).getDelegates(); - if (delegates.length > 0) + if (delegates.length != 0) return getImage(delegates[0]); } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/Lazy.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/Lazy.java index b1807e1528f..d7ecc99d26f 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/Lazy.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/Lazy.java @@ -28,7 +28,7 @@ public abstract class Lazy<E> { * @return The value of this object. */ @SuppressWarnings("unchecked") - public E value() { + public final E value() { if (value == NOT_INITIALIZED) { value = calculateValue(); } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/ParameterGuessingProposal.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/ParameterGuessingProposal.java index b4d94a9e238..0de68014854 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/ParameterGuessingProposal.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/ParameterGuessingProposal.java @@ -14,6 +14,7 @@ package org.eclipse.cdt.internal.ui.text.contentassist; import java.util.ArrayList; import java.util.Arrays; +import java.util.List; import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.BadPositionCategoryException; @@ -56,18 +57,18 @@ import org.eclipse.cdt.internal.ui.editor.EditorHighlightingSynchronizer; * with a list of suggestions for each parameter. */ public class ParameterGuessingProposal extends FunctionCompletionProposal { - private ICompletionProposal[][] fChoices; // initialized by guessParameters() - private Position[] fPositions; // initialized by guessParameters() - private IRegion fSelectedRegion; // initialized by apply() + private ICompletionProposal[][] fChoices; // Initialized by guessParameters() + private Position[] fPositions; // Initialized by guessParameters() + private IRegion fSelectedRegion; // Initialized by apply() private IPositionUpdater fUpdater; - private String fFullPrefix; // The string from the start of the statement to the invocation offset. + private String fFullPrefix; // The string from the start of the statement to the invocation offset. private CEditor fCEditor; private char[][] fParametersNames; private IType[] fParametersTypes; - private ArrayList<IBinding> fAssignableElements; + private List<IBinding> fAssignableElements; public static ParameterGuessingProposal createProposal(CContentAssistInvocationContext context, - ArrayList<IBinding> availableElements, CCompletionProposal proposal, IFunction function, + List<IBinding> availableElements, CCompletionProposal proposal, IFunction function, String prefix) { String replacement = getParametersList(function); String fullPrefix = function.getName() + "("; //$NON-NLS-1$ @@ -92,7 +93,7 @@ public class ParameterGuessingProposal extends FunctionCompletionProposal { } catch (BadLocationException e1) { } try { - // remove ')' from the replacement string if it is auto appended. + // Remove ')' from the replacement string if it is auto appended. if (document.getChar(invocationOffset) == ')') replacement = replacement.substring(0, replacement.length() - 1); } catch (BadLocationException e) { @@ -133,7 +134,8 @@ public class ParameterGuessingProposal extends FunctionCompletionProposal { public ParameterGuessingProposal(String replacementString, int replacementOffset, int replacementLength, Image image, String displayString, String idString, int relevance, ITextViewer viewer, - IFunction function, int invocationOffset, int parseOffset, ITranslationUnit tu, IDocument document) { + IFunction function, int invocationOffset, int parseOffset, ITranslationUnit tu, + IDocument document) { super(replacementString, replacementOffset, replacementLength, image, displayString, idString, relevance, viewer, function, invocationOffset, parseOffset, tu, document); } @@ -145,9 +147,6 @@ public class ParameterGuessingProposal extends FunctionCompletionProposal { return invocationOffset - parseOffset != 0; } - /** - * {@inheritDoc} - */ @Override public CharSequence getPrefixCompletionText(IDocument document, int completionOffset) { if (isInsideBracket(fInvocationOffset, fParseOffset)) { @@ -163,7 +162,7 @@ public class ParameterGuessingProposal extends FunctionCompletionProposal { public void apply(final IDocument document, char trigger, int offset) { super.apply(document, trigger, offset); - // Initialize necessary fields + // Initialize necessary fields. fParametersNames = getFunctionParametersNames(fFunctionParameters); fParametersTypes = getFunctionParametersTypes(fFunctionParameters); @@ -204,7 +203,7 @@ public class ParameterGuessingProposal extends FunctionCompletionProposal { LinkedModeUI ui = new EditorLinkedModeUI(model, fTextViewer); ui.setExitPosition(fTextViewer, baseOffset + replacement.length(), 0, Integer.MAX_VALUE); - // exit character can be either ')' or ';' + // Exit character can be either ')' or ';' final char exitChar = replacement.charAt(replacement.length() - 1); ui.setExitPolicy(new ExitPolicy(exitChar) { @Override @@ -350,7 +349,7 @@ public class ParameterGuessingProposal extends FunctionCompletionProposal { } /** - * Returns the c editor, or <code>null</code> if it cannot be determined. + * Returns the C/C++ editor, or {@code null} if it cannot be determined. */ private static CEditor getCEditor(IEditorPart editorPart) { if (editorPart instanceof CEditor) { diff --git a/util/org.eclipse.cdt.util/src/org/eclipse/cdt/internal/core/parser/util/DOMSearchUtil.java b/util/org.eclipse.cdt.util/src/org/eclipse/cdt/internal/core/parser/util/DOMSearchUtil.java index 35675f81669..dcd934e42a2 100644 --- a/util/org.eclipse.cdt.util/src/org/eclipse/cdt/internal/core/parser/util/DOMSearchUtil.java +++ b/util/org.eclipse.cdt.util/src/org/eclipse/cdt/internal/core/parser/util/DOMSearchUtil.java @@ -69,16 +69,16 @@ public class DOMSearchUtil { { shouldVisitNames = true; } - public List<IASTName> nameList = new ArrayList<IASTName>(); + public List<IASTName> nameList = new ArrayList<>(); @Override public int visit(IASTName name) { - nameList.add( name ); + nameList.add(name); return PROCESS_CONTINUE; } - public IASTName getName( int idx ){ - if( idx < 0 || idx >= nameList.size() ) + public IASTName getName(int idx) { + if (idx < 0 || idx >= nameList.size()) return null; return nameList.get(idx); } |