From 11963d3ec565744758c2fa4ac4b8e947ee71733d Mon Sep 17 00:00:00 2001 From: Marc-Andre Laperle Date: Mon, 18 Jul 2011 02:49:09 -0400 Subject: [PATCH 01/10] Bug 352262 - Link to Name Style preference page from Generate Getters and Setters page --- .../GenerateGettersAndSettersInputPage.java | 44 ++++++++++++++++++- .../GetterSetterContext.java | 11 +++++ .../GetterSetterInsertEditProvider.java | 14 +++--- .../GetterSetterNameGenerator.java | 24 ++++++++++ .../gettersandsetters/Messages.java | 2 + .../gettersandsetters/Messages.properties | 2 + 6 files changed, 90 insertions(+), 7 deletions(-) diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/gettersandsetters/GenerateGettersAndSettersInputPage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/gettersandsetters/GenerateGettersAndSettersInputPage.java index 52766bd1a4a..5b272b2cf80 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/gettersandsetters/GenerateGettersAndSettersInputPage.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/gettersandsetters/GenerateGettersAndSettersInputPage.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2009 Institute for Software, HSR Hochschule fuer Technik + * Copyright (c) 2008, 2011 Institute for Software, HSR Hochschule fuer Technik * Rapperswil, University of applied sciences and others * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -14,6 +14,10 @@ package org.eclipse.cdt.internal.ui.refactoring.gettersandsetters; import java.util.Set; import java.util.SortedSet; +import org.eclipse.core.runtime.preferences.IEclipsePreferences; +import org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener; +import org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent; +import org.eclipse.core.runtime.preferences.InstanceScope; import org.eclipse.jface.viewers.CheckStateChangedEvent; import org.eclipse.jface.viewers.ICheckStateListener; import org.eclipse.ltk.ui.refactoring.UserInputWizardPage; @@ -25,12 +29,17 @@ import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Link; import org.eclipse.ui.dialogs.ContainerCheckedTreeViewer; +import org.eclipse.ui.dialogs.PreferencesUtil; +import org.eclipse.cdt.ui.CUIPlugin; + +import org.eclipse.cdt.internal.ui.preferences.NameStylePreferencePage; import org.eclipse.cdt.internal.ui.refactoring.gettersandsetters.GetterSetterContext.FieldWrapper; import org.eclipse.cdt.internal.ui.refactoring.gettersandsetters.GetterSetterInsertEditProvider.AccessorKind; -public class GenerateGettersAndSettersInputPage extends UserInputWizardPage { +public class GenerateGettersAndSettersInputPage extends UserInputWizardPage implements IPreferenceChangeListener { private GetterSetterContext context; private ContainerCheckedTreeViewer variableSelectionView; private GetterSetterLabelProvider labelProvider; @@ -38,6 +47,9 @@ public class GenerateGettersAndSettersInputPage extends UserInputWizardPage { public GenerateGettersAndSettersInputPage(GetterSetterContext context) { super(Messages.GettersAndSetters_Name); this.context = context; + IEclipsePreferences node = InstanceScope.INSTANCE.getNode(CUIPlugin.PLUGIN_ID); + // We are listening for changes in the Name Style preferences + node.addPreferenceChangeListener(this); } public void createControl(Composite parent) { @@ -59,6 +71,8 @@ public class GenerateGettersAndSettersInputPage extends UserInputWizardPage { final Button placeImplemetation = new Button(comp, SWT.CHECK); placeImplemetation.setText(Messages.GenerateGettersAndSettersInputPage_PlaceImplHeader); gd = new GridData(); + gd.horizontalSpan = 2; + gd.heightHint = 40; placeImplemetation.setLayoutData(gd); placeImplemetation.setSelection(context.isImplementationInHeader()); placeImplemetation.addSelectionListener(new SelectionAdapter() { @@ -68,6 +82,21 @@ public class GenerateGettersAndSettersInputPage extends UserInputWizardPage { } }); + Link link= new Link(comp, SWT.WRAP); + link.setText(Messages.GenerateGettersAndSettersInputPage_LinkDescription); + link.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + String id = NameStylePreferencePage.PREF_ID; + PreferencesUtil.createPreferenceDialogOn(getShell(), id, new String [] { id }, null).open(); + } + }); + link.setToolTipText(Messages.GenerateGettersAndSettersInputPage_LinkTooltip); + + gd = new GridData(SWT.FILL, SWT.CENTER, true, false); + gd.grabExcessHorizontalSpace = true; + link.setLayoutData(gd); + setControl(comp); } @@ -189,4 +218,15 @@ public class GenerateGettersAndSettersInputPage extends UserInputWizardPage { } }); } + + public void preferenceChange(PreferenceChangeEvent event) { + if (variableSelectionView.getTree().isDisposed()) { + return; + } + + if (GetterSetterNameGenerator.getGenerateGetterSettersPreferenceKeys().contains(event.getKey())) { + context.refresh(); + variableSelectionView.refresh(); + } + } } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/gettersandsetters/GetterSetterContext.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/gettersandsetters/GetterSetterContext.java index 8d70806bdf2..757619cb40c 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/gettersandsetters/GetterSetterContext.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/gettersandsetters/GetterSetterContext.java @@ -78,6 +78,17 @@ public class GetterSetterContext implements ITreeContentProvider { public Object[] getElements(Object inputElement) { return getWrappedFields().toArray(); } + + public void refresh() { + // We only recreate the function declarations instead of recreating GetterSetterInsertEditProviders. + // That way, selectedFunctions is still valid. Also, the objects inside the TreeViewer are still the same + // which is convenient because that way we don't need to save then restore the collapsed/expanded+checked/unchecked state of the TreeViewer. + for (FieldWrapper wrapper : wrappedFields) { + for (GetterSetterInsertEditProvider provider : wrapper.childNodes) { + provider.createFunctionDeclaration(); + } + } + } public void dispose() { } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/gettersandsetters/GetterSetterInsertEditProvider.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/gettersandsetters/GetterSetterInsertEditProvider.java index 7a17d6604b1..05eb4e954b1 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/gettersandsetters/GetterSetterInsertEditProvider.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/gettersandsetters/GetterSetterInsertEditProvider.java @@ -36,7 +36,15 @@ public class GetterSetterInsertEditProvider implements Comparable generateGetterSettersPreferenceKeys = new HashSet(); + static { + generateGetterSettersPreferenceKeys.add(PreferenceConstants.NAME_STYLE_GETTER_CAPITALIZATION); + generateGetterSettersPreferenceKeys.add(PreferenceConstants.NAME_STYLE_GETTER_WORD_DELIMITER); + generateGetterSettersPreferenceKeys.add(PreferenceConstants.NAME_STYLE_GETTER_PREFIX_FOR_BOOLEAN); + generateGetterSettersPreferenceKeys.add(PreferenceConstants.NAME_STYLE_GETTER_PREFIX); + generateGetterSettersPreferenceKeys.add(PreferenceConstants.NAME_STYLE_GETTER_SUFFIX); + generateGetterSettersPreferenceKeys.add(PreferenceConstants.NAME_STYLE_SETTER_CAPITALIZATION); + generateGetterSettersPreferenceKeys.add(PreferenceConstants.NAME_STYLE_SETTER_WORD_DELIMITER); + generateGetterSettersPreferenceKeys.add(PreferenceConstants.NAME_STYLE_SETTER_PREFIX); + generateGetterSettersPreferenceKeys.add(PreferenceConstants.NAME_STYLE_SETTER_SUFFIX); + generateGetterSettersPreferenceKeys.add(PreferenceConstants.NAME_STYLE_VARIABLE_CAPITALIZATION); + generateGetterSettersPreferenceKeys.add(PreferenceConstants.NAME_STYLE_VARIABLE_WORD_DELIMITER); + generateGetterSettersPreferenceKeys.add(PreferenceConstants.NAME_STYLE_VARIABLE_PREFIX); + generateGetterSettersPreferenceKeys.add(PreferenceConstants.NAME_STYLE_VARIABLE_SUFFIX); + } + public static Set getGenerateGetterSettersPreferenceKeys() { + return generateGetterSettersPreferenceKeys; + } + public static String generateGetterName(IASTName fieldName) { IPreferencesService preferences = Platform.getPreferencesService(); int capitalization = preferences.getInt(CUIPlugin.PLUGIN_ID, diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/gettersandsetters/Messages.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/gettersandsetters/Messages.java index d74929b29c5..80944883754 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/gettersandsetters/Messages.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/gettersandsetters/Messages.java @@ -20,6 +20,8 @@ public final class Messages extends NLS { public static String GenerateGettersAndSettersInputPage_SelectAll; public static String GenerateGettersAndSettersInputPage_SelectGetters; public static String GenerateGettersAndSettersInputPage_SelectSetters; + public static String GenerateGettersAndSettersInputPage_LinkDescription; + public static String GenerateGettersAndSettersInputPage_LinkTooltip; public static String GenerateGettersAndSettersRefactoring_NoCassDefFound; public static String GenerateGettersAndSettersRefactoring_NoFields; public static String GenerateGettersAndSettersRefactoring_NoImplFile; diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/gettersandsetters/Messages.properties b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/gettersandsetters/Messages.properties index bb018b58168..c9cf1f7cc39 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/gettersandsetters/Messages.properties +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/gettersandsetters/Messages.properties @@ -16,6 +16,8 @@ GenerateGettersAndSettersInputPage_PlaceImplHeader=Place implementation in heade GenerateGettersAndSettersInputPage_SelectAll=Select All GenerateGettersAndSettersInputPage_SelectGetters=Select Getters GenerateGettersAndSettersInputPage_SelectSetters=Select Setters +GenerateGettersAndSettersInputPage_LinkDescription=The names of getters and setters may be configured on the Name Style preference page. +GenerateGettersAndSettersInputPage_LinkTooltip=Show the name style preferences. GenerateGettersAndSettersRefactoring_NoCassDefFound=No class definition found GenerateGettersAndSettersRefactoring_NoFields=The class does not contain any fields. GenerateGettersAndSettersRefactoring_NoImplFile=No implementation file found. Inserting definition into the header file. From 0c0e19f36e881efcd52702d88262d46d9064fc85 Mon Sep 17 00:00:00 2001 From: Marc-Andre Laperle Date: Tue, 19 Jul 2011 12:26:52 -0400 Subject: [PATCH 02/10] Bug 352257 - Getter and Setter in Name Style preview can differ from generated code --- .../utils/AccessorNameGeneratorTest.java | 58 ------------------- .../utils/IdentifierHelperTest.java | 1 - .../refactoring/utils/NameComposerTest.java | 42 +++++++++++++- .../ui/preferences/NameStyleBlock.java | 14 ++++- .../GetterSetterNameGenerator.java | 50 +--------------- .../cdt/internal/ui/util/NameComposer.java | 42 ++++++++++++++ 6 files changed, 98 insertions(+), 109 deletions(-) delete mode 100644 core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/utils/AccessorNameGeneratorTest.java diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/utils/AccessorNameGeneratorTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/utils/AccessorNameGeneratorTest.java deleted file mode 100644 index df82a4d5dde..00000000000 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/utils/AccessorNameGeneratorTest.java +++ /dev/null @@ -1,58 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2010 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 - * - * Contributors: - * Marc-Andre Laperle - Initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.ui.tests.refactoring.utils; - -import junit.framework.TestCase; - -import org.eclipse.cdt.internal.ui.refactoring.gettersandsetters.GetterSetterNameGenerator; - -public class AccessorNameGeneratorTest extends TestCase { - - public void testTrimFieldName() { - assertEquals("f", GetterSetterNameGenerator.trimFieldName("f_")); - assertEquals("F", GetterSetterNameGenerator.trimFieldName("F_")); - assertEquals("oo", GetterSetterNameGenerator.trimFieldName("F_oo")); - assertEquals("o", GetterSetterNameGenerator.trimFieldName("f_o")); - - assertEquals("M", GetterSetterNameGenerator.trimFieldName("a_M_")); - assertEquals("bs", GetterSetterNameGenerator.trimFieldName("a_bs_")); - assertEquals("foo_bar", GetterSetterNameGenerator.trimFieldName("foo_bar")); - assertEquals("foo_bar", GetterSetterNameGenerator.trimFieldName("foo_bar_")); - - assertEquals("foo_b", GetterSetterNameGenerator.trimFieldName("foo_b_")); - - assertEquals("foo", GetterSetterNameGenerator.trimFieldName("foo")); - assertEquals("foo", GetterSetterNameGenerator.trimFieldName("_foo")); - assertEquals("bar", GetterSetterNameGenerator.trimFieldName("_f_bar")); - - assertEquals("f", GetterSetterNameGenerator.trimFieldName("f__")); - assertEquals("f", GetterSetterNameGenerator.trimFieldName("__f")); - assertEquals("O__b", GetterSetterNameGenerator.trimFieldName("fO__b")); - assertEquals("Oo", GetterSetterNameGenerator.trimFieldName("fOo")); - assertEquals("O", GetterSetterNameGenerator.trimFieldName("fO")); - assertEquals("MyStatic", GetterSetterNameGenerator.trimFieldName("sMyStatic")); - assertEquals("MyMember", GetterSetterNameGenerator.trimFieldName("mMyMember")); - - assertEquals("8", GetterSetterNameGenerator.trimFieldName("_8")); - - assertEquals("8bar", GetterSetterNameGenerator.trimFieldName("_8bar_")); - assertEquals("8bar_8", GetterSetterNameGenerator.trimFieldName("_8bar_8")); - assertEquals("8bAr", GetterSetterNameGenerator.trimFieldName("_8bAr")); - assertEquals("b8Ar", GetterSetterNameGenerator.trimFieldName("_b8Ar")); - - assertEquals("Id", GetterSetterNameGenerator.trimFieldName("Id")); - assertEquals("ID", GetterSetterNameGenerator.trimFieldName("ID")); - assertEquals("IDS", GetterSetterNameGenerator.trimFieldName("IDS")); - assertEquals("ID", GetterSetterNameGenerator.trimFieldName("bID")); - assertEquals("Id", GetterSetterNameGenerator.trimFieldName("MId")); - assertEquals("IdA", GetterSetterNameGenerator.trimFieldName("IdA")); - } -} diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/utils/IdentifierHelperTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/utils/IdentifierHelperTest.java index 181b0b7d544..a43cee1d5a2 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/utils/IdentifierHelperTest.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/utils/IdentifierHelperTest.java @@ -30,7 +30,6 @@ public class IdentifierHelperTest extends TestSuite { suite.addTest(new EmptyCaseTest()); suite.addTest(new IllegalCharCaseTest()); suite.addTest(new KeywordCaseTest()); - suite.addTestSuite(AccessorNameGeneratorTest.class); return suite; } } diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/utils/NameComposerTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/utils/NameComposerTest.java index 8fddfe0be19..907c6b036de 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/utils/NameComposerTest.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/refactoring/utils/NameComposerTest.java @@ -23,7 +23,7 @@ public class NameComposerTest extends TestCase { private static final int CAPITALIZATION_CAMEL_CASE = PreferenceConstants.NAME_STYLE_CAPITALIZATION_CAMEL_CASE; private static final int CAPITALIZATION_LOWER_CAMEL_CASE = PreferenceConstants.NAME_STYLE_CAPITALIZATION_LOWER_CAMEL_CASE; - public void testTrimFieldName() { + public void testCompose() { NameComposer composer = new NameComposer(CAPITALIZATION_ORIGINAL, "", "", ".h"); assertEquals("MyClass.h", composer.compose("MyClass")); composer = new NameComposer(CAPITALIZATION_LOWER_CASE, "-", "", ".cc"); @@ -44,4 +44,44 @@ public class NameComposerTest extends TestCase { composer = new NameComposer(CAPITALIZATION_ORIGINAL, "_", "", ""); assertEquals("RGB_Value", composer.compose("RGBValue")); } + + public void testTrimFieldName() { + assertEquals("f", NameComposer.trimFieldName("f_")); + assertEquals("F", NameComposer.trimFieldName("F_")); + assertEquals("oo", NameComposer.trimFieldName("F_oo")); + assertEquals("o", NameComposer.trimFieldName("f_o")); + + assertEquals("M", NameComposer.trimFieldName("a_M_")); + assertEquals("bs", NameComposer.trimFieldName("a_bs_")); + assertEquals("foo_bar", NameComposer.trimFieldName("foo_bar")); + assertEquals("foo_bar", NameComposer.trimFieldName("foo_bar_")); + + assertEquals("foo_b", NameComposer.trimFieldName("foo_b_")); + + assertEquals("foo", NameComposer.trimFieldName("foo")); + assertEquals("foo", NameComposer.trimFieldName("_foo")); + assertEquals("bar", NameComposer.trimFieldName("_f_bar")); + + assertEquals("f", NameComposer.trimFieldName("f__")); + assertEquals("f", NameComposer.trimFieldName("__f")); + assertEquals("O__b", NameComposer.trimFieldName("fO__b")); + assertEquals("Oo", NameComposer.trimFieldName("fOo")); + assertEquals("O", NameComposer.trimFieldName("fO")); + assertEquals("MyStatic", NameComposer.trimFieldName("sMyStatic")); + assertEquals("MyMember", NameComposer.trimFieldName("mMyMember")); + + assertEquals("8", NameComposer.trimFieldName("_8")); + + assertEquals("8bar", NameComposer.trimFieldName("_8bar_")); + assertEquals("8bar_8", NameComposer.trimFieldName("_8bar_8")); + assertEquals("8bAr", NameComposer.trimFieldName("_8bAr")); + assertEquals("b8Ar", NameComposer.trimFieldName("_b8Ar")); + + assertEquals("Id", NameComposer.trimFieldName("Id")); + assertEquals("ID", NameComposer.trimFieldName("ID")); + assertEquals("IDS", NameComposer.trimFieldName("IDS")); + assertEquals("ID", NameComposer.trimFieldName("bID")); + assertEquals("Id", NameComposer.trimFieldName("MId")); + assertEquals("IdA", NameComposer.trimFieldName("IdA")); + } } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/NameStyleBlock.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/NameStyleBlock.java index c97931e4fe3..f0f168ea7ec 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/NameStyleBlock.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/NameStyleBlock.java @@ -191,7 +191,8 @@ public class NameStyleBlock extends OptionsConfigurationBlock { .setAlternativePrefixKey(KEY_GETTER_PREFIX_FOR_BOOLEAN) .setSuffixKey(KEY_GETTER_SUFFIX) .setSeedNameGenerator(fieldCategory) - .setNameValidator(IDENTIFIER_VALIDATOR); + .setNameValidator(IDENTIFIER_VALIDATOR) + .setTrimFieldName(true); new Category(PreferencesMessages.NameStyleBlock_setter_node, PreferencesMessages.NameStyleBlock_setter_node_description, EXAMPLE_FIELD_NAME, codeCategory) @@ -200,7 +201,8 @@ public class NameStyleBlock extends OptionsConfigurationBlock { .setPrefixKey(KEY_SETTER_PREFIX) .setSuffixKey(KEY_SETTER_SUFFIX) .setSeedNameGenerator(fieldCategory) - .setNameValidator(IDENTIFIER_VALIDATOR); + .setNameValidator(IDENTIFIER_VALIDATOR) + .setTrimFieldName(true); Category fileCategory = new Category(PreferencesMessages.NameStyleBlock_files_node); new Category(PreferencesMessages.NameStyleBlock_cpp_header_node, PreferencesMessages.NameStyleBlock_cpp_header_node_description, EXAMPLE_CLASS_NAME, @@ -444,6 +446,7 @@ public class NameStyleBlock extends OptionsConfigurationBlock { private Text previewText; private Composite editorArea; + private boolean trimFieldName = false; Category(String name, String description, String seedName, Category parent) { this.name = name; @@ -568,8 +571,15 @@ public class NameStyleBlock extends OptionsConfigurationBlock { NameComposer composer = new NameComposer(capitalization, wordDelimiter, prefix, suffix); String name = seedNameGenerator != null ? seedNameGenerator.composeExampleName(settings) : seedName; + if (trimFieldName) { + name = NameComposer.trimFieldName(name); + } return composer.compose(name); } + + void setTrimFieldName(boolean trimSeedName) { + this.trimFieldName = trimSeedName; + } } private abstract static class NameValidator { diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/gettersandsetters/GetterSetterNameGenerator.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/gettersandsetters/GetterSetterNameGenerator.java index 3574b0bff47..229fe842b5f 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/gettersandsetters/GetterSetterNameGenerator.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/gettersandsetters/GetterSetterNameGenerator.java @@ -16,7 +16,6 @@ import java.util.Set; import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.preferences.IPreferencesService; -import com.ibm.icu.text.BreakIterator; import org.eclipse.cdt.core.dom.ast.IASTDeclarator; import org.eclipse.cdt.core.dom.ast.IASTName; @@ -27,7 +26,6 @@ import org.eclipse.cdt.ui.PreferenceConstants; import org.eclipse.cdt.internal.core.dom.parser.cpp.semantics.CPPVisitor; -import org.eclipse.cdt.internal.ui.text.CBreakIterator; import org.eclipse.cdt.internal.ui.util.NameComposer; public class GetterSetterNameGenerator { @@ -72,7 +70,7 @@ public class GetterSetterNameGenerator { String suffix = preferences.getString(CUIPlugin.PLUGIN_ID, PreferenceConstants.NAME_STYLE_GETTER_SUFFIX, "", null); //$NON-NLS-1$ NameComposer composer = new NameComposer(capitalization, wordDelimiter, prefix, suffix); - String name = GetterSetterNameGenerator.trimFieldName(fieldName.toString()); + String name = NameComposer.trimFieldName(fieldName.toString()); return composer.compose(name); } @@ -99,7 +97,7 @@ public class GetterSetterNameGenerator { String suffix = preferences.getString(CUIPlugin.PLUGIN_ID, PreferenceConstants.NAME_STYLE_SETTER_SUFFIX, "", null); //$NON-NLS-1$ NameComposer composer = new NameComposer(capitalization, wordDelimiter, prefix, suffix); - String name = GetterSetterNameGenerator.trimFieldName(fieldName.toString()); + String name = NameComposer.trimFieldName(fieldName.toString()); return composer.compose(name); } @@ -115,49 +113,7 @@ public class GetterSetterNameGenerator { String suffix = preferences.getString(CUIPlugin.PLUGIN_ID, PreferenceConstants.NAME_STYLE_VARIABLE_SUFFIX, "", null); //$NON-NLS-1$ NameComposer composer = new NameComposer(capitalization, wordDelimiter, prefix, suffix); - String name = GetterSetterNameGenerator.trimFieldName(fieldName.toString()); + String name = NameComposer.trimFieldName(fieldName.toString()); return composer.compose(name); } - - /** - * Returns the trimmed field name. Leading and trailing non-alphanumeric characters are trimmed. - * If the first word of the name consists of a single letter and the name contains more than - * one word, the first word is removed. - * - * @param fieldName a field name to trim - * @return the trimmed field name - */ - public static String trimFieldName(String fieldName){ - CBreakIterator iterator = new CBreakIterator(); - iterator.setText(fieldName); - int firstWordStart = -1; - int firstWordEnd = -1; - int secondWordStart = -1; - int lastWordEnd = -1; - int end; - for (int start = iterator.first(); (end = iterator.next()) != BreakIterator.DONE; start = end) { - if (Character.isLetterOrDigit(fieldName.charAt(start))) { - int pos = end; - while (--pos >= start && !Character.isLetterOrDigit(fieldName.charAt(pos))) { - } - lastWordEnd = pos + 1; - if (firstWordStart < 0) { - firstWordStart = start; - firstWordEnd = lastWordEnd; - } else if (secondWordStart < 0) { - secondWordStart = start; - } - } - } - // Skip the first word if it consists of a single letter and the name contains more than - // one word. - if (firstWordStart >= 0 && firstWordStart + 1 == firstWordEnd && secondWordStart >= 0) { - firstWordStart = secondWordStart; - } - if (firstWordStart < 0) { - return fieldName; - } else { - return fieldName.substring(firstWordStart, lastWordEnd); - } - } } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/util/NameComposer.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/util/NameComposer.java index 133d216cdbe..4492bcacbc0 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/util/NameComposer.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/util/NameComposer.java @@ -146,4 +146,46 @@ public class NameComposer { Character.toUpperCase(word.charAt(i)) : Character.toLowerCase(word.charAt(i))); } } + + /** + * Returns the trimmed field name. Leading and trailing non-alphanumeric characters are trimmed. + * If the first word of the name consists of a single letter and the name contains more than + * one word, the first word is removed. + * + * @param fieldName a field name to trim + * @return the trimmed field name + */ + public static String trimFieldName(String fieldName){ + CBreakIterator iterator = new CBreakIterator(); + iterator.setText(fieldName); + int firstWordStart = -1; + int firstWordEnd = -1; + int secondWordStart = -1; + int lastWordEnd = -1; + int end; + for (int start = iterator.first(); (end = iterator.next()) != BreakIterator.DONE; start = end) { + if (Character.isLetterOrDigit(fieldName.charAt(start))) { + int pos = end; + while (--pos >= start && !Character.isLetterOrDigit(fieldName.charAt(pos))) { + } + lastWordEnd = pos + 1; + if (firstWordStart < 0) { + firstWordStart = start; + firstWordEnd = lastWordEnd; + } else if (secondWordStart < 0) { + secondWordStart = start; + } + } + } + // Skip the first word if it consists of a single letter and the name contains more than + // one word. + if (firstWordStart >= 0 && firstWordStart + 1 == firstWordEnd && secondWordStart >= 0) { + firstWordStart = secondWordStart; + } + if (firstWordStart < 0) { + return fieldName; + } else { + return fieldName.substring(firstWordStart, lastWordEnd); + } + } } From 163a57b8b7ea789cbec84e578c9992243579767a Mon Sep 17 00:00:00 2001 From: Marc Khouzam Date: Tue, 19 Jul 2011 13:59:58 -0400 Subject: [PATCH 03/10] Bug 352493:Trace control buttons are disabled after a start trace failure --- .../cdt/dsf/gdb/service/GDBTraceControl_7_2.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBTraceControl_7_2.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBTraceControl_7_2.java index 13f51dd5684..b90b214ec84 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBTraceControl_7_2.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/service/GDBTraceControl_7_2.java @@ -20,6 +20,7 @@ import org.eclipse.cdt.dsf.datamodel.AbstractDMContext; import org.eclipse.cdt.dsf.datamodel.AbstractDMEvent; import org.eclipse.cdt.dsf.datamodel.DMContexts; import org.eclipse.cdt.dsf.datamodel.IDMContext; +import org.eclipse.cdt.dsf.datamodel.IDMEvent; import org.eclipse.cdt.dsf.debug.service.ICachingService; import org.eclipse.cdt.dsf.debug.service.IRunControl.IContainerDMContext; import org.eclipse.cdt.dsf.debug.service.IRunControl.IExecutionDMContext; @@ -503,6 +504,18 @@ public class GDBTraceControl_7_2 extends AbstractDsfService implements IGDBTrace getSession().dispatchEvent(new TracingStartedEvent(context), getProperties()); rm.done(); } + @Override + protected void handleError() { + // Send an event to cause a refresh of the button states + IDMEvent event; + if (fIsTracingActive) { + event = new TracingStartedEvent(context); + } else { + event = new TracingStoppedEvent(context); + } + getSession().dispatchEvent(event, getProperties()); + rm.done(); + } }); } }); From 9d9efe8e9d73583167fd33ac7b696403bbccfebc Mon Sep 17 00:00:00 2001 From: Jens Elmenthaler Date: Wed, 20 Jul 2011 10:41:59 +0200 Subject: [PATCH 04/10] Bug 352350 - Outline view corrupts expansion state of namespace nodes --- .../core/model/tests/CModelElementsTests.java | 17 ++++++++++++++++- .../resources/cfiles/CModelElementsTestStart.h | 5 +++++ .../cdt/internal/core/model/CElement.java | 12 +++++------- 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/model/tests/CModelElementsTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/model/tests/CModelElementsTests.java index d33d356ae7b..7cdf2374137 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/model/tests/CModelElementsTests.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/model/tests/CModelElementsTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2002, 2007 IBM Corporation and others. + * Copyright (c) 2002, 2011 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 @@ -69,6 +69,7 @@ public class CModelElementsTests extends TestCase { super(name); } + @Override protected void setUp() throws Exception { monitor = new NullProgressMonitor(); fCProject= CProjectHelper.createCCProject("TestProject1", "bin", IPDOMManager.ID_FAST_INDEXER); @@ -93,6 +94,7 @@ public class CModelElementsTests extends TestCase { } + @Override protected void tearDown() { CProjectHelper.delete(fCProject); } @@ -133,6 +135,7 @@ public class CModelElementsTests extends TestCase { checkArrays(tu); checkBug180815(tu); + checkBug352350(tu); } // https://bugs.eclipse.org/bugs/show_bug.cgi?id=180815 @@ -144,6 +147,18 @@ public class CModelElementsTests extends TestCase { assertEquals(2, struct.getChildren().length); } + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=352350 + private void checkBug352350(IParent parent) throws CModelException { + List namespaces = parent.getChildrenOfType(ICElement.C_NAMESPACE); + assertEquals(2, namespaces.size()); + for (Object o : namespaces) { + INamespace namespace = (INamespace)o; + if (namespace.getElementName().length() == 0) { + assertTrue(namespace.equals(namespace)); + } + } + } + private void checkInclude(IParent tu) throws CModelException{ List tuIncludes = tu.getChildrenOfType(ICElement.C_INCLUDE); IInclude inc1 = (IInclude) tuIncludes.get(0); diff --git a/core/org.eclipse.cdt.core.tests/resources/cfiles/CModelElementsTestStart.h b/core/org.eclipse.cdt.core.tests/resources/cfiles/CModelElementsTestStart.h index 45bfd1fb15e..df422c6e855 100644 --- a/core/org.eclipse.cdt.core.tests/resources/cfiles/CModelElementsTestStart.h +++ b/core/org.eclipse.cdt.core.tests/resources/cfiles/CModelElementsTestStart.h @@ -139,3 +139,8 @@ namespace MyPackage struct bug180815 { int i,j; } bug180815_var0, bug180815_var1; + +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=352350 +namespace { + int bug352350; +} \ No newline at end of file diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CElement.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CElement.java index 349b9cc4909..2624bc16bfc 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CElement.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CElement.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2009 QNX Software Systems and others. + * Copyright (c) 2000, 2011 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 @@ -40,11 +40,6 @@ import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.PlatformObject; -/** - * TLETODO Document CElement. - * - * @since 5.0 - */ public abstract class CElement extends PlatformObject implements ICElement { public static final char CEM_ESCAPE = '\\'; @@ -270,12 +265,15 @@ public abstract class CElement extends PlatformObject implements ICElement { } public static boolean equals(ICElement lhs, ICElement rhs) { + if (lhs == rhs) { + return true; + } if (lhs.getElementType() != rhs.getElementType()) { return false; } String lhsName= lhs.getElementName(); String rhsName= rhs.getElementName(); - if( lhsName == null || rhsName == null || lhsName.length() == 0 || + if( lhsName == null || rhsName == null || lhsName.length() != rhsName.length() || !lhsName.equals(rhsName)) { return false; } From 34fdfb11964bdd89930641b0bff118f089fdb126 Mon Sep 17 00:00:00 2001 From: Markus Schorn Date: Wed, 20 Jul 2011 12:05:13 +0200 Subject: [PATCH 05/10] Bug 351547: Resolution of delete expressions. --- .../tests/ast2/AST2CPPImplicitNameTests.java | 34 ++++- .../parser/cpp/semantics/CPPSemantics.java | 131 ++++++++++-------- 2 files changed, 107 insertions(+), 58 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPImplicitNameTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPImplicitNameTests.java index 70f6b939bcf..40ddef7549d 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPImplicitNameTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2CPPImplicitNameTests.java @@ -18,6 +18,7 @@ import org.eclipse.cdt.core.dom.ast.IASTImplicitName; import org.eclipse.cdt.core.dom.ast.IASTImplicitNameOwner; import org.eclipse.cdt.core.dom.ast.IASTNodeSelector; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; +import org.eclipse.cdt.core.dom.ast.IBinding; import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor; import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction; import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod; @@ -367,8 +368,8 @@ public class AST2CPPImplicitNameTests extends AST2BaseTest { // struct X { // ~X(); - // void operator delete(); - // void operator delete[](); + // void operator delete(void *); + // void operator delete[](void *); // }; // // int test(X* x) { @@ -393,11 +394,38 @@ public class AST2CPPImplicitNameTests extends AST2BaseTest { names = ba.getImplicitNames("delete[] x;", 6); assertEquals(1, names.length); - assertSame(col.getName(3).resolveBinding(), names[0].resolveBinding()); + assertSame(col.getName(4).resolveBinding(), names[0].resolveBinding()); ba.assertNoImplicitName("delete 1;", 6); } + // struct A { + // void operator delete(void * a); + // }; + // struct B {}; + // void operator delete(void * b); + // + // void test() { + // A *a = new A; + // delete a; + // + // B* b = new B; + // delete b; + // } + public void testOverloadedDelete_Bug351547() throws Exception { + BindingAssertionHelper bh= new BindingAssertionHelper(getAboveComment(), true); + IBinding m= bh.assertNonProblem("operator delete(void * a)", 15); + IBinding f= bh.assertNonProblem("operator delete(void * b)", 15); + + IASTImplicitName[] names = bh.getImplicitNames("delete a;", 6); + assertEquals(2, names.length); + assertSame(m, names[1].resolveBinding()); + + names = bh.getImplicitNames("delete b;", 6); + assertEquals(2, names.length); + assertSame(f, names[1].resolveBinding()); + } + // struct X {} // int test(X* x) { // X* xs = new X[5]; diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java index 822b794a9ce..dfa676eeb50 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPSemantics.java @@ -2962,14 +2962,14 @@ public class CPPSemantics { } } IASTInitializerClause[] argArray = args.toArray(new IASTInitializerClause[args.size()]); - return findOverloadedOperator(exp, argArray, type, op, LookupMode.ALL_GLOBALS); + return findOverloadedOperator(exp, argArray, type, op, LookupMode.GLOBALS_IF_NO_MEMBERS); } public static ICPPFunction findOverloadedOperator(ICPPASTDeleteExpression exp) { OverloadableOperator op = OverloadableOperator.fromDeleteExpression(exp); IType classType = getNestedClassType(exp); - IASTExpression[] args = new IASTExpression[] {createArgForType(exp, classType)}; - return findOverloadedOperator(exp, args, classType, op, LookupMode.ALL_GLOBALS); + IASTExpression[] args = new IASTExpression[] {createArgForType(exp, classType), exp.getOperand()}; + return findOverloadedOperator(exp, args, classType, op, LookupMode.GLOBALS_IF_NO_MEMBERS); } private static ICPPClassType getNestedClassType(ICPPASTDeleteExpression exp) { @@ -3228,7 +3228,7 @@ public class CPPSemantics { return findOverloadedOperator(fieldRef, new IASTExpression[] {arg}, classType, OverloadableOperator.ARROW, LookupMode.NO_GLOBALS); } - private static enum LookupMode {NO_GLOBALS, LIMITED_GLOBALS, ALL_GLOBALS} + private static enum LookupMode {NO_GLOBALS, GLOBALS_IF_NO_MEMBERS, LIMITED_GLOBALS, ALL_GLOBALS} private static ICPPFunction findOverloadedOperator(IASTExpression parent, IASTInitializerClause[] args, IType methodLookupType, OverloadableOperator operator, LookupMode mode) { ICPPClassType callToObjectOfClassType= null; @@ -3281,43 +3281,64 @@ public class CPPSemantics { funcName.setParent(parent); funcName.setPropertyInParent(STRING_LOOKUP_PROPERTY); LookupData funcData = new LookupData(funcName); + if (operator == OverloadableOperator.DELETE || operator == OverloadableOperator.DELETE_ARRAY) { + args= ArrayUtil.removeFirst(args); + } funcData.setFunctionArguments(true, args); funcData.ignoreMembers = true; // (13.3.1.2.3) - if (mode != LookupMode.NO_GLOBALS || callToObjectOfClassType != null) { + boolean haveMembers= methodData != null && methodData.hasResults(); + if (mode == LookupMode.ALL_GLOBALS || mode == LookupMode.LIMITED_GLOBALS + || (mode == LookupMode.GLOBALS_IF_NO_MEMBERS && !haveMembers)) { try { - if (mode != LookupMode.NO_GLOBALS) { - IScope scope = CPPVisitor.getContainingScope(parent); - if (scope == null) - return null; - lookup(funcData, scope); - try { - doKoenigLookup(funcData); - } catch (DOMException e) { - } - // Filter with file-set - IASTTranslationUnit tu= parent.getTranslationUnit(); - if (tu != null && funcData.foundItems instanceof Object[]) { - final IIndexFileSet fileSet = tu.getIndexFileSet(); - if (fileSet != null) { - int j=0; - final Object[] items= (Object[]) funcData.foundItems; - for (int i = 0; i < items.length; i++) { - Object item = items[i]; - items[i]= null; - if (item instanceof IIndexBinding) { - if (!fileSet.containsDeclaration((IIndexBinding) item)) { - continue; - } + IScope scope = CPPVisitor.getContainingScope(parent); + if (scope == null) + return null; + lookup(funcData, scope); + try { + doKoenigLookup(funcData); + } catch (DOMException e) { + } + // Filter with file-set + IASTTranslationUnit tu= parent.getTranslationUnit(); + if (tu != null && funcData.foundItems instanceof Object[]) { + final IIndexFileSet fileSet = tu.getIndexFileSet(); + if (fileSet != null) { + int j=0; + final Object[] items= (Object[]) funcData.foundItems; + for (int i = 0; i < items.length; i++) { + Object item = items[i]; + items[i]= null; + if (item instanceof IIndexBinding) { + if (!fileSet.containsDeclaration((IIndexBinding) item)) { + continue; } - items[j++]= item; } + items[j++]= item; } } } } catch (DOMException e) { return null; } - + + if (operator == OverloadableOperator.NEW || operator == OverloadableOperator.DELETE + || operator == OverloadableOperator.NEW_ARRAY || operator == OverloadableOperator.DELETE_ARRAY) { + + // Those operators replace the built-in operator + Object[] items= (Object[]) funcData.foundItems; + int j= 0; + for (Object object : items) { + if (object instanceof ICPPFunction) { + ICPPFunction func= (ICPPFunction) object; + if (!(func instanceof CPPImplicitFunction)) + items[j++]= func; + } + } + if (j>0) { + while (j < items.length) + items[j++]= null; + } + } // 13.3.1.2.3 // However, if no operand type has class type, only those non-member functions ... if (mode == LookupMode.LIMITED_GLOBALS) { @@ -3348,31 +3369,31 @@ public class CPPSemantics { } } } - - if (callToObjectOfClassType != null) { - try { - // 13.3.1.1.2 call to object of class type - ICPPMethod[] ops = SemanticUtil.getConversionOperators(callToObjectOfClassType); - for (ICPPMethod op : ops) { - if (op.isExplicit()) - continue; - IFunctionType ft= op.getType(); - if (ft != null) { - IType rt= SemanticUtil.getNestedType(ft.getReturnType(), SemanticUtil.TDEF); - if (rt instanceof IPointerType) { - IType ptt= SemanticUtil.getNestedType(((IPointerType) rt).getType(), SemanticUtil.TDEF); - if (ptt instanceof IFunctionType) { - IFunctionType ft2= (IFunctionType) ptt; - IBinding sf= createSurrogateCallFunction(parent.getTranslationUnit().getScope(), ft2.getReturnType(), rt, ft2.getParameterTypes()); - mergeResults(funcData, sf, false); - } - } - } - } - } catch (DOMException e) { - return null; - } - } + } + + if (callToObjectOfClassType != null) { + try { + // 13.3.1.1.2 call to object of class type + ICPPMethod[] ops = SemanticUtil.getConversionOperators(callToObjectOfClassType); + for (ICPPMethod op : ops) { + if (op.isExplicit()) + continue; + IFunctionType ft= op.getType(); + if (ft != null) { + IType rt= SemanticUtil.getNestedType(ft.getReturnType(), SemanticUtil.TDEF); + if (rt instanceof IPointerType) { + IType ptt= SemanticUtil.getNestedType(((IPointerType) rt).getType(), SemanticUtil.TDEF); + if (ptt instanceof IFunctionType) { + IFunctionType ft2= (IFunctionType) ptt; + IBinding sf= createSurrogateCallFunction(parent.getTranslationUnit().getScope(), ft2.getReturnType(), rt, ft2.getParameterTypes()); + mergeResults(funcData, sf, false); + } + } + } + } + } catch (DOMException e) { + return null; + } } if (methodLookupType instanceof ICPPClassType || type2 instanceof ICPPClassType) { From d226e960f9c1b40edd2dadefa005d092d1831fdf Mon Sep 17 00:00:00 2001 From: Markus Schorn Date: Wed, 20 Jul 2011 14:01:49 +0200 Subject: [PATCH 06/10] Bug 351609: Adjust parameter types in instantiated function type. --- .../core/parser/tests/ast2/AST2TemplateTests.java | 14 ++++++++++++++ .../dom/parser/cpp/semantics/CPPTemplates.java | 7 +++++++ .../core/dom/parser/cpp/semantics/CPPVisitor.java | 2 +- 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java index bb429562e67..3e1bc2db256 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java @@ -5402,4 +5402,18 @@ public class AST2TemplateTests extends AST2BaseTest { public void testAddressOfMethodForInstantiation_Bug344310() throws Exception { parseAndCheckBindings(); } + + // template struct Callback { + // Callback(void (*function)(Arg arg)) {} + // }; + // + // void Subscribe(const Callback& callback){} + // void CallMe(const int){} + // + // int test() { + // Subscribe(Callback(&CallMe)); // invalid arguments, symbol not + // } + public void testParameterAdjustementInInstantiatedFunctionType_351609() throws Exception { + parseAndCheckBindings(); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java index a8c9c6cb1b7..cb5e1389025 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/CPPTemplates.java @@ -1054,6 +1054,13 @@ public class CPPTemplates { if (ret == r && params == ps) { return type; } + // The parameter types need to be adjusted. + for (int i=0; i Date: Wed, 20 Jul 2011 09:28:49 -0400 Subject: [PATCH 07/10] Bug 352562: Tracepoint Action 'eval' has changed to 'teval' --- .../cdt/dsf/gdb/internal/tracepointactions/messages.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/internal/tracepointactions/messages.properties b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/internal/tracepointactions/messages.properties index 04653efcc60..8ab0c0f533a 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/internal/tracepointactions/messages.properties +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/internal/tracepointactions/messages.properties @@ -18,6 +18,6 @@ TracepointActions_Evaluate_Name=Evaluate Action TracepointActions_WhileStepping_Name=While-Stepping Action # START NON-TRANSLATABLE TracepointActions_Collect_text=collect {0} -TracepointActions_Evaluate_text=eval {0} +TracepointActions_Evaluate_text=teval {0} TracepointActions_WhileStepping_text=while-stepping {0} {1} # END NON-TRANSLATABLE From 5c46a13bd31fe7a9f5e19a629b965cb1ca66ea47 Mon Sep 17 00:00:00 2001 From: Markus Schorn Date: Wed, 20 Jul 2011 15:38:20 +0200 Subject: [PATCH 08/10] Bug 351927: Argument deduction with reference types --- .../parser/tests/ast2/AST2TemplateTests.java | 18 ++++++++++++++++++ .../semantics/TemplateArgumentDeduction.java | 8 ++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java index 3e1bc2db256..fc1b4bcd99f 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java @@ -5416,4 +5416,22 @@ public class AST2TemplateTests extends AST2BaseTest { public void testParameterAdjustementInInstantiatedFunctionType_351609() throws Exception { parseAndCheckBindings(); } + + // template struct CT { + // int g; + // }; + // template struct CT { + // int ref; + // }; + // template struct CT { + // int rref; + // }; + // void test() { + // CT::g; + // CT::ref; + // CT::rref; + // } + public void testRRefVsRef_351927() throws Exception { + parseAndCheckBindings(); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/TemplateArgumentDeduction.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/TemplateArgumentDeduction.java index 021c2faaa83..be23516639f 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/TemplateArgumentDeduction.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/TemplateArgumentDeduction.java @@ -678,8 +678,12 @@ public class TemplateArgumentDeduction { if (!(a instanceof ICPPReferenceType)) { return false; } - p = ((ICPPReferenceType) p).getType(); - a = ((ICPPReferenceType) a).getType(); + final ICPPReferenceType rp = (ICPPReferenceType) p; + final ICPPReferenceType ra = (ICPPReferenceType) a; + if (ra.isRValueReference() != rp.isRValueReference()) + return false; + p = rp.getType(); + a = ra.getType(); } else if (p instanceof IArrayType) { if (!(a instanceof IArrayType)) { return false; From 9840061bd608aaf9b5a14c38dbb7da8bca9bd097 Mon Sep 17 00:00:00 2001 From: Markus Schorn Date: Wed, 20 Jul 2011 15:54:43 +0200 Subject: [PATCH 09/10] Bug 352266: Template paramter without name, but with default value --- .../core/parser/tests/ast2/AST2TemplateTests.java | 5 +++++ .../core/dom/parser/cpp/GNUCPPSourceParser.java | 14 +++++++------- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java index fc1b4bcd99f..2a88223ceff 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/AST2TemplateTests.java @@ -5434,4 +5434,9 @@ public class AST2TemplateTests extends AST2BaseTest { public void testRRefVsRef_351927() throws Exception { parseAndCheckBindings(); } + + // template class A {}; + public void testTemplateParameterWithoutName_352266() throws Exception { + parseAndCheckBindings(); + } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java index 2d13fb9e1e4..46bbf254f39 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/GNUCPPSourceParser.java @@ -2097,16 +2097,16 @@ public class GNUCPPSourceParser extends AbstractGNUSourceCodeParser { if (LT(1) == IToken.tIDENTIFIER) { // optional identifier identifierName = identifier(); endOffset = calculateEndOffset(identifierName); - if (LT(1) == IToken.tASSIGN) { // optional = type-id - if (parameterPack) - throw backtrack; - consume(); - defaultValue = typeId(DeclarationOptions.TYPEID); // type-id - endOffset = calculateEndOffset(defaultValue); - } } else { identifierName = nodeFactory.newName(); } + if (LT(1) == IToken.tASSIGN) { // optional = type-id + if (parameterPack) + throw backtrack; + consume(); + defaultValue = typeId(DeclarationOptions.TYPEID); // type-id + endOffset = calculateEndOffset(defaultValue); + } // Check if followed by comma switch (LT(1)) { From f60aad128c86e5294328a1384b95d7cda3202bcf Mon Sep 17 00:00:00 2001 From: Anton Leherbauer Date: Wed, 20 Jul 2011 14:57:50 +0200 Subject: [PATCH 10/10] Bug 352544 - the end of certain string definitions (e.g. R"(") is not correctly identified --- .../cdt/ui/tests/text/CPartitionerTest.java | 19 ++++++++++++++++++- .../ui/text/FastCPartitionScanner.java | 4 ++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CPartitionerTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CPartitionerTest.java index 33a4fc9e475..656a833102b 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CPartitionerTest.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/CPartitionerTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2010 IBM Corporation and others. + * Copyright (c) 2000, 2011 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 @@ -1296,6 +1296,23 @@ public class CPartitionerTest extends TestCase { } } + public void testRawString_Bug352544() { + try { + + fDocument.replace(0, fDocument.getLength(), "BAR\"(\";"); + ITypedRegion[] result= fDocument.computePartitioning(0, fDocument.getLength()); + TypedRegion[] expectation= { + new TypedRegion(0, 3, IDocument.DEFAULT_CONTENT_TYPE), + new TypedRegion(3, 3, ICPartitions.C_STRING), + new TypedRegion(6, 1, IDocument.DEFAULT_CONTENT_TYPE), + }; + checkPartitioning(expectation, result); + + } catch (BadLocationException x) { + assertTrue(false); + } + } + public void testEditingRawString1() { try { diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/FastCPartitionScanner.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/FastCPartitionScanner.java index 57b18b608ba..ea242474479 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/FastCPartitionScanner.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/FastCPartitionScanner.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. + * Copyright (c) 2000, 2011 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 @@ -388,7 +388,7 @@ public final class FastCPartitionScanner implements IPartitionTokenScanner, ICPa consume(); break; default: - if ('a' <= ch && ch <= 'z' || 'A' <= ch && 'Z' <= ch || ch =='_') { + if ('a' <= ch && ch <= 'z' || 'A' <= ch && ch <= 'Z' || ch =='_') { fLast = IDENT; fTokenOffset++; } else if ('0' <= ch && ch <= '9' && fLast == IDENT) {