1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-23 17:05:26 +02:00

Fix for 172862: [Content Assist] Make it possible to sort proposals by relevance

This commit is contained in:
Anton Leherbauer 2008-03-17 14:37:27 +00:00
parent d35bf75b1c
commit 9ee674e447
44 changed files with 359 additions and 211 deletions

View file

@ -237,7 +237,7 @@ public class ContentAssistTests extends BaseUITestCase {
results = getResults( cu, c2.indexOf( "::" ) + 2 ); //$NON-NLS-1$
assertEquals( 2, results.length );
assertEquals( "getAbility(void) enum _Ability", results[1].getDisplayString() ); //$NON-NLS-1$
assertEquals( "getAbility(void) : enum _Ability", results[1].getDisplayString() ); //$NON-NLS-1$
assertEquals( "Strategy(enum _Ability a)", results[0].getDisplayString() ); //$NON-NLS-1$
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2004, 2007 IBM Corporation and others.
* Copyright (c) 2004, 2008 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
@ -31,9 +31,9 @@ public class CompletionTest_FunctionReference_Prefix extends CompletionProposal
"xLocal : int",
"xAClassField : float",
"xVariable : int",
"xAClassMethod(int x) void",
"xFunction(void) bool",
"xOtherFunction(void) void",
"xAClassMethod(int x) : void",
"xFunction(void) : bool",
"xOtherFunction(void) : void",
"xNamespace",
"xOtherClass",
"xFirstEnum",

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2004, 2007 IBM Corporation and others.
* Copyright (c) 2004, 2008 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
@ -29,8 +29,8 @@ public class CompletionTest_MemberReference_Arrow_NoPrefix extends CompletionPr
private final String[] expectedResults = {
"aField : int",
"xAClassField : float",
"aMethod(void) int",
"xAClassMethod(int x) void",
"aMethod(void) : int",
"xAClassMethod(int x) : void",
"aClass" // aClass is valid
};

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2006, 2007 Symbian Software Systems and others.
* Copyright (c) 2006, 2008 Symbian 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
@ -22,8 +22,8 @@ public class CompletionTest_MemberReference_Arrow_NoPrefix2 extends CompletionP
private final String headerFileFullPath ="resources/contentassist/" + headerFileName;
private final String expectedPrefix = "";
private final String[] expectedResults = {
"A", "foo(void) void",
"operator ->(void) B *"
"A", "foo(void) : void",
"operator ->(void) : B*"
};
public CompletionTest_MemberReference_Arrow_NoPrefix2(String name) {

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2006, 2007 Symbian Software Systems and others.
* Copyright (c) 2006, 2008 Symbian 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
@ -22,7 +22,7 @@ public class CompletionTest_MemberReference_Arrow_NoPrefix3 extends CompletionP
private final String headerFileFullPath ="resources/contentassist/" + headerFileName;
private final String expectedPrefix = "";
private final String[] expectedResults = {
"B", "bar(void) void"
"B", "bar(void) : void"
};
public CompletionTest_MemberReference_Arrow_NoPrefix3(String name) {

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2004, 2007 IBM Corporation and others.
* Copyright (c) 2004, 2008 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
@ -27,7 +27,7 @@ public class CompletionTest_MemberReference_Arrow_Prefix extends CompletionProp
private final String expectedPrefix = "a";
private final String[] expectedResults = {
"aField : int",
"aMethod(void) int",
"aMethod(void) : int",
"aClass" // aClass is valid
};

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2004, 2007 IBM Corporation and others.
* Copyright (c) 2004, 2008 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
@ -28,7 +28,7 @@ public class CompletionTest_MemberReference_Arrow_Prefix2 extends CompletionPro
private final String[] expectedResults = {
"aClass", // aClass is valid
"aField : int",
"aMethod(void) int"
"aMethod(void) : int"
};
public CompletionTest_MemberReference_Arrow_Prefix2(String name) {

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2004, 2007 IBM Corporation and others.
* Copyright (c) 2004, 2008 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
@ -28,8 +28,8 @@ public class CompletionTest_MemberReference_Dot_NoPrefix extends CompletionProp
private final String[] expectedResults = {
"aField : int",
"xAClassField : float",
"aMethod(void) int",
"xAClassMethod(int x) void",
"aMethod(void) : int",
"xAClassMethod(int x) : void",
"aClass" // aClass is valid
};

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2004, 2007 IBM Corporation and others.
* Copyright (c) 2004, 2008 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
@ -27,7 +27,7 @@ public class CompletionTest_MemberReference_Dot_Prefix extends CompletionPropos
private final String expectedPrefix = "a";
private final String[] expectedResults = {
"aField : int",
"aMethod(void) int",
"aMethod(void) : int",
"aClass" // aClass is valid
};

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2004, 2006 IBM Corporation and others.
* Copyright (c) 2004, 2008 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
@ -27,7 +27,7 @@ public class CompletionTest_ScopedReference_NoPrefix extends CompletionProposal
private final String headerFileFullPath ="resources/contentassist/" + headerFileName;
private final String expectedPrefix = "";
private final String[] expectedResults = {
"aNamespaceFunction(void) void"
"aNamespaceFunction(void) : void"
};
public CompletionTest_ScopedReference_NoPrefix(String name) {

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2004, 2007 IBM Corporation and others.
* Copyright (c) 2004, 2008 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
@ -28,8 +28,8 @@ public class CompletionTest_ScopedReference_NonCodeScope extends CompletionProp
private final String expectedPrefix = "";
private final String[] expectedResults = {
"Foo(void)",
"bar(void) void",
"fum(void) void",
"bar(void) : void",
"fum(void) : void",
"x : int"
};

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2004, 2007 IBM Corporation and others.
* Copyright (c) 2004, 2008 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
@ -27,7 +27,7 @@ public class CompletionTest_ScopedReference_Prefix extends CompletionProposalsB
private final String headerFileFullPath ="resources/contentassist/" + headerFileName;
private final String expectedPrefix = "a";
private final String[] expectedResults = {
"aNamespaceFunction(void) void"
"aNamespaceFunction(void) : void"
};
public CompletionTest_ScopedReference_Prefix(String name) {

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2004, 2007 IBM Corporation and others.
* Copyright (c) 2004, 2008 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
@ -28,12 +28,12 @@ public class CompletionTest_SingleName_Method_Prefix extends CompletionProposa
private final String[] expectedResults = {
"anotherField : int",
"aVariable : int",
"anotherMethod(void) void",
"aFunction(void) bool",
"anotherFunction(void) void",
"anotherMethod(void) : void",
"aFunction(void) : bool",
"anotherFunction(void) : void",
"aClass",
"anotherClass",
"anotherClass(const anotherClass &)",
"anotherClass(const anotherClass&)",
"anotherClass(void)",
"aNamespace",
"anEnumeration",
@ -53,7 +53,7 @@ public class CompletionTest_SingleName_Method_Prefix extends CompletionProposa
suite.addTest(new CompletionTest_SingleName_Method_Prefix("testCompletionProposals"));
return suite;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.codeassist.tests.CompletionProposalsTest#getCompletionPosition()
*/

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2004, 2007 IBM Corporation and others.
* Copyright (c) 2004, 2008 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
@ -29,11 +29,11 @@ public class CompletionTest_SingleName_NoPrefix extends CompletionProposalsBase
"x : int",
"aVariable : int",
"xVariable : int",
"aFunction(void) bool",
"anotherFunction(void) void",
"foo(int x) void",
"xFunction(void) bool",
"xOtherFunction(void) void",
"aFunction(void) : bool",
"anotherFunction(void) : void",
"foo(int x) : void",
"xFunction(void) : bool",
"xOtherFunction(void) : void",
"aClass",
"anotherClass",
"xOtherClass",

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2004, 2007 IBM Corporation and others.
* Copyright (c) 2004, 2008 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
@ -26,8 +26,8 @@ public class CompletionTest_SingleName_Prefix2 extends CompletionProposalsBaseT
private final String expectedPrefix = "a";
private final String[] expectedResults = {
"aVariable : int",
"aFunction(void) bool",
"anotherFunction(void) void",
"aFunction(void) : bool",
"anotherFunction(void) : void",
"aClass",
"anotherClass",
"aNamespace",

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2004, 2007 IBM Corporation and others.
* Copyright (c) 2004, 2008 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
@ -28,8 +28,8 @@ public class CompletionTest_VariableType_NestedPrefix extends CompletionProposa
private final String expectedPrefix = "";
private final String[] expectedResults = {
"Foo(void)",
"bar(void) void",
"fum(void) void",
"bar(void) : void",
"fum(void) : void",
"DEF",
"x : int"
};

View file

@ -828,7 +828,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"
"func(my_struct s) : void"
};
assertCompletionResults(fCursorOffset, expected, AbstractContentAssistTest.COMPARE_DISP_STRINGS);
}
@ -939,7 +939,7 @@ public class CompletionTests extends AbstractContentAssistTest {
// #include "header191315.h"
// void xxx() { c_lin/*cursor*/
public void testExtenC_bug191315() throws Exception {
public void testExternC_bug191315() throws Exception {
StringBuffer[] content= getContentsForTest(3);
createFile(fProject, "header191315.h", content[0].toString());
createFile(fProject, "source191315.c", content[0].toString());

View file

@ -66,35 +66,35 @@ public class ParameterHintTests extends AbstractContentAssistTest {
//void foo(){aFunc(
public void testFunction() throws Exception {
assertParameterHints(new String[] {
"aFunc(int i) void"
"aFunc(int i) : void"
});
}
//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<int>(
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"
});
}
//void foo(){int a=pie(
public void testAccurateName() throws Exception {
assertParameterHints(new String[] {
"pie(aClass a) int"
"pie(aClass a) : int"
});
}
@ -106,16 +106,16 @@ public class ParameterHintTests extends AbstractContentAssistTest {
//void aClass::aMethod(
public void testMethodDefinition() throws Exception {
assertParameterHints(new String[] {
"aMethod(char c) void",
"aMethod(char c,int x) void"
"aMethod(char c) : void",
"aMethod(char c,int x) : void"
});
}
//void aClass::aMethod(char c){aMethod(c,aFi
public void testMethodScope() throws Exception {
assertParameterHints(new String[] {
"aMethod(char c) void",
"aMethod(char c,int x) void"
"aMethod(char c) : void",
"aMethod(char c,int x) : void"
});
}
@ -123,7 +123,7 @@ public class ParameterHintTests extends AbstractContentAssistTest {
public void testConstructor() throws Exception {
assertParameterHints(new String[] {
"aClass(void)",
"aClass(const aClass &)"
"aClass(const aClass&)"
});
}
@ -132,7 +132,7 @@ public class ParameterHintTests extends AbstractContentAssistTest {
assertParameterHints(new String[] {
"bClass(int x)",
"bClass(int x,int y)",
"bClass(const bClass &)"
"bClass(const bClass&)"
});
}
@ -140,7 +140,7 @@ public class ParameterHintTests extends AbstractContentAssistTest {
public void testTemplateConstructor() throws Exception {
assertParameterHints(new String[] {
"tClass(T t)",
"tClass(const tClass &)"
"tClass(const tClass&)"
});
}
@ -148,14 +148,14 @@ public class ParameterHintTests extends AbstractContentAssistTest {
public void _testTemplateConstructor2() throws Exception {
assertParameterHints(new String[] {
"tClass(T t)",
"tClass(const tClass &)"
"tClass(const tClass&)"
});
}
//int pi = 3;void foo(){pi(
public void testFunctionsOnly() throws Exception {
assertParameterHints(new String[] {
"pi(aClass a) int"
"pi(aClass a) : int"
});
}
@ -169,7 +169,7 @@ 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"
});
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 338 B

View file

@ -427,6 +427,7 @@ ParserProposalCategory=Parsing-based Proposals
DefaultProposalCategory= &Basic Proposals
TemplateProposalCategory= Te&mplate Proposals
TextProposalCategory= &Word Proposals
HelpProposalCategory= Help Proposals
SpecificContentAssist.name= C/C++ Content Assist
SpecificContentAssist.desc= A parameterizable command that invokes content assist with a single completion proposal category

View file

@ -2160,6 +2160,13 @@
<proposalCategory
icon="$nl$/icons/elcl16/templateprop_co.gif"/>
</extension>
<extension
point="org.eclipse.cdt.ui.completionProposalComputer"
id="helpProposalCategory"
name="%HelpProposalCategory">
<proposalCategory
icon="$nl$/icons/elcl16/helpprop_co.gif"/>
</extension>
<extension
point="org.eclipse.cdt.ui.completionProposalComputer"
id="textProposalCategory"
@ -2209,7 +2216,17 @@
<partition type="__c_singleline_comment"/>
</completionProposalComputer>
</extension>
<!-- hippie word completions -->
<!-- help provider proposals -->
<extension
point="org.eclipse.cdt.ui.completionProposalComputer"
id="HelpCompletionProposalComputer">
<completionProposalComputer
class="org.eclipse.cdt.internal.ui.text.contentassist.HelpCompletionProposalComputer"
categoryId="org.eclipse.cdt.ui.helpProposalCategory">
<partition type="__dftl_partition_content_type"/>
</completionProposalComputer>
</extension>
<!-- hippie word proposals -->
<extension
point="org.eclipse.cdt.ui.completionProposalComputer"
id="HippieCompletionProposalComputer">

View file

@ -1,10 +1,10 @@
<?xml version='1.0' encoding='UTF-8'?>
<!-- Schema file written by PDE -->
<schema targetNamespace="org.eclipse.cdt.ui">
<schema targetNamespace="org.eclipse.cdt.ui" xmlns="http://www.w3.org/2001/XMLSchema">
<annotation>
<appInfo>
<meta.schema plugin="org.eclipse.cdt.ui" id="CodeCompletionFilter" name="Code Completion Filter"/>
</appInfo>
<appinfo>
<meta.schema plugin="org.eclipse.cdt.ui" id="ProposalFilter" name="Completion Proposal Filter"/>
</appinfo>
<documentation>
When the user requests code completion for an identifier prefix then proposals are gathered from a variety of sources. It is quite common that several proposals for the same completion are gathered. After gathering it is therefore necessary to filter proposals and present them in an optimal ordering to the user.
@ -38,9 +38,9 @@ The decision about which filter will actually be used remains with the user who
<documentation>
</documentation>
<appInfo>
<appinfo>
<meta.attribute translatable="true"/>
</appInfo>
</appinfo>
</annotation>
</attribute>
</complexType>
@ -60,9 +60,9 @@ The decision about which filter will actually be used remains with the user who
<documentation>
The required name of the ProposalFilter. This name will appear in the preferences combo and should therefore be informative for the user.
</documentation>
<appInfo>
<appinfo>
<meta.attribute translatable="true"/>
</appInfo>
</appinfo>
</annotation>
</attribute>
<attribute name="class" type="string" use="required">
@ -70,54 +70,55 @@ The decision about which filter will actually be used remains with the user who
<documentation>
The required fully qualified name of the implementing class which must implement org.eclipse.cdt.ui.text.contentassist.IProposalFilter
</documentation>
<appInfo>
<appinfo>
<meta.attribute kind="java" basedOn="org.eclipse.cdt.ui.text.contentassist.IProposalFilter"/>
</appInfo>
</appinfo>
</annotation>
</attribute>
</complexType>
</element>
<annotation>
<appInfo>
<appinfo>
<meta.section type="since"/>
</appInfo>
</appinfo>
<documentation>
CDT 3.1
</documentation>
</annotation>
<annotation>
<appInfo>
<appinfo>
<meta.section type="examples"/>
</appInfo>
</appinfo>
<documentation>
See the default implementation in org.eclipse.cdt.internal.ui.text.contentassist.DefaultProposalFilter as an example.
</documentation>
</annotation>
<annotation>
<appInfo>
<meta.section type="apiInfo"/>
</appInfo>
<appinfo>
<meta.section type="apiinfo"/>
</appinfo>
<documentation>
ProposalFilters must implement interface org.eclipse.cdt.ui.text.contentassist.IProposalFilter
ProposalFilters must implement interface &lt;code&gt;org.eclipse.cdt.ui.text.contentassist.IProposalFilter&lt;code&gt;.
</documentation>
</annotation>
<annotation>
<appInfo>
<appinfo>
<meta.section type="implementation"/>
</appInfo>
</appinfo>
<documentation>
The default implementation in org.eclipse.cdt.internal.ui.text.contentassist.DefaultProposalFilter is the default filtering method which is used as long as the user preference is not changed.
</documentation>
</annotation>
<annotation>
<appInfo>
<appinfo>
<meta.section type="copyright"/>
</appInfo>
</appinfo>
<documentation>
Copyright (c) 2006 Norbert Ploett and others.

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2002, 2007 QNX Software Systems and others.
* Copyright (c) 2002, 2008 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
@ -51,7 +51,7 @@ public class CodeAssistPreferencePage extends AbstractPreferencePage {
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, ContentAssistPreference.AUTOACTIVATION_TRIGGERS_ARROW));
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.STRING, ContentAssistPreference.AUTOACTIVATION_TRIGGERS_DOUBLECOLON));
// overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, ContentAssistPreference.SHOW_DOCUMENTED_PROPOSALS));
// overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, ContentAssistPreference.ORDER_PROPOSALS));
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, ContentAssistPreference.ORDER_PROPOSALS));
// overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, ContentAssistPreference.ADD_INCLUDE));
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, ContentAssistPreference.CURRENT_FILE_SEARCH_SCOPE));
overlayKeys.add(new OverlayPreferenceStore.OverlayKey(OverlayPreferenceStore.BOOLEAN, ContentAssistPreference.PROJECT_SEARCH_SCOPE));
@ -111,12 +111,12 @@ public class CodeAssistPreferencePage extends AbstractPreferencePage {
// addTextField(insertionGroup, label, ContentAssistPreference.TIMEOUT_DELAY, 6, 0, true);
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
// sorting and filtering
// sorting and filtering
label = PreferencesMessages.CEditorPreferencePage_ContentAssistPage_sortingSection_title;
Group sortingGroup = addGroupBox(contentAssistComposite, label, 2);
// label= PreferencesMessages.CEditorPreferencePage_ContentAssistPage_showProposalsInAlphabeticalOrder;
// addCheckBox(sortingGroup, label, ContentAssistPreference.ORDER_PROPOSALS, 0);
label= PreferencesMessages.CEditorPreferencePage_ContentAssistPage_showProposalsInAlphabeticalOrder;
addCheckBox(sortingGroup, label, ContentAssistPreference.ORDER_PROPOSALS, 0);
label = PreferencesMessages.CEditorPreferencePage_ContentAssistPage_proposalFilterSelect ;
addComboBox(sortingGroup, label, ContentAssistPreference.PROPOSALS_FILTER, NO_TEXT_LIMIT, 0);
@ -163,7 +163,7 @@ public class CodeAssistPreferencePage extends AbstractPreferencePage {
store.setDefault(ContentAssistPreference.AUTOINSERT, true);
store.setDefault(ContentAssistPreference.PREFIX_COMPLETION, true);
// store.setDefault(ContentAssistPreference.ORDER_PROPOSALS, false);
store.setDefault(ContentAssistPreference.ORDER_PROPOSALS, false);
// store.setDefault(ContentAssistPreference.ADD_INCLUDE, true);
store.setDefault(ContentAssistPreference.PROPOSALS_FILTER, ProposalFilterPreferencesUtil.getProposalFilternamesAsString()); // $NON_NLS 1$

View file

@ -45,7 +45,7 @@ public final class PreferencesMessages extends NLS {
public static String CEditorPreferencePage_ContentAssistPage_insertionGroupTitle;
public static String CEditorPreferencePage_ContentAssistPage_insertSingleProposalAutomatically;
public static String CEditorPreferencePage_ContentAssistPage_insertCommonProposalAutomatically;
// public static String CEditorPreferencePage_ContentAssistPage_showProposalsInAlphabeticalOrder;
public static String CEditorPreferencePage_ContentAssistPage_showProposalsInAlphabeticalOrder;
// public static String CEditorPreferencePage_ContentAssistPage_timeoutDelay;
public static String CEditorPreferencePage_ContentAssistPage_autoActivationGroupTitle;
public static String CEditorPreferencePage_ContentAssistPage_autoActivationEnableDot;

View file

@ -24,7 +24,7 @@ CEditorPreferencePage_colors=Synta&x
CEditorPreferencePage_ContentAssistPage_insertionGroupTitle=Insertion
CEditorPreferencePage_ContentAssistPage_insertSingleProposalAutomatically=&Insert single proposals automatically
CEditorPreferencePage_ContentAssistPage_insertCommonProposalAutomatically=Insert common prefixes automatically
#CEditorPreferencePage_ContentAssistPage_showProposalsInAlphabeticalOrder=Present proposals in a&lphabetical order
CEditorPreferencePage_ContentAssistPage_showProposalsInAlphabeticalOrder=Present proposals in a&lphabetical order
#CEditorPreferencePage_ContentAssistPage_timeoutDelay=Content Assist parsing &timeout (ms)
CEditorPreferencePage_ContentAssistPage_autoActivationGroupTitle=Auto-Activation
CEditorPreferencePage_ContentAssistPage_autoActivationEnableDot=Enable "." as trigger

View file

@ -1,12 +1,12 @@
/*******************************************************************************
* Copyright (c) 2004, 2007 IBM Corporation and others.
* Copyright (c) 2004, 2008 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
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Rational Software - Initial API and implementation
* IBM Rational Software - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.internal.ui.text.contentassist;
@ -259,7 +259,7 @@ public class CCompletionProposal implements ICCompletionProposal, ICompletionPro
} catch (BadPositionCategoryException e) {
// should not happen
CUIPlugin.getDefault().log(e);
CUIPlugin.log(e);
}
}
@ -276,7 +276,7 @@ public class CCompletionProposal implements ICCompletionProposal, ICompletionPro
} catch (BadPositionCategoryException e) {
// should not happen
CUIPlugin.getDefault().log(e);
CUIPlugin.log(e);
}
return fPosition.getOffset();
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2007 QNX Software Systems and others.
* Copyright (c) 2000, 2008 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
@ -7,6 +7,7 @@
*
* Contributors:
* QNX Software Systems - Initial API and implementation
* Anton Leherbauer (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.ui.text.contentassist;
@ -15,7 +16,7 @@ import java.util.Comparator;
import org.eclipse.cdt.ui.text.ICCompletionProposal;
public class CCompletionProposalComparator implements Comparator {
public class CCompletionProposalComparator implements Comparator<ICCompletionProposal> {
private boolean fOrderAlphabetically;
@ -30,13 +31,10 @@ public class CCompletionProposalComparator implements Comparator {
fOrderAlphabetically= orderAlphabetically;
}
/* (non-Javadoc)
/*
* @see Comparator#compare(Object, Object)
*/
public int compare(Object o1, Object o2) {
ICCompletionProposal c1= (ICCompletionProposal) o1;
ICCompletionProposal c2= (ICCompletionProposal) o2;
public int compare(ICCompletionProposal c1, ICCompletionProposal c2) {
if (!fOrderAlphabetically) {
int relevanceDif= c2.getRelevance() - c1.getRelevance();
if (relevanceDif != 0) {

View file

@ -137,7 +137,7 @@ public class CContentAssistInvocationContext extends ContentAssistInvocationCont
fCN = fTU.getCompletionNode(fIndex, flags, offset);
} catch (CoreException e) {
CUIPlugin.getDefault().log(e);
CUIPlugin.log(e);
}
return fCN;

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2007 IBM Corporation and others.
* Copyright (c) 2000, 2008 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
@ -14,6 +14,7 @@
package org.eclipse.cdt.internal.ui.text.contentassist;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
@ -69,7 +70,7 @@ public class CContentAssistProcessor extends ContentAssistProcessor {
* @see org.eclipse.cdt.ui.text.ICCompletionProposal#getRelevance()
*/
public int getRelevance() {
return -1;
return RelevanceConstants.CASE_MATCH_RELEVANCE + RelevanceConstants.KEYWORD_TYPE_RELEVANCE;
}
/*
@ -149,25 +150,45 @@ public class CContentAssistProcessor extends ContentAssistProcessor {
IProposalFilter filter = getCompletionFilter();
ICCompletionProposal[] proposalsInput= new ICCompletionProposal[proposals.size()];
// wrap proposals which are no ICCompletionProposals
boolean wrapped= false;
int i=0;
for (Iterator iterator = proposals.iterator(); iterator.hasNext(); ) {
ICompletionProposal proposal= (ICompletionProposal) iterator.next();
if (proposal instanceof ICCompletionProposal) {
proposalsInput[i++]= (ICCompletionProposal)proposal;
} else {
wrapped= true;
proposalsInput[i++]= new CCompletionProposalWrapper(proposal);
}
}
// filter
ICCompletionProposal[] proposalsFiltered = filter.filterProposals(proposalsInput);
// unwrap again
ArrayList filteredList= new ArrayList(proposalsFiltered.length);
for (int j= 0; j < proposalsFiltered.length; j++) {
ICCompletionProposal proposal= proposalsFiltered[j];
if (proposal instanceof CCompletionProposalWrapper) {
filteredList.add(((CCompletionProposalWrapper)proposal).unwrap());
} else {
filteredList.add(proposal);
// sort
boolean sortByAlphabet= CUIPlugin.getDefault().getPreferenceStore().getBoolean(ContentAssistPreference.ORDER_PROPOSALS);
if (sortByAlphabet) {
// already sorted alphabetically by DefaultProposalFilter
// in case of custom proposal filter, keep ordering applied by filter
} else {
// sort by relevance
CCompletionProposalComparator propsComp= new CCompletionProposalComparator();
propsComp.setOrderAlphabetically(sortByAlphabet);
Arrays.sort(proposalsFiltered, propsComp);
}
List filteredList;
if (wrapped) {
// unwrap again
filteredList= new ArrayList(proposalsFiltered.length);
for (int j= 0; j < proposalsFiltered.length; j++) {
ICCompletionProposal proposal= proposalsFiltered[j];
if (proposal instanceof CCompletionProposalWrapper) {
filteredList.add(((CCompletionProposalWrapper)proposal).unwrap());
} else {
filteredList.add(proposal);
}
}
} else {
filteredList= Arrays.asList(proposalsFiltered);
}
return filteredList;
}
@ -185,10 +206,10 @@ public class CContentAssistProcessor extends ContentAssistProcessor {
}
} catch (InvalidRegistryObjectException e) {
// No action required since we will be using the fail-safe default filter
CUIPlugin.getDefault().log(e);
CUIPlugin.log(e);
} catch (CoreException e) {
// No action required since we will be using the fail-safe default filter
CUIPlugin.getDefault().log(e);
CUIPlugin.log(e);
}
if (null == filter) {

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2005, 2007 IBM Corporation and others.
* Copyright (c) 2005, 2008 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
@ -109,7 +109,7 @@ public final class CompletionProposalCategory {
Object[] args= { getId(), fElement.getContributor().getName(), attribute };
String message= Messages.format(ContentAssistMessages.CompletionProposalComputerDescriptor_illegal_attribute_message, args);
IStatus status= new Status(IStatus.WARNING, CUIPlugin.getPluginId(), IStatus.OK, message, null);
CUIPlugin.getDefault().log(status);
CUIPlugin.log(status);
throw new InvalidRegistryObjectException();
}
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2005, 2007 IBM Corporation and others.
* Copyright (c) 2005, 2008 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
@ -11,6 +11,7 @@
*******************************************************************************/
package org.eclipse.cdt.internal.ui.text.contentassist;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
@ -87,11 +88,7 @@ final class CompletionProposalComputerDescriptor {
static {
Set partitions= new HashSet();
partitions.add(IDocument.DEFAULT_CONTENT_TYPE);
partitions.add(ICPartitions.C_PREPROCESSOR);
partitions.add(ICPartitions.C_MULTI_LINE_COMMENT);
partitions.add(ICPartitions.C_SINGLE_LINE_COMMENT);
partitions.add(ICPartitions.C_STRING);
partitions.add(ICPartitions.C_CHARACTER);
partitions.addAll(Arrays.asList(ICPartitions.ALL_CPARTITIONS));
PARTITION_SET= Collections.unmodifiableSet(partitions);
}
@ -197,7 +194,7 @@ final class CompletionProposalComputerDescriptor {
Object[] args= { getId(), fElement.getContributor().getName(), attribute };
String message= Messages.format(ContentAssistMessages.CompletionProposalComputerDescriptor_illegal_attribute_message, args);
IStatus status= new Status(IStatus.WARNING, CUIPlugin.getPluginId(), IStatus.OK, message, null);
CUIPlugin.getDefault().log(status);
CUIPlugin.log(status);
throw new InvalidRegistryObjectException();
}
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2007 IBM Corporation and others.
* Copyright (c) 2000, 2008 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
@ -325,7 +325,7 @@ public final class CompletionProposalComputerRegistry {
* @param status a status object that will be logged
*/
void informUser(CompletionProposalComputerDescriptor descriptor, IStatus status) {
CUIPlugin.getDefault().log(status);
CUIPlugin.log(status);
String title= ContentAssistMessages.CompletionProposalComputerRegistry_error_dialog_title;
CompletionProposalCategory category= descriptor.getCategory();
IContributor culprit= descriptor.getContributor();
@ -390,7 +390,7 @@ public final class CompletionProposalComputerRegistry {
}
private void informUser(IStatus status) {
CUIPlugin.getDefault().log(status);
CUIPlugin.log(status);
String title= ContentAssistMessages.CompletionProposalComputerRegistry_error_dialog_title;
String message= status.getMessage();
MessageDialog.openError(CUIPlugin.getActiveWorkbenchShell(), title, message);

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2007 IBM Corporation and others.
* Copyright (c) 2000, 2008 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
@ -56,8 +56,8 @@ public class ContentAssistPreference {
// /** Preference key for visibility of proposals (unused) */
// public final static String SHOW_DOCUMENTED_PROPOSALS= "content_assist_show_visible_proposals"; //$NON-NLS-1$
// /** Preference key for alphabetic ordering of proposals (unused) */
// public final static String ORDER_PROPOSALS= "content_assist_order_proposals"; //$NON-NLS-1$
/** Preference key for alphabetic ordering of proposals */
public final static String ORDER_PROPOSALS= "content_assist_order_proposals"; //$NON-NLS-1$
// /** Preference key for case sensitivity of propsals */
// public final static String CASE_SENSITIVITY= "content_assist_case_sensitivity";
// /** Preference key for adding includes on code assist (unused) */

View file

@ -41,21 +41,26 @@ import org.eclipse.cdt.core.dom.ast.IField;
import org.eclipse.cdt.core.dom.ast.IFunction;
import org.eclipse.cdt.core.dom.ast.IFunctionType;
import org.eclipse.cdt.core.dom.ast.IParameter;
import org.eclipse.cdt.core.dom.ast.IScope;
import org.eclipse.cdt.core.dom.ast.IType;
import org.eclipse.cdt.core.dom.ast.ITypedef;
import org.eclipse.cdt.core.dom.ast.IVariable;
import org.eclipse.cdt.core.dom.ast.c.ICFunctionScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTQualifiedName;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDeclaration;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPASTUsingDirective;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBlockScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassTemplate;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPField;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionScope;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionTemplate;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMember;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPUsingDeclaration;
import org.eclipse.cdt.core.model.IMethod;
import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility;
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
import org.eclipse.cdt.ui.CUIPlugin;
@ -95,7 +100,7 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
try {
prefix= context.computeIdentifierPrefix().toString();
} catch (BadLocationException exc) {
CUIPlugin.getDefault().log(exc);
CUIPlugin.log(exc);
}
}
addMacroProposals(context, prefix, proposals);
@ -123,7 +128,7 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
if (bindings != null)
for (int j = 0; j < bindings.length; ++j)
handleBinding(bindings[j], context, astContext, proposals);
handleBinding(bindings[j], context, prefix, astContext, proposals);
}
if (handleMacros)
@ -186,26 +191,28 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
if (macros != null)
for (int i = 0; i < macros.length; ++i)
if (CharArrayUtils.equals(macros[i].getName().toCharArray(), 0, prefixChars.length, prefixChars, true))
handleMacro(macros[i], context, proposals);
handleMacro(macros[i], context, prefix, proposals);
macros = completionNode.getTranslationUnit().getBuiltinMacroDefinitions();
if (macros != null)
for (int i = 0; i < macros.length; ++i)
if (CharArrayUtils.equals(macros[i].getName().toCharArray(), 0, prefixChars.length, prefixChars, true))
handleMacro(macros[i], context, proposals);
handleMacro(macros[i], context, prefix, proposals);
}
private void handleMacro(IASTPreprocessorMacroDefinition macro, CContentAssistInvocationContext context, List<CCompletionProposal> proposals) {
String macroName = macro.getName().toString();
private void handleMacro(IASTPreprocessorMacroDefinition macro, CContentAssistInvocationContext context, String prefix, List<CCompletionProposal> proposals) {
final String macroName = macro.getName().toString();
final int baseRelevance= computeBaseRelevance(prefix, macroName);
Image image = getImage(CElementImageProvider.getMacroImageDescriptor());
if (macro instanceof IASTPreprocessorFunctionStyleMacroDefinition) {
IASTPreprocessorFunctionStyleMacroDefinition functionMacro = (IASTPreprocessorFunctionStyleMacroDefinition)macro;
StringBuffer repStringBuff = new StringBuffer();
StringBuilder repStringBuff = new StringBuilder();
repStringBuff.append(macroName);
repStringBuff.append('(');
StringBuffer args = new StringBuffer();
StringBuilder args = new StringBuilder();
IASTFunctionStyleMacroParameter[] params = functionMacro.getParameters();
if (params != null)
@ -216,7 +223,7 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
}
String argString = args.toString();
StringBuffer descStringBuff = new StringBuffer(repStringBuff.toString());
StringBuilder descStringBuff = new StringBuilder(repStringBuff.toString());
descStringBuff.append(argString);
descStringBuff.append(')');
@ -224,7 +231,7 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
String repString = repStringBuff.toString();
String descString = descStringBuff.toString();
CCompletionProposal proposal = createProposal(repString, descString, image, context);
CCompletionProposal proposal = createProposal(repString, descString, image, baseRelevance + RelevanceConstants.MACRO_TYPE_RELEVANCE, context);
if (!context.isContextInformationStyle()) {
proposal.setCursorPosition(repString.length() - 1);
}
@ -237,12 +244,15 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
proposals.add(proposal);
} else
proposals.add(createProposal(macroName, macroName, image, context));
proposals.add(createProposal(macroName, macroName, image, baseRelevance + RelevanceConstants.MACRO_TYPE_RELEVANCE, context));
}
protected void handleBinding(IBinding binding,
CContentAssistInvocationContext cContext,
IASTCompletionContext astContext, List<CCompletionProposal> proposals) {
String prefix,
IASTCompletionContext astContext,
List<CCompletionProposal> proposals) {
if ((binding instanceof CPPImplicitFunction
|| binding instanceof CPPImplicitFunctionTemplate || binding instanceof CPPImplicitTypedef)
&& !(binding instanceof CPPImplicitMethod)) {
@ -250,17 +260,25 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
}
if (!isAnonymousBinding(binding)) {
final String name = binding.getName();
final int baseRelevance= computeBaseRelevance(prefix, name);
if (binding instanceof ICPPClassType) {
handleClass((ICPPClassType) binding, astContext, cContext, proposals);
handleClass((ICPPClassType) binding, astContext, cContext, baseRelevance, proposals);
} else if (binding instanceof IFunction) {
handleFunction((IFunction)binding, cContext, proposals);
handleFunction((IFunction)binding, cContext, baseRelevance, proposals);
} else if (!cContext.isContextInformationStyle()) {
if (binding instanceof IVariable) {
handleVariable((IVariable) binding, cContext, proposals);
handleVariable((IVariable) binding, cContext, baseRelevance, proposals);
} else if (binding instanceof ITypedef) {
proposals.add(createProposal(name, name, getImage(binding), baseRelevance + RelevanceConstants.TYPEDEF_TYPE_RELEVANCE, cContext));
} else if (binding instanceof ICPPNamespace) {
handleNamespace((ICPPNamespace) binding, astContext, cContext, proposals);
handleNamespace((ICPPNamespace) binding, astContext, cContext, baseRelevance, proposals);
} else if (binding instanceof IEnumeration) {
proposals.add(createProposal(name, name, getImage(binding), baseRelevance + RelevanceConstants.ENUMERATION_TYPE_RELEVANCE, cContext));
} else if (binding instanceof IEnumerator) {
proposals.add(createProposal(name, name, getImage(binding), baseRelevance + RelevanceConstants.ENUMERATOR_TYPE_RELEVANCE, cContext));
} else {
proposals.add(createProposal(binding.getName(), binding.getName(), getImage(binding), cContext));
proposals.add(createProposal(name, name, getImage(binding), baseRelevance, cContext));
}
}
}
@ -271,35 +289,50 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
return name.length == 0 || name[0] == '{';
}
private void handleClass(ICPPClassType classType, IASTCompletionContext astContext, CContentAssistInvocationContext context, List<CCompletionProposal> proposals) {
private void handleClass(ICPPClassType classType, IASTCompletionContext astContext, CContentAssistInvocationContext context, int baseRelevance, List<CCompletionProposal> proposals) {
if (context.isContextInformationStyle()) {
try {
ICPPConstructor[] constructors = classType.getConstructors();
for (int i = 0; i < constructors.length; i++) {
handleFunction(constructors[i], context, proposals);
handleFunction(constructors[i], context, baseRelevance, proposals);
}
} catch (DOMException e) {
}
} else {
int relevance= 0;
try {
switch(classType.getKey()) {
case ICPPClassType.k_class:
relevance= RelevanceConstants.CLASS_TYPE_RELEVANCE;
break;
case ICPPClassType.k_struct:
relevance= RelevanceConstants.STRUCT_TYPE_RELEVANCE;
break;
case ICPPClassType.k_union:
relevance= RelevanceConstants.UNION_TYPE_RELEVANCE;
break;
}
} catch (DOMException exc) {
}
if (astContext instanceof IASTName && !(astContext instanceof ICPPASTQualifiedName)) {
IASTName name= (IASTName)astContext;
if (name.getParent() instanceof IASTDeclarator) {
proposals.add(createProposal(classType.getName()+"::", classType.getName(), getImage(classType), context)); //$NON-NLS-1$
proposals.add(createProposal(classType.getName()+"::", classType.getName(), getImage(classType), baseRelevance + relevance, context)); //$NON-NLS-1$
}
}
proposals.add(createProposal(classType.getName(), classType.getName(), getImage(classType), context));
proposals.add(createProposal(classType.getName(), classType.getName(), getImage(classType), baseRelevance + RelevanceConstants.CLASS_TYPE_RELEVANCE, context));
}
}
private void handleFunction(IFunction function, CContentAssistInvocationContext context, List<CCompletionProposal> proposals) {
private void handleFunction(IFunction function, CContentAssistInvocationContext context, int baseRelevance, List<CCompletionProposal> proposals) {
Image image = getImage(function);
StringBuffer repStringBuff = new StringBuffer();
StringBuilder repStringBuff = new StringBuilder();
repStringBuff.append(function.getName());
repStringBuff.append('(');
StringBuffer dispargs = new StringBuffer(); // for the displayString
StringBuffer idargs = new StringBuffer(); // for the idString
StringBuilder dispargs = new StringBuilder(); // for the displayString
StringBuilder idargs = new StringBuilder(); // for the idString
String returnTypeStr = null;
try {
IParameter[] params = function.getParameters();
@ -344,16 +377,16 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
String dispargString = dispargs.toString();
String idargString = idargs.toString();
StringBuffer dispStringBuff = new StringBuffer(repStringBuff.toString());
StringBuilder dispStringBuff = new StringBuilder(repStringBuff.toString());
dispStringBuff.append(dispargString);
dispStringBuff.append(')');
if (returnTypeStr != null && returnTypeStr.length() > 0) {
dispStringBuff.append(' ');
dispStringBuff.append(" : "); //$NON-NLS-1$
dispStringBuff.append(returnTypeStr);
}
String dispString = dispStringBuff.toString();
StringBuffer idStringBuff = new StringBuffer(repStringBuff.toString());
StringBuilder idStringBuff = new StringBuilder(repStringBuff.toString());
idStringBuff.append(idargString);
idStringBuff.append(')');
String idString = idStringBuff.toString();
@ -361,7 +394,8 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
repStringBuff.append(')');
String repString = repStringBuff.toString();
CCompletionProposal proposal = createProposal(repString, dispString, idString, image, context);
final int relevance = function instanceof IMethod ? RelevanceConstants.METHOD_TYPE_RELEVANCE : RelevanceConstants.FUNCTION_TYPE_RELEVANCE;
CCompletionProposal proposal = createProposal(repString, dispString, idString, image, baseRelevance + relevance, context);
if (!context.isContextInformationStyle()) {
proposal.setCursorPosition(repString.length() - 1);
}
@ -375,8 +409,8 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
proposals.add(proposal);
}
private void handleVariable(IVariable variable, CContentAssistInvocationContext context, List<CCompletionProposal> proposals) {
StringBuffer repStringBuff = new StringBuffer();
private void handleVariable(IVariable variable, CContentAssistInvocationContext context, int baseRelevance, List<CCompletionProposal> proposals) {
StringBuilder repStringBuff = new StringBuilder();
repStringBuff.append(variable.getName());
String returnTypeStr = "<unknown>"; //$NON-NLS-1$
@ -387,34 +421,70 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
} catch (DOMException e) {
}
StringBuffer dispStringBuff = new StringBuffer(repStringBuff.toString());
StringBuilder dispStringBuff = new StringBuilder(repStringBuff.toString());
if (returnTypeStr != null) {
dispStringBuff.append(" : "); //$NON-NLS-1$
dispStringBuff.append(returnTypeStr);
}
String dispString = dispStringBuff.toString();
StringBuffer idStringBuff = new StringBuffer(repStringBuff.toString());
StringBuilder idStringBuff = new StringBuilder(repStringBuff.toString());
String idString = idStringBuff.toString();
String repString = repStringBuff.toString();
Image image = getImage(variable);
CCompletionProposal proposal = createProposal(repString, dispString, idString, image, context);
final int relevance = isLocalVariable(variable)
? RelevanceConstants.LOCAL_VARIABLE_TYPE_RELEVANCE
: isField(variable)
? RelevanceConstants.FIELD_TYPE_RELEVANCE
: RelevanceConstants.VARIABLE_TYPE_RELEVANCE;
CCompletionProposal proposal = createProposal(repString, dispString, idString, image, baseRelevance + relevance, context);
proposals.add(proposal);
}
private static boolean isField(IVariable variable) {
return variable instanceof IField;
}
private static boolean isLocalVariable(IVariable variable) {
try {
return isLocalScope(variable.getScope());
} catch (DOMException exc) {
return false;
}
}
private static boolean isLocalScope(IScope scope) {
while (scope != null) {
if (scope instanceof ICPPFunctionScope ||
scope instanceof ICPPBlockScope ||
scope instanceof ICFunctionScope) {
return true;
}
try {
scope= scope.getParent();
} catch (DOMException e) {
scope= null;
}
}
return false;
}
private void handleNamespace(ICPPNamespace namespace,
IASTCompletionContext astContext,
CContentAssistInvocationContext cContext, List<CCompletionProposal> proposals) {
CContentAssistInvocationContext cContext,
int baseRelevance,
List<CCompletionProposal> proposals) {
if (astContext instanceof ICPPASTQualifiedName) {
IASTCompletionContext parent = ((ICPPASTQualifiedName) astContext)
.getCompletionContext();
handleNamespace(namespace, parent, cContext, proposals);
handleNamespace(namespace, parent, cContext, baseRelevance, proposals);
return;
}
StringBuffer repStringBuff = new StringBuffer();
StringBuilder repStringBuff = new StringBuilder();
repStringBuff.append(namespace.getName());
if (!(astContext instanceof ICPPASTUsingDeclaration)
@ -423,14 +493,14 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
}
String repString = repStringBuff.toString();
proposals.add(createProposal(repString, namespace.getName(), getImage(namespace), cContext));
proposals.add(createProposal(repString, namespace.getName(), getImage(namespace), baseRelevance + RelevanceConstants.NAMESPACE_TYPE_RELEVANCE, cContext));
}
private CCompletionProposal createProposal(String repString, String dispString, Image image, CContentAssistInvocationContext context) {
return createProposal(repString, dispString, null, image, context);
private CCompletionProposal createProposal(String repString, String dispString, Image image, int relevance, CContentAssistInvocationContext context) {
return createProposal(repString, dispString, null, image, relevance, context);
}
private CCompletionProposal createProposal(String repString, String dispString, String idString, Image image, CContentAssistInvocationContext context) {
private CCompletionProposal createProposal(String repString, String dispString, String idString, Image image, int relevance, CContentAssistInvocationContext context) {
int parseOffset = context.getParseOffset();
int invocationOffset = context.getInvocationOffset();
boolean doReplacement = !context.isContextInformationStyle();
@ -439,7 +509,7 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
int repOffset = doReplacement ? parseOffset - repLength : invocationOffset;
repString = doReplacement ? repString : ""; //$NON-NLS-1$
return new CCompletionProposal(repString, repOffset, repLength, image, dispString, idString, 1, context.getViewer());
return new CCompletionProposal(repString, repOffset, repLength, image, dispString, idString, relevance, context.getViewer());
}
private Image getImage(ImageDescriptor desc) {

View file

@ -1,12 +1,13 @@
/*******************************************************************************
* Copyright (c) 2007 QNX Software Systems and others.
* Copyright (c) 2007, 2008 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
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Bryan Wilkinson (QNX) - Initial API and implementation
* Bryan Wilkinson (QNX) - Initial API and implementation
* Anton Leherbauer (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.ui.text.contentassist;
@ -92,6 +93,7 @@ public class HelpCompletionProposalComputer extends ParsingBasedProposalComputer
.getPrototype();
String fargs = fproto.getArguments();
int relevance = computeBaseRelevance(prefix, summary.getName()) + RelevanceConstants.HELP_TYPE_RELEVANCE;
CCompletionProposal proposal;
proposal = new CCompletionProposal(
fname,
@ -99,7 +101,7 @@ public class HelpCompletionProposalComputer extends ParsingBasedProposalComputer
repLength,
image,
fproto.getPrototypeString(true),
2,
relevance,
cContext.getViewer());
if (fdesc != null) {
@ -123,4 +125,5 @@ public class HelpCompletionProposalComputer extends ParsingBasedProposalComputer
return proposals;
}
}

View file

@ -46,28 +46,31 @@ public class KeywordCompletionProposalComputer extends ParsingBasedProposalCompu
try {
prefix= context.computeIdentifierPrefix().toString();
} catch (BadLocationException exc) {
CUIPlugin.getDefault().log(exc);
CUIPlugin.log(exc);
}
}
final int prefixLength = prefix.length();
// No prefix, no completions
if (prefix.length() == 0 || context.isContextInformationStyle())
if (prefixLength == 0 || context.isContextInformationStyle())
return Collections.emptyList();
String[] keywords;
// keywords are matched case-sensitive
final int relevance = RelevanceConstants.CASE_MATCH_RELEVANCE + RelevanceConstants.KEYWORD_TYPE_RELEVANCE;
List<CCompletionProposal> proposals = new ArrayList<CCompletionProposal>();
if (inPreprocessorDirective(context)) {
// TODO split this into a separate proposal computer?
boolean needDirectiveKeyword= inPreprocessorKeyword(context);
keywords= preprocessorKeywords;
String[] keywords= preprocessorKeywords;
// add matching preprocessor keyword proposals
ImageDescriptor imagedesc = CElementImageProvider.getKeywordImageDescriptor();
Image image = imagedesc != null ? CUIPlugin.getImageDescriptorRegistry().get(imagedesc) : null;
for (int i = 0; i < keywords.length; ++i) {
String repString= keywords[i];
if (repString.startsWith(prefix)) {
int repLength = prefix.length();
if (repString.startsWith(prefix) && keywords[i].length() > prefixLength) {
int repLength = prefixLength;
int repOffset = context.getInvocationOffset() - repLength;
if (prefix.charAt(0) == '#') {
// strip leading '#' from replacement
@ -78,7 +81,7 @@ public class KeywordCompletionProposalComputer extends ParsingBasedProposalCompu
continue;
}
proposals.add(new CCompletionProposal(repString, repOffset,
repLength, image, keywords[i], 1, context.getViewer()));
repLength, image, keywords[i], relevance, context.getViewer()));
}
}
} else {
@ -87,7 +90,7 @@ public class KeywordCompletionProposalComputer extends ParsingBasedProposalCompu
ITranslationUnit tu = context.getTranslationUnit();
keywords = cppkeywords; // default to C++
String[] keywords = cppkeywords; // default to C++
if (tu != null && tu.isCLanguage())
keywords = ckeywords;
@ -95,11 +98,11 @@ public class KeywordCompletionProposalComputer extends ParsingBasedProposalCompu
ImageDescriptor imagedesc = CElementImageProvider.getKeywordImageDescriptor();
Image image = imagedesc != null ? CUIPlugin.getImageDescriptorRegistry().get(imagedesc) : null;
for (int i = 0; i < keywords.length; ++i) {
if (keywords[i].startsWith(prefix)) {
int repLength = prefix.length();
if (keywords[i].startsWith(prefix) && keywords[i].length() > prefixLength) {
int repLength = prefixLength;
int repOffset = context.getInvocationOffset() - repLength;
proposals.add(new CCompletionProposal(keywords[i], repOffset,
repLength, image, keywords[i], 1, context.getViewer()));
repLength, image, keywords[i], relevance, context.getViewer()));
}
}
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2007 QNX Software Systems and others.
* Copyright (c) 2007, 2008 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
@ -7,6 +7,7 @@
*
* Contributors:
* QNX - Initial API and implementation
* Anton Leherbauer (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.ui.text.contentassist;
@ -54,7 +55,7 @@ public abstract class ParsingBasedProposalComputer implements ICompletionProposa
}
} catch (Exception e) {
fErrorMessage = e.toString();
CUIPlugin.getDefault().log(e);
CUIPlugin.log(e);
}
return Collections.EMPTY_LIST;
@ -93,4 +94,24 @@ public abstract class ParsingBasedProposalComputer implements ICompletionProposa
public void sessionStarted() {
fErrorMessage = null;
}
/**
* Compute base relevance depending on quality of name / prefix match.
*
* @param prefix the completion pefix
* @param match the matching identifier
* @return a relevance value inidicating the quality of the name match
*/
protected int computeBaseRelevance(String prefix, String match) {
int baseRelevance= RelevanceConstants.DEFAULT_TYPE_RELEVANCE;
boolean caseMatch= prefix.length() > 0 && match.startsWith(prefix);
if (caseMatch) {
baseRelevance += RelevanceConstants.CASE_MATCH_RELEVANCE;
}
boolean exactNameMatch= match.equalsIgnoreCase(prefix);
if (exactNameMatch) {
baseRelevance += RelevanceConstants.EXACT_NAME_MATCH_RELEVANCE;
}
return baseRelevance;
}
}

View file

@ -1,19 +1,27 @@
/*******************************************************************************
* Copyright (c) 2002, 2006 IBM Corporation and others.
* Copyright (c) 2002, 2008 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
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Rational Software - Initial API and implementation
* IBM Rational Software - Initial API and implementation
* Anton Leherbauer (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.ui.text.contentassist;
public interface RelevanceConstants {
final int CASE_MATCH_RELEVANCE = 160;
/** Relevance increment for same case matches */
final int CASE_MATCH_RELEVANCE = 1000;
/** Relevance increment for exact name matches (disregarding case) */
final int EXACT_NAME_MATCH_RELEVANCE = 40;
/** Relevance constant for proposals contributed by help provider */
final int HELP_TYPE_RELEVANCE = 200;
// parsing-based relevance constants
final int LOCAL_VARIABLE_TYPE_RELEVANCE = 140;
final int FIELD_TYPE_RELEVANCE = 130;
final int VARIABLE_TYPE_RELEVANCE = 120;
@ -27,6 +35,12 @@ public interface RelevanceConstants {
final int ENUMERATOR_TYPE_RELEVANCE = 40;
final int ENUMERATION_TYPE_RELEVANCE = 30;
final int MACRO_TYPE_RELEVANCE = 20;
/** Relevance constant for (key-)word proposals */
final int KEYWORD_TYPE_RELEVANCE = 10;
/** Relevance constant for editor template proposals */
final int TEMPLATE_TYPE_RELEVANCE = 5;
final int DEFAULT_TYPE_RELEVANCE = 0;
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2006 IBM Corporation and others.
* Copyright (c) 2000, 2008 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
@ -167,7 +167,7 @@ public class CCorrectionAssistant extends QuickAssistAssistant {
fViewer.revealRange(newOffset, 0);
}
} catch (BadLocationException e) {
CUIPlugin.getDefault().log(e);
CUIPlugin.log(e);
}
fCurrentAnnotations= (Annotation[]) resultingAnnotations.toArray(new Annotation[resultingAnnotations.size()]);

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2007 IBM Corporation and others.
* Copyright (c) 2000, 2008 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
@ -8,6 +8,7 @@
* Contributors:
* IBM Corporation - initial API and implementation
* Sergey Prigogin (Google)
* Anton Leherbauer (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.ui.text.correction;
@ -66,7 +67,7 @@ public class CCorrectionProcessor implements IQuickAssistProcessor {
if (status.isOK()) {
res.add(desc);
} else {
CUIPlugin.getDefault().log(status);
CUIPlugin.log(status);
}
}
return (ContributedProcessorDescriptor[]) res.toArray(new ContributedProcessorDescriptor[res.size()]);
@ -195,19 +196,19 @@ public class CCorrectionProcessor implements IQuickAssistProcessor {
fErrorMessage= null;
ICompletionProposal[] res= null;
ICCompletionProposal[] res= null;
if (model != null && annotations != null) {
ArrayList proposals= new ArrayList(10);
IStatus status= collectProposals(context, model, annotations, true, !fAssistant.isUpdatedOffset(), proposals);
res= (ICompletionProposal[]) proposals.toArray(new ICompletionProposal[proposals.size()]);
res= (ICCompletionProposal[]) proposals.toArray(new ICCompletionProposal[proposals.size()]);
if (!status.isOK()) {
fErrorMessage= status.getMessage();
CUIPlugin.getDefault().log(status);
CUIPlugin.log(status);
}
}
if (res == null || res.length == 0) {
return new ICompletionProposal[]
return new ICCompletionProposal[]
{ new CCompletionProposal("", 0, 0, null, CorrectionMessages.NoCorrectionProposal_description, 0) }; //$NON-NLS-1$
}
if (res.length > 1) {

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2006 IBM Corporation and others.
* Copyright (c) 2000, 2008 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
@ -100,7 +100,7 @@ public final class ContributedProcessorDescriptor {
fLastResult= !(expression.evaluate(evalContext) != EvaluationResult.TRUE);
return fLastResult;
} catch (CoreException e) {
CUIPlugin.getDefault().log(e);
CUIPlugin.log(e);
}
}
fStatus= Boolean.FALSE;

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2006 IBM Corporation and others.
* Copyright (c) 2000, 2008 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
@ -62,7 +62,7 @@ public class MarkerResolutionProposal implements ICCompletionProposal {
return CorrectionMessages.bind(CorrectionMessages.MarkerResolutionProposal_additionaldesc,
problemDesc);
} catch (CoreException e) {
CUIPlugin.getDefault().log(e);
CUIPlugin.log(e);
}
return null;
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2007 IBM Corporation and others.
* Copyright (c) 2000, 2008 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
@ -48,6 +48,7 @@ import org.eclipse.cdt.internal.corext.template.c.TranslationUnitContextType;
import org.eclipse.cdt.internal.ui.CPluginImages;
import org.eclipse.cdt.internal.ui.text.c.hover.SourceViewerInformationControl;
import org.eclipse.cdt.internal.ui.text.contentassist.RelevanceConstants;
public class TemplateEngine {
@ -82,7 +83,7 @@ public class TemplateEngine {
* @param image
*/
public CTemplateProposal(Template template, TemplateContext context, IRegion region, Image image) {
super(template, context, region, image, 90);
super(template, context, region, image, RelevanceConstants.CASE_MATCH_RELEVANCE + RelevanceConstants.TEMPLATE_TYPE_RELEVANCE);
}
public String getIdString() {

View file

@ -1415,7 +1415,7 @@ public class PreferenceConstants {
// content assist
store.setDefault(PreferenceConstants.CODEASSIST_EXCLUDED_CATEGORIES, "org.eclipse.cdt.ui.textProposalCategory\0"); //$NON-NLS-1$
store.setDefault(PreferenceConstants.CODEASSIST_CATEGORY_ORDER, "org.eclipse.cdt.ui.parserProposalCategory:65539\0org.eclipse.cdt.ui.textProposalCategory:65541\0org.eclipse.cdt.ui.templateProposalCategory:2\0"); //$NON-NLS-1$
store.setDefault(PreferenceConstants.CODEASSIST_CATEGORY_ORDER, "org.eclipse.cdt.ui.parserProposalCategory:65539\0org.eclipse.cdt.ui.textProposalCategory:65541\0org.eclipse.cdt.ui.templateProposalCategory:2\0org.eclipse.cdt.ui.helpProposalCategory:5\0"); //$NON-NLS-1$
setDefaultAndFireEvent(
store,