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 df559f84097..bc3ab7236b0 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 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2013 IBM Corporation and others. + * Copyright (c) 2004, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -10,6 +10,7 @@ * Anton Leherbauer (Wind River Systems) * Bryan Wilkinson (QNX) * Markus Schorn (Wind River Systems) + * Thomas Corbat (IFS) *******************************************************************************/ package org.eclipse.cdt.ui.tests.text.contentassist2; @@ -30,6 +31,7 @@ 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.testplugin.CTestPlugin; @@ -45,10 +47,10 @@ import org.eclipse.cdt.internal.ui.text.contentassist.CContentAssistProcessor; import org.eclipse.cdt.internal.ui.text.contentassist.RelevanceConstants; public abstract class AbstractContentAssistTest extends BaseUITestCase { - public static final int COMPARE_ID_STRINGS = 0; - public static final int COMPARE_DISP_STRINGS = 1; - public static final int COMPARE_REP_STRINGS = 2; - + public static enum CompareType { + ID, DISPLAY, REPLACEMENT, CONTEXT, INFORMATION + } + protected ICProject fCProject; private IFile fCFile; protected ITextEditor fEditor; @@ -95,7 +97,7 @@ public abstract class AbstractContentAssistTest extends BaseUITestCase { super.tearDown(); } - protected void assertContentAssistResults(int offset, int length, String[] expected, boolean isCompletion, boolean isTemplate, boolean filterResults, int compareType) throws Exception { + protected void assertContentAssistResults(int offset, int length, String[] expected, boolean isCompletion, boolean isTemplate, boolean filterResults, CompareType compareType) throws Exception { if (CTestPlugin.getDefault().isDebugging()) { System.out.println("\n\n\n\n\nTesting "+this.getClass().getName()); } @@ -159,12 +161,12 @@ public abstract class AbstractContentAssistTest extends BaseUITestCase { assertEquals("Extra results!", toString(expected), toString(resultStrings)); } } - - protected void assertContentAssistResults(int offset, int length, String[] expected, boolean isCompletion, boolean isTemplate, int 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, int compareType) throws Exception { + protected void assertContentAssistResults(int offset, String[] expected, boolean isCompletion, CompareType compareType) throws Exception { assertContentAssistResults(offset, 0, expected, isCompletion, false, compareType); } @@ -212,32 +214,46 @@ public abstract class AbstractContentAssistTest extends BaseUITestCase { return filtered.toArray(); } - private String[] toStringArray(Object[] results, int compareType) { - String[] strings= new String[results.length]; - for(int i=0; i< results.length; i++){ + private String[] toStringArray(Object[] results, CompareType type) { + String[] strings = new String[results.length]; + + for (int i = 0; i < results.length; i++) { Object result = results[i]; - if (result instanceof CCompletionProposal) { - if (compareType == COMPARE_ID_STRINGS) { - strings[i]= ((CCompletionProposal)result).getIdString(); - } else if (compareType == COMPARE_DISP_STRINGS) { - strings[i]= ((CCompletionProposal)result).getDisplayString(); - } else { - strings[i]= ((CCompletionProposal)result).getReplacementString(); + switch (type) { + case ID: + if (result instanceof ICCompletionProposal) { + strings[i] = ((ICCompletionProposal) result).getIdString(); } - } else if (result instanceof ICCompletionProposal) { - if (compareType == COMPARE_ID_STRINGS) { - strings[i]= ((ICCompletionProposal)result).getIdString(); - } else if (compareType == COMPARE_DISP_STRINGS) { - strings[i]= ((ICCompletionProposal)result).getDisplayString(); - } else { - strings[i]= ((ICCompletionProposal)result).getDisplayString(); + break; + + case DISPLAY: + if (result instanceof ICompletionProposal) { + strings[i] = ((ICompletionProposal) result).getDisplayString(); } - } else if (result instanceof ICompletionProposal) { - strings[i]= ((ICompletionProposal)result).getDisplayString(); - } else if (result instanceof IContextInformation) { - strings[i]= ((IContextInformation)result).getContextDisplayString(); - } else { - strings[i]= result.toString(); + break; + + case REPLACEMENT: + if (result instanceof CCompletionProposal) { + strings[i] = ((CCompletionProposal) result).getReplacementString(); + } else if (result instanceof ICCompletionProposal) { + strings[i] = ((ICCompletionProposal) result).getDisplayString(); + } + break; + + case CONTEXT: + if (result instanceof ICompletionProposal) { + result = ((CCompletionProposal) result).getContextInformation(); + } + if (result instanceof IContextInformation) { + strings[i] = ((IContextInformation) result).getContextDisplayString(); + } + break; + + case INFORMATION: + if (result instanceof IContextInformation) { + strings[i] = ((IContextInformation) result).getInformationDisplayString(); + } + break; } } return strings; @@ -271,4 +287,16 @@ public abstract class AbstractContentAssistTest extends BaseUITestCase { protected IDocument getDocument() { return EditorTestHelper.getDocument(fEditor); } + + + + protected void setCommaAfterFunctionParameter(String value) { + fCProject.setOption( + DefaultCodeFormatterConstants.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); + } } diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/CompletionProposalsBaseTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/CompletionProposalsBaseTest.java index de8069a6555..e798f5463a6 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/CompletionProposalsBaseTest.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/CompletionProposalsBaseTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2007 IBM Corporation and others. + * Copyright (c) 2004, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -97,13 +97,12 @@ public abstract class CompletionProposalsBaseTest extends AbstractContentAssistT return bodyFile; } - protected void assertCompletionResults(int offset, String[] expected, int compareType) throws Exception { + protected void assertCompletionResults(int offset, String[] expected, CompareType compareType) throws Exception { assertContentAssistResults(offset, expected, true, compareType); } public void testCompletionProposals() throws Exception { String[] expected = getExpectedResultsValues(); - assertCompletionResults(getCompletionPosition(), expected, - AbstractContentAssistTest.COMPARE_DISP_STRINGS); + assertCompletionResults(getCompletionPosition(), expected, CompareType.DISPLAY); } } \ No newline at end of file diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/CompletionTests.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/CompletionTests.java index 01e804f022f..2d0ab6c3062 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/CompletionTests.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/CompletionTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2013 Wind River Systems, Inc. and others. + * Copyright (c) 2006, 2014 Wind River Systems, Inc. and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -13,6 +13,7 @@ * Sergey Prigogin (Google) * Jens Elmenthaler - http://bugs.eclipse.org/173458 (camel case completion) * Nathan Ridge + * Thomas Corbat (IFS) *******************************************************************************/ package org.eclipse.cdt.ui.tests.text.contentassist2; @@ -27,9 +28,12 @@ import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; import org.eclipse.jface.text.IDocument; +import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.testplugin.TestScannerProvider; import org.eclipse.cdt.core.testplugin.util.BaseTestCase; +import static org.eclipse.cdt.ui.tests.text.contentassist2.AbstractContentAssistTest.CompareType.*; + /** * A collection of code completion tests. * @@ -219,7 +223,7 @@ public class CompletionTests extends AbstractContentAssistTest { fCheckExtraResults= check; } - private void assertMinimumCompletionResults(int offset, String[] expected, int compareType) throws Exception { + private void assertMinimumCompletionResults(int offset, String[] expected, CompareType compareType) throws Exception { setCheckExtraResults(false); try { assertCompletionResults(offset, expected, compareType); @@ -228,16 +232,16 @@ public class CompletionTests extends AbstractContentAssistTest { } } - protected void assertCompletionResults(int offset, String[] expected, int compareType) throws Exception { + protected void assertCompletionResults(int offset, String[] expected, CompareType compareType) throws Exception { assertContentAssistResults(offset, expected, true, compareType); } protected void assertCompletionResults(String[] expected) throws Exception { - assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_REP_STRINGS); + assertCompletionResults(fCursorOffset, expected, REPLACEMENT); } protected void assertParameterHint(String[] expected) throws Exception { - assertContentAssistResults(fCursorOffset, expected, false, AbstractContentAssistTest.COMPARE_DISP_STRINGS); + assertContentAssistResults(fCursorOffset, expected, false, CONTEXT); } //void gfunc() {C1 v; v.m/*cursor*/ @@ -245,7 +249,7 @@ public class CompletionTests extends AbstractContentAssistTest { final String[] expected= { "m123(void)", "m12(void)", "m13(void)" }; - assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_ID_STRINGS); + assertCompletionResults(fCursorOffset, expected, ID); } //void gfunc() {C1 v; v.fMySelf->m/*cursor*/ @@ -253,7 +257,7 @@ public class CompletionTests extends AbstractContentAssistTest { final String[] expected= { "m123(void)", "m12(void)", "m13(void)" }; - assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_ID_STRINGS); + assertCompletionResults(fCursorOffset, expected, ID); } //void gfunc() {C1 v; v.m12()->m/*cursor*/ @@ -261,7 +265,7 @@ public class CompletionTests extends AbstractContentAssistTest { final String[] expected= { "m123(void)", "m12(void)", "m13(void)" }; - assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_ID_STRINGS); + assertCompletionResults(fCursorOffset, expected, ID); } //void gfunc() {gfC1()->m/*cursor*/ @@ -269,7 +273,7 @@ public class CompletionTests extends AbstractContentAssistTest { final String[] expected= { "m123(void)", "m12(void)", "m13(void)" }; - assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_ID_STRINGS); + assertCompletionResults(fCursorOffset, expected, ID); } //void C1::self() {m/*cursor*/ @@ -277,7 +281,7 @@ public class CompletionTests extends AbstractContentAssistTest { final String[] expected= { "m123(void)", "m12(void)", "m13(void)", "m1private(void)", "m1protected(void)" }; - assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_ID_STRINGS); + assertCompletionResults(fCursorOffset, expected, ID); } //void C1::self() {this->m/*cursor*/ @@ -285,7 +289,7 @@ public class CompletionTests extends AbstractContentAssistTest { final String[] expected= { "m123(void)", "m12(void)", "m13(void)", "m1private(void)", "m1protected(void)" }; - assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_ID_STRINGS); + assertCompletionResults(fCursorOffset, expected, ID); } //void gfunc() {try{int bla;}catch(C1 v) {v.fMySelf->m/*cursor*/ @@ -293,7 +297,7 @@ public class CompletionTests extends AbstractContentAssistTest { final String[] expected= { "m123(void)", "m12(void)", "m13(void)" }; - assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_ID_STRINGS); + assertCompletionResults(fCursorOffset, expected, ID); } //void gfunc() {try{int bla;}catch(C2 c){} catch(C1 v) {v.fMySelf->m/*cursor*/ @@ -301,7 +305,7 @@ public class CompletionTests extends AbstractContentAssistTest { final String[] expected= { "m123(void)", "m12(void)", "m13(void)" }; - assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_ID_STRINGS); + assertCompletionResults(fCursorOffset, expected, ID); } //void f() {gC/*cursor*/ @@ -309,7 +313,7 @@ public class CompletionTests extends AbstractContentAssistTest { final String[] expected= { "gC1", "gC2", "gfC1(void)", "gfC2(void)" }; - assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_ID_STRINGS); + assertCompletionResults(fCursorOffset, expected, ID); } //void C1::f() {gC/*cursor*/ @@ -317,7 +321,7 @@ public class CompletionTests extends AbstractContentAssistTest { final String[] expected= { "gC1", "gC2", "gfC1(void)", "gfC2(void)" }; - assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_ID_STRINGS); + assertCompletionResults(fCursorOffset, expected, ID); } //void f() {C2* cLocal1; while(true) {C1* cLocal2; cL/*cursor*/ @@ -325,7 +329,7 @@ public class CompletionTests extends AbstractContentAssistTest { final String[] expected= { "cLocal1", "cLocal2" }; - assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_ID_STRINGS); + assertCompletionResults(fCursorOffset, expected, ID); } //void C2::f() {C2* cLocal1; while(true) {C1* cLocal2; cL/*cursor*/ @@ -333,19 +337,19 @@ public class CompletionTests extends AbstractContentAssistTest { final String[] expected= { "cLocal1", "cLocal2" }; - assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_ID_STRINGS); + assertCompletionResults(fCursorOffset, expected, ID); } //void f() {C2* cLocal1; cLocal1->f/*cursor*/ public void testDataMembers_GlobalScope() throws Exception { final String[] expected= { "fMySelf" }; - assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_ID_STRINGS); + assertCompletionResults(fCursorOffset, expected, ID); } //void C2::f() {while(true) {f/*cursor*/ public void testDataMembers_MethodScope() throws Exception { final String[] expected= { "fMySelf" }; - assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_ID_STRINGS); + assertCompletionResults(fCursorOffset, expected, ID); } //void f() {gf/*cursor*/ @@ -353,7 +357,7 @@ public class CompletionTests extends AbstractContentAssistTest { final String[] expected= { "gfC1(void)", "gfC2(void)" }; - assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_ID_STRINGS); + assertCompletionResults(fCursorOffset, expected, ID); } //void C3::f() {gf/*cursor*/ @@ -361,7 +365,7 @@ public class CompletionTests extends AbstractContentAssistTest { final String[] expected= { "gfC1(void)", "gfC2(void)" }; - assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_ID_STRINGS); + assertCompletionResults(fCursorOffset, expected, ID); } //void f() {C1* l1; l1->m/*cursor*/ @@ -369,7 +373,7 @@ public class CompletionTests extends AbstractContentAssistTest { final String[] expected= { "m123(void)", "m12(void)", "m13(void)" }; - assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_ID_STRINGS); + assertCompletionResults(fCursorOffset, expected, ID); } //void C3::f() {m/*cursor*/ @@ -378,13 +382,13 @@ public class CompletionTests extends AbstractContentAssistTest { "m123(void)", "m12(void)", "m13(void)", "m23(void)", "m1protected(void)", "m2protected(void)", "m3private(void)", "m3protected(void)" }; - assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_ID_STRINGS); + assertCompletionResults(fCursorOffset, expected, ID); } //void f() {C/*cursor*/ public void testTypes_GlobalScope() throws Exception { final String[] expected= { "C1", "C2", "C3" }; - assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_ID_STRINGS); + assertCompletionResults(fCursorOffset, expected, ID); } //class _friend_class { C3* x; void m() {x->m/*cursor*/ @@ -393,7 +397,7 @@ public class CompletionTests extends AbstractContentAssistTest { "m123(void)", "m12(void)", "m13(void)", "m23(void)", "m1protected(void)", "m2protected(void)", "m2private(void)" }; - assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_ID_STRINGS); + assertCompletionResults(fCursorOffset, expected, ID); } //namespace ns { class _friend_class { C3* x; void m() {x->m/*cursor*/ // Not a friend due to namespace @@ -401,7 +405,7 @@ public class CompletionTests extends AbstractContentAssistTest { final String[] expected= { "m123(void)", "m12(void)", "m13(void)", "m23(void)" }; - assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_ID_STRINGS); + assertCompletionResults(fCursorOffset, expected, ID); } //void _friend_function(C3* x) { x->m/*cursor*/ @@ -410,228 +414,228 @@ public class CompletionTests extends AbstractContentAssistTest { "m123(void)", "m12(void)", "m13(void)", "m23(void)", "m1protected(void)", "m2protected(void)", "m2private(void)" }; - assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_ID_STRINGS); + assertCompletionResults(fCursorOffset, expected, ID); } //void _friend_function(C2* x) { x->m/*cursor*/ // Not a friend due to parameter type mismatch public void testTypes_FakeFriendFunction() throws Exception { final String[] expected= { "m123(void)", "m12(void)", "m13(void)", "m23(void)" }; - assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_ID_STRINGS); + assertCompletionResults(fCursorOffset, expected, ID); } //void C2::f() {T/*cursor*/ public void testTypes_MethodScope() throws Exception { final String[] expected= { "T1", "T2", "T3", "TClass" }; - assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_ID_STRINGS); + assertCompletionResults(fCursorOffset, expected, ID); } //namespace ns {void nsfunc(){C/*cursor*/ public void testTypes_NamespaceScope() throws Exception { final String[] expected= { "C1", "C2", "C3", "CNS" }; - assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_ID_STRINGS); + assertCompletionResults(fCursorOffset, expected, ID); } //namespace ns {void gfunc(){::C/*cursor*/ public void testTypes_GlobalQualification() throws Exception { final String[] expected= { "C1", "C2", "C3" }; - assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_ID_STRINGS); + assertCompletionResults(fCursorOffset, expected, ID); } //void f() {e/*cursor*/ public void testEnums_GlobalScope() throws Exception { final String[] expected= { "e11", "e12", "E1" }; - assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_ID_STRINGS); + assertCompletionResults(fCursorOffset, expected, ID); } //void C3::f() {e/*cursor*/ public void testEnums_MethodScope() throws Exception { final String[] expected= { "e11", "e12", "e21", "e22", "E1", "E2" }; - assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_ID_STRINGS); + assertCompletionResults(fCursorOffset, expected, ID); } //void f() {C3* l1; l1->C/*cursor*/ public void testQualificationForAccess1() throws Exception { // TLETODO ordering is significant here (currently ignored) final String[] expected= { "C3", "C2", "C1" }; - assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_ID_STRINGS); + assertCompletionResults(fCursorOffset, expected, ID); } //void f() {C2* l1; l1->C/*cursor*/ public void testQualificationForAccess2() throws Exception { // TLETODO ordering is significant here (currently ignored) final String[] expected= { "C2", "C1" }; - assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_ID_STRINGS); + assertCompletionResults(fCursorOffset, expected, ID); } //void f() {C3* l1; l1->C3::fMySelf->iam/*cursor*/ public void testQualifiedAccess1() throws Exception { // TLETODO ordering is significant here (currently ignored) final String[] expected= { "iam3(void)", "iam2(void)", "iam1(void)" }; - assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_ID_STRINGS); + assertCompletionResults(fCursorOffset, expected, ID); } //void f() {C3* l1; l1->C2::fMySelf->iam/*cursor*/ public void testQualifiedAccess2() throws Exception { // TLETODO ordering is significant here (currently ignored) final String[] expected= { "iam2(void)", "iam1(void)" }; - assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_ID_STRINGS); + assertCompletionResults(fCursorOffset, expected, ID); } //void f() {C3* l1; l1->C1::fMySelf->iam/*cursor*/ public void testQualifiedAccess3() throws Exception { final String[] expected= { "iam1(void)" }; - assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_ID_STRINGS); + assertCompletionResults(fCursorOffset, expected, ID); } //void f() {C3* l1; l1->T3::fMySelf->iam/*cursor*/ public void testQualifiedAccess_TypedefAsQualifier1() throws Exception { // TLETODO ordering is significant here (currently ignored) final String[] expected= { "iam3(void)", "iam2(void)", "iam1(void)" }; - assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_ID_STRINGS); + assertCompletionResults(fCursorOffset, expected, ID); } //void f() {C3* l1; l1->T2::fMySelf->iam/*cursor*/ public void testQualifiedAccess_TypedefAsQualifier2() throws Exception { // TLETODO ordering is significant here (currently ignored) final String[] expected= { "iam2(void)", "iam1(void)" }; - assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_ID_STRINGS); + assertCompletionResults(fCursorOffset, expected, ID); } //void f() {C3* l1; l1->T1::fMySelf->iam/*cursor*/ public void testQualifiedAccess_TypedefAsQualifier3() throws Exception { final String[] expected= { "iam1(void)" }; - assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_ID_STRINGS); + assertCompletionResults(fCursorOffset, expected, ID); } //void f() {C1().iam/*cursor*/ public void testTemporaryObject() throws Exception { final String[] expected= { "iam1(void)" }; - assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_ID_STRINGS); + assertCompletionResults(fCursorOffset, expected, ID); } //void f() {C1 c; (&c)->iam/*cursor*/ public void testAddressOf() throws Exception { final String[] expected= { "iam1(void)" }; - assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_ID_STRINGS); + assertCompletionResults(fCursorOffset, expected, ID); } //void f() {C1* c; (*c).iam/*cursor*/ public void testDereferencingOperator1() throws Exception { final String[] expected= { "iam1(void)" }; - assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_ID_STRINGS); + assertCompletionResults(fCursorOffset, expected, ID); } //void f() {C1** c; (**c).iam/*cursor*/ public void testDereferencingOperator2() throws Exception { final String[] expected= { "iam1(void)" }; - assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_ID_STRINGS); + assertCompletionResults(fCursorOffset, expected, ID); } //void f() {C1** c; (*c)->iam/*cursor*/ public void testDereferencingOperator3() throws Exception { final String[] expected= { "iam1(void)" }; - assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_ID_STRINGS); + assertCompletionResults(fCursorOffset, expected, ID); } //void f() {C1* c; c[0].iam/*cursor*/ public void testArrayAccessOperator1() throws Exception { final String[] expected= { "iam1(void)" }; - assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_ID_STRINGS); + assertCompletionResults(fCursorOffset, expected, ID); } //void f() {C1** c; c[0][1].iam/*cursor*/ public void testArrayAccessOperator2() throws Exception { final String[] expected= { "iam1(void)" }; - assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_ID_STRINGS); + assertCompletionResults(fCursorOffset, expected, ID); } //void f() {C1** c; c[0]->iam/*cursor*/ public void testArrayAccessOperator3() throws Exception { final String[] expected= { "iam1(void)" }; - assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_ID_STRINGS); + assertCompletionResults(fCursorOffset, expected, ID); } //void f() {C1* c; (&c[0])->iam/*cursor*/ public void testArrayAccessOperator4() throws Exception { final String[] expected= { "iam1(void)" }; - assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_ID_STRINGS); + assertCompletionResults(fCursorOffset, expected, ID); } //void f() {void* c; ((C1*)c)->iam/*cursor*/ public void testCasts1() throws Exception { final String[] expected= { "iam1(void)" }; - assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_ID_STRINGS); + assertCompletionResults(fCursorOffset, expected, ID); } //void g(int a) {}; void f() {void* c; g(((C1*)c)->iam/*cursor*/ public void testCasts2() throws Exception { final String[] expected= { "iam1(void)" }; - assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_ID_STRINGS); + assertCompletionResults(fCursorOffset, expected, ID); } //void f() {C1* c; c++->iam/*cursor*/ public void testPointerArithmetic1() throws Exception { final String[] expected= { "iam1(void)" }; - assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_ID_STRINGS); + assertCompletionResults(fCursorOffset, expected, ID); } //void f() {C1* c; (*++c).iam/*cursor*/ public void testPointerArithmetic2() throws Exception { final String[] expected= { "iam1(void)" }; - assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_ID_STRINGS); + assertCompletionResults(fCursorOffset, expected, ID); } //void f() {C1* c; c--->iam/*cursor*/ public void testPointerArithmetic3() throws Exception { final String[] expected= { "iam1(void)" }; - assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_ID_STRINGS); + assertCompletionResults(fCursorOffset, expected, ID); } //void f() {C1 c; (&c+1)->iam/*cursor*/ public void testPointerArithmetic4() throws Exception { final String[] expected= { "iam1(void)" }; - assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_ID_STRINGS); + assertCompletionResults(fCursorOffset, expected, ID); } //void f() {C1 c; (&c-1)->iam/*cursor*/ public void testPointerArithmetic5() throws Exception { final String[] expected= { "iam1(void)" }; - assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_ID_STRINGS); + assertCompletionResults(fCursorOffset, expected, ID); } //void f() {int localVar=0; if (*cond && somefunc(&local/*cursor*/ public void testNestedCalls() throws Exception { final String[] expected= { "localVar" }; - assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_ID_STRINGS); + assertCompletionResults(fCursorOffset, expected, ID); } //int a[] = {1,2}; void f(int _0306_b) {_0306_b/*cursor*/ public void testCuttingInput1() throws Exception { final String[] expected= { "_0306_b" }; - assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_ID_STRINGS); + assertCompletionResults(fCursorOffset, expected, ID); } //int a[] = {1,2}; void f(int b) {int _0306_b[] = {2,3}; _0306_b/*cursor*/ public void testCuttingInput2() throws Exception { final String[] expected= { "_0306_b" }; - assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_ID_STRINGS); + assertCompletionResults(fCursorOffset, expected, ID); } //enum EnumType function() {int _031209_v; _031209/*cursor*/ public void testDisturbingMacros() throws Exception { final String[] expected= { "_031209_v" }; - assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_ID_STRINGS); + assertCompletionResults(fCursorOffset, expected, ID); } //namespace ns {void x() {NSCO/*cursor*/ public void testAccessToNamespaceFromClassMember1() throws Exception { final String[] expected= { "NSCONST" }; - assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_ID_STRINGS); + assertCompletionResults(fCursorOffset, expected, ID); } //void ns::CNS::mcns(){NSCO/*cursor*/ public void testAccessToNamespaceFromClassMember2() throws Exception { final String[] expected= { "NSCONST" }; - assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_ID_STRINGS); + assertCompletionResults(fCursorOffset, expected, ID); } //#i/*cursor*/ @@ -639,34 +643,34 @@ public class CompletionTests extends AbstractContentAssistTest { final String[] expected= { "#if", "#ifdef", "#ifndef", "#include" }; - assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_ID_STRINGS); + assertCompletionResults(fCursorOffset, expected, ID); } //# d/*cursor*/ public void testCompletePreprocessorDirective2() throws Exception { final String[] expected= { "define " }; assertCompletionResults(fCursorOffset, expected, - AbstractContentAssistTest.COMPARE_REP_STRINGS); + REPLACEMENT); } //# if d/*cursor*/ public void testCompletePreprocessorDirective3() throws Exception { final String[] expected= { "defined" }; - assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_ID_STRINGS); + assertCompletionResults(fCursorOffset, expected, ID); } //void gfunc(){TClass t(0); t.a/*cursor*/ public void testTemplateClassMethod() throws Exception { // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=172436 final String[] expected= { "add(int)" }; - assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_ID_STRINGS); + assertCompletionResults(fCursorOffset, expected, ID); } //void gfunc(){C3 c3; c3.t/*cursor*/ public void testTemplateMethod() throws Exception { // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=172436 final String[] expected= { "tConvert(void)" }; - assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_ID_STRINGS); + assertCompletionResults(fCursorOffset, expected, ID); } // struct A {}; @@ -687,25 +691,25 @@ public class CompletionTests extends AbstractContentAssistTest { // } public void testAliasTemplate_418479() throws Exception { final String[] expected = { "D", "E" }; - assertContentAssistResults(fCursorOffset, expected, true, COMPARE_ID_STRINGS); + assertContentAssistResults(fCursorOffset, expected, true, ID); } //using namespace ns;void gfunc(){NSC/*cursor*/ public void testUsingDirective() throws Exception { final String[] expected= { "NSCONST" }; - assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_ID_STRINGS); + assertCompletionResults(fCursorOffset, expected, ID); } //void gfunc(){n/*cursor*/ public void testAutoColons() throws Exception { final String[] expected= { "ns::" }; - assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_REP_STRINGS); + assertCompletionResults(fCursorOffset, expected, REPLACEMENT); } //using namespace n/*cursor*/ public void testAutoColons2() throws Exception { final String[] expected= { "ns" }; - assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_REP_STRINGS); + assertCompletionResults(fCursorOffset, expected, REPLACEMENT); } //// to_be_replaced_ @@ -722,7 +726,7 @@ public class CompletionTests extends AbstractContentAssistTest { // EditorTestHelper.joinBackgroundActivities((AbstractTextEditor)fEditor); final String[] expected= { "aNewGlobalVar" }; - assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_ID_STRINGS); + assertCompletionResults(fCursorOffset, expected, ID); } //void Printer::InitPrinter(unsigned char port) { @@ -730,7 +734,7 @@ public class CompletionTests extends AbstractContentAssistTest { public void testPrivateStaticMember_109480() throws Exception { // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=109480 final String[] expected= { "InitPrinter()", "port" }; - assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_REP_STRINGS); + assertCompletionResults(fCursorOffset, expected, REPLACEMENT); } // class vector3 { @@ -741,7 +745,7 @@ public class CompletionTests extends AbstractContentAssistTest { public void testForwardMembersInInlineMethods_103857a() throws Exception { // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=103857 final String[] expected= { "x" }; - assertMinimumCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_REP_STRINGS); + assertMinimumCompletionResults(fCursorOffset, expected, REPLACEMENT); } // struct S { @@ -757,14 +761,14 @@ public class CompletionTests extends AbstractContentAssistTest { public void testForwardMembersInInlineMethods_103857b() throws Exception { // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=185652 final String[] expected= { "mem" }; - assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_REP_STRINGS); + assertCompletionResults(fCursorOffset, expected, REPLACEMENT); } // void Pri/*cursor*/ public void testMethodDefinitionClassName_190296() throws Exception { // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=190296 final String[] expected= { "Printer::" }; - assertMinimumCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_REP_STRINGS); + assertMinimumCompletionResults(fCursorOffset, expected, REPLACEMENT); } // typedef struct { @@ -778,7 +782,7 @@ public class CompletionTests extends AbstractContentAssistTest { public void testFunctionWithTypedefToAnonymousType_bug192787() throws Exception { // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=192787 final String[] expected= { "func(my_struct s) : void" }; - assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_DISP_STRINGS); + assertCompletionResults(fCursorOffset, expected, DISPLAY); } // namespace gns { @@ -797,59 +801,59 @@ public class CompletionTests extends AbstractContentAssistTest { String disturbContent= readTaggedComment(DISTURB_FILE_NAME); IFile dfile= createFile(fProject, DISTURB_FILE_NAME, disturbContent); waitForIndexer(fCProject); - assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_REP_STRINGS); + assertCompletionResults(fCursorOffset, expected, REPLACEMENT); dfile.delete(true, npm()); waitForIndexer(fCProject); - assertCompletionResults(fCursorOffset, expected2, AbstractContentAssistTest.COMPARE_REP_STRINGS); + assertCompletionResults(fCursorOffset, expected2, REPLACEMENT); } // struct Struct/*cursor*/ public void testElaboratedTypeSpecifierStruct_bug208710() throws Exception { final String[] expected= { "Struct1", "Struct2" }; - assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_REP_STRINGS); + assertCompletionResults(fCursorOffset, expected, REPLACEMENT); } // struct Union/*cursor*/ public void testElaboratedTypeSpecifierNotStruct_bug208710() throws Exception { final String[] expected= new String[0]; - assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_REP_STRINGS); + assertCompletionResults(fCursorOffset, expected, REPLACEMENT); } // struct C/*cursor*/ public void testElaboratedTypeSpecifierNotStruct2_bug208710() throws Exception { final String[] expected= new String[0]; - assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_REP_STRINGS); + assertCompletionResults(fCursorOffset, expected, REPLACEMENT); } // union Union/*cursor*/ public void testElaboratedTypeSpecifierUnion_bug208710() throws Exception { final String[] expected= { "Union1", "Union2" }; - assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_REP_STRINGS); + assertCompletionResults(fCursorOffset, expected, REPLACEMENT); } // union Struct/*cursor*/ public void testElaboratedTypeSpecifierNotUnion_bug208710() throws Exception { final String[] expected= new String[0]; - assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_REP_STRINGS); + assertCompletionResults(fCursorOffset, expected, REPLACEMENT); } // union C/*cursor*/ public void testElaboratedTypeSpecifierNotUnion2_bug208710() throws Exception { final String[] expected= new String[0]; - assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_REP_STRINGS); + assertCompletionResults(fCursorOffset, expected, REPLACEMENT); } // class C/*cursor*/ public void testElaboratedTypeSpecifierClass_bug208710() throws Exception { final String[] expected= { "C1", "C2", "C3" }; - assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_REP_STRINGS); + assertCompletionResults(fCursorOffset, expected, REPLACEMENT); } // class Struct/*cursor*/ public void testElaboratedTypeSpecifierNotClass_bug208710() throws Exception { final String[] expected= new String[0]; - assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_REP_STRINGS); + assertCompletionResults(fCursorOffset, expected, REPLACEMENT); } // void test() { @@ -859,19 +863,19 @@ public class CompletionTests extends AbstractContentAssistTest { final String[] expected= { "E2", "e21", "e22" }; - assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_ID_STRINGS); + assertCompletionResults(fCursorOffset, expected, ID); } // class Union/*cursor*/ public void testElaboratedTypeSpecifierNotClass2_bug208710() throws Exception { final String[] expected= new String[0]; - assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_REP_STRINGS); + assertCompletionResults(fCursorOffset, expected, REPLACEMENT); } // void func() {float a; a= 1./*cursor*/} public void testCompletionInFloatingPointLiteral_193464() throws Exception { final String[] expected= new String[0]; - assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_REP_STRINGS); + assertCompletionResults(fCursorOffset, expected, REPLACEMENT); } // #ifdef __cplusplus__ @@ -895,7 +899,7 @@ public class CompletionTests extends AbstractContentAssistTest { final String[] expected= { "c_linkage()" }; - assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_REP_STRINGS); + assertCompletionResults(fCursorOffset, expected, REPLACEMENT); } //#include "/*cursor*/ @@ -914,21 +918,21 @@ public class CompletionTests extends AbstractContentAssistTest { "\"sub1/\"", "\"inc2.h\"" }; - assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_REP_STRINGS); + assertCompletionResults(fCursorOffset, expected, REPLACEMENT); getDocument().replace(fCursorOffset++, 0, "i"); expected= new String[] { "\"inc1.h\"", "\"inc2.h\"" }; - assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_REP_STRINGS); + assertCompletionResults(fCursorOffset, expected, REPLACEMENT); getDocument().replace(fCursorOffset, 0, "\""); expected= new String[] { "\"inc1.h", "\"inc2.h" }; - assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_REP_STRINGS); + assertCompletionResults(fCursorOffset, expected, REPLACEMENT); createFile(fProject, "inc113568.h", ""); expected= new String[] { @@ -936,13 +940,13 @@ public class CompletionTests extends AbstractContentAssistTest { "\"inc113568.h", "\"inc2.h" }; - assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_REP_STRINGS); + assertCompletionResults(fCursorOffset, expected, REPLACEMENT); getDocument().replace(fCursorOffset - 1, 1, "sub1/"); expected= new String[] { "\"sub1/inc11.h" }; - assertCompletionResults(fCursorOffset += 4, expected, AbstractContentAssistTest.COMPARE_REP_STRINGS); + assertCompletionResults(fCursorOffset += 4, expected, REPLACEMENT); // bug 278967 getDocument().replace(fCursorOffset - 5, 5, "../"); @@ -950,7 +954,7 @@ public class CompletionTests extends AbstractContentAssistTest { "\"../h1/", "\"../h2/", }; - assertCompletionResults(fCursorOffset -= 2, expected, AbstractContentAssistTest.COMPARE_REP_STRINGS); + assertCompletionResults(fCursorOffset -= 2, expected, REPLACEMENT); } finally { deleteDir(tempDir); } @@ -990,7 +994,7 @@ public class CompletionTests extends AbstractContentAssistTest { // switch(loc/*cursor*/ public void testSwitchStatement() throws Exception { final String[] expected= { "local" }; - assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_REP_STRINGS); + assertCompletionResults(fCursorOffset, expected, REPLACEMENT); } // void test() { @@ -998,7 +1002,7 @@ public class CompletionTests extends AbstractContentAssistTest { // while(loc/*cursor*/ public void testWhileStatement() throws Exception { final String[] expected= { "local" }; - assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_REP_STRINGS); + assertCompletionResults(fCursorOffset, expected, REPLACEMENT); } // void test() { @@ -1006,7 +1010,7 @@ public class CompletionTests extends AbstractContentAssistTest { // for(loc/*cursor*/ public void testForStatement1() throws Exception { final String[] expected= { "local" }; - assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_REP_STRINGS); + assertCompletionResults(fCursorOffset, expected, REPLACEMENT); } // void test() { @@ -1014,7 +1018,7 @@ public class CompletionTests extends AbstractContentAssistTest { // for(int i=0;i @@ -1136,7 +1140,7 @@ public class CompletionTests extends AbstractContentAssistTest { //}; public void testContentAssistInDeferredClassInstance_194592() throws Exception { final String[] expected= { "add()" }; - assertCompletionResults(fCursorOffset, expected, COMPARE_REP_STRINGS); + assertCompletionResults(fCursorOffset, expected, REPLACEMENT); } //namespace ns { @@ -1166,7 +1170,7 @@ public class CompletionTests extends AbstractContentAssistTest { // to compile with gcc (e.g. 4.1.2), you need to write // ::ns::Base() instead of just Base(). "ns" }; - assertCompletionResults(fCursorOffset, expected, COMPARE_ID_STRINGS); + assertCompletionResults(fCursorOffset, expected, ID); } //namespace ns { @@ -1190,7 +1194,7 @@ public class CompletionTests extends AbstractContentAssistTest { //}; public void testCunstructorInitializerList_NameContextInput_266586() throws Exception { final String[] expected= { "ns" }; - assertCompletionResults(fCursorOffset, expected, COMPARE_ID_STRINGS); + assertCompletionResults(fCursorOffset, expected, ID); } //namespace ns { @@ -1214,7 +1218,7 @@ public class CompletionTests extends AbstractContentAssistTest { //}; public void testCunstructorInitializerList_MemberInput_266586() throws Exception { final String[] expected= { "mOne" }; - assertCompletionResults(fCursorOffset, expected, COMPARE_ID_STRINGS); + assertCompletionResults(fCursorOffset, expected, ID); } //namespace ns { @@ -1238,7 +1242,7 @@ public class CompletionTests extends AbstractContentAssistTest { //}; public void testConstructorInitializerList_BaseClassInput_266586() throws Exception { final String[] expected= { "Helper", "Helper(void)", "Helper(const Helper &)" }; - assertCompletionResults(fCursorOffset, expected, COMPARE_ID_STRINGS); + assertCompletionResults(fCursorOffset, expected, ID); } // template struct vector { @@ -1259,7 +1263,7 @@ public class CompletionTests extends AbstractContentAssistTest { // Ref/*cursor*/ public void testUsingDeclaration_331056() throws Exception { final String[] expected= { "Reference" }; - assertCompletionResults(fCursorOffset, expected, COMPARE_ID_STRINGS); + assertCompletionResults(fCursorOffset, expected, ID); } // template struct BaseClass { @@ -1272,7 +1276,7 @@ public class CompletionTests extends AbstractContentAssistTest { // }; public void testDeferredBaseClass_330762() throws Exception { final String[] expected= { "BaseMethod(void)" }; - assertCompletionResults(fCursorOffset, expected, COMPARE_ID_STRINGS); + assertCompletionResults(fCursorOffset, expected, ID); } // #define fooBar @@ -1280,13 +1284,14 @@ public class CompletionTests extends AbstractContentAssistTest { // fB/*cursor*/ public void testUserMacroSegmentMatch() throws Exception { final String[] expected= { "fooBar", "foo_bar" }; - assertCompletionResults(fCursorOffset, expected, COMPARE_ID_STRINGS); + assertCompletionResults(fCursorOffset, expected, ID); } // __bVA/*cursor*/ public void testBuiltinMacroSegmentMatch() throws Exception { + setCommaAfterFunctionParameter(CCorePlugin.INSERT); final String[] expected= { "__builtin_va_arg(ap, type)" }; - assertCompletionResults(fCursorOffset, expected, COMPARE_ID_STRINGS); + assertCompletionResults(fCursorOffset, expected, ID); } // namespace N { @@ -1295,13 +1300,13 @@ public class CompletionTests extends AbstractContentAssistTest { // using N::f/*cursor*/ public void testUsingDeclaration_379631() throws Exception { final String[] expected= { "foo;" }; - assertCompletionResults(fCursorOffset, expected, COMPARE_REP_STRINGS); + assertCompletionResults(fCursorOffset, expected, REPLACEMENT); } // template " }; - assertContentAssistResults(fCursorOffset, expected, true, COMPARE_ID_STRINGS); + assertContentAssistResults(fCursorOffset, expected, true, DISPLAY); + } + + // void foo() { Specialization" }; + assertContentAssistResults(fCursorOffset, expected, true, DISPLAY); + } + + // namespace N { + // void foo(int); + // } + // using N::fo/*cursor*/; + public void testUsingCompletionWithFollowingSemicolon() throws Exception { + final String[] expected = { "foo" }; + assertContentAssistResults(fCursorOffset, expected, true, REPLACEMENT); + final String[] expectedInformation = { "null" }; + assertContentAssistResults(fCursorOffset, expectedInformation, true, CONTEXT); + } + + // namespace N { + // template struct Tpl {}; + // } + // using N::Tp/*cursor*/; + public void testUsingCompletionWithoutTemplateArguments() throws Exception { + final String[] expected = { "Tpl" }; + assertContentAssistResults(fCursorOffset, expected, true, REPLACEMENT); + } + + // namespace N { + // template struct Tpl {}; + // } + // using N::Tp/*cursor*/ + public void testUsingCompletionWithoutTemplateArgumentsButSemicolon() throws Exception { + final String[] expected = { "Tpl;" }; + assertContentAssistResults(fCursorOffset, expected, true, REPLACEMENT); } // using Alias = C/*cursor*/ public void testAliasDeclarationCompletion() throws Exception { final String[] expectedID = { "C1", "C2", "C3" }; - assertContentAssistResults(fCursorOffset, expectedID, true, COMPARE_ID_STRINGS); + assertContentAssistResults(fCursorOffset, expectedID, true, ID); } } diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/CompletionTests_PlainC.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/CompletionTests_PlainC.java index d6583096a79..46f3547672b 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/CompletionTests_PlainC.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/CompletionTests_PlainC.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2011 Wind River Systems, Inc. and others. + * Copyright (c) 2007, 2014 Wind River Systems, Inc. and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -186,7 +186,7 @@ public class CompletionTests_PlainC extends AbstractContentAssistTest { } protected void assertCompletionResults(String[] expected) throws Exception { - assertContentAssistResults(fCursorOffset, expected, true, AbstractContentAssistTest.COMPARE_ID_STRINGS); + assertContentAssistResults(fCursorOffset, expected, true, CompareType.ID); } //void test() { diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/ParameterHintTests.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/ParameterHintTests.java index 3971ed282f9..231dac00fd2 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/ParameterHintTests.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/ParameterHintTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2010 QNX Software Systems and others. + * Copyright (c) 2007, 2014 QNX Software Systems and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -17,6 +17,7 @@ import junit.framework.Test; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; +import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.testplugin.util.BaseTestCase; public class ParameterHintTests extends AbstractContentAssistTest { @@ -61,8 +62,7 @@ public class ParameterHintTests extends AbstractContentAssistTest { } protected void assertParameterHints(String[] expected) throws Exception { - assertContentAssistResults(getBuffer().length() - 1, expected, false, - AbstractContentAssistTest.COMPARE_ID_STRINGS); + assertContentAssistResults(getBuffer().length() - 1, expected, false, CompareType.CONTEXT); } //void foo(){aFunc( @@ -75,21 +75,21 @@ public class ParameterHintTests extends AbstractContentAssistTest { //void foo(){tFunc( public void testTemplateFunction() throws Exception { assertParameterHints(new String[] { - "tFunc(T x,T y) : void" + "tFunc(T x, T y) : void" }); } //void foo(){tFunc( public void testTemplateFunction2() throws Exception { assertParameterHints(new String[] { - "tFunc(T x,T y) : void" + "tFunc(T x, T y) : void" }); } //void foo(){int a=5;aFunc ( anotherFunc ( a , (in public void testOffsetCalculation() throws Exception { assertParameterHints(new String[] { - "anotherFunc(int i,int j) : int" + "anotherFunc(int i, int j) : int" }); } @@ -109,7 +109,7 @@ public class ParameterHintTests extends AbstractContentAssistTest { public void testMethodDefinition() throws Exception { assertParameterHints(new String[] { "aMethod(char c) : void", - "aMethod(char c,int x) : void" + "aMethod(char c, int x) : void" }); } @@ -117,7 +117,7 @@ public class ParameterHintTests extends AbstractContentAssistTest { public void testMethodScope() throws Exception { assertParameterHints(new String[] { "aMethod(char c) : void", - "aMethod(char c,int x) : void" + "aMethod(char c, int x) : void" }); } @@ -133,7 +133,7 @@ public class ParameterHintTests extends AbstractContentAssistTest { // http://bugs.eclipse.org/223660 assertParameterHints(new String[] { "bClass(int x)", - "bClass(int x,int y)", + "bClass(int x, int y)", "bClass(const bClass &)" }); } @@ -145,7 +145,7 @@ public class ParameterHintTests extends AbstractContentAssistTest { // http://bugs.eclipse.org/327064 assertParameterHints(new String[] { "bClass(int x)", - "bClass(int x,int y)", + "bClass(int x, int y)", "bClass(const bClass &)" }); } @@ -184,7 +184,14 @@ public class ParameterHintTests extends AbstractContentAssistTest { // int i= (int) oc->getChar( public void testMethodWithCast() throws Exception { assertParameterHints(new String[] { - "getChar(int a,int b) : char" + "getChar(int a, int b) : char" }); } + + // void foo(int i, int j) { + // foo( + public void testFormatterConfiguredWithSpaceAfterComma() throws Exception { + setCommaAfterFunctionParameter(CCorePlugin.INSERT); + assertParameterHints(new String[] { "foo(int i, int j) : void" }); + } } diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/ShowCamelCasePreferenceTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/ShowCamelCasePreferenceTest.java index f61e98b8e2e..299be909268 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/ShowCamelCasePreferenceTest.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/ShowCamelCasePreferenceTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011 Jens Elmenthaler and others + * Copyright (c) 2011, 2014 Jens Elmenthaler and others * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -66,12 +66,12 @@ public class ShowCamelCasePreferenceTest extends AbstractContentAssistTest { super.tearDown(); } - protected void assertCompletionResults(int offset, String[] expected, int compareType) throws Exception { + protected void assertCompletionResults(int offset, String[] expected, CompareType compareType) throws Exception { assertContentAssistResults(offset, expected, true, compareType); } protected void assertCompletionResults(String[] expected) throws Exception { - assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_REP_STRINGS); + assertCompletionResults(fCursorOffset, expected, CompareType.REPLACEMENT); } private void setShowCamelCaseMatches(boolean enabled) { diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/TemplateProposalTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/TemplateProposalTest.java index d9c080794b4..f636b32ff23 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/TemplateProposalTest.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/TemplateProposalTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2012 Marc-Andre Laperle and others. All rights reserved. This + * Copyright (c) 2012, 2014 Marc-Andre Laperle and others. All rights reserved. This * program and the accompanying materials are made available under the terms of * the Eclipse Public License v1.0 which accompanies this distribution, and is * available at http://www.eclipse.org/legal/epl-v10.html @@ -114,7 +114,7 @@ public class TemplateProposalTest extends AbstractContentAssistTest { final String[] expected= { TEMPLATE_NAME_LINE_SELECTION_DISP }; - assertContentAssistResults(fSelectionOffset, fSelectionLength, expected, true, true, AbstractContentAssistTest.COMPARE_ID_STRINGS); + assertContentAssistResults(fSelectionOffset, fSelectionLength, expected, true, true, CompareType.ID); } //void func() { @@ -127,7 +127,7 @@ public class TemplateProposalTest extends AbstractContentAssistTest { final String[] expected= { TEMPLATE_NAME_LINE_SELECTION_DISP }; - assertContentAssistResults(fSelectionOffset, fSelectionLength, expected, true, true, AbstractContentAssistTest.COMPARE_ID_STRINGS); + assertContentAssistResults(fSelectionOffset, fSelectionLength, expected, true, true, CompareType.ID); } //void func() { @@ -139,7 +139,7 @@ public class TemplateProposalTest extends AbstractContentAssistTest { final String[] expected= { TEMPLATE_NAME_WORD_SELECTION_DISP }; - assertContentAssistResults(fSelectionOffset, fSelectionLength, expected, true, true, AbstractContentAssistTest.COMPARE_ID_STRINGS); + assertContentAssistResults(fSelectionOffset, fSelectionLength, expected, true, true, CompareType.ID); } //void func() { @@ -151,7 +151,7 @@ public class TemplateProposalTest extends AbstractContentAssistTest { final String[] expected= { TEMPLATE_NAME_WORD_SELECTION_DISP }; - assertContentAssistResults(fSelectionOffset, fSelectionLength, expected, true, true, AbstractContentAssistTest.COMPARE_ID_STRINGS); + assertContentAssistResults(fSelectionOffset, fSelectionLength, expected, true, true, CompareType.ID); } //void func() { @@ -164,7 +164,7 @@ public class TemplateProposalTest extends AbstractContentAssistTest { final String[] expected= { TEMPLATE_NAME_WORD_SELECTION_DISP }; - assertContentAssistResults(fSelectionOffset, fSelectionLength, expected, true, true, AbstractContentAssistTest.COMPARE_ID_STRINGS); + assertContentAssistResults(fSelectionOffset, fSelectionLength, expected, true, true, CompareType.ID); } //void func() { @@ -175,7 +175,7 @@ public class TemplateProposalTest extends AbstractContentAssistTest { final String[] expected= { TEMPLATE_NAME_LINE_SELECTION_DISP }; - assertContentAssistResults(fSelectionOffset, fSelectionLength, expected, true, true, AbstractContentAssistTest.COMPARE_ID_STRINGS); + assertContentAssistResults(fSelectionOffset, fSelectionLength, expected, true, true, CompareType.ID); } //void func() { @@ -188,7 +188,7 @@ public class TemplateProposalTest extends AbstractContentAssistTest { final String[] expected= { TEMPLATE_NAME_LINE_SELECTION_DISP }; - assertContentAssistResults(fSelectionOffset, fSelectionLength, expected, true, true, AbstractContentAssistTest.COMPARE_ID_STRINGS); + assertContentAssistResults(fSelectionOffset, fSelectionLength, expected, true, true, CompareType.ID); } //void func() { @@ -201,7 +201,7 @@ public class TemplateProposalTest extends AbstractContentAssistTest { TEMPLATE_NAME_LINE_SELECTION_DISP, TEMPLATE_NAME_WORD_SELECTION_DISP }; - assertContentAssistResults(fSelectionOffset, fSelectionLength, expected, true, true, AbstractContentAssistTest.COMPARE_ID_STRINGS); + assertContentAssistResults(fSelectionOffset, fSelectionLength, expected, true, true, CompareType.ID); } //void func() { @@ -214,7 +214,7 @@ public class TemplateProposalTest extends AbstractContentAssistTest { TEMPLATE_NAME_LINE_SELECTION_DISP, TEMPLATE_NAME_WORD_SELECTION_DISP }; - assertContentAssistResults(fSelectionOffset, fSelectionLength, expected, true, true, AbstractContentAssistTest.COMPARE_ID_STRINGS); + assertContentAssistResults(fSelectionOffset, fSelectionLength, expected, true, true, CompareType.ID); } } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/CContentAssistInvocationContext.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/CContentAssistInvocationContext.java index 0399e672b7b..71c09a3b9b0 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/CContentAssistInvocationContext.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/CContentAssistInvocationContext.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2012 IBM Corporation and others. + * Copyright (c) 2005, 2014 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -9,16 +9,21 @@ * IBM Corporation - initial API and implementation * Anton Leherbauer (Wind River Systems) * Bryan Wilkinson (QNX) + * Thomas Corbat (IFS) *******************************************************************************/ package org.eclipse.cdt.internal.ui.text.contentassist; +import java.util.Map; + import org.eclipse.core.runtime.Assert; import org.eclipse.core.runtime.CoreException; +import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.ITextViewer; import org.eclipse.ui.IEditorPart; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.dom.ast.IASTCompletionNode; +import org.eclipse.cdt.core.formatter.DefaultCodeFormatterConstants; import org.eclipse.cdt.core.index.IIndex; import org.eclipse.cdt.core.index.IIndexManager; import org.eclipse.cdt.core.model.ICProject; @@ -42,20 +47,152 @@ import org.eclipse.cdt.internal.ui.text.Symbols; * @since 4.0 */ public class CContentAssistInvocationContext extends ContentAssistInvocationContext implements ICEditorContentAssistInvocationContext { - private final IEditorPart fEditor; private final boolean fIsCompletion; private final boolean fIsAutoActivated; - - private ITranslationUnit fTU= null; - private boolean fTUComputed= false; - private int fParseOffset= -1; - private boolean fParseOffsetComputed= false; - private IASTCompletionNode fCN= null; - private boolean fCNComputed= false; private IIndex fIndex = null; - private int fContextInfoPosition; - + private Lazy fContextInfoPosition = new Lazy() { + @Override + protected Integer calculateValue() { + return guessContextInformationPosition(); + } + }; + + private final Lazy fTU; + + private final Lazy fParseOffset = new Lazy() { + @Override + protected Integer calculateValue() { + if (fIsCompletion) { + return guessCompletionPosition(getInvocationOffset()); + } + int contextInfoPosition = fContextInfoPosition.value(); + if (contextInfoPosition > 0) { + return guessCompletionPosition(contextInfoPosition); + } + return -1; + } + }; + + private final Lazy fCN = new Lazy() { + @Override + protected IASTCompletionNode calculateValue() { + int offset = getParseOffset(); + if (offset < 0) return null; + + ICProject proj= getProject(); + if (proj == null) return null; + + try { + IIndexManager manager= CCorePlugin.getIndexManager(); + fIndex = manager.getIndex(proj, IIndexManager.ADD_DEPENDENCIES | IIndexManager.ADD_EXTENSION_FRAGMENTS_CONTENT_ASSIST); + + try { + fIndex.acquireReadLock(); + } catch (InterruptedException e) { + fIndex = null; + } + + boolean parseNonIndexed= CUIPlugin.getDefault().getPreferenceStore().getBoolean(PreferenceConstants.PREF_USE_STRUCTURAL_PARSE_MODE); + int flags = parseNonIndexed ? ITranslationUnit.AST_SKIP_INDEXED_HEADERS : ITranslationUnit.AST_SKIP_ALL_HEADERS; + flags |= ITranslationUnit.AST_CONFIGURE_USING_SOURCE_CONTEXT; + + return fTU.value().getCompletionNode(fIndex, flags, offset); + } catch (CoreException e) { + CUIPlugin.log(e); + } + return null; + } + }; + + private final Lazy afterOpeningAngleBracket = new Lazy() { + @Override + protected Boolean calculateValue() { + final int parseOffset = getParseOffset(); + final int invocationOffset = getInvocationOffset(); + final CHeuristicScanner scanner = new CHeuristicScanner(getDocument()); + final int parenthesisOffset = scanner.findOpeningPeer(invocationOffset, parseOffset, '<', '>'); + return parenthesisOffset != CHeuristicScanner.NOT_FOUND; + } + }; + + private final Lazy afterOpeningParenthesis = new Lazy() { + @Override + protected Boolean calculateValue() { + final int invocationOffset = getInvocationOffset(); + final int parseOffset = getParseOffset(); + final int bound = Math.max(-1, parseOffset - 1); + final CHeuristicScanner scanner = new CHeuristicScanner(getDocument()); + final int parenthesisOffset = scanner.findOpeningPeer(invocationOffset, bound, '(', ')'); + return parenthesisOffset != CHeuristicScanner.NOT_FOUND; + } + }; + + private final Lazy inUsingDeclaration = new Lazy() { + /** + * Checks whether the invocation offset is inside a using-declaration. + * + * @return {@code true} if the invocation offset is inside a using-declaration + */ + @Override + protected Boolean calculateValue() { + IDocument doc = getDocument(); + int offset = Math.max(0, getInvocationOffset() - 1); + + // Look at the tokens preceding the invocation offset. + CHeuristicScanner.TokenStream tokenStream = new CHeuristicScanner.TokenStream(doc, offset); + int token = tokenStream.previousToken(); + + // There may be a partially typed identifier which is being completed. + if (token == Symbols.TokenIDENT) + token = tokenStream.previousToken(); + + // Before that, there may be any number of "namespace::" token pairs. + while (token == Symbols.TokenDOUBLECOLON) { + token = tokenStream.previousToken(); + if (token == Symbols.TokenUSING) { // there could also be a leading "::" for global namespace + return true; + } else if (token != Symbols.TokenIDENT) { + return false; + } else { + token = tokenStream.previousToken(); + } + } + + // Before that, there must be a "using" token. + return token == Symbols.TokenUSING; + } + }; + + private final Lazy followedBySemicolon = new Lazy() { + @Override + protected Boolean calculateValue() { + final IDocument doc = getDocument(); + final int offset = getInvocationOffset(); + final CHeuristicScanner.TokenStream tokenStream = new CHeuristicScanner.TokenStream(doc, offset); + final int token = tokenStream.nextToken(); + return token == Symbols.TokenSEMICOLON; + } + }; + + private final Lazy functionParameterDelimiter = new Lazy() { + @Override + protected String calculateValue() { + String propertyKey = DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_COMMA_IN_METHOD_DECLARATION_PARAMETERS; + Map options = getProject().getOptions(true); + return options.get(propertyKey).equals(CCorePlugin.INSERT) ? ", " : ","; //$NON-NLS-1$ //$NON-NLS-2$ + } + }; + + private final Lazy templateParameterDelimiter = new Lazy() { + @Override + protected String calculateValue() { + String propertyKey = DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_COMMA_IN_TEMPLATE_PARAMETERS; + Map options = getProject().getOptions(true); + return options.get(propertyKey).equals(CCorePlugin.INSERT) ? ", " : ","; //$NON-NLS-1$ //$NON-NLS-2$ + } + }; + /** * Creates a new context. * @@ -70,6 +207,12 @@ public class CContentAssistInvocationContext extends ContentAssistInvocationCont fEditor= editor; fIsCompletion= isCompletion; fIsAutoActivated= isAutoActivated; + fTU = new Lazy() { + @Override + protected ITranslationUnit calculateValue() { + return CUIPlugin.getDefault().getWorkingCopyManager().getWorkingCopy(fEditor.getEditorInput()); + } + }; } /** @@ -77,10 +220,14 @@ public class CContentAssistInvocationContext extends ContentAssistInvocationCont * * @param unit the translation unit in document */ - public CContentAssistInvocationContext(ITranslationUnit unit, boolean isCompletion) { + public CContentAssistInvocationContext(final ITranslationUnit unit, boolean isCompletion) { super(); - fTU= unit; - fTUComputed= true; + fTU= new Lazy() { + @Override + protected ITranslationUnit calculateValue() { + return unit; + } + }; fEditor= null; fIsCompletion= isCompletion; fIsAutoActivated= false; @@ -94,11 +241,7 @@ public class CContentAssistInvocationContext extends ContentAssistInvocationCont */ @Override public ITranslationUnit getTranslationUnit() { - if (!fTUComputed) { - fTUComputed= true; - fTU= CUIPlugin.getDefault().getWorkingCopyManager().getWorkingCopy(fEditor.getEditorInput()); - } - return fTU; + return fTU.value(); } /** @@ -115,7 +258,6 @@ public class CContentAssistInvocationContext extends ContentAssistInvocationCont @Override public IASTCompletionNode getCompletionNode() { - //for scalability if (fEditor != null && fEditor instanceof CEditor) { CEditor editor = (CEditor)fEditor; @@ -134,54 +276,12 @@ public class CContentAssistInvocationContext extends ContentAssistInvocationCont } } } - - if (fCNComputed) return fCN; - - fCNComputed = true; - - int offset = getParseOffset(); - if (offset < 0) return null; - - ICProject proj= getProject(); - if (proj == null) return null; - - try { - IIndexManager manager= CCorePlugin.getIndexManager(); - fIndex = manager.getIndex(proj, IIndexManager.ADD_DEPENDENCIES | IIndexManager.ADD_EXTENSION_FRAGMENTS_CONTENT_ASSIST); - - try { - fIndex.acquireReadLock(); - } catch (InterruptedException e) { - fIndex = null; - } - - boolean parseNonIndexed= CUIPlugin.getDefault().getPreferenceStore().getBoolean(PreferenceConstants.PREF_USE_STRUCTURAL_PARSE_MODE); - int flags = parseNonIndexed ? ITranslationUnit.AST_SKIP_INDEXED_HEADERS : ITranslationUnit.AST_SKIP_ALL_HEADERS; - flags |= ITranslationUnit.AST_CONFIGURE_USING_SOURCE_CONTEXT; - - fCN = fTU.getCompletionNode(fIndex, flags, offset); - } catch (CoreException e) { - CUIPlugin.log(e); - } - - return fCN; + return fCN.value(); } @Override public int getParseOffset() { - if (!fParseOffsetComputed) { - fParseOffsetComputed= true; - fContextInfoPosition= guessContextInformationPosition(); - if (fIsCompletion) { - fParseOffset = guessCompletionPosition(getInvocationOffset()); - } else if (fContextInfoPosition > 0) { - fParseOffset = guessCompletionPosition(fContextInfoPosition); - } else { - fParseOffset = -1; - } - } - - return fParseOffset; + return fParseOffset.value(); } /** @@ -189,13 +289,12 @@ public class CContentAssistInvocationContext extends ContentAssistInvocationCont */ @Override public int getContextInformationOffset() { - getParseOffset(); - return fContextInfoPosition; + return fContextInfoPosition.value(); } /** * Try to find a sensible completion position backwards in case the given offset - * is inside a function call argument list. + * is inside a function call argument list or in template arguments. * * @param contextPosition the starting position * @return a sensible completion offset @@ -210,13 +309,15 @@ public class CContentAssistInvocationContext extends ContentAssistInvocationCont int token= scanner.previousToken(pos, bound); if (token == Symbols.TokenCOMMA) { - pos= scanner.findOpeningPeer(pos, bound, '(', ')'); + int openingParenthesisPos = scanner.findOpeningPeer(pos, bound, '(', ')'); + int openingAngleBracketPos = scanner.findOpeningPeer(pos, bound, '<', '>'); + pos = Math.max(openingParenthesisPos, openingAngleBracketPos); if (pos == CHeuristicScanner.NOT_FOUND) return contextPosition; token = scanner.previousToken(pos, bound); } - if (token == Symbols.TokenLPAREN) { + if (token == Symbols.TokenLPAREN || token == Symbols.TokenLESSTHAN) { pos= scanner.findNonWhitespaceBackward(pos - 1, bound); if (pos == CHeuristicScanner.NOT_FOUND) return contextPosition; @@ -256,15 +357,17 @@ public class CContentAssistInvocationContext extends ContentAssistInvocationCont int pos= contextPosition - 1; do { int paren= scanner.findOpeningPeer(pos, bound, '(', ')'); - if (paren == CHeuristicScanner.NOT_FOUND) + int angle= scanner.findOpeningPeer(pos, bound, '<', '>'); + int nearestPeer = Math.max(paren, angle); + if (nearestPeer == CHeuristicScanner.NOT_FOUND) break; - int token= scanner.previousToken(paren - 1, bound); + int token= scanner.previousToken(nearestPeer - 1, bound); // next token must be a method name (identifier) or the closing angle of a // constructor call of a template type. if (token == Symbols.TokenIDENT || token == Symbols.TokenGREATERTHAN) { - return paren + 1; + return nearestPeer + 1; } - pos= paren - 1; + pos= nearestPeer - 1; } while (true); return -1; @@ -296,4 +399,28 @@ public class CContentAssistInvocationContext extends ContentAssistInvocationCont } super.dispose(); } + + public boolean isAfterOpeningParenthesis() { + return afterOpeningParenthesis.value(); + } + + public boolean isAfterOpeningAngleBracket() { + return afterOpeningAngleBracket.value(); + } + + public boolean isInUsingDirective() { + return inUsingDeclaration.value(); + } + + public boolean isFollowedBySemicolon() { + return followedBySemicolon.value(); + } + + public String getFunctionParameterDelimiter() { + return functionParameterDelimiter.value(); + } + + public String getTemplateParameterDelimiter() { + return templateParameterDelimiter.value(); + } } 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 b2d361defe7..d336de28ecd 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 @@ -91,8 +91,6 @@ import org.eclipse.cdt.internal.core.dom.parser.cpp.ClassTypeHelper; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.AccessContext; import org.eclipse.cdt.internal.core.parser.util.ContentAssistMatcherFactory; -import org.eclipse.cdt.internal.ui.text.CHeuristicScanner; -import org.eclipse.cdt.internal.ui.text.Symbols; import org.eclipse.cdt.internal.ui.viewsupport.CElementImageProvider; /** @@ -165,40 +163,6 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer return proposals; } - /** - * Checks whether the invocation offset is inside a using-declaration. - * - * @param context the invocation context - * @return {@code true} if the invocation offset is inside a using-declaration - */ - private boolean inUsingDeclaration(CContentAssistInvocationContext context) { - IDocument doc = context.getDocument(); - int offset = context.getInvocationOffset(); - - // Look at the tokens preceding the invocation offset. - CHeuristicScanner.TokenStream tokenStream = new CHeuristicScanner.TokenStream(doc, offset); - int token = tokenStream.previousToken(); - - // There may be a partially typed identifier which is being completed. - if (token == Symbols.TokenIDENT) - token = tokenStream.previousToken(); - - // Before that, there may be any number of "namespace::" token pairs. - while (token == Symbols.TokenDOUBLECOLON) { - token = tokenStream.previousToken(); - if (token == Symbols.TokenUSING) { // there could also be a leading "::" for global namespace - return true; - } else if (token != Symbols.TokenIDENT) { - return false; - } else { - token = tokenStream.previousToken(); - } - } - - // Before that, there must be a "using" token. - return token == Symbols.TokenUSING; - } - /** * Test whether the invocation offset is inside or before the preprocessor directive keyword. * @@ -299,9 +263,11 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer IASTFunctionStyleMacroParameter[] params = functionMacro.getParameters(); if (params != null) { + final String parameterDelimiter = context.getFunctionParameterDelimiter(); for (int i = 0; i < params.length; ++i) { - if (i > 0) - args.append(", "); //$NON-NLS-1$ + if (i > 0) { + args.append(parameterDelimiter); + } args.append(params[i].getParameter()); } } @@ -391,32 +357,40 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer int baseRelevance, List proposals) { int relevance = getClassTypeRelevance(templateType); StringBuilder representation = new StringBuilder(templateType.getName()); - representation.append("<{0}>"); //$NON-NLS-1$ - + boolean inUsingDeclaration = context.isInUsingDirective(); + String templateParameterRepresentation = ""; //$NON-NLS-1$ + if (!inUsingDeclaration) { + representation.append("<{0}>"); //$NON-NLS-1$ + templateParameterRepresentation = buildTemplateParameters(templateType, context); + } else if (!context.isFollowedBySemicolon()) { + representation.append(';'); + } String representationString = MessageFormat.format(representation.toString(), ""); //$NON-NLS-1$ - - String templateParameterRepresentation = buildTemplateParameters(templateType); String displayString = MessageFormat.format(representation.toString(), templateParameterRepresentation); - CCompletionProposal proposal = createProposal(representationString, displayString, getImage(templateType), baseRelevance + relevance, context); - CProposalContextInformation info = - new CProposalContextInformation(getImage(templateType), displayString, templateParameterRepresentation); - info.setContextInformationPosition(context.getContextInformationOffset()); - proposal.setContextInformation(info); - proposal.setCursorPosition(representationString.length() - 1); + if (!inUsingDeclaration) { + CProposalContextInformation info = + new CProposalContextInformation(getImage(templateType), displayString, templateParameterRepresentation); + info.setContextInformationPosition(context.getContextInformationOffset()); + proposal.setContextInformation(info); + if (!context.isContextInformationStyle()) { + proposal.setCursorPosition(representationString.length() - 1); + } + } proposals.add(proposal); } - private String buildTemplateParameters(ICPPClassTemplate templateType) { + private String buildTemplateParameters(ICPPClassTemplate templateType, CContentAssistInvocationContext context) { ICPPTemplateParameter[] parameters = templateType.getTemplateParameters(); StringBuilder representation = new StringBuilder(); + final String parameterDelimiter = context.getTemplateParameterDelimiter(); for (int i = 0; i < parameters.length; i++) { ICPPTemplateParameter parameter = parameters[i]; if (i > 0) { - representation.append(", "); //$NON-NLS-1$ + representation.append(parameterDelimiter); } if (parameter instanceof ICPPTemplateNonTypeParameter) { IType parameterType = ((ICPPTemplateNonTypeParameter) parameter).getType(); @@ -425,7 +399,7 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer } else if (parameter instanceof ICPPTemplateTypeParameter) { representation.append(TYPENAME); } else if (parameter instanceof ICPPTemplateTemplateParameter) { - String templateParameterParameters = buildTemplateParameters((ICPPTemplateTemplateParameter) parameter); + String templateParameterParameters = buildTemplateParameters((ICPPTemplateTemplateParameter) parameter, context); representation.append(MessageFormat.format(TEMPLATE_PARAMETER_PATTERN, templateParameterParameters)); representation.append(templateParameterParameters); } @@ -440,7 +414,7 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer private void handleClass(ICPPClassType classType, IASTCompletionContext astContext, CContentAssistInvocationContext context, int baseRelevance, List proposals) { - if (context.isContextInformationStyle()) { + if (context.isContextInformationStyle() && context.isAfterOpeningParenthesis()) { addProposalsForConstructors(classType, context, baseRelevance, proposals); } else if (classType instanceof ICPPClassTemplate) { addProposalForClassTemplate((ICPPClassTemplate) classType, context, baseRelevance, proposals); @@ -497,16 +471,18 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer String returnTypeStr = null; IParameter[] params = function.getParameters(); if (params != null) { + final String parameterDelimiter = context.getFunctionParameterDelimiter(); for (int i = 0; i < params.length; ++i) { - IType paramType = params[i].getType(); + IParameter param = params[i]; + IType paramType = param.getType(); if (i > 0) { - dispargs.append(','); - idargs.append(','); + dispargs.append(parameterDelimiter); + idargs.append(parameterDelimiter); } dispargs.append(ASTTypeUtil.getType(paramType, false)); idargs.append(ASTTypeUtil.getType(paramType, false)); - String paramName = params[i].getName(); + String paramName = param.getName(); if (paramName != null && paramName.length() > 0) { dispargs.append(' '); dispargs.append(paramName); @@ -515,8 +491,8 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer if (function.takesVarArgs()) { if (params.length > 0) { - dispargs.append(','); - idargs.append(','); + dispargs.append(parameterDelimiter); + idargs.append(parameterDelimiter); } dispargs.append("..."); //$NON-NLS-1$ idargs.append("..."); //$NON-NLS-1$ @@ -554,10 +530,12 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer // In a using declaration, emitting parentheses after the function // name is useless, since the user will just have to delete them. // Instead, emitting a semicolon is useful. - boolean inUsingDeclaration = inUsingDeclaration(context); + boolean inUsingDeclaration = context.isInUsingDirective(); if (inUsingDeclaration) { repStringBuff.setLength(repStringBuff.length() - 1); // Remove opening parenthesis - repStringBuff.append(';'); + if (!context.isFollowedBySemicolon()) { + repStringBuff.append(';'); + } } else { repStringBuff.append(')'); } @@ -573,7 +551,7 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer proposal.setCursorPosition(cursorPosition); } - if (contextDispargString != null) { + if (contextDispargString != null && !inUsingDeclaration) { CProposalContextInformation info = new CProposalContextInformation(image, dispString, contextDispargString); info.setContextInformationPosition(context.getContextInformationOffset()); 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 new file mode 100644 index 00000000000..ff0e85f77ce --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/Lazy.java @@ -0,0 +1,45 @@ +/******************************************************************************* + * Copyright (c) 2014 Institute for Software, HSR Hochschule fuer Technik + * Rapperswil, University of applied sciences. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Thomas Corbat (IFS) - Initial API and implementation + *******************************************************************************/ +package org.eclipse.cdt.internal.ui.text.contentassist; + +/** + * This class represents a field or variable which shall be initialized lazily when accessed the + * first time. It's value is computed once by the calculateValue() method. The value is + * accessed by value(). + * + * This implementation is NOT thread-safe! + * + * @param The type of the lazy initialized variable. + */ +public abstract class Lazy { + private final static Object NOT_INITIALIZED = new Object(); + private Object value = NOT_INITIALIZED; + + /** + * @return The value of this object. + */ + @SuppressWarnings("unchecked") + public E value() { + if (value == NOT_INITIALIZED) { + value = calculateValue(); + } + return (E) value; + } + + /** + * Calculates the value of this object. This method is called only once, when the value is + * accessed the first time. + * + * @return the value assigned to this object. + */ + protected abstract E calculateValue(); +} \ No newline at end of file