diff options
author | Doug Schaefer | 2006-04-12 17:11:14 +0000 |
---|---|---|
committer | Doug Schaefer | 2006-04-12 17:11:14 +0000 |
commit | c394f40e489dd37280520439c09530c1c4a9e61f (patch) | |
tree | 93675fecb6128a0d5c6fe2b0101661838bed71bd /core/org.eclipse.cdt.ui.tests | |
parent | 160774ed3d29b0766ed646ac6eae690d7ff1ddd4 (diff) | |
download | org.eclipse.cdt-c394f40e489dd37280520439c09530c1c4a9e61f.tar.gz org.eclipse.cdt-c394f40e489dd37280520439c09530c1c4a9e61f.tar.xz org.eclipse.cdt-c394f40e489dd37280520439c09530c1c4a9e61f.zip |
Testing the scalability of the Commit Files dialog. No really, I've removed the old indexer, search and type cache and have fixed all the compile errors that doing so caused. A number of features are disabled to be re-enabled later.
Diffstat (limited to 'core/org.eclipse.cdt.ui.tests')
25 files changed, 57 insertions, 6091 deletions
diff --git a/core/org.eclipse.cdt.ui.tests/META-INF/MANIFEST.MF b/core/org.eclipse.cdt.ui.tests/META-INF/MANIFEST.MF index 074055d7549..c93912ef0bf 100644 --- a/core/org.eclipse.cdt.ui.tests/META-INF/MANIFEST.MF +++ b/core/org.eclipse.cdt.ui.tests/META-INF/MANIFEST.MF @@ -10,9 +10,7 @@ Export-Package: org.eclipse.cdt.ui.testplugin, org.eclipse.cdt.ui.testplugin.util, org.eclipse.cdt.ui.tests, org.eclipse.cdt.ui.tests.DOMAST, - org.eclipse.cdt.ui.tests.IndexerView, org.eclipse.cdt.ui.tests.chelp, - org.eclipse.cdt.ui.tests.regression, org.eclipse.cdt.ui.tests.text, org.eclipse.cdt.ui.tests.text.contentassist, org.eclipse.cdt.ui.tests.text.selectiontests diff --git a/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/DOMAST/DOMAST.java b/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/DOMAST/DOMAST.java index 56c416a5b3d..c29d9c3da28 100644 --- a/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/DOMAST/DOMAST.java +++ b/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/DOMAST/DOMAST.java @@ -877,20 +877,6 @@ public class DOMAST extends ViewPart { searchNamesAction.setToolTipText(SEARCH_FOR_IASTNAME); searchNamesAction.setImageDescriptor(DOMASTPluginImages.DESC_SEARCH_NAMES); - openDeclarationsAction = new DisplayDeclarationsAction(); - openDeclarationsAction.setText(OPEN_DECLARATIONS); - openDeclarationsAction.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages() - .getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK)); - - openReferencesAction = new DisplayReferencesAction(); - openReferencesAction.setText(OPEN_REFERENCES); - openReferencesAction.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages() - .getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK)); - - displayProblemsAction = new DisplayProblemsResultAction(); - displayProblemsAction.setText(DISPLAY_PROBLEMS); - displayProblemsAction.setImageDescriptor(DOMASTPluginImages.DESC_IASTProblem); - displayNodeTypeAction = new Action() { public void run() { ISelection selection = viewer.getSelection(); @@ -1038,82 +1024,6 @@ public class DOMAST extends ViewPart { } - private class DisplayDeclarationsAction extends DisplaySearchResultAction { - private static final String STRING_QUOTE = "\""; //$NON-NLS-1$ - public void run() { - ISelection selection = viewer.getSelection(); - if (selection instanceof IStructuredSelection && - ((IStructuredSelection)selection).getFirstElement() instanceof DOMASTNodeLeaf && - ((DOMASTNodeLeaf)((IStructuredSelection)selection).getFirstElement()).getNode() instanceof IASTName) { - IASTName name = (IASTName)((DOMASTNodeLeaf)((IStructuredSelection)selection).getFirstElement()).getNode(); - StringBuffer pattern = new StringBuffer(STRING_QUOTE); - if (name.toString() != null) - pattern.append(name.toString()); - pattern.append(STRING_QUOTE); - - if (lang == ParserLanguage.CPP) { - IASTName[] names = ((DOMASTNodeLeaf)((IStructuredSelection)selection).getFirstElement()).getNode().getTranslationUnit().getDeclarations(name.resolveBinding()); - displayNames(names, OPEN_DECLARATIONS, pattern.toString()); - } else { - IASTName[] names = ((DOMASTNodeLeaf)((IStructuredSelection)selection).getFirstElement()).getNode().getTranslationUnit().getDeclarations(name.resolveBinding()); - displayNames(names, OPEN_DECLARATIONS, pattern.toString()); - } - } - } - } - - private class DisplayReferencesAction extends DisplaySearchResultAction { - private static final String STRING_QUOTE = "\""; //$NON-NLS-1$ - public void run() { - ISelection selection = viewer.getSelection(); - if (selection instanceof IStructuredSelection && - ((IStructuredSelection)selection).getFirstElement() instanceof DOMASTNodeLeaf && - ((DOMASTNodeLeaf)((IStructuredSelection)selection).getFirstElement()).getNode() instanceof IASTName) { - IASTName name = (IASTName)((DOMASTNodeLeaf)((IStructuredSelection)selection).getFirstElement()).getNode(); - StringBuffer pattern = new StringBuffer(STRING_QUOTE); - if (name.toString() != null) - pattern.append(name.toString()); - pattern.append(STRING_QUOTE); - - if (lang == ParserLanguage.CPP) { - IASTName[] names = ((DOMASTNodeLeaf)((IStructuredSelection)selection).getFirstElement()).getNode().getTranslationUnit().getReferences(name.resolveBinding()); - displayNames(names, OPEN_REFERENCES, pattern.toString()); - } else { - IASTName[] names = ((DOMASTNodeLeaf)((IStructuredSelection)selection).getFirstElement()).getNode().getTranslationUnit().getReferences(name.resolveBinding()); - displayNames(names, OPEN_REFERENCES, pattern.toString()); - } - } - } - } - - private class DisplaySearchResultAction extends Action { - protected void displayNames(IASTName[] names, String queryLabel, String pattern) { - DOMDisplaySearchNames job = new DOMDisplaySearchNames(names, queryLabel, pattern); - NewSearchUI.activateSearchResultView(); - NewSearchUI.runQueryInBackground(job); - } - } - - private class DisplayProblemsResultAction extends Action { - private static final String IASTPROBLEM = "IASTProblem"; //$NON-NLS-1$ - private static final String PROBLEMS_FOUND = "Problems Found"; //$NON-NLS-1$ - protected void displayProblems(IASTProblem[] problems, String queryLabel, String pattern) { - DOMDisplaySearchNames job = new DOMDisplaySearchNames(problems, queryLabel, pattern); - NewSearchUI.activateSearchResultView(); - NewSearchUI.runQueryInBackground(job); - } - - public void run() { - if (viewer.getTree().getItems().length == 0) { - showMessage(DOM_AST_HAS_NO_CONTENT); - } - - if (viewer.getContentProvider() instanceof ViewContentProvider) { - displayProblems(((ViewContentProvider)viewer.getContentProvider()).getASTProblems(), PROBLEMS_FOUND, IASTPROBLEM); - } - } - } - private void hookSingleClickAction() { viewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { diff --git a/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/DOMAST/DOMDisplaySearchNames.java b/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/DOMAST/DOMDisplaySearchNames.java deleted file mode 100644 index a371801a9cc..00000000000 --- a/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/DOMAST/DOMDisplaySearchNames.java +++ /dev/null @@ -1,262 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005 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 - *******************************************************************************/ -package org.eclipse.cdt.ui.tests.DOMAST; - -import org.eclipse.cdt.core.dom.ast.ASTTypeUtil; -import org.eclipse.cdt.core.dom.ast.DOMException; -import org.eclipse.cdt.core.dom.ast.IASTFileLocation; -import org.eclipse.cdt.core.dom.ast.IASTName; -import org.eclipse.cdt.core.dom.ast.IASTNode; -import org.eclipse.cdt.core.dom.ast.IASTProblem; -import org.eclipse.cdt.core.dom.ast.IBinding; -import org.eclipse.cdt.core.dom.ast.ICompositeType; -import org.eclipse.cdt.core.dom.ast.IEnumeration; -import org.eclipse.cdt.core.dom.ast.IEnumerator; -import org.eclipse.cdt.core.dom.ast.IField; -import org.eclipse.cdt.core.dom.ast.IFunction; -import org.eclipse.cdt.core.dom.ast.IMacroBinding; -import org.eclipse.cdt.core.dom.ast.ITypedef; -import org.eclipse.cdt.core.dom.ast.IVariable; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType; -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.model.ICElement; -import org.eclipse.cdt.core.parser.ParserUtil; -import org.eclipse.cdt.core.search.BasicSearchMatch; -import org.eclipse.cdt.core.search.IMatch; -import org.eclipse.cdt.core.search.IOffsetLocatable; -import org.eclipse.cdt.core.search.OffsetLocatable; -import org.eclipse.cdt.internal.ui.search.CSearchQuery; -import org.eclipse.cdt.internal.ui.search.CSearchResult; -import org.eclipse.cdt.internal.ui.search.NewSearchResultCollector; -import org.eclipse.cdt.ui.CUIPlugin; -import org.eclipse.cdt.utils.PathUtil; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.OperationCanceledException; -import org.eclipse.core.runtime.Path; -import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.SubProgressMonitor; -import org.eclipse.search.ui.ISearchQuery; -import org.eclipse.search.ui.ISearchResult; - -/** - * This is used for the DOM AST Viewer only... it requires that the names to be displayed - * in the search view were already found elsewhere. - * @author dsteffle - */ -public class DOMDisplaySearchNames extends CSearchQuery implements ISearchQuery { - - private static final String BLANK_STRING = ""; //$NON-NLS-1$ - private CSearchResult _result; - private IASTNode[] nodes = null; - private String queryLabel = null; - - /** - * - */ - public DOMDisplaySearchNames(IASTNode[] nodes, String queryLabel, String pattern) { - super(CUIPlugin.getWorkspace(), pattern, false, null, null, null, queryLabel); - this.nodes = nodes; - this.queryLabel = queryLabel; - } - - /* (non-Javadoc) - * @see org.eclipse.search.ui.ISearchQuery#run(org.eclipse.core.runtime.IProgressMonitor) - */ - public IStatus run(IProgressMonitor monitor) - throws OperationCanceledException { - - final CSearchResult textResult= (CSearchResult) getSearchResult(); - - IProgressMonitor mainSearchPM= new SubProgressMonitor(monitor, 1000); - NewSearchResultCollector collector = new NewSearchResultCollector(textResult, mainSearchPM); - - collector.aboutToStart(); - - for (int i=0; i<nodes.length; i++) { - try { - String fileName = null; - IPath path = null; - int start = 0; - int end = 0; - if ( nodes[i] != null ) { - IASTFileLocation location = nodes[i].getFileLocation(); - if (location == null) { - return new Status(IStatus.ERROR, CUIPlugin.getPluginId(), 0, "Null Location associated with IASTFileLocation.", null); //$NON-NLS-1$ - } - fileName = location.getFileName(); - start = location.getNodeOffset(); - end = location.getNodeOffset() + location.getNodeLength(); - path = new Path(fileName); - Object fileResource=null; - IResource res = ParserUtil.getResourceForFilename(fileName); - if (res != null) - fileResource = res; - else { - fileResource = PathUtil.getWorkspaceRelativePath(fileName); - } - - collector.acceptMatch( createMatch(fileResource, start, end, nodes[i], path ) ); - } - } catch (CoreException ce) {} - } - - mainSearchPM.done(); - collector.done(); - - return new Status(IStatus.OK, CUIPlugin.getPluginId(), 0, BLANK_STRING, null); //$NON-NLS-1$ - } - - public IMatch createMatch( Object fileResource, int start, int end, IASTNode node, IPath referringElement ) { - BasicSearchMatch result = new BasicSearchMatch(); - - if( fileResource instanceof IResource ) - result.setResource((IResource) fileResource); - else if( fileResource instanceof IPath ) - result.setPath((IPath) fileResource); - - IOffsetLocatable locatable = new OffsetLocatable(start,end); - result.setLocatable(locatable); - - result.setParentName(BLANK_STRING); //$NON-NLS-1$ - result.setReferringElement(referringElement); - - if (node instanceof IASTName) - result.setName( node.toString()); - else if (node instanceof IASTProblem) - result.setName(((IASTProblem)node).getMessage()); - else - result.setName(node.toString()); - - // set the type and visibility of the match - if (node instanceof IASTName) { - IBinding binding = ((IASTName)node).resolveBinding(); - if (binding instanceof ICPPClassType) { - result.setType(ICElement.C_CLASS); - } else if (binding instanceof ICompositeType) { - int key=ICompositeType.k_struct; - try { - key = ((ICompositeType)binding).getKey(); - } catch (DOMException e) {} - switch (key) { - case ICompositeType.k_struct: - result.setType(ICElement.C_STRUCT); - break; - case ICompositeType.k_union: - result.setType(ICElement.C_UNION); - break; - } - } else if (binding instanceof ICPPNamespace) { - result.setType(ICElement.C_NAMESPACE); - } else if (binding instanceof IEnumeration) { - result.setType(ICElement.C_ENUMERATION); - } else if (binding instanceof IMacroBinding) { - result.setType(ICElement.C_MACRO); - } else if (binding instanceof IField) { - result.setType(ICElement.C_FIELD); - try { - result.setStatic(((IField)binding).isStatic()); - } catch (DOMException e) {} - if (binding instanceof ICPPMember) { - try { - switch (((ICPPMember)binding).getVisibility()) { - case ICPPMember.v_private: - result.setVisibility(ICElement.CPP_PRIVATE); - break; - case ICPPMember.v_public: - result.setVisibility(ICElement.CPP_PUBLIC); - break; - // no ICElement.CPP_PROTECTED - } - } catch (DOMException e) {} - } - try { - result.setConst(ASTTypeUtil.isConst(((IField)binding).getType())); - } catch (DOMException e) {} - } else if (binding instanceof IVariable) { - result.setType(ICElement.C_VARIABLE); - try { - result.setConst(ASTTypeUtil.isConst(((IVariable)binding).getType())); - } catch (DOMException e) {} - } else if (binding instanceof IEnumerator) { - result.setType(ICElement.C_ENUMERATOR); - } else if (binding instanceof ICPPMethod) { - result.setType(ICElement.C_METHOD); - if (binding instanceof ICPPMember) { - try { - switch (((ICPPMember)binding).getVisibility()) { - case ICPPMember.v_private: - result.setVisibility(ICElement.CPP_PRIVATE); - break; - case ICPPMember.v_public: - result.setVisibility(ICElement.CPP_PUBLIC); - break; - // there is no ICElement.CPP_PROTECTED - } - } catch (DOMException e) {} - } - try { - result.setConst(ASTTypeUtil.isConst(((ICPPMethod)binding).getType())); - } catch (DOMException e) {} - } else if (binding instanceof IFunction) { - result.setType(ICElement.C_FUNCTION); - try { - result.setStatic(((IFunction)binding).isStatic()); - } catch (DOMException e) {} - } else if (binding instanceof ITypedef) { - result.setType(ICElement.C_TYPEDEF); - } - } else { - result.setType(ICElement.C_UNKNOWN_DECLARATION); - } - - result.setReturnType(BLANK_STRING); - - return result; - } - - - /* (non-Javadoc) - * @see org.eclipse.search.ui.ISearchQuery#getLabel() - */ - public String getLabel() { - return queryLabel; - } - - /* (non-Javadoc) - * @see org.eclipse.search.ui.ISearchQuery#canRerun() - */ - public boolean canRerun() { - return true; - } - - /* (non-Javadoc) - * @see org.eclipse.search.ui.ISearchQuery#canRunInBackground() - */ - public boolean canRunInBackground() { - return true; - } - - /* (non-Javadoc) - * @see org.eclipse.search.ui.ISearchQuery#getSearchResult() - */ - public ISearchResult getSearchResult() { - if (_result == null) - _result= new CSearchResult(this); - return _result; - } - -} diff --git a/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/IndexerView/FilterIndexerViewDialog.java b/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/IndexerView/FilterIndexerViewDialog.java deleted file mode 100644 index 6f00aad4b57..00000000000 --- a/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/IndexerView/FilterIndexerViewDialog.java +++ /dev/null @@ -1,692 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005 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 - *******************************************************************************/ -package org.eclipse.cdt.ui.tests.IndexerView; -import org.eclipse.cdt.internal.core.index.IIndex; -//import org.eclipse.cdt.internal.core.index.cindexstorage.Index; -import org.eclipse.cdt.ui.CUIPlugin; -import org.eclipse.jface.dialogs.Dialog; -import org.eclipse.jface.dialogs.IDialogConstants; -import org.eclipse.jface.dialogs.IDialogSettings; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.graphics.Rectangle; -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.Control; -import org.eclipse.swt.widgets.Event; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Text; - -/** - * @author dsteffle - */ -public class FilterIndexerViewDialog extends Dialog { - - private static String getStringDescription(int index) { - return buttonNames[index]; - } - - private static String getUniqueStringDescription(int index) { - //return Index.getDescriptionOf(meta, kind, ref); - //return buttonNames[index] + new String(ICIndexStorageConstants.encodingTypes[iAllTypes[index][2]]); - return String.valueOf(index); - } - private static final int DECL_BUTTON_ID = 3; - private static final int REF_BUTTON_ID = 2; - private static final int TYPE_BUTTON_ID = 1; - private static final int ALL_BUTTON_ID = 0; - private static final String GROUPED_SELECTIONS_LABEL = "Grouped Selections:"; //$NON-NLS-1$ - private static final String ALL_BUTTON = "All"; //$NON-NLS-1$ - private static final String TYPE_BUTTON = "type"; //$NON-NLS-1$ - private static final String DECL_BUTTON = "Decl"; //$NON-NLS-1$ - private static final String REF_BUTTON = "Ref"; //$NON-NLS-1$ - private static final String BLANK_STRING = ""; //$NON-NLS-1$ - private static final String PAGE_SIZE_ = "Page Size:"; //$NON-NLS-1$ - private static final String TYPESELECTIONDIALOG_DeclLABEL = "Declarations:"; //$NON-NLS-1$ - private static final String TYPESELECTIONDIALOG_RefLABEL = "References:"; //$NON-NLS-1$ - private static final String FILTER_INDEXER_RESULTS = "Filter Indexer Results"; //$NON-NLS-1$ - private static final String SETTINGS = "Settings"; //$NON-NLS-1$ - private static final String PAGE_SIZE = "PAGE_SIZE"; //$NON-NLS-1$ - private static final String FILTER_TEXT = "Filter"; //$NON-NLS-1$ - private String fFilter = BLANK_STRING; //$NON-NLS-1$ - Text filterText = null; - private int pageSize = IndexerNodeParent.PAGE_SIZE; - Text pageSizeText = null; - protected boolean [] fFilterMatcher = new boolean [iAllTypes.length]; - protected boolean[] groupedButtonSelections; - - private String message = "Filter Indexer Results (. = any character, .* = any string):"; //$NON-NLS-1$ - - public static final int ENTRY_MACRO_DECL = 0; - public static final int ENTRY_FUNCTION_DECL = 1; - public static final int ENTRY_NAMESPACE_DECL = 2; - public static final int ENTRY_FUNCTION_REF = 3; - public static final int ENTRY_NAMESPACE_REF = 4; - public static final int ENTRY_FIELD_DECL = 5; - public static final int ENTRY_ENUMTOR_DECL = 6; - public static final int ENTRY_METHOD_DECL = 7; - public static final int ENTRY_FIELD_REF = 8; - public static final int ENTRY_ENUMTOR_REF = 9; - public static final int ENTRY_METHOD_REF = 10; - public static final int ENTRY_TYPE_REF = 11; - public static final int ENTRY_TYPE_DECL_TYPEDEF = 12; - public static final int ENTRY_TYPE_DECL_CLASS = 13; - public static final int ENTRY_TYPE_DECL_VAR = 14; - public static final int ENTRY_TYPE_DECL_STRUCT = 15; - public static final int ENTRY_TYPE_DECL_ENUM = 16; - public static final int ENTRY_TYPE_DECL_UNION = 17; - public static final int ENTRY_TYPE_DECL_DERIVED = 18; - public static final int ENTRY_TYPE_DECL_FRIEND = 19; - public static final int ENTRY_INCLUDE_REF = 20; - - private String fDialogSection; - - private static final String DIALOG_SETTINGS = FilterIndexerViewDialog.class.getName(); - private static final String SETTINGS_X_POS = "x"; //$NON-NLS-1$ - private static final String SETTINGS_Y_POS = "y"; //$NON-NLS-1$ - private static final String SETTINGS_WIDTH = "width"; //$NON-NLS-1$ - private static final String SETTINGS_HEIGHT = "height"; //$NON-NLS-1$ - - private Point fLocation; - private Point fSize; - - IndexerNodeParent root = null; - - private String projName = null; - - // this also determines the order that the buttons are displayed - private static int[][] iAllTypes = { - {IIndex.MACRO, IIndex.ANY, IIndex.DECLARATION}, - {IIndex.FUNCTION, IIndex.ANY, IIndex.DECLARATION}, - {IIndex.NAMESPACE, IIndex.ANY, IIndex.DECLARATION}, - {IIndex.FUNCTION, IIndex.ANY, IIndex.REFERENCE}, - {IIndex.NAMESPACE, IIndex.ANY, IIndex.REFERENCE}, - {IIndex.FIELD, IIndex.ANY, IIndex.DECLARATION}, - {IIndex.ENUMTOR, IIndex.ANY, IIndex.DECLARATION}, - {IIndex.METHOD, IIndex.ANY, IIndex.DECLARATION}, - {IIndex.FIELD, IIndex.ANY, IIndex.REFERENCE}, - {IIndex.ENUMTOR, IIndex.ANY, IIndex.REFERENCE}, - {IIndex.METHOD, IIndex.ANY, IIndex.REFERENCE}, - {IIndex.TYPE, IIndex.ANY, IIndex.REFERENCE}, - {IIndex.TYPE, IIndex.TYPE_TYPEDEF, IIndex.DECLARATION}, - {IIndex.TYPE, IIndex.TYPE_CLASS, IIndex.DECLARATION}, - {IIndex.VAR, IIndex.ANY, IIndex.DECLARATION}, - {IIndex.TYPE, IIndex.TYPE_STRUCT, IIndex.DECLARATION}, - {IIndex.TYPE, IIndex.TYPE_ENUM, IIndex.DECLARATION}, - {IIndex.TYPE, IIndex.TYPE_UNION, IIndex.DECLARATION}, - {IIndex.TYPE, IIndex.TYPE_DERIVED, IIndex.DECLARATION}, - {IIndex.TYPE, IIndex.TYPE_FRIEND, IIndex.DECLARATION}, - {IIndex.INCLUDE, IIndex.ANY, IIndex.REFERENCE} - }; - - private static String [] buttonNames = { - "Macro", - "Function", - "Namepace", - "Function", - "Namespace", - "Field", - "Enumtor", - "Method", - "Field", - "Enumtor", - "Method", - "Type", - "Typedef", - "Class", - "Variable", - "Struct", - "Enum", - "Union", - "Derived", - "Friend", - "Include" - }; - // keep track of the buttons to programmatically change their state - protected Button[] buttons = new Button[iAllTypes.length]; - protected Button allButton = null; - protected Button typeButton = null; - protected Button declButton = null; - protected Button refButton = null; - - protected FilterIndexerViewDialog(Shell parentShell, IndexerNodeParent root, String projName) { - super(parentShell); - - this.root = root; - this.projName = projName; - - for (int i = 0; i < iAllTypes.length; i++) - fFilterMatcher[i] = false; - - groupedButtonSelections = new boolean[DECL_BUTTON_ID + 1]; - for (int j = ALL_BUTTON_ID; j <= DECL_BUTTON_ID; j++) - groupedButtonSelections[j] = false; - - setDialogSettings(DIALOG_SETTINGS); - } - - /** - * Sets section name to use when storing the dialog settings. - * - * @param section Name of section. - */ - public void setDialogSettings(String section) { - fDialogSection = section + SETTINGS + projName; - } - - public boolean close() { - return super.close(); - } - - /* - * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell) - */ - protected void configureShell(Shell newShell) { - super.configureShell(newShell); - newShell.setText(FILTER_INDEXER_RESULTS); - } - - /* - * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite) - */ - protected Control createDialogArea(Composite parent) { - readSettings(getDialogSettings()); - - Composite composite = new Composite(parent, SWT.NONE); - GridLayout layout = new GridLayout(); - layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN); - layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN); - layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING); - layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING); - composite.setLayout(layout); - composite.setLayoutData(new GridData(GridData.FILL_BOTH)); - applyDialogFont(composite); - - createMessageArea(composite); - createFilterText(composite); - createTypeFilterArea(composite); - createGroupedArea(composite); - createPageSizeArea(composite); - - return composite; - } - - /** - * Creates a label if name was not <code>null</code>. - * - * @param parent - * the parent composite. - * @param name - * the name of the label. - * @return returns a label if a name was given, <code>null</code> - * otherwise. - */ - protected Label createLabel(Composite parent, String name) { - if (name == null) - return null; - Label label = new Label(parent, SWT.NONE); - label.setText(name); - label.setFont(parent.getFont()); - return label; - } - - /** - * Creates a type filter checkbox. - */ - private void createTypeCheckbox(Composite parent, int type) { - String name = getStringDescription(type); - Image icon = IndexerViewPluginImages.get(type); - - Composite composite = new Composite(parent, SWT.NONE); - GridLayout layout = new GridLayout(2, false); - layout.marginHeight = 0; - composite.setLayout(layout); - - final int type1 = type; - Button checkbox = new Button(composite, SWT.CHECK); - checkbox.setFont(composite.getFont()); - checkbox.setText(name); - checkbox.setImage(icon); - checkbox.setSelection(fFilterMatcher[type]); - checkbox.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - if (e.widget instanceof Button) { - Button aCheckbox = (Button) e.widget; - fFilterMatcher[type1] = aCheckbox.getSelection(); - } - } - }); - - Label label = new Label(composite, SWT.LEFT); - label.setFont(composite.getFont()); - label.setText(name); - - buttons[type] = checkbox; - } - - - /** - * Creates an area to filter types. - * - * @param parent - * area to create controls in - */ - private void createTypeFilterArea(Composite parent) { - createLabel(parent,TYPESELECTIONDIALOG_DeclLABEL); - - Composite upperRow = new Composite(parent, SWT.NONE); - GridLayout upperLayout = new GridLayout(3, true); - upperLayout.verticalSpacing = 2; - upperLayout.marginHeight = 0; - upperLayout.marginWidth = 0; - upperRow.setLayout(upperLayout); - - // the for loop is here to guarantee we always - // create the checkboxes in the same order - for (int i = 0; i < iAllTypes.length; ++i) { - if(iAllTypes[i][2] == IIndex.DECLARATION) - createTypeCheckbox(upperRow, i); - } - - createLabel(parent,TYPESELECTIONDIALOG_RefLABEL); - - Composite lowerRow = new Composite(parent, SWT.NONE); - lowerRow.setLayout(upperLayout); - - // the for loop is here to guarantee we always - // create the checkboxes in the same order - for (int i = 0; i < iAllTypes.length; ++i) { - if(iAllTypes[i][2] == IIndex.REFERENCE) - createTypeCheckbox(lowerRow, i); - } - } - - private void createGroupedArea(Composite parent) { - createLabel(parent, GROUPED_SELECTIONS_LABEL); - - Composite upperRow = new Composite(parent, SWT.NONE); - GridLayout upperLayout = new GridLayout(8, true); - upperLayout.verticalSpacing = 2; - upperLayout.marginHeight = 0; - upperLayout.marginWidth = 0; - upperRow.setLayout(upperLayout); - - allButton = new Button(upperRow, SWT.CHECK); - allButton.setFont(upperRow.getFont()); - allButton.setText(ALL_BUTTON); - allButton.setImage(IndexerViewPluginImages.get(IndexerViewPluginImages.IMG_GROUPED_ALL)); - allButton.setSelection(groupedButtonSelections[ALL_BUTTON_ID]); - allButton.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - if (e.widget instanceof Button) { - Button aCheckbox = (Button) e.widget; - boolean isChecked = aCheckbox.getSelection(); - - Event event = new Event(); - - // select/deselect all of the buttons in the buttons array - for(int i=0; i<buttons.length; i++) { - if (buttons[i]!=null) { - buttons[i].setSelection(isChecked); - event.widget = buttons[i]; - buttons[i].notifyListeners(SWT.Selection, event); - } - } - - // select/deselect the type, decl, ref buttons - typeButton.setSelection(isChecked); - groupedButtonSelections[TYPE_BUTTON_ID] = isChecked; - declButton.setSelection(isChecked); - groupedButtonSelections[DECL_BUTTON_ID] = isChecked; - refButton.setSelection(isChecked); - groupedButtonSelections[REF_BUTTON_ID] = isChecked; - groupedButtonSelections[ALL_BUTTON_ID] = isChecked; - - } - } - }); - - Label label = new Label(upperRow, SWT.LEFT); - label.setFont(upperRow.getFont()); - label.setText(ALL_BUTTON); - - typeButton = new Button(upperRow, SWT.CHECK); - typeButton.setFont(upperRow.getFont()); - typeButton.setText(TYPE_BUTTON); - typeButton.setImage(IndexerViewPluginImages.get(IndexerViewPluginImages.IMG_GROUPED_TYPE)); - typeButton.setSelection(groupedButtonSelections[TYPE_BUTTON_ID]); - typeButton.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - if (e.widget instanceof Button) { - Button aCheckbox = (Button) e.widget; - boolean isChecked = aCheckbox.getSelection(); - - Event event = new Event(); - - // select/deselect all of the buttons in the buttons array - for(int i=0; i<buttons.length; i++) { - if (buttons[i] != null) { - if (iAllTypes[i][0] == IIndex.TYPE) { - buttons[i].setSelection(isChecked); - event.widget = buttons[i]; - buttons[i].notifyListeners(SWT.Selection, event); - } - } - } - - groupedButtonSelections[TYPE_BUTTON_ID] = isChecked; - checkAllButton(); - } - } - }); - - label = new Label(upperRow, SWT.LEFT); - label.setFont(upperRow.getFont()); - label.setText(TYPE_BUTTON); - - declButton = new Button(upperRow, SWT.CHECK); - declButton.setFont(upperRow.getFont()); - declButton.setText(DECL_BUTTON); - declButton.setImage(IndexerViewPluginImages.get(IndexerViewPluginImages.IMG_GROUPED_DECL)); - declButton.setSelection(groupedButtonSelections[DECL_BUTTON_ID]); - declButton.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - if (e.widget instanceof Button) { - Button aCheckbox = (Button) e.widget; - boolean isChecked = aCheckbox.getSelection(); - - Event event = new Event(); - - // select/deselect all of the buttons in the buttons array - for(int i=0; i<buttons.length; i++) { - if (buttons[i] != null) { - if (iAllTypes[i][2] == IIndex.DECLARATION) { - buttons[i].setSelection(isChecked); - event.widget = buttons[i]; - buttons[i].notifyListeners(SWT.Selection, event); - } - } - } - - groupedButtonSelections[DECL_BUTTON_ID] = isChecked; - checkAllButton(); - } - } - }); - - label = new Label(upperRow, SWT.LEFT); - label.setFont(upperRow.getFont()); - label.setText(DECL_BUTTON); - - refButton = new Button(upperRow, SWT.CHECK); - refButton.setFont(upperRow.getFont()); - refButton.setText(REF_BUTTON); - refButton.setImage(IndexerViewPluginImages.get(IndexerViewPluginImages.IMG_GROUPED_REF)); - refButton.setSelection(groupedButtonSelections[REF_BUTTON_ID]); - refButton.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - if (e.widget instanceof Button) { - Button aCheckbox = (Button) e.widget; - boolean isChecked = aCheckbox.getSelection(); - - Event event = new Event(); - - // select/deselect all of the buttons in the buttons array - for(int i=0; i<buttons.length; i++) { - if (buttons[i] != null) { - if (iAllTypes[i][2] == IIndex.REFERENCE) { - buttons[i].setSelection(isChecked); - event.widget = buttons[i]; - buttons[i].notifyListeners(SWT.Selection, event); - } - } - } - - groupedButtonSelections[REF_BUTTON_ID] = isChecked; - checkAllButton(); - } - } - }); - - label = new Label(upperRow, SWT.LEFT); - label.setFont(upperRow.getFont()); - label.setText(REF_BUTTON); - } - - void checkAllButton() { - // alter the state of allButton if everything is checked or not - boolean isChecked=true; - for(int i=0; i<buttons.length; i++) { - if (!buttons[i].getSelection()) { - isChecked=false; - break; - } - } - - allButton.setSelection(isChecked); - groupedButtonSelections[ALL_BUTTON_ID] = isChecked; - } - - /** - * Creates an area to filter types. - * - * @param parent - * area to create controls in - */ - private void createPageSizeArea(Composite parent) { - createLabel(parent, PAGE_SIZE_); - - pageSizeText = new Text(parent, SWT.BORDER); - - GridData data = new GridData(); - data.grabExcessVerticalSpace = false; - data.grabExcessHorizontalSpace = true; - data.horizontalAlignment = GridData.FILL; - data.verticalAlignment = GridData.BEGINNING; - pageSizeText.setLayoutData(data); - pageSizeText.setFont(parent.getFont()); - - pageSizeText.setText(String.valueOf(pageSize)); - } - - /** - * Creates the message text widget and sets layout data. - * - * @param composite - * the parent composite of the message area. - */ - protected Label createMessageArea(Composite composite) { - Label label = new Label(composite, SWT.NONE); - if (message != null) { - label.setText(message); - } - label.setFont(composite.getFont()); - - GridData data = new GridData(); - data.grabExcessVerticalSpace = false; - data.grabExcessHorizontalSpace = true; - data.horizontalAlignment = GridData.FILL; - data.verticalAlignment = GridData.BEGINNING; - label.setLayoutData(data); - - return label; - } - - protected Text createFilterText(Composite parent) { - filterText = new Text(parent, SWT.BORDER); - - GridData data = new GridData(); - data.grabExcessVerticalSpace = false; - data.grabExcessHorizontalSpace = true; - data.horizontalAlignment = GridData.FILL; - data.verticalAlignment = GridData.BEGINNING; - filterText.setLayoutData(data); - filterText.setFont(parent.getFont()); - - filterText.setText((fFilter == null ? BLANK_STRING : fFilter)); - - return filterText; - } - - /* - * @see org.eclipse.jface.dialogs.Dialog#buttonPressed(int) - */ - protected void buttonPressed(int buttonId) { - if (buttonId == IDialogConstants.OK_ID) { - apply(); - } - - super.buttonPressed(buttonId); - } - - public IDialogSettings getDialogSettings() { - IDialogSettings allSettings = CUIPlugin.getDefault().getDialogSettings(); - IDialogSettings section = allSettings.getSection(fDialogSection); - if (section == null) { - section = allSettings.addNewSection(fDialogSection); - writeDefaultSettings(section); - } - return section; - } - - /** - * Stores current configuration in the dialog store. - */ - protected void writeSettings(IDialogSettings section) { - Point location = getShell().getLocation(); - section.put(SETTINGS_X_POS, location.x); - section.put(SETTINGS_Y_POS, location.y); - - Point size = getShell().getSize(); - section.put(SETTINGS_WIDTH, size.x); - section.put(SETTINGS_HEIGHT, size.y); - - for(int i = 0; i < iAllTypes.length; i++) { - section.put( - getUniqueStringDescription(i), - fFilterMatcher[i] ); - } - - section.put(ALL_BUTTON, groupedButtonSelections[ALL_BUTTON_ID]); - section.put(TYPE_BUTTON, groupedButtonSelections[TYPE_BUTTON_ID]); - section.put(REF_BUTTON, groupedButtonSelections[REF_BUTTON_ID]); - section.put(DECL_BUTTON, groupedButtonSelections[DECL_BUTTON_ID]); - - section.put(PAGE_SIZE, pageSize); - section.put(FILTER_TEXT, fFilter); - } - - /** - * Stores default dialog settings. - */ - protected void writeDefaultSettings(IDialogSettings section) { - for(int i = 0; i < iAllTypes.length; i++) { - String description = getUniqueStringDescription(i); - section.put(description, true); - } - - section.put(FILTER_TEXT, fFilter); - section.put(PAGE_SIZE, IndexerNodeParent.PAGE_SIZE); - } - - protected Point getInitialLocation(Point initialSize) { - Point result = super.getInitialLocation(initialSize); - if (fLocation != null) { - result.x = fLocation.x; - result.y = fLocation.y; - Rectangle display = getShell().getDisplay().getClientArea(); - int xe = result.x + initialSize.x; - if (xe > display.width) { - result.x -= xe - display.width; - } - int ye = result.y + initialSize.y; - if (ye > display.height) { - result.y -= ye - display.height; - } - } - return result; - } - - protected Point getInitialSize() { - Point result = super.getInitialSize(); - if (fSize != null) { - result.x = Math.max(result.x, fSize.x); - result.y = Math.max(result.y, fSize.y); - Rectangle display = getShell().getDisplay().getClientArea(); - result.x = Math.min(result.x, display.width); - result.y = Math.min(result.y, display.height); - } - return result; - } - - /** - * Initializes itself from the dialog settings with the same state - * as at the previous invocation. - */ - public void readSettings(IDialogSettings section) { - try { - int x = section.getInt(SETTINGS_X_POS); - int y = section.getInt(SETTINGS_Y_POS); - fLocation = new Point(x, y); - int width = section.getInt(SETTINGS_WIDTH); - int height = section.getInt(SETTINGS_HEIGHT); - fSize = new Point(width, height); - - pageSize = section.getInt(PAGE_SIZE); - } catch (NumberFormatException e) { - fLocation = null; - fSize = null; - } - - for(int i = 0; i < iAllTypes.length; i++) { - fFilterMatcher[i] = section.getBoolean(getUniqueStringDescription(i)); - } - - // get the grouped button selection status - groupedButtonSelections[ALL_BUTTON_ID] = section.getBoolean(ALL_BUTTON); - groupedButtonSelections[TYPE_BUTTON_ID] = section.getBoolean(TYPE_BUTTON); - groupedButtonSelections[REF_BUTTON_ID] = section.getBoolean(REF_BUTTON); - groupedButtonSelections[DECL_BUTTON_ID] = section.getBoolean(DECL_BUTTON); - fFilter = section.get(FILTER_TEXT); - if (fFilter == null) - fFilter = BLANK_STRING; - } - - public IndexerFilterManager createFilterManager() { - return new IndexerFilterManager(fFilterMatcher, fFilter); - } - - private void apply() { - fFilter = filterText.getText(); - pageSize=IndexerNodeParent.PAGE_SIZE; - try { - pageSize = Integer.valueOf(pageSizeText.getText()).intValue(); - if (pageSize<=0) - pageSize=IndexerNodeParent.PAGE_SIZE; - } catch (NumberFormatException e) {} - - root.setFilterManager(fFilterMatcher, fFilter); - root.setPageSize(pageSize); - root.reset(); - writeSettings(getDialogSettings()); - } - - public int getPageSize() { - return pageSize; - } - -} diff --git a/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/IndexerView/IndexerFilterManager.java b/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/IndexerView/IndexerFilterManager.java deleted file mode 100644 index 4872abb1f22..00000000000 --- a/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/IndexerView/IndexerFilterManager.java +++ /dev/null @@ -1,44 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005 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 - *******************************************************************************/ -package org.eclipse.cdt.ui.tests.IndexerView; - -/** - * @author dsteffle - */ -public class IndexerFilterManager { - private static final String BLANK_STRING = ""; //$NON-NLS-1$ - private static final String COMMA_SEPARATOR = ","; //$NON-NLS-1$ - boolean [] filters = null; - String nameFilter = null; - String [] nameFilters; - - public IndexerFilterManager(boolean [] filters, String nameFilter) { - this.filters = filters; - this.nameFilter = nameFilter; - nameFilters = nameFilter.split(COMMA_SEPARATOR); - for(int i=0; i<nameFilters.length; i++) { - if (nameFilters != null) nameFilters[i] = nameFilters[i].trim(); - } - - } - - public boolean isFiltered(IndexerNodeLeaf leaf) { - if (!filters[leaf.getFiltersType()]) - return false; - if (leaf.getName() != null && nameFilters != null && nameFilters.length > 0) { - for(int l=0; l<nameFilters.length; l++) - if (nameFilters[l].equals(BLANK_STRING) || leaf.getShortName().matches(nameFilters[l])) - return true; - return false; - } - return true; - } -} diff --git a/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/IndexerView/IndexerNodeLeaf.java b/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/IndexerView/IndexerNodeLeaf.java deleted file mode 100644 index 70b563585ce..00000000000 --- a/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/IndexerView/IndexerNodeLeaf.java +++ /dev/null @@ -1,196 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005 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 - *******************************************************************************/ -package org.eclipse.cdt.ui.tests.IndexerView; - -import org.eclipse.cdt.core.parser.util.ArrayUtil; -import org.eclipse.cdt.internal.core.index.IEntryResult; -import org.eclipse.cdt.internal.core.index.IIndex; -import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.ui.views.properties.IPropertyDescriptor; -import org.eclipse.ui.views.properties.IPropertySource; -import org.eclipse.ui.views.properties.TextPropertyDescriptor; - -/** - * @author dsteffle - */ -public class IndexerNodeLeaf implements IAdaptable { - private static final char EMPTY_SPACE = ' '; - private int filtersType=0; - - private IEntryResult result = null; - private String [] fileMap = null; - - public String[] getFileMap() { - return fileMap; - } - - private IndexerNodeParent parent = null; - - public IndexerNodeLeaf(IEntryResult result, String[] fileMap) { - this.result = result; - this.fileMap = fileMap; - if (result != null) - this.filtersType = IndexerView.getKey(result.getMetaKind(), result.getKind(), result.getRefKind()); - } - - public IndexerNodeParent getParent() { - return parent; - } - - public void setParent(IndexerNodeParent parent) { - this.parent = parent; - } - - public Object getAdapter(Class adapter) { - if (adapter == IPropertySource.class) - return new IndexerPropertySource(result); - - return null; - } - - private class IndexerPropertySource implements IPropertySource { - - private static final String IENTRYRESULT = "IEntryResult"; //$NON-NLS-1$ - private static final String NAME = "Encoded Name"; //$NON-NLS-1$ - private static final String DNAME = "Display Name"; //$NON-NLS-1$ - private static final String IENTRYRESULT_GETWORD__ = "IEntryResult#getWord()"; //$NON-NLS-1$ - private static final String REFS = "References"; //$NON-NLS-1$ - private static final String OFFSETS_LINE = "Line "; //$NON-NLS-1$ - private static final String OFFSETS_OFFSET = "Offset "; //$NON-NLS-1$ - private static final int DEFAULT_DESCRIPTOR_SIZE = 64; - IEntryResult entryResult = null; - - public IndexerPropertySource(IEntryResult result) { - this.entryResult = result; - } - - public Object getEditableValue() { - return null; - } - - public IPropertyDescriptor[] getPropertyDescriptors() { - IPropertyDescriptor[] descriptors = new IPropertyDescriptor[DEFAULT_DESCRIPTOR_SIZE]; - - TextPropertyDescriptor text = null; - - // Add reference block - int[] references = entryResult.getFileReferences(); - int[][]offsets = entryResult.getOffsets(); - int[][]offsetLengths = entryResult.getOffsetLengths(); - if (offsets != null){ - for (int j=0; j<offsets.length; j++){ - String id = fileMap[references[j]]; - String offsetString = ""; //$NON-NLS-1$ - for (int k=0; k<offsets[j].length; k++){ - String rawOffset = String.valueOf(offsets[j][k]) ; - String offsetLocation = String.valueOf(offsetLengths[j][k]); - switch(rawOffset.charAt(0)){ - case '1': - offsetString += OFFSETS_LINE + rawOffset.substring(1) + " "; //$NON-NLS-1$ - break; - case '2': - offsetString += OFFSETS_OFFSET + rawOffset.substring(1) + ":" + offsetLocation + " "; //$NON-NLS-1$ //$NON-NLS-2$ - break; - } - - } - text = new TextPropertyDescriptor(new TextDescriptorId(id, offsetString), id); - text.setCategory(REFS); - descriptors = (IPropertyDescriptor[])ArrayUtil.append(IPropertyDescriptor.class, descriptors, text); - } - } - - // add Name Block - text = new TextPropertyDescriptor(new TextDescriptorId(NAME, entryResult.getName()), NAME); - text.setCategory(IENTRYRESULT); - descriptors = (IPropertyDescriptor[])ArrayUtil.append(IPropertyDescriptor.class, descriptors, text); - - text = new TextPropertyDescriptor(new TextDescriptorId(DNAME, entryResult.getDisplayString()), DNAME); - text.setCategory(IENTRYRESULT); - descriptors = (IPropertyDescriptor[])ArrayUtil.append(IPropertyDescriptor.class, descriptors, text); - - // add IEntryResult - text = new TextPropertyDescriptor(new TextDescriptorId("MetaKind", entryResult.getStringMetaKind()), "MetaKind"); - text.setCategory(IENTRYRESULT); - descriptors = (IPropertyDescriptor[])ArrayUtil.append(IPropertyDescriptor.class, descriptors, text); - - if (entryResult.getMetaKind() == IIndex.TYPE) { - text = new TextPropertyDescriptor(new TextDescriptorId("TypeKind", entryResult.getStringKind()), "TypeKind"); - text.setCategory(IENTRYRESULT); - descriptors = (IPropertyDescriptor[])ArrayUtil.append(IPropertyDescriptor.class, descriptors, text); - } - text = new TextPropertyDescriptor(new TextDescriptorId("ReferenceKind", entryResult.getStringRefKind()), "ReferenceKind"); - text.setCategory(IENTRYRESULT); - descriptors = (IPropertyDescriptor[])ArrayUtil.append(IPropertyDescriptor.class, descriptors, text); - - return (IPropertyDescriptor[])ArrayUtil.trim(IPropertyDescriptor.class, descriptors); - } - - private class TextDescriptorId { - String id = null; - String file = null; - - public TextDescriptorId(String id, String file) { - this.id=id; - this.file=file; - } - - public String getFile() { - return file; - } - - } - - public Object getPropertyValue(Object id) { - if (id instanceof TextDescriptorId) { - return ((TextDescriptorId)id).getFile(); - } - - return null; - } - - public boolean isPropertySet(Object id) { - return false; - } - - public void resetPropertyValue(Object id) { } - - public void setPropertyValue(Object id, Object value) { } - - } - - public IEntryResult getResult() { - return result; - } - - public void setResult(IEntryResult result) { - this.result = result; - } - - public String toString() { - if (!parent.isDisplayFullName()) - return getShortName(); - - return result.getDisplayString(); - } - - public int getFiltersType() { - return filtersType; - } - - public String getName() { - return result.getName(); - } - - public String getShortName() { - return result.extractSimpleName(); - } -} diff --git a/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/IndexerView/IndexerNodeParent.java b/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/IndexerView/IndexerNodeParent.java deleted file mode 100644 index 59d62e449da..00000000000 --- a/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/IndexerView/IndexerNodeParent.java +++ /dev/null @@ -1,283 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005 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 - *******************************************************************************/ -package org.eclipse.cdt.ui.tests.IndexerView; - -import org.eclipse.cdt.core.parser.util.ArrayUtil; -import org.eclipse.cdt.internal.core.index.IEntryResult; -import org.eclipse.cdt.ui.testplugin.CTestPlugin; - -/** - * @author dsteffle - */ -public class IndexerNodeParent extends IndexerNodeLeaf { - public static final int PAGE_SIZE = 40; - private int pageSize=PAGE_SIZE; - private static final IndexerNodeLeaf[] EMPTY_INDEXER_NODE_LEAVES = new IndexerNodeLeaf[0]; - private IndexerNodeLeaf[] children = EMPTY_INDEXER_NODE_LEAVES; - private IndexerNodeLeaf[] childrenToDisplay = new IndexerNodeLeaf[PAGE_SIZE]; - private int lastBackwardDisplayed = 0; - private int lastForwardDisplayed=0; - private boolean isForward=true; - private boolean firstDisplay=true; - private IndexerFilterManager filterManager = null; - private IndexerView.ViewContentProvider view=null; - private boolean sort=true; - private boolean displayFullName=true; - private boolean navigate=false; - private int totalNumberOfFilesIndexed=0; - - public IndexerNodeParent(IEntryResult result, String [] fileMap, IndexerView.ViewContentProvider view) { - super(result, fileMap); - - // create an IndexerFilterManager using the FilterIndexerViewDialog (since all of the work is done there anyways) - FilterIndexerViewDialog dialog = new FilterIndexerViewDialog(CTestPlugin.getStandardDisplay().getActiveShell(), this, view.getProjectName()); - dialog.readSettings(dialog.getDialogSettings()); - - filterManager = dialog.createFilterManager(); - pageSize = dialog.getPageSize(); - - this.view = view; - } - - public IndexerNodeLeaf[] getChildren() { - // if there is nothing to display return an empty list - if (children.length == 0) return EMPTY_INDEXER_NODE_LEAVES; - - // navigate is used to determine if the array should be traversed or not (button pressed or first loading) - if (!navigate) { - return (IndexerNodeLeaf[])ArrayUtil.removeNulls(IndexerNodeLeaf.class, childrenToDisplay); - } else { - navigate = false; - } - - // obey the bounds of the list! - if (!firstDisplay && (!isForward && lastBackwardDisplayed==0 || - isForward && lastForwardDisplayed==children.length-1)) { - if (isForward) - view.setDisplayForwards(false); - else - view.setDisplayBackwards(false); - - return (IndexerNodeLeaf[])ArrayUtil.removeNulls(IndexerNodeLeaf.class, childrenToDisplay); - } - - if (firstDisplay && children.length > 1) { - if (sort) {// sort children based on name - quickSort(children, 0, children.length - 1, true); - } else {// sort children based on word - quickSort(children, 0, children.length - 1, false); - } - } - - int start=0; - if (isForward) { - if (lastForwardDisplayed==0) start=0; - else start=lastForwardDisplayed+1; - } else { - if (lastBackwardDisplayed==0) start=0; - else start=lastBackwardDisplayed-1; - } - boolean shouldDisplay=true; - int numAdded=0; - - int i=start, j=(isForward?0:pageSize-1); - IndexerNodeLeaf[] temp = new IndexerNodeLeaf[pageSize]; - boolean tempIsUseful=false; - while(numAdded<pageSize && i<children.length && i >=0) { - // only add the child to the children to display if it matches the current filters set on the view - shouldDisplay = filterManager.isFiltered(children[i]); - - if (shouldDisplay) { - tempIsUseful=true; - - temp[j] = children[i]; - numAdded++; - if (isForward) lastForwardDisplayed=i; - else if (j==pageSize-1) lastForwardDisplayed=i; - if (j==0) lastBackwardDisplayed=i; - - // move the index to the next entry in the array to store the next valid child to display - if (isForward) { - if (j+1<temp.length) j++; - } else { - if (j-1>=0) j--; - } - } - - shouldDisplay=true; // reset this value - - // move the index to the next child to analyze - if (isForward) { - i++; - } else { - i--; - } - } - - // if there is useful content on the next page, return it, otherwise just return what is being displayed - if (tempIsUseful) { - childrenToDisplay = new IndexerNodeLeaf[pageSize]; // blank the old array being displayed - // copy the temp array into the actual array - for(int k=0, l=0; k<temp.length; k++) { - if (temp[k] != null) { - childrenToDisplay[k] = temp[k]; - l++; - } - } - - if (isForward) { - if (firstDisplay) - view.setDisplayForwards(true); - else - view.setDisplayBackwards(true); - } else { - view.setDisplayForwards(true); - } - } else { - if (isForward) - view.setDisplayForwards(false); - else - view.setDisplayBackwards(false); - } - - firstDisplay=false; - - return (IndexerNodeLeaf[])ArrayUtil.removeNulls(IndexerNodeLeaf.class, childrenToDisplay); - } - - private static void quickSort(IndexerNodeLeaf[] list, int left, int right, boolean sortName) { - int original_left= left; - int original_right= right; - String mid=null; - if (sortName) { - mid= list[(left + right) / 2].getName().toUpperCase(); - } else { - mid= new String(list[(left + right) / 2].getResult().getName()).toUpperCase(); - } - do { - String compareL = null; - String compareR = null; - if (sortName) { - compareL = list[left].getName().toUpperCase(); - compareR = list[right].getName().toUpperCase(); - } else { - compareL = new String(list[left].getResult().getName()).toUpperCase(); - compareR = new String(list[right].getResult().getName()).toUpperCase(); - } - while (compareL.compareTo(mid) < 0) { - left++; - if (sortName) { - compareL = list[left].getName().toUpperCase(); - } else { - compareL = new String(list[left].getResult().getName()).toUpperCase(); - } - } - while (mid.compareTo(compareR) < 0) { - right--; - if (sortName) { - compareR = list[right].getName().toUpperCase(); - } else { - compareR = new String(list[right].getResult().getName()).toUpperCase(); - } - } - if (left <= right) { - IndexerNodeLeaf tmp= list[left]; - list[left]= list[right]; - list[right]= tmp; - left++; - right--; - } - } while (left <= right); - if (original_left < right) { - quickSort(list, original_left, right, sortName); - } - if (left < original_right) { - quickSort(list, left, original_right, sortName); - } - } - - public void setChildren(IndexerNodeLeaf[] children) { - this.children = children; - } - - public boolean hasChildren() { - return (children!=null && children.length > 0); - } - - public int getFullLength() { - return children.length; - } - - public void setIsForward(boolean direction) { - isForward = direction; - } - - public void setFilterManager(boolean [] filters, String filterName) { - this.filterManager = new IndexerFilterManager(filters, filterName); - } - - public void reset() { - navigate=true; - lastBackwardDisplayed = 0; - lastForwardDisplayed=0; - isForward=true; - firstDisplay=true; - childrenToDisplay = EMPTY_INDEXER_NODE_LEAVES; - } - - public void setPageSize(int size) { - pageSize = size; - } - - public void setView(IndexerView.ViewContentProvider view) { - this.view = view; - } - - public int getFilteredCount() { - int filteredCount=0; - for(int i=0; i<children.length; i++) { - if (filterManager.isFiltered(children[i])) filteredCount++; - } - return filteredCount; - } - - public boolean isSort() { - return sort; - } - - public void setSort(boolean sort) { - this.sort = sort; - } - - public boolean isDisplayFullName() { - return displayFullName; - } - - public void setDisplayFullName(boolean displayFullName) { - this.displayFullName = displayFullName; - } - - public boolean isNavigate() { - return navigate; - } - - public void setNavigate(boolean navigate) { - this.navigate = navigate; - } - - public int getTotalNumberOfFilesIndexed() { - return totalNumberOfFilesIndexed; - } - - public void setTotalNumberOfFilesIndexed(int totalNumberOfFilesIndexed) { - this.totalNumberOfFilesIndexed = totalNumberOfFilesIndexed; - } -} diff --git a/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/IndexerView/IndexerQuery.java b/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/IndexerView/IndexerQuery.java deleted file mode 100644 index 1155935906e..00000000000 --- a/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/IndexerView/IndexerQuery.java +++ /dev/null @@ -1,254 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005 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 - *******************************************************************************/ -package org.eclipse.cdt.ui.tests.IndexerView; - -import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.cdt.core.parser.util.ArrayUtil; -import org.eclipse.cdt.core.search.BasicSearchMatch; -import org.eclipse.cdt.core.search.IMatch; -import org.eclipse.cdt.core.search.IMatchLocatable; -import org.eclipse.cdt.core.search.LineLocatable; -import org.eclipse.cdt.core.search.OffsetLocatable; -import org.eclipse.cdt.internal.core.index.IEntryResult; -import org.eclipse.cdt.internal.core.index.IIndex; -import org.eclipse.cdt.internal.ui.search.CSearchQuery; -import org.eclipse.cdt.internal.ui.search.CSearchResult; -import org.eclipse.cdt.internal.ui.search.NewSearchResultCollector; -import org.eclipse.cdt.ui.testplugin.CTestPlugin; -import org.eclipse.cdt.utils.PathUtil; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.OperationCanceledException; -import org.eclipse.core.runtime.Path; -import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.SubProgressMonitor; -import org.eclipse.search.ui.ISearchQuery; -import org.eclipse.search.ui.ISearchResult; - -/** - * @author dsteffle - */ -public class IndexerQuery extends CSearchQuery implements ISearchQuery { - private static final int DEFAULT_MATCH_INFO_SIZE = 4; - private static final String BLANK_STRING = ""; //$NON-NLS-1$ - private CSearchResult _result; - private IndexerNodeLeaf leaf=null; - private String queryLabel = null; - - /** - * - */ - public IndexerQuery(IndexerNodeLeaf leaf, String queryLabel, String pattern) { - super(CTestPlugin.getWorkspace(), pattern, false, null, null, null, queryLabel); - this.leaf = leaf; - this.queryLabel = queryLabel; - } - - /* (non-Javadoc) - * @see org.eclipse.search.ui.ISearchQuery#run(org.eclipse.core.runtime.IProgressMonitor) - */ - public IStatus run(IProgressMonitor monitor) - throws OperationCanceledException { - - final CSearchResult textResult= (CSearchResult) getSearchResult(); - - IProgressMonitor mainSearchPM= new SubProgressMonitor(monitor, 1000); - NewSearchResultCollector collector = new NewSearchResultCollector(textResult, mainSearchPM); - - collector.aboutToStart(); - - MatchInfo[] matches = generateMatchInfo(); - for (int i=0; i<matches.length; i++) { - try { - if ( matches[i] != null ) { - Object fileResource = null; - IResource tempResource = matches[i].getResource(); - IPath tempPath = matches[i].getPath(); - //Determine whether this match is internal (ie. has a resource) or - //external (ie. has a path) and create a match based on the result - if (tempResource != null) - fileResource =tempResource; - else - fileResource = tempPath; - collector.acceptMatch( createMatch(fileResource, matches[i].getOffsetType(), matches[i].getStart(), - matches[i].getEnd(), matches[i].getName(), matches[i].getPath()) ); - } - } catch (CoreException ce) {} - } - - mainSearchPM.done(); - collector.done(); - - return new Status(IStatus.OK, CTestPlugin.getPluginId(), 0, BLANK_STRING, null); //$NON-NLS-1$ - } - - private MatchInfo[] generateMatchInfo() { - String [] fileMap = leaf.getFileMap(); - IEntryResult entryResult = leaf.getResult(); - MatchInfo[] matches = new MatchInfo[DEFAULT_MATCH_INFO_SIZE]; - - int[] references = entryResult.getFileReferences(); - int[][]offsets = entryResult.getOffsets(); - int[][]offsetLengths = entryResult.getOffsetLengths(); - if (offsets != null){ - for (int j=0; j<offsets.length; j++){ - for (int k=0; k<offsets[j].length; k++){ - MatchInfo match = new MatchInfo(); - if (references.length > j-1) { - String file = fileMap[references[j]]; - if (file != null){ - IPath filePath = new Path(file); - //If we can verify that the file exists within the workspace, we'll use it - //to open the appropriate editor - if not we can just set the path and we'll - //use the external editor mechanism - IFile tempFile = ResourcesPlugin.getWorkspace().getRoot().getFile(filePath); - if (tempFile != null && tempFile.exists()) - match.setResource(tempFile); - else { - match.setPath(PathUtil.getWorkspaceRelativePath(file)); - } - - } - } - int offsetType=0; - int start=0; - int end=0; - try { - offsetType=Integer.valueOf(String.valueOf(offsets[j][k]).substring(0,1)).intValue(); - start=Integer.valueOf(String.valueOf(offsets[j][k]).substring(1)).intValue(); - end=start+offsetLengths[j][k]; - } catch (NumberFormatException nfe) {} - - match.setOffsetType(offsetType); - match.setStart(start) ; - match.setEnd(end); - match.setName(leaf.getName()); - - matches = (MatchInfo[])ArrayUtil.append(MatchInfo.class, matches, match); - } - } - } - - return matches; - } - - private class MatchInfo { - private IPath path=null; - private int offsetType=0; - private int start=0; - private int end=0; - private String name=null; - private IResource resource=null; - - public IPath getPath() { - return path; - } - public void setOffsetType(int offsetType){ - this.offsetType=offsetType; - } - public int getOffsetType() { - return offsetType; - } - public void setPath(IPath path) { - this.path = path; - } - public int getEnd() { - return end; - } - public void setEnd(int end) { - this.end = end; - } - public String getName() { - return name; - } - public void setName(String name) { - this.name = name; - } - public int getStart() { - return start; - } - public void setStart(int start) { - this.start = start; - } - public IResource getResource() { - return resource; - } - public void setResource(IResource resource) { - this.resource = resource; - } - } - - public IMatch createMatch( Object fileResource,int offsetType, int start, int end, String name, IPath referringElement ) { - BasicSearchMatch result = new BasicSearchMatch(); - if( fileResource instanceof IResource ) - result.setResource((IResource) fileResource); - else if( fileResource instanceof IPath ) - result.setPath((IPath) fileResource); - - IMatchLocatable locatable=null; - if (offsetType == IIndex.LINE) - { - locatable = new LineLocatable(start,end); - } - else if (offsetType == IIndex.OFFSET){ - locatable = new OffsetLocatable(start,end); - } - result.setLocatable(locatable); - result.setParentName(BLANK_STRING); //$NON-NLS-1$ - result.setReferringElement(referringElement); - - result.setName(name); - - result.setType(ICElement.C_FIELD); // TODO Devin static for now, want something like BasicSearchResultCollector#setElementInfo - result.setVisibility(ICElement.CPP_PUBLIC); // TODO Devin static for now, want something like BasicSearchResultCollector#setElementInfo - result.setReturnType(BLANK_STRING); - - return result; - } - - - /* (non-Javadoc) - * @see org.eclipse.search.ui.ISearchQuery#getLabel() - */ - public String getLabel() { - return queryLabel; - } - - /* (non-Javadoc) - * @see org.eclipse.search.ui.ISearchQuery#canRerun() - */ - public boolean canRerun() { - // TODO Auto-generated method stub - return false; - } - - /* (non-Javadoc) - * @see org.eclipse.search.ui.ISearchQuery#canRunInBackground() - */ - public boolean canRunInBackground() { - return true; - } - - /* (non-Javadoc) - * @see org.eclipse.search.ui.ISearchQuery#getSearchResult() - */ - public ISearchResult getSearchResult() { - if (_result == null) - _result= new CSearchResult(this); - return _result; - } - -} diff --git a/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/IndexerView/IndexerView.java b/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/IndexerView/IndexerView.java deleted file mode 100644 index 78ea8b6f43f..00000000000 --- a/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/IndexerView/IndexerView.java +++ /dev/null @@ -1,618 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005 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 - *******************************************************************************/ -package org.eclipse.cdt.ui.tests.IndexerView; - -import java.io.IOException; - -import org.eclipse.cdt.core.index.ICDTIndexer; -import org.eclipse.cdt.internal.core.index.IEntryResult; -import org.eclipse.cdt.internal.core.index.IIndex; -import org.eclipse.cdt.ui.testplugin.CTestPlugin; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.jobs.Job; -import org.eclipse.jface.action.Action; -import org.eclipse.jface.action.IMenuListener; -import org.eclipse.jface.action.IMenuManager; -import org.eclipse.jface.action.IToolBarManager; -import org.eclipse.jface.action.MenuManager; -import org.eclipse.jface.action.Separator; -import org.eclipse.jface.dialogs.IDialogConstants; -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.ISelectionChangedListener; -import org.eclipse.jface.viewers.IStructuredContentProvider; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.ITreeContentProvider; -import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.jface.viewers.SelectionChangedEvent; -import org.eclipse.jface.viewers.TableViewer; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.jface.viewers.ViewerFilter; -import org.eclipse.search.ui.NewSearchUI; -import org.eclipse.swt.SWT; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Menu; -import org.eclipse.swt.widgets.TableItem; -import org.eclipse.ui.IActionBars; -import org.eclipse.ui.IViewPart; -import org.eclipse.ui.IWorkbenchActionConstants; -import org.eclipse.ui.part.ViewPart; -import org.eclipse.ui.views.properties.PropertySheet; - -/** - * @author dsteffle - */ -public class IndexerView extends ViewPart { - private static final int DEFAULT_INDEXER_SIZE = 1; - private static final String SWITCH_FULL_NAMES = "Switch Full Names"; //$NON-NLS-1$ - private static final String SORT_RESULTS = "Sort Results"; //$NON-NLS-1$ - private static final String SEARCH_LOCATIONS = "Search Locations"; //$NON-NLS-1$ - private static final String _TOTAL_IENTRYRESULTS = " total IEntryResults\n"; //$NON-NLS-1$ - private static final String _FILTERED_IENTRY_RESULTS_ = " filtered IEntry Results\n"; //$NON-NLS-1$ - private static final String _TOTAL_INDEXEDFILES = " total files indexed"; //$NON-NLS-1$ - private static final String INDEXER_STATS = "Indexer Stats"; //$NON-NLS-1$ - private static final String DISPLAY_INDEX_STATS = "Display Index Stats"; //$NON-NLS-1$ - private static final String INDEXER_VIEW___ = "Indexer View - "; //$NON-NLS-1$ - private static final String _INDEXER_MENU_MANAGER = "#Indexer_Menu_Manager"; //$NON-NLS-1$ - private static final String SET_FILTERS = "Set Filters"; //$NON-NLS-1$ - private static final String NEXT_PAGE = "Next Page"; //$NON-NLS-1$ - private static final String PREVIOUS_PAGE = "Previous Page"; //$NON-NLS-1$ - public static final String VIEW_ID = "org.eclipse.cdt.ui.tests.IndexerView"; //$NON-NLS-1$ - private static final String PROPERTIES_VIEW = "org.eclipse.ui.views.PropertySheet"; //$NON-NLS-1$ - protected static final String BLANK_STRING = ""; //$NON-NLS-1$ - static TableViewer viewer; - protected Action searchLocationAction; - protected Action previousPageAction; - protected Action nextPageAction; - protected Action singleClickAction; - protected Action setFiltersAction; - protected Action sortAction; - protected Action displayFullNameAction; - protected Action displayStatsAction; - protected ICDTIndexer[] indexers = new ICDTIndexer[DEFAULT_INDEXER_SIZE]; // support 1 indexer for now new IIndexer[CTestPlugin.getWorkspace().getRoot().getProjects().length]; - protected IProject project = null; - - protected static ViewContentProvider.StartInitializingIndexerView initializeIndexerViewJob = null; - - public class ViewContentProvider implements IStructuredContentProvider, - ITreeContentProvider { - - private static final String POPULATING_INDEXER_VIEW = "populating indexer view"; //$NON-NLS-1$ - protected IndexerNodeParent invisibleRoot; - - protected boolean displayForwards=false; - protected boolean displayBackwards=false; - - private class InitializeView extends Job { - private static final String NULL_PROJECT_SELECTED = "A null project was selected."; //$NON-NLS-1$ - private static final String ALL_NAME_SEARCH = "*"; //$NON-NLS-1$ - private static final String INDEXER_VIEW = "Indexer View"; //$NON-NLS-1$ - TableViewer theViewer = null; - - public InitializeView(String name, TableViewer viewer) { - super(name); - this.theViewer = viewer; - } - - protected IStatus run(IProgressMonitor monitor) { - - for(int i=0; i<indexers.length; i++) { - if (indexers[i] instanceof ICDTIndexer) { - if (project == null) { - CTestPlugin.getStandardDisplay().asyncExec(new Runnable() { - public void run() { - MessageDialog.openInformation(theViewer.getControl().getShell(), INDEXER_VIEW, - NULL_PROJECT_SELECTED); - } - }); - - return Status.CANCEL_STATUS; - } - - IIndex index = ((ICDTIndexer)indexers[i]).getIndex(project.getFullPath(), true, true); - - if (index==null) return Status.CANCEL_STATUS; - - try { - IEntryResult[] results = index.getEntries(IIndex.ANY, IIndex.ANY, IIndex.ANY ); - - - if (results == null) return Status.CANCEL_STATUS; - String [] fileMap = index.getDocumentList(); - //Subtract 1 to take into account null in position 0 - invisibleRoot.setTotalNumberOfFilesIndexed(fileMap.length - 1); - - int size = results.length; - IndexerNodeLeaf[] children = new IndexerNodeLeaf[size]; - for(int j=0; j<size; j++) { - children[j] = new IndexerNodeLeaf(results[j], fileMap); - children[j].setParent(invisibleRoot); - } - - invisibleRoot.setChildren(children); - - invisibleRoot.setIsForward(true); // initial display direction is forward - } catch (IOException e) { - e.printStackTrace(); - } - } - } - - return Status.OK_STATUS; - } - } - - public class InitializeRunnable implements Runnable { - TableViewer view = null; - boolean updateView = true; - - public InitializeRunnable(TableViewer view, boolean updateView) { - this.view = view; - this.updateView = updateView; - } - - /* (non-Javadoc) - * @see java.lang.Runnable#run() - */ - public void run() { - if (!updateView) return; - - enableButtons(false); - view.refresh(); - - if (view.getTable().getItems().length > 0) { - TableItem[] selection = new TableItem[1]; - selection[0] = view.getTable().getItems()[0]; - - // select the first item to prevent it from being selected accidentally (and possibly switching editors accidentally) - view.getTable().setSelection(selection); - } - - enableButtons(true); - previousPageAction.setEnabled(displayBackwards); - nextPageAction.setEnabled(displayForwards); - } - } - - private class StartInitializingIndexerView extends Job { - private static final String INITIALIZE_INDEXER_VIEW = "initialize Indexer View"; //$NON-NLS-1$ - InitializeView job = null; - boolean updateView=true; - - public StartInitializingIndexerView(InitializeView job, boolean updateView) { - super(INITIALIZE_INDEXER_VIEW); - this.job = job; - this.updateView = updateView; - } - - protected IStatus run(IProgressMonitor monitor) { - job.schedule(); - - try { - job.join(); - } catch (InterruptedException ie) { - return Status.CANCEL_STATUS; - } - - CTestPlugin.getStandardDisplay().asyncExec(new InitializeRunnable(viewer, updateView)); // update the view from the Display thread - - updateView=true; - - return job.getResult(); - } - } - - public ViewContentProvider() { - this(null, false, false); - } - - public void setDisplayForwards(boolean displayForwards) { - this.displayForwards = displayForwards; - } - - public void setDisplayBackwards(boolean displayBackwards) { - this.displayBackwards = displayBackwards; - } - - public ViewContentProvider(IndexerNodeParent parent, boolean displayForwards, boolean displayBackwards) { - if (parent == null) { - invisibleRoot = new IndexerNodeParent(null, null, this); - initializeIndexerViewJob = new StartInitializingIndexerView(new InitializeView(POPULATING_INDEXER_VIEW, viewer), true); - initializeIndexerViewJob.schedule(); - } else { - invisibleRoot = parent; - initializeIndexerViewJob = new StartInitializingIndexerView(new InitializeView(POPULATING_INDEXER_VIEW, viewer), false); - initializeIndexerViewJob.schedule(); - } - - invisibleRoot.reset(); - this.displayForwards=displayForwards; - this.displayBackwards=displayBackwards; - } - - public Object[] getElements(Object inputElement) { - if (inputElement.equals(getViewSite())) { - return getChildren(invisibleRoot); - } - return getChildren(inputElement); - } - - public void dispose() {} - - public void inputChanged(Viewer aViewer, Object oldInput, Object newInput) { - // TODO Auto-generated method stub - } - - public Object[] getChildren(Object parentElement) { - if (parentElement instanceof IndexerNodeParent) { - return ((IndexerNodeParent) parentElement).getChildren(); - } - return new Object[0]; - } - - public Object getParent(Object element) { - if (element instanceof IndexerNodeLeaf) { - return ((IndexerNodeLeaf) element).getParent(); - } - return null; - } - - public boolean hasChildren(Object element) { - if (element instanceof IndexerNodeParent) - return ((IndexerNodeParent) element).hasChildren(); - return false; - } - - public IndexerNodeParent getInvisibleRoot() { - return invisibleRoot; - } - - public boolean isDisplayForwards() { - return displayForwards; - } - - public boolean isDisplayBackwards() { - return displayBackwards; - } - - public String getProjectName() { - if (project == null) return BLANK_STRING; - - return project.getName(); - } - } - - class ViewLabelProvider extends LabelProvider { - - public String getText(Object obj) { - if (obj == null) return BLANK_STRING; - return obj.toString(); - } - - public Image getImage(Object obj) { - if (obj instanceof IndexerNodeLeaf) { - IEntryResult result = ((IndexerNodeLeaf)obj).getResult(); - int index = getKey(result.getMetaKind(), result.getKind(), result.getRefKind()); - if (index > -1) - return IndexerViewPluginImages.get(index); - } - - return IndexerViewPluginImages.get(IndexerViewPluginImages.IMG_WARNING); - } - } - - public void createPartControl(Composite parent) { - viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL); - - viewer.setContentProvider(new ViewContentProvider()); - - viewer.setLabelProvider(new ViewLabelProvider()); - viewer.setInput(getViewSite()); - - makeActions(); - hookContextMenu(); - hookSingleClickAction(); - - contributeToActionBars(); - } - - protected void enableButtons(boolean value) { - setFiltersAction.setEnabled(value); - setFiltersAction.setEnabled(value); - sortAction.setEnabled(value); - displayFullNameAction.setEnabled(value); - } - - private void makeActions() { - searchLocationAction = new SearchLocationsAction(); - searchLocationAction.setText(SEARCH_LOCATIONS); - searchLocationAction.setToolTipText(SEARCH_LOCATIONS); - searchLocationAction.setImageDescriptor(IndexerViewPluginImages.DESC_SEARCH_LOCATION); - - previousPageAction = new Action() { - public void run() { - if (viewer.getContentProvider() instanceof ViewContentProvider) { - IndexerNodeParent root = ((ViewContentProvider)viewer.getContentProvider()).getInvisibleRoot(); - root.setIsForward(false); - root.setNavigate(true); - } - viewer.refresh(); - - setEnabled(((ViewContentProvider)viewer.getContentProvider()).isDisplayBackwards()); - nextPageAction.setEnabled(((ViewContentProvider)viewer.getContentProvider()).isDisplayForwards()); - } - }; - previousPageAction.setText(PREVIOUS_PAGE); - previousPageAction.setToolTipText(PREVIOUS_PAGE); - previousPageAction.setImageDescriptor(IndexerViewPluginImages.DESC_BACK); - - nextPageAction = new Action() { - public void run() { - if (viewer.getContentProvider() instanceof ViewContentProvider) { - IndexerNodeParent root = ((ViewContentProvider)viewer.getContentProvider()).getInvisibleRoot(); - root.setIsForward(true); - root.setNavigate(true); - } - viewer.refresh(); - - previousPageAction.setEnabled(((ViewContentProvider)viewer.getContentProvider()).isDisplayBackwards()); - setEnabled(((ViewContentProvider)viewer.getContentProvider()).isDisplayForwards()); - } - }; - nextPageAction.setText(NEXT_PAGE); - nextPageAction.setToolTipText(NEXT_PAGE); - nextPageAction.setImageDescriptor(IndexerViewPluginImages.DESC_NEXT); - - setFiltersAction = new Action() { - public void run() { - if (!(viewer.getContentProvider() instanceof ViewContentProvider)) return; - - FilterIndexerViewDialog dialog = new FilterIndexerViewDialog(getSite().getShell(), ((ViewContentProvider)viewer.getContentProvider()).getInvisibleRoot(), (project==null?BLANK_STRING:project.getName())); - int result = dialog.open(); - - if (result == IDialogConstants.OK_ID) { - // reset the view but remember the buttons being displayed from the old content provider - ((ViewContentProvider)viewer.getContentProvider()).getInvisibleRoot().reset(); - viewer.refresh(); - } - } - }; - setFiltersAction.setText(SET_FILTERS); - setFiltersAction.setToolTipText(SET_FILTERS); - setFiltersAction.setImageDescriptor(IndexerViewPluginImages.DESC_FILTER_BUTTON); - - sortAction = new Action() { - public void run() { - if (viewer.getContentProvider() instanceof ViewContentProvider) { - enableButtons(false); - if (((ViewContentProvider)viewer.getContentProvider()).getInvisibleRoot().isSort()) { - ((ViewContentProvider)viewer.getContentProvider()).getInvisibleRoot().setSort(false); - ((ViewContentProvider)viewer.getContentProvider()).getInvisibleRoot().reset(); - viewer.refresh(); - this.setImageDescriptor(IndexerViewPluginImages.DESC_SORT); - } else { - ((ViewContentProvider)viewer.getContentProvider()).getInvisibleRoot().setSort(true); - ((ViewContentProvider)viewer.getContentProvider()).getInvisibleRoot().reset(); - viewer.refresh(); - this.setImageDescriptor(IndexerViewPluginImages.DESC_SORTED); - } - enableButtons(true); - } - } - }; - sortAction.setText(SORT_RESULTS); - sortAction.setToolTipText(SORT_RESULTS); - sortAction.setImageDescriptor(IndexerViewPluginImages.DESC_SORTED); - - displayFullNameAction = new Action() { - public void run() { - if (viewer.getContentProvider() instanceof ViewContentProvider) { - if (((ViewContentProvider)viewer.getContentProvider()).getInvisibleRoot().isDisplayFullName()) { - ((ViewContentProvider)viewer.getContentProvider()).getInvisibleRoot().setDisplayFullName(false); - viewer.refresh(); - this.setImageDescriptor(IndexerViewPluginImages.DESC_DISPLAY_FULL_NAME); - } else { - ((ViewContentProvider)viewer.getContentProvider()).getInvisibleRoot().setDisplayFullName(true); - viewer.refresh(); - this.setImageDescriptor(IndexerViewPluginImages.DESC_FULL_NAME_DISPLAYED); - } - } - } - }; - displayFullNameAction.setText(SWITCH_FULL_NAMES); - displayFullNameAction.setToolTipText(SWITCH_FULL_NAMES); - displayFullNameAction.setImageDescriptor(IndexerViewPluginImages.DESC_FULL_NAME_DISPLAYED); - - displayStatsAction = new Action() { - public void run() { - CTestPlugin.getStandardDisplay().asyncExec(new Runnable() { - public void run() { - if (viewer.getContentProvider() instanceof ViewContentProvider) { - IndexerNodeParent root = ((ViewContentProvider)viewer.getContentProvider()).getInvisibleRoot(); - - MessageDialog.openInformation(getSite().getShell(), INDEXER_STATS, - root.getFilteredCount() + _FILTERED_IENTRY_RESULTS_ + root.getFullLength() + _TOTAL_IENTRYRESULTS + root.getTotalNumberOfFilesIndexed() + _TOTAL_INDEXEDFILES); - } - } - }); - } - }; - displayStatsAction.setText(DISPLAY_INDEX_STATS); - displayStatsAction.setToolTipText(DISPLAY_INDEX_STATS); - displayStatsAction.setImageDescriptor(IndexerViewPluginImages.DESC_STATS); - - singleClickAction = new IndexerHighlighterAction(); - } - - private void hookContextMenu() { - MenuManager menuMgr = new MenuManager(_INDEXER_MENU_MANAGER); - menuMgr.setRemoveAllWhenShown(true); - menuMgr.addMenuListener(new IMenuListener() { - private void hideMenuItems(IMenuManager manager) { - } - - public void menuAboutToShow(IMenuManager manager) { - IndexerView.this.fillContextMenu(manager); - hideMenuItems(manager); - } - }); - Menu menu = menuMgr.createContextMenu(viewer.getControl()); - viewer.getControl().setMenu(menu); - getSite().registerContextMenu(menuMgr, viewer); - } - - void fillContextMenu(IMenuManager manager) { - manager.add(searchLocationAction); - manager.add(new Separator()); - // Other plug-ins can contribute there actions here - manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS)); - } - - private class IndexerHighlighterAction extends Action { - public void run() { - ISelection selection = viewer.getSelection(); - - IViewPart part = getSite().getPage().findView(PROPERTIES_VIEW); - if (part instanceof PropertySheet) { - ((PropertySheet)part).selectionChanged(getSite().getPart(), selection); - } - } - } - - private void hookSingleClickAction() { - viewer.addSelectionChangedListener(new ISelectionChangedListener() { - public void selectionChanged(SelectionChangedEvent event) { - singleClickAction.run(); - } - }); - } - - private void contributeToActionBars() { - IActionBars bars = getViewSite().getActionBars(); - fillLocalPullDown(bars.getMenuManager()); - fillLocalToolBar(bars.getToolBarManager()); - } - - private void fillLocalPullDown(IMenuManager manager) {} - - private void fillLocalToolBar(IToolBarManager manager) { - manager.add(previousPageAction); - manager.add(nextPageAction); - manager.add(new Separator()); - manager.add(sortAction); - manager.add(displayFullNameAction); - manager.add(setFiltersAction); - manager.add(new Separator()); - manager.add(displayStatsAction); - manager.add(new Separator()); - } - - public void setFocus() { - IViewPart part = getSite().getPage().findView(PROPERTIES_VIEW); - if (part instanceof PropertySheet) { - ((PropertySheet)part).selectionChanged(getSite().getPart(), viewer.getSelection()); - } - } - - public void appendIndexer(ICDTIndexer indexer) { -// indexers = (IIndexer[])ArrayUtil.append(IIndexer.class, indexers, indexer); - // only support 1 indexer for now - indexers[0] = indexer; - } - - public void clearIndexers() { - // for now only support 1 indexer at a time - indexers = new ICDTIndexer[1]; - } - - public void setContentProvider(ViewContentProvider provider) { - viewer.setContentProvider(provider); - } - - public void setProject(IProject project) { - this.setPartName(INDEXER_VIEW___ + project.getName()); - this.project=project; - } - - public static ViewerFilter[] getViewerFilters() { - return viewer.getFilters(); - } - - public String getProjectName() { - if (project == null) return BLANK_STRING; - - return project.getName(); - } - - private class SearchLocationsAction extends Action { - private static final String LOCATIONS = "Locations"; //$NON-NLS-1$ - private static final String INDEX = "Index"; //$NON-NLS-1$ - protected void displayLocations(IndexerNodeLeaf leaf, String queryLabel, String pattern) { - IndexerQuery job = new IndexerQuery(leaf, queryLabel, pattern); - NewSearchUI.activateSearchResultView(); - NewSearchUI.runQueryInBackground(job); - } - - public void run() { - if (viewer.getSelection() instanceof IStructuredSelection && - ((IStructuredSelection)viewer.getSelection()).getFirstElement() instanceof IndexerNodeLeaf) { - displayLocations((IndexerNodeLeaf)((IStructuredSelection)viewer.getSelection()).getFirstElement(), - INDEX, LOCATIONS); - } - } - } - - public static int getKey(int meta, int kind, int ref) { - switch (ref) { - case IIndex.REFERENCE : - switch (meta) { - case IIndex.TYPE : return FilterIndexerViewDialog.ENTRY_TYPE_REF; - case IIndex.FUNCTION : return FilterIndexerViewDialog.ENTRY_FUNCTION_REF; - case IIndex.METHOD : return FilterIndexerViewDialog.ENTRY_METHOD_REF; - case IIndex.FIELD : return FilterIndexerViewDialog.ENTRY_FIELD_REF; - case IIndex.MACRO : return -1; - case IIndex.NAMESPACE : return FilterIndexerViewDialog.ENTRY_NAMESPACE_REF; - case IIndex.ENUMTOR : return FilterIndexerViewDialog.ENTRY_ENUMTOR_REF; - case IIndex.INCLUDE : return FilterIndexerViewDialog.ENTRY_INCLUDE_REF; - case IIndex.VAR : return FilterIndexerViewDialog.ENTRY_TYPE_DECL_VAR; - } - break; - case IIndex.DEFINITION : - case IIndex.DECLARATION : - switch (meta) { - case IIndex.TYPE : - switch (kind) { - case IIndex.TYPE_CLASS : return FilterIndexerViewDialog.ENTRY_TYPE_DECL_CLASS; - case IIndex.TYPE_STRUCT : return FilterIndexerViewDialog.ENTRY_TYPE_DECL_STRUCT; - case IIndex.TYPE_UNION : return FilterIndexerViewDialog.ENTRY_TYPE_DECL_UNION; - case IIndex.TYPE_ENUM : return FilterIndexerViewDialog.ENTRY_TYPE_DECL_ENUM; - case IIndex.TYPE_TYPEDEF : return FilterIndexerViewDialog.ENTRY_TYPE_DECL_TYPEDEF; - case IIndex.TYPE_DERIVED : return FilterIndexerViewDialog.ENTRY_TYPE_DECL_DERIVED; - case IIndex.TYPE_FRIEND : return FilterIndexerViewDialog.ENTRY_TYPE_DECL_FRIEND; - } - case IIndex.FUNCTION : return FilterIndexerViewDialog.ENTRY_FUNCTION_DECL; - case IIndex.METHOD : return FilterIndexerViewDialog.ENTRY_METHOD_DECL; - case IIndex.FIELD : return FilterIndexerViewDialog.ENTRY_FIELD_DECL; - case IIndex.MACRO : return FilterIndexerViewDialog.ENTRY_MACRO_DECL; - case IIndex.NAMESPACE : return FilterIndexerViewDialog.ENTRY_NAMESPACE_DECL; - case IIndex.ENUMTOR : return FilterIndexerViewDialog.ENTRY_ENUMTOR_DECL; - case IIndex.INCLUDE : return -1; - case IIndex.VAR : return FilterIndexerViewDialog.ENTRY_TYPE_DECL_VAR; - } - break; - } - return 0; - } -} diff --git a/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/IndexerView/IndexerViewPluginImages.java b/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/IndexerView/IndexerViewPluginImages.java deleted file mode 100644 index 663a445838d..00000000000 --- a/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/IndexerView/IndexerViewPluginImages.java +++ /dev/null @@ -1,150 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005 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 - *******************************************************************************/ -package org.eclipse.cdt.ui.tests.IndexerView; - -import java.net.MalformedURLException; -import java.net.URL; - -import org.eclipse.cdt.ui.CUIPlugin; -import org.eclipse.cdt.ui.testplugin.CTestPlugin; -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.jface.resource.ImageRegistry; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.widgets.Display; - -/** - * @author dsteffle - */ -public class IndexerViewPluginImages { - private static ImageRegistry imageRegistry = new ImageRegistry(CUIPlugin.getStandardDisplay()); - - /** - * Returns the standard display to be used. The method first checks, if - * the thread calling this method has an associated display. If so, this - * display is returned. Otherwise the method returns the default display. - */ - public static Display getStandardDisplay() { - Display display= Display.getCurrent(); - if (display == null) { - display= Display.getDefault(); - } - return display; - } - - // Subdirectory (under the package containing this class) where 16 color images are - private static URL fgIconBaseURL; - - static { - try { - fgIconBaseURL= new URL(CTestPlugin.getDefault().getBundle().getEntry("/"), "icons/" ); //$NON-NLS-1$ //$NON-NLS-2$ - } catch (MalformedURLException e) {} - } - public static final String PLUGIN_ID = "org.eclipse.cdt.testplugin.CTestPlugin"; //$NON-NLS-1$ - public static final String NAME_PREFIX= PLUGIN_ID + '.'; - private static final int NAME_PREFIX_LENGTH= NAME_PREFIX.length(); - public static final String ICON_PREFIX= "indexer_view/"; //$NON-NLS-1$ - - public static final String [] icon_images = { - "macroDecl_obj.gif", - "function_obj.gif", - "namespace_obj.gif", - "function_ref_obj.gif", - "namespace_ref_obj.gif", - "field_obj.gif", - "enumerator_obj.gif", - "method_public_obj.gif", - "field_ref_obj.gif", - "enumerator_ref_obj.gif", - "method_public_ref_obj.gif", - "typedecl_ref_obj.gif", - "typedef_obj.gif", - "class_obj.gif", - "variable_obj.gif", - "struct_obj.gif", - "enum_obj.gif", - "union_obj.gif", - "derived.gif", - "friend.gif", - "include_obj.gif" - }; - - public static final String IMG_REF= NAME_PREFIX + "ref_obj.gif"; //$NON-NLS-1$ - public static final String IMG_TYPE_DECL= NAME_PREFIX + "typedecl_obj.gif"; //$NON-NLS-1$ - public static final String IMG_SUPER_REF= NAME_PREFIX + "super_co.gif"; //$NON-NLS-1$ - public static final String IMG_BACK= NAME_PREFIX + "ngback.gif"; //$NON-NLS-1$ - public static final String IMG_NEXT= NAME_PREFIX + "ngnext.gif"; //$NON-NLS-1$ - public static final String IMG_WARNING= NAME_PREFIX + "warning_icon.gif"; //$NON-NLS-1$ - public static final String IMG_FILTER_BUTTON= NAME_PREFIX + "filterbutton.gif"; //$NON-NLS-1$ - public static final String IMG_STATS= NAME_PREFIX + "stats.gif"; //$NON-NLS-1$ - public static final String IMG_GROUPED_ALL= NAME_PREFIX + "grouped_all.gif"; //$NON-NLS-1$ - public static final String IMG_GROUPED_DECL= NAME_PREFIX + "grouped_decl.gif"; //$NON-NLS-1$ - public static final String IMG_GROUPED_REF= NAME_PREFIX + "grouped_ref.gif"; //$NON-NLS-1$ - public static final String IMG_GROUPED_TYPE= NAME_PREFIX + "grouped_type.gif"; //$NON-NLS-1$ - public static final String IMG_SEARCH_LOCATION= NAME_PREFIX + "search_decl_obj.gif"; //$NON-NLS-1$ - public static final String IMG_SORT= NAME_PREFIX + "alphab_sort.gif"; //$NON-NLS-1$ - public static final String IMG_SORTED= NAME_PREFIX + "alphab_sorted.gif"; //$NON-NLS-1$ - public static final String IMG_FULL_NAME_DISPLAYED= NAME_PREFIX + "full_name_displayed.gif"; //$NON-NLS-1$ - public static final String IMG_DISPLAY_FULL_NAME= NAME_PREFIX + "display_full_name.gif"; //$NON-NLS-1$ - - public static final ImageDescriptor DESC_REF= createManaged(ICON_PREFIX, IMG_REF); - static { - for (int i = 0 ; i < icon_images.length; i++) { - createManaged(ICON_PREFIX, NAME_PREFIX + icon_images[i]); - } - createManaged(ICON_PREFIX, IMG_TYPE_DECL); - createManaged(ICON_PREFIX, IMG_SUPER_REF); - createManaged(ICON_PREFIX, IMG_WARNING); - createManaged(ICON_PREFIX, IMG_GROUPED_ALL); - createManaged(ICON_PREFIX, IMG_GROUPED_DECL); - createManaged(ICON_PREFIX, IMG_GROUPED_REF); - createManaged(ICON_PREFIX, IMG_GROUPED_TYPE); - } - - public static final ImageDescriptor DESC_BACK= createManaged(ICON_PREFIX, IMG_BACK); - public static final ImageDescriptor DESC_NEXT= createManaged(ICON_PREFIX, IMG_NEXT); - public static final ImageDescriptor DESC_FILTER_BUTTON= createManaged(ICON_PREFIX, IMG_FILTER_BUTTON); - public static final ImageDescriptor DESC_STATS= createManaged(ICON_PREFIX, IMG_STATS); - public static final ImageDescriptor DESC_SEARCH_LOCATION= createManaged(ICON_PREFIX, IMG_SEARCH_LOCATION); - public static final ImageDescriptor DESC_SORT= createManaged(ICON_PREFIX, IMG_SORT); - public static final ImageDescriptor DESC_SORTED= createManaged(ICON_PREFIX, IMG_SORTED); - public static final ImageDescriptor DESC_FULL_NAME_DISPLAYED= createManaged(ICON_PREFIX, IMG_FULL_NAME_DISPLAYED); - public static final ImageDescriptor DESC_DISPLAY_FULL_NAME= createManaged(ICON_PREFIX, IMG_DISPLAY_FULL_NAME); - - private static ImageDescriptor createManaged(String prefix, String name) { - return createManaged(imageRegistry, prefix, name); - } - - private static ImageDescriptor createManaged(ImageRegistry registry, String prefix, String name) { - ImageDescriptor result= ImageDescriptor.createFromURL(makeIconFileURL(prefix, name.substring(NAME_PREFIX_LENGTH))); - registry.put(name, result); - return result; - } - - private static URL makeIconFileURL(String prefix, String name) { - StringBuffer buffer= new StringBuffer(prefix); - buffer.append(name); - try { - return new URL(fgIconBaseURL, buffer.toString()); - } catch (MalformedURLException e) { - CUIPlugin.getDefault().log(e); - return null; - } - } - - public static Image get(String key) { - return imageRegistry.get(key); - } - public static Image get(int key) { - return imageRegistry.get(NAME_PREFIX + icon_images[key]); - } - - -} diff --git a/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/IndexerView/OpenIndexerViewAction.java b/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/IndexerView/OpenIndexerViewAction.java deleted file mode 100644 index 777e77c2053..00000000000 --- a/core/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/ui/tests/IndexerView/OpenIndexerViewAction.java +++ /dev/null @@ -1,80 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005 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 - *******************************************************************************/ -package org.eclipse.cdt.ui.tests.IndexerView; - -import org.eclipse.cdt.core.CCorePlugin; -import org.eclipse.cdt.core.index.ICDTIndexer; -import org.eclipse.cdt.internal.core.model.CProject; -import org.eclipse.core.resources.IProject; -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.ui.IEditorActionDelegate; -import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.IObjectActionDelegate; -import org.eclipse.ui.IViewActionDelegate; -import org.eclipse.ui.IViewPart; -import org.eclipse.ui.IWorkbenchPart; -import org.eclipse.ui.PartInitException; - -/** - * @author dsteffle - */ -public class OpenIndexerViewAction implements IViewActionDelegate, - IEditorActionDelegate, IObjectActionDelegate { - - IViewPart viewPart = null; - IProject proj = null; - public static int numViewsOpen=0; - - public void init(IViewPart view) { - this.viewPart = view; - } - - public void run(IAction action) { - IViewPart tempView = null; - - try { - tempView = viewPart.getSite().getPage().showView(IndexerView.VIEW_ID); - if (tempView instanceof IndexerView) - ((IndexerView)tempView).setProject(proj); - - OpenIndexerViewAction.numViewsOpen++; - } catch (PartInitException pie) {} - - if (tempView != null) { - if (tempView instanceof IndexerView) { - ((IndexerView)tempView).clearIndexers(); - ICDTIndexer indexer = CCorePlugin.getDefault().getCoreModel().getIndexManager().getIndexerForProject(proj); - ((IndexerView)tempView).appendIndexer(indexer); - ((IndexerView)tempView).setContentProvider(((IndexerView)tempView).new ViewContentProvider()); - } - } - - viewPart.getSite().getPage().activate(tempView); - } - - public void selectionChanged(IAction action, ISelection selection) { - if (selection instanceof IStructuredSelection && - ((IStructuredSelection)selection).getFirstElement() instanceof CProject) { - proj = ((CProject)((IStructuredSelection)selection).getFirstElement()).getProject(); - } - } - - public void setActiveEditor(IAction action, IEditorPart targetEditor) { - // TODO Auto-generated method stub - } - - public void setActivePart(IAction action, IWorkbenchPart targetPart) { - // TODO Auto-generated method stub - } - -} diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/AutomatedSuite.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/AutomatedSuite.java index b524a06b5cc..7e2d3aa2bd8 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/AutomatedSuite.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/AutomatedSuite.java @@ -13,7 +13,6 @@ package org.eclipse.cdt.ui.tests; import junit.framework.Test; import junit.framework.TestSuite; -import org.eclipse.cdt.ui.tests.regression.RegressionTestsUISuite; import org.eclipse.cdt.ui.tests.text.contentassist.CompletionFailedTest_MemberReference_Arrow_Prefix2; import org.eclipse.cdt.ui.tests.text.contentassist.CompletionTest_ArgumentType_NoPrefix; import org.eclipse.cdt.ui.tests.text.contentassist.CompletionTest_ArgumentType_NoPrefix2; @@ -121,7 +120,6 @@ public class AutomatedSuite extends TestSuite { addTest(CompletionTest_VariableType_NestedPrefix.suite()); addTest( ContentAssistTests.suite() ); - addTest( RegressionTestsUISuite.suite() ); // Failed Tests addTest(CompletionFailedTest_MemberReference_Arrow_Prefix2.suite()); @@ -136,4 +134,3 @@ public class AutomatedSuite extends TestSuite { } } - diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/regression/ContentAssistRegressionTests.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/regression/ContentAssistRegressionTests.java deleted file mode 100644 index 23c4282f5ef..00000000000 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/regression/ContentAssistRegressionTests.java +++ /dev/null @@ -1,1853 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2005 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 Corporation - initial API and implementation - *******************************************************************************/ - -/* - * Created on Oct 4, 2004 - */ -package org.eclipse.cdt.ui.tests.regression; - -import java.io.StringWriter; - -import junit.framework.Test; -import junit.framework.TestSuite; - -import org.eclipse.cdt.core.model.CModelException; -import org.eclipse.cdt.core.model.CoreModel; -import org.eclipse.cdt.core.model.ITranslationUnit; -import org.eclipse.cdt.core.model.IWorkingCopy; -import org.eclipse.cdt.core.tests.BaseTestFramework; -import org.eclipse.cdt.core.tests.FailingTest; -import org.eclipse.cdt.internal.core.browser.cache.TypeCacheManager; -import org.eclipse.cdt.internal.ui.CHelpProviderManager; -import org.eclipse.cdt.internal.ui.text.CHelpBookDescriptor; -import org.eclipse.cdt.internal.ui.text.contentassist.CCompletionProcessor; -import org.eclipse.cdt.ui.text.ICHelpInvocationContext; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.jface.text.Document; -import org.eclipse.jface.text.contentassist.ICompletionProposal; - -/** - * @author aniefer - */ -public class ContentAssistRegressionTests extends BaseTestFramework { - static boolean disabledHelpContributions = false; - final int TIMEOUT = 100; - public ContentAssistRegressionTests() - { - super(); - } - /** - * @param name - */ - public ContentAssistRegressionTests(String name) - { - super(name); - } - - protected void setUp() throws Exception { - //TEMPORARY: Disable Type Cache - super.setUp(); - TypeCacheManager typeCacheManager = TypeCacheManager.getInstance(); - typeCacheManager.setProcessTypeCacheEvents(false); - } - - private void disableContributions (){ - //disable the help books so we don't get proposals we weren't expecting - final IProject proj = project; - CHelpBookDescriptor helpBooks[]; - helpBooks = CHelpProviderManager.getDefault().getCHelpBookDescriptors(new ICHelpInvocationContext(){ - public IProject getProject(){return proj;} - public ITranslationUnit getTranslationUnit(){return null;} - } - ); - for( int i = 0; i < helpBooks.length; i++ ){ - if( helpBooks[i] != null ) - helpBooks[i].enable( false ); - } - } - protected ICompletionProposal[] getResults( IFile file, int offset ) throws Exception { - if( !disabledHelpContributions ) - disableContributions(); - ITranslationUnit tu = (ITranslationUnit)CoreModel.getDefault().create( file ); - String buffer = tu.getBuffer().getContents(); - IWorkingCopy wc = null; - try{ - wc = tu.getWorkingCopy(); - }catch (CModelException e){ - fail("Failed to get working copy"); //$NON-NLS-1$ - } - - // call the CompletionProcessor - CCompletionProcessor completionProcessor = new CCompletionProcessor(null); - ICompletionProposal[] results = completionProcessor.evalProposals( new Document(buffer), offset, wc, null); - //This should be replaced with a notification from the CCompletionProcessor - Thread.sleep(TIMEOUT); - return ( results != null ? results : new ICompletionProposal [0] ); - } - - public static Test suite(){ - return suite( true ); - } - public static Test suite( boolean cleanup ) { - TestSuite suite = new TestSuite("ContentAssistRegressionTests"); //$NON-NLS-1$ - suite.addTest( new ContentAssistRegressionTests("testMemberCompletion") ); //$NON-NLS-1$ - suite.addTest( new ContentAssistRegressionTests("testUnqualifiedWithPrefix") ); //$NON-NLS-1$ - suite.addTest( new ContentAssistRegressionTests("testQualifiedWithPrefix") ); //$NON-NLS-1$ - suite.addTest( new FailingTest(new ContentAssistRegressionTests("test76398"),76398) ); //$NON-NLS-1$ - suite.addTest( new ContentAssistRegressionTests("testQualifiedNoPrefix") ); //$NON-NLS-1$ - suite.addTest( new ContentAssistRegressionTests("testSourceExtensions") ); //$NON-NLS-1$ - suite.addTest( new FailingTest(new ContentAssistRegressionTests("test76480"),76480) ); //$NON-NLS-1$ - suite.addTest( new ContentAssistRegressionTests("testField") ); //$NON-NLS-1$ - suite.addTest( new ContentAssistRegressionTests("testFieldExpression") ); //$NON-NLS-1$ - suite.addTest( new ContentAssistRegressionTests("testScope") ); //$NON-NLS-1$ - suite.addTest( new ContentAssistRegressionTests("testClass") ); //$NON-NLS-1$ - suite.addTest( new FailingTest(new ContentAssistRegressionTests("test72723"),72723) ); //$NON-NLS-1$ - suite.addTest( new FailingTest(new ContentAssistRegressionTests("test72541"),72541) ); //$NON-NLS-1$ - suite.addTest( new ContentAssistRegressionTests("testFunction") ); //$NON-NLS-1$ - suite.addTest( new ContentAssistRegressionTests("testArgument") ); //$NON-NLS-1$ - suite.addTest( new FailingTest(new ContentAssistRegressionTests("test76805"),76805) ); //$NON-NLS-1$ - suite.addTest( new ContentAssistRegressionTests("testCStyleCast") ); //$NON-NLS-1$ - suite.addTest( new ContentAssistRegressionTests("testMethod") ); //$NON-NLS-1$ - suite.addTest( new ContentAssistRegressionTests("testEnumerations") ); //$NON-NLS-1$ - suite.addTest( new ContentAssistRegressionTests("testLongTokens") ); //$NON-NLS-1$ - suite.addTest( new ContentAssistRegressionTests("testCastMultiLevel") ); //$NON-NLS-1$ - suite.addTest( new ContentAssistRegressionTests("testHeaderExtensions") ); //$NON-NLS-1$ - suite.addTest( new ContentAssistRegressionTests("testEmptyDocument") ); //$NON-NLS-1$ - suite.addTest( new ContentAssistRegressionTests("testVariable") ); //$NON-NLS-1$ - suite.addTest( new FailingTest(new ContentAssistRegressionTests("test80510"),80510) ); //$NON-NLS-1$ - suite.addTest( new ContentAssistRegressionTests("testSingleNameReference") ); //$NON-NLS-1$ - suite.addTest( new ContentAssistRegressionTests("testNamespace") ); //$NON-NLS-1$ - suite.addTest( new FailingTest(new ContentAssistRegressionTests("testNamespaceAlias80612"),80612) ); //$NON-NLS-1$ - suite.addTest( new ContentAssistRegressionTests("testMacro") ); //$NON-NLS-1$ - suite.addTest( new ContentAssistRegressionTests("testConstructor") ); //$NON-NLS-1$ - suite.addTest( new ContentAssistRegressionTests("testUnion") ); //$NON-NLS-1$ - suite.addTest( new ContentAssistRegressionTests("testKeyword") ); //$NON-NLS-1$ - suite.addTest( new ContentAssistRegressionTests("testBase") ); //$NON-NLS-1$ - suite.addTest( new ContentAssistRegressionTests("testThis") ); //$NON-NLS-1$ - suite.addTest( new ContentAssistRegressionTests("testClassScope") ); //$NON-NLS-1$ - suite.addTest( new FailingTest(new ContentAssistRegressionTests("testClassScope72564"),72564) ); //$NON-NLS-1$ - suite.addTest( new ContentAssistRegressionTests("testMultiLevelQualifiers") ); //$NON-NLS-1$ - suite.addTest( new ContentAssistRegressionTests("testCase") ); //$NON-NLS-1$ - suite.addTest( new ContentAssistRegressionTests("testType") ); //$NON-NLS-1$ - suite.addTest( new ContentAssistRegressionTests("testTryCatch") ); //$NON-NLS-1$ - suite.addTest( new ContentAssistRegressionTests("testArrays") ); //$NON-NLS-1$ - suite.addTest( new ContentAssistRegressionTests("testStruct") ); //$NON-NLS-1$ - - //Test framework doesn't include templates - //suite.addTest( new ContentAssistRegressionTests("testCodeTemplate") ); //$NON-NLS-1$ - - if( cleanup ) - suite.addTest( new ContentAssistRegressionTests("cleanupProject") ); //$NON-NLS-1$ - - return suite; - } - - public void removeFile(String filename) throws Exception { - IResource [] members = project.members(); - for( int i = 0; i < members.length; i++ ){ - if( members[i].getName().equals( filename ) ) - members[i].delete( false, monitor ); - } - } - public void testMemberCompletion() throws Exception { - StringWriter writer = new StringWriter(); - writer.write("class A { \n"); //$NON-NLS-1$ - writer.write(" int var; \n"); //$NON-NLS-1$ - writer.write(" void f(); \n"); //$NON-NLS-1$ - writer.write("}; \n"); //$NON-NLS-1$ - writer.write("void A::f(){ \n"); //$NON-NLS-1$ - writer.write(" v[^] \n"); //$NON-NLS-1$ - writer.write("} \n"); //$NON-NLS-1$ - - String code = writer.toString(); - IFile t = importFile( "testMemberCompletion.cpp", code ); //$NON-NLS-1$ - ICompletionProposal [] results = getResults( t, code.indexOf( "[^]" ) ); //$NON-NLS-1$ - - assertEquals( 4, results.length); - assertEquals( "var : int", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( "virtual", results[1].getDisplayString()); //$NON-NLS-1$ - assertEquals( "void", results[2].getDisplayString()); //$NON-NLS-1$ - assertEquals( "volatile", results[3].getDisplayString()); //$NON-NLS-1$ - } - //test 1 with prefix 'z', inside various scopes - public void testUnqualifiedWithPrefix() throws Exception { - StringWriter writer = new StringWriter(); - writer.write("int zVar0; \n"); //$NON-NLS-1$ - writer.write("class zClass { \n"); //$NON-NLS-1$ - writer.write("public: \n"); //$NON-NLS-1$ - writer.write(" zClass(); \n"); //$NON-NLS-1$ - writer.write(" int zField; \n"); //$NON-NLS-1$ - writer.write(" void zMethod(); \n"); //$NON-NLS-1$ - writer.write("}; \n"); //$NON-NLS-1$ - writer.write("void zFunction0(); \n"); //$NON-NLS-1$ - - String codeH = writer.toString(); - importFile( "testUnqualifiedWithPrefix.h", codeH ); //$NON-NLS-1$ - - writer = new StringWriter(); - writer.write("#include \"testUnqualifiedWithPrefix.h\" \n"); //$NON-NLS-1$ - writer.write("int zVar; \n"); //$NON-NLS-1$ - writer.write("void zFunction(bool); \n"); //$NON-NLS-1$ - writer.write("struct zStruct { int b;}; \n"); //$NON-NLS-1$ - writer.write("zClass c;//vp1 \n"); //$NON-NLS-1$ - writer.write("namespace test { \n"); //$NON-NLS-1$ - writer.write(" zStruct s;//vp2 \n"); //$NON-NLS-1$ - writer.write(" const int zVar = zVar0 + zVar;//vp3 \n"); //$NON-NLS-1$ - writer.write("} \n"); //$NON-NLS-1$ - writer.write("int main(int argc, char **argv) { \n"); //$NON-NLS-1$ - writer.write(" zVar=0;//vp4 \n"); //$NON-NLS-1$ - writer.write(" using namespace test; \n"); //$NON-NLS-1$ - writer.write(" zClass c2;//vp5 \n"); //$NON-NLS-1$ - writer.write(" ::zVar=0;//vp6 \n"); //$NON-NLS-1$ - writer.write(" test::zVar;//vp7 \n"); //$NON-NLS-1$ - writer.write(" return (0); \n"); //$NON-NLS-1$ - writer.write("} \n"); //$NON-NLS-1$ - writer.write("void zClass::zMethod(){ \n"); //$NON-NLS-1$ - writer.write(" zField=0;//vp8 \n"); //$NON-NLS-1$ - writer.write("} \n"); //$NON-NLS-1$ - String code = writer.toString(); - IFile t = importFile( "testUnqualifiedWithPrefix.cpp", code ); //$NON-NLS-1$ - //vp1 - ICompletionProposal [] results = getResults( t, code.indexOf( "Class c;//vp1" ) ); //$NON-NLS-1$ - assertEquals( 2, results.length); - assertEquals( "zClass", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( "zStruct", results[1].getDisplayString()); //$NON-NLS-1$ - //vp2 - results = getResults( t, code.indexOf( "Struct s;//vp2" ) ); //$NON-NLS-1$ - assertEquals( 2, results.length); - assertEquals( "zClass", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( "zStruct", results[1].getDisplayString()); //$NON-NLS-1$ - //vp3 - results = getResults( t, code.indexOf( "Var0 + zVar;//vp3" ) ); //$NON-NLS-1$ - assertEquals( 6, results.length); - assertEquals( "zVar : int", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( "zVar0 : int", results[1].getDisplayString()); //$NON-NLS-1$ - assertEquals( "zFunction(bool) void", results[2].getDisplayString()); //$NON-NLS-1$ - assertEquals( "zFunction0() void", results[3].getDisplayString()); //$NON-NLS-1$ - assertEquals( "zClass", results[4].getDisplayString()); //$NON-NLS-1$ - assertEquals( "zStruct", results[5].getDisplayString()); //$NON-NLS-1$ - //vp4 - results = getResults( t, code.indexOf( "Var=0;//vp4" ) ); //$NON-NLS-1$ - assertEquals( 6, results.length); - assertEquals( "zVar : int", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( "zVar0 : int", results[1].getDisplayString()); //$NON-NLS-1$ - assertEquals( "zFunction(bool) void", results[2].getDisplayString()); //$NON-NLS-1$ - assertEquals( "zFunction0() void", results[3].getDisplayString()); //$NON-NLS-1$ - assertEquals( "zClass", results[4].getDisplayString()); //$NON-NLS-1$ - assertEquals( "zStruct", results[5].getDisplayString()); //$NON-NLS-1$ - //vp5 zVar is ambiguous so it won't show up - results = getResults( t, code.indexOf( "Class c2;//vp5" ) ); //$NON-NLS-1$ - assertEquals( 5, results.length); - assertEquals( "zVar0 : int", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( "zFunction(bool) void", results[1].getDisplayString()); //$NON-NLS-1$ - assertEquals( "zFunction0() void", results[2].getDisplayString()); //$NON-NLS-1$ - assertEquals( "zClass", results[3].getDisplayString()); //$NON-NLS-1$ - assertEquals( "zStruct", results[4].getDisplayString()); //$NON-NLS-1$ - //vp6 - results = getResults( t, code.indexOf( "Var=0;//vp6" ) ); //$NON-NLS-1$ - assertEquals( 6, results.length); - assertEquals( "zVar : int", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( "zVar0 : int", results[1].getDisplayString()); //$NON-NLS-1$ - //vp7 - results = getResults( t, code.indexOf( "Var;//vp7" ) ); //$NON-NLS-1$ - assertEquals( 1, results.length); - assertEquals( "zVar : const int", results[0].getDisplayString()); //$NON-NLS-1$ - //vp8 - results = getResults( t, code.indexOf( "Field=0;//vp8" ) ); //$NON-NLS-1$ - assertEquals( 8, results.length); - assertEquals( "zField : int", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( "zMethod() void", results[3].getDisplayString()); //$NON-NLS-1$ - - } - //test 2 with prefix 'z', qualified, inside 4 scopes - public void testQualifiedWithPrefix() throws Exception { - StringWriter writer = new StringWriter(); - writer.write("class zClass { \n"); //$NON-NLS-1$ - writer.write(" public: \n"); //$NON-NLS-1$ - writer.write(" zClass(){} \n"); //$NON-NLS-1$ - writer.write(" static const int zField=1; \n"); //$NON-NLS-1$ - writer.write(" void zMethod(); \n"); //$NON-NLS-1$ - writer.write("}; \n"); //$NON-NLS-1$ - writer.write("int zVar0; \n"); //$NON-NLS-1$ - writer.write(" void zFunction0(); \n"); //$NON-NLS-1$ - - String codeH = writer.toString(); - importFile( "testQualifiedWithPrefix.h", codeH ); //$NON-NLS-1$ - - writer = new StringWriter(); - writer.write("#include \"testQualifiedWithPrefix.h\" \n"); //$NON-NLS-1$ - writer.write("zClass c; \n"); //$NON-NLS-1$ - writer.write("int i = c.zField;//vp1-2res \n"); //$NON-NLS-1$ - writer.write("namespace test { \n"); //$NON-NLS-1$ - writer.write(" zClass c; \n"); //$NON-NLS-1$ - writer.write(" int i=c.zField;//vp2-2res \n"); //$NON-NLS-1$ - writer.write("} \n"); //$NON-NLS-1$ - writer.write("int main(int argc, char **argv) { \n"); //$NON-NLS-1$ - writer.write(" c.zField;//vp3-2res \n"); //$NON-NLS-1$ - writer.write(" using namespace test; \n"); //$NON-NLS-1$ - writer.write(" //c.z;//vpxxx defect 76398 \n"); //$NON-NLS-1$ - writer.write(" ::c.zMethod();//vp4-2res \n"); //$NON-NLS-1$ - writer.write(" test::c.zField;//vp5-2res \n"); //$NON-NLS-1$ - writer.write(" return (0); \n"); //$NON-NLS-1$ - writer.write("} \n"); //$NON-NLS-1$ - writer.write("void zClass::zMethod(){ \n"); //$NON-NLS-1$ - writer.write(" zzClass zz; \n"); //$NON-NLS-1$ - writer.write(" zz.zMethod();//vp6 \n"); //$NON-NLS-1$ - writer.write("} \n"); //$NON-NLS-1$ - - String code = writer.toString(); - IFile t = importFile( "testQualifiedWithPrefix.cpp", code ); //$NON-NLS-1$ - //vp1 global scope - ICompletionProposal [] results = getResults( t, code.indexOf( "Field;//vp1" ) ); //$NON-NLS-1$ - assertEquals( 2, results.length); - assertEquals( "zField : const int", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( "zMethod() void", results[1].getDisplayString()); //$NON-NLS-1$ - //vp2 namespace scope - results = getResults( t, code.indexOf( "Field;//vp2" ) ); //$NON-NLS-1$ - assertEquals( 2, results.length); - assertEquals( "zField : const int", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( "zMethod() void", results[1].getDisplayString()); //$NON-NLS-1$ - //vp3 function scope, global class member ref - results = getResults( t, code.indexOf( "Field;//vp3" ) ); //$NON-NLS-1$ - assertEquals( 2, results.length); - assertEquals( "zField : const int", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( "zMethod() void", results[1].getDisplayString()); //$NON-NLS-1$ - //vp4 function scope, ambiguous clarified(global) class member ref - results = getResults( t, code.indexOf( "Method();//vp4" ) ); //$NON-NLS-1$ - assertEquals( 2, results.length); - assertEquals( "zField : const int", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( "zMethod() void", results[1].getDisplayString()); //$NON-NLS-1$ - //vp5 function scope, ambiguous clarified(namespace) class member ref - results = getResults( t, code.indexOf( "Field;//vp5" ) ); //$NON-NLS-1$ - assertEquals( 2, results.length); - assertEquals( "zField : const int", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( "zMethod() void", results[1].getDisplayString()); //$NON-NLS-1$ - //vp6 method scope - results = getResults( t, code.indexOf( "Method();//vp6" ) ); //$NON-NLS-1$ - assertEquals( 2, results.length); - assertEquals( "zField : const int", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( "zMethod() void", results[1].getDisplayString()); //$NON-NLS-1$ - - } - //with prefix 'z', qualified, inside function scope - ////76398 function scope, ambiguous unclarified class member ref - public void test76398() throws Exception { - StringWriter writer = new StringWriter(); - writer.write("class zClass { \n"); //$NON-NLS-1$ - writer.write(" public: \n"); //$NON-NLS-1$ - writer.write(" zClass(){} \n"); //$NON-NLS-1$ - writer.write(" static const int zField=1; \n"); //$NON-NLS-1$ - writer.write(" void zMethod(); \n"); //$NON-NLS-1$ - writer.write("}; \n"); //$NON-NLS-1$ - writer.write("int zVar0; \n"); //$NON-NLS-1$ - writer.write("void zFunction0(); \n"); //$NON-NLS-1$ - writer.write("zClass c; \n"); //$NON-NLS-1$ - writer.write("namespace test { \n"); //$NON-NLS-1$ - writer.write(" zClass c; \n"); //$NON-NLS-1$ - writer.write("} \n"); //$NON-NLS-1$ - writer.write("int main(int argc, char **argv) { \n"); //$NON-NLS-1$ - writer.write(" c.zField;//vp3-function scope,2res \n"); //$NON-NLS-1$ - writer.write(" using namespace test; \n"); //$NON-NLS-1$ - writer.write(" c.z;//76398 \n"); //$NON-NLS-1$ - writer.write(" return (0); \n"); //$NON-NLS-1$ - writer.write("} \n"); //$NON-NLS-1$ - - String code = writer.toString(); - IFile t = importFile( "test76398.cpp", code ); //$NON-NLS-1$ - //should not show completions for zField, zMethod since they are - // ambiguous - //The defect is the zVar0 and zFunction0 and zClass are showing up when - // they shouldn't - ICompletionProposal [] results = getResults( t, code.indexOf( ";//76398" ) ); //$NON-NLS-1$ - assertEquals( 0, results.length); - } -// test 3 without prefix 'z', qualified, inside scopes - public void testQualifiedNoPrefix() throws Exception { - StringWriter writer = new StringWriter(); - writer.write("class zClass { \n"); //$NON-NLS-1$ - writer.write(" public: \n"); //$NON-NLS-1$ - writer.write(" zClass(){} \n"); //$NON-NLS-1$ - writer.write(" static const int zField=1; \n"); //$NON-NLS-1$ - writer.write(" int zMethod(int i); \n"); //$NON-NLS-1$ - writer.write("}; \n"); //$NON-NLS-1$ - writer.write("zClass c; \n"); //$NON-NLS-1$ - writer.write("int i = c.zField;//vp1-2res \n"); //$NON-NLS-1$ - writer.write("namespace test { \n"); //$NON-NLS-1$ - writer.write(" zClass c; \n"); //$NON-NLS-1$ - writer.write(" int i=c.zField;//vp2-2res \n"); //$NON-NLS-1$ - writer.write("} \n"); //$NON-NLS-1$ - writer.write("int main(int argc, char **argv) { \n"); //$NON-NLS-1$ - writer.write(" c.zField;//vp3-2res \n"); //$NON-NLS-1$ - writer.write(" using namespace test; \n"); //$NON-NLS-1$ - writer.write(" ::c.zMethod(3);//vp4-2res \n"); //$NON-NLS-1$ - writer.write(" test::c.zField;//vp5-2res \n"); //$NON-NLS-1$ - writer.write(" return (0); \n"); //$NON-NLS-1$ - writer.write("} \n"); //$NON-NLS-1$ - writer.write("int zClass::zMethod(int i){ \n"); //$NON-NLS-1$ - writer.write(" if (i==0) return (0); \n"); //$NON-NLS-1$ - writer.write(" zClass zz; \n"); //$NON-NLS-1$ - writer.write(" return (zz.zMethod(i-1));//vp6 \n"); //$NON-NLS-1$ - writer.write("} \n"); //$NON-NLS-1$ - - String code = writer.toString(); - IFile t = importFile( "testQualifiedNoPrefix.cpp", code ); //$NON-NLS-1$ - //vp1 global scope - ICompletionProposal [] results = getResults( t, code.indexOf( "zField;//vp1" ) ); //$NON-NLS-1$ - assertEquals( 2, results.length); - assertEquals( "zField : const int", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( "zMethod(int) int", results[1].getDisplayString()); //$NON-NLS-1$ - //vp2 namespace scope - results = getResults( t, code.indexOf( "zField;//vp2" ) ); //$NON-NLS-1$ - assertEquals( 2, results.length); - assertEquals( "zField : const int", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( "zMethod(int) int", results[1].getDisplayString()); //$NON-NLS-1$ - //vp3 function scope, global class member ref - results = getResults( t, code.indexOf( "zField;//vp3" ) ); //$NON-NLS-1$ - assertEquals( 2, results.length); - assertEquals( "zField : const int", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( "zMethod(int) int", results[1].getDisplayString()); //$NON-NLS-1$ - //vp4 function scope, ambiguous clarified(global) class member ref - results = getResults( t, code.indexOf( "zMethod(3);//vp4" ) ); //$NON-NLS-1$ - assertEquals( 2, results.length); - assertEquals( "zField : const int", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( "zMethod(int) int", results[1].getDisplayString()); //$NON-NLS-1$ - //vp5 function scope, ambiguous clarified(namespace) class member ref - results = getResults( t, code.indexOf( "zField;//vp5" ) ); //$NON-NLS-1$ - assertEquals( 2, results.length); - assertEquals( "zField : const int", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( "zMethod(int) int", results[1].getDisplayString()); //$NON-NLS-1$ - //vp6 method scope - results = getResults( t, code.indexOf( "zMethod(i-1));//vp6" ) ); //$NON-NLS-1$ - assertEquals( 2, results.length); - assertEquals( "zField : const int", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( "zMethod(int) int", results[1].getDisplayString()); //$NON-NLS-1$ - - } - // test 7 different file types - public void testSourceExtensions() throws Exception { - StringWriter writer = new StringWriter(); - writer.write("int zVar; \n"); //$NON-NLS-1$ - writer.write("int zFunction(int); \n"); //$NON-NLS-1$ - writer.write("struct zStruct {int b;}; \n"); //$NON-NLS-1$ - writer.write("struct zStruct a;//vp1-1res \n"); //$NON-NLS-1$ - writer.write("int main(int argc, char **argv) { \n"); //$NON-NLS-1$ - writer.write(" zVar=0;//vp2-3res \n"); //$NON-NLS-1$ - writer.write(" return (0); \n"); //$NON-NLS-1$ - writer.write("} \n"); //$NON-NLS-1$ - String code = writer.toString(); - IFile t = importFile( "testSourceExtensions.c", code ); //$NON-NLS-1$ - //vp1 cfile global scope - ICompletionProposal [] results = getResults( t, code.indexOf( "Struct a;//vp1" ) ); //$NON-NLS-1$ - assertEquals( 1, results.length); - assertEquals( "zStruct", results[0].getDisplayString()); //$NON-NLS-1$ - //vp2 c file function scope - results = getResults( t, code.indexOf( "Var=0;//vp2" ) ); //$NON-NLS-1$ - assertEquals( 3, results.length); - assertEquals( "zVar : int", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( "zFunction(int) int", results[1].getDisplayString()); //$NON-NLS-1$ - assertEquals( "zStruct", results[2].getDisplayString()); //$NON-NLS-1$ - - removeFile("testSourceExtensions.c"); //$NON-NLS-1$ - t = importFile( "testSourceExtensions.C", code ); //$NON-NLS-1$ - //vp1 C file global scope - results = getResults( t, code.indexOf( "Struct a;//vp1" ) ); //$NON-NLS-1$ - assertEquals( 1, results.length); - assertEquals( "zStruct", results[0].getDisplayString()); //$NON-NLS-1$ - //vp2 C file function scope - results = getResults( t, code.indexOf( "Var=0;//vp2" ) ); //$NON-NLS-1$ - assertEquals( 3, results.length); - assertEquals( "zVar : int", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( "zFunction(int) int", results[1].getDisplayString()); //$NON-NLS-1$ - assertEquals( "zStruct", results[2].getDisplayString()); //$NON-NLS-1$ - removeFile("testSourceExtensions.C"); //$NON-NLS-1$ - t = importFile( "testSourceExtensions.cxx", code ); //$NON-NLS-1$ - //vp1 cxx file global scope - results = getResults( t, code.indexOf( "Struct a;//vp1" ) ); //$NON-NLS-1$ - assertEquals( 1, results.length); - assertEquals( "zStruct", results[0].getDisplayString()); //$NON-NLS-1$ - //vp2 css file function scope - results = getResults( t, code.indexOf( "Var=0;//vp2" ) ); //$NON-NLS-1$ - assertEquals( 3, results.length); - assertEquals( "zVar : int", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( "zFunction(int) int", results[1].getDisplayString()); //$NON-NLS-1$ - assertEquals( "zStruct", results[2].getDisplayString()); //$NON-NLS-1$ - removeFile("testSourceExtensions.cxx"); //$NON-NLS-1$ - t = importFile( "testSourceExtensions.cc", code ); //$NON-NLS-1$ - //vp1 cc file global scope - results = getResults( t, code.indexOf( "Struct a;//vp1" ) ); //$NON-NLS-1$ - assertEquals( 1, results.length); - assertEquals( "zStruct", results[0].getDisplayString()); //$NON-NLS-1$ - //vp2 cc file function scope - results = getResults( t, code.indexOf( "Var=0;//vp2" ) ); //$NON-NLS-1$ - assertEquals( 3, results.length); - assertEquals( "zVar : int", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( "zFunction(int) int", results[1].getDisplayString()); //$NON-NLS-1$ - assertEquals( "zStruct", results[2].getDisplayString()); //$NON-NLS-1$ - - } - //c code scope operator shouldn't provide CA contributions - public void test76480() throws Exception { - StringWriter writer = new StringWriter(); - writer.write("int zVar; \n"); //$NON-NLS-1$ - writer.write("int zFunction(int); \n"); //$NON-NLS-1$ - writer.write("struct zStruct {int b;}; \n"); //$NON-NLS-1$ - writer.write("int main(int argc, char **argv) { \n"); //$NON-NLS-1$ - writer.write(" ::zVar=0;//vp1-0res \n"); //$NON-NLS-1$ - writer.write(" return (0); \n"); //$NON-NLS-1$ - writer.write("} \n"); //$NON-NLS-1$ - String code = writer.toString(); - IFile t = importFile( "test76480.c", code ); //$NON-NLS-1$ - //vp1 function scope - ICompletionProposal [] results = getResults( t, code.indexOf( "Var=0;//vp1" ) ); //$NON-NLS-1$ - assertEquals( 0, results.length); - - } - // test27: Complete on a field type - // named struct with bitfield & typedef struct - public void testField() throws Exception { - StringWriter writer = new StringWriter(); - writer = new StringWriter(); - writer.write("struct simplestruct { \n"); //$NON-NLS-1$ - writer.write(" unsigned field1: 2; // range 0-3 \n"); //$NON-NLS-1$ - writer.write(" unsigned int field2: 1; // range 0-1 \n"); //$NON-NLS-1$ - writer.write("}; \n"); //$NON-NLS-1$ - writer.write("typedef struct { \n"); //$NON-NLS-1$ - writer.write(" static int const field2=5; \n"); //$NON-NLS-1$ - writer.write("} structtype; \n"); //$NON-NLS-1$ - writer.write("class A{ \n"); //$NON-NLS-1$ - writer.write(" public: struct {int aa;} a; \n"); //$NON-NLS-1$ - writer.write("}; \n"); //$NON-NLS-1$ - writer.write("int main(int argc, char **argv) { \n"); //$NON-NLS-1$ - writer.write(" struct simplestruct aStruct={3,0}, *pStruct;\n"); //$NON-NLS-1$ - writer.write(" aStruct.field1;//vp1 \n"); //$NON-NLS-1$ - writer.write(" pStruct->field1;//vp2 \n"); //$NON-NLS-1$ - writer.write(" structtype anotherStruct; \n"); //$NON-NLS-1$ - writer.write(" structtype::field2;//vp3 \n"); //$NON-NLS-1$ - writer.write(" class A myClass; \n"); //$NON-NLS-1$ - writer.write(" int i = myClass.a.aa;//vp4 \n"); //$NON-NLS-1$ - writer.write(" return (0); \n"); //$NON-NLS-1$ - writer.write("} \n"); //$NON-NLS-1$ - String code = writer.toString(); - IFile t = importFile( "testField.cpp", code ); //$NON-NLS-1$ - //vp1 bitfield accessed from named struct with "." - ICompletionProposal [] results = getResults( t, code.indexOf( "field1;//vp1" ) ); //$NON-NLS-1$ - assertEquals( 2, results.length); - assertEquals( "field1 : unsigned", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( "field2 : unsigned int", results[1].getDisplayString()); //$NON-NLS-1$ - //vp2 bitfield accessed from named struct with "->" - results = getResults( t, code.indexOf( "field1;//vp2" ) ); //$NON-NLS-1$ - assertEquals( 2, results.length); - assertEquals( "field1 : unsigned", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( "field2 : unsigned int", results[1].getDisplayString()); //$NON-NLS-1$ - //vp3 static const field accessed from typedef struct with "::" - results = getResults( t, code.indexOf( "field2;//vp3" ) ); //$NON-NLS-1$ - assertEquals( 1, results.length); - assertEquals( "field2 : const int", results[0].getDisplayString()); //$NON-NLS-1$ - //vp4 class field of type anonymous struct - results = getResults( t, code.indexOf( "a.aa;//vp4" ) ); //$NON-NLS-1$ - assertEquals( 1, results.length); - assertEquals( "a : ", results[0].getDisplayString()); //$NON-NLS-1$ - - } - public void testFieldExpression() throws Exception { - StringWriter writer = new StringWriter(); - writer.write("struct myStruct_c{ \n" ); //$NON-NLS-1$ - writer.write("int m; struct {int m2;} n; \n" ); //$NON-NLS-1$ - writer.write("}ss1={1},ss2={2}; \n" ); //$NON-NLS-1$ - writer.write("void f(){ \n" ); //$NON-NLS-1$ - writer.write("int i=(ss1.m > ss2.m/*vp1*/ ? ss1.n/*vp2*/ : ss2.n/*vp3*/).m2/*vp4*/;\n" ); //$NON-NLS-1$ - writer.write("} \n" ); //$NON-NLS-1$ - String code = writer.toString(); - IFile f=importFile( "testFieldExpression.cpp", code ); //$NON-NLS-1$ - //vp1 first operand of ?: on rhs of > - ICompletionProposal [] results = getResults( f, code.indexOf( "m/*vp1*/" ) ); //$NON-NLS-1$ - assertEquals( "m : int", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( "n : ", results[1].getDisplayString()); //$NON-NLS-1$ - assertEquals( 2, results.length); - //vp2 second operand of ?: - results = getResults( f, code.indexOf( "n/*vp2*/" ) ); //$NON-NLS-1$ - assertEquals( "m : int", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( "n : ", results[1].getDisplayString()); //$NON-NLS-1$ - assertEquals( 2, results.length); - //vp3 third operand of ?: - results = getResults( f, code.indexOf( "n/*vp3*/" ) ); //$NON-NLS-1$ - assertEquals( "m : int", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( "n : ", results[1].getDisplayString()); //$NON-NLS-1$ - assertEquals( 2, results.length); - //vp4 dot reference after ?: expression (note ?: expression cannot be lhs of =) - results = getResults( f, code.indexOf( "m2/*vp4*/" ) ); //$NON-NLS-1$ - assertEquals( "m2 : int", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( 1, results.length); - } - // test30: Complete on scoped reference - // nested class/namespaces, unambiguous scoped & unscoped namespace, ambiguous namespace - public void testScope() throws Exception { - StringWriter writer = new StringWriter(); - writer = new StringWriter(); - writer.write("namespace NN1 { \n" ); //$NON-NLS-1$ - writer.write(" class C1 {}; \n" ); //$NON-NLS-1$ - writer.write(" namespace NN2 { \n" ); //$NON-NLS-1$ - writer.write(" class C2{}; \n" ); //$NON-NLS-1$ - writer.write(" class NNA{}; \n" ); //$NON-NLS-1$ - writer.write(" namespace NN3 { \n" ); //$NON-NLS-1$ - writer.write(" class NNA{};\n" ); //$NON-NLS-1$ - writer.write(" class C3{ \n" ); //$NON-NLS-1$ - writer.write(" public: \n" ); //$NON-NLS-1$ - writer.write(" class C4{};\n" ); //$NON-NLS-1$ - writer.write(" }; \n" ); //$NON-NLS-1$ - writer.write(" } \n" ); //$NON-NLS-1$ - writer.write(" } \n" ); //$NON-NLS-1$ - writer.write("} \n" ); //$NON-NLS-1$ - String codeH = writer.toString(); - importFile( "testScope.h", codeH ); //$NON-NLS-1$ - - writer.write("#include \"testScope.h\" \n" ); //$NON-NLS-1$ - writer.write("int main(int argc, char **argv) { \n" ); //$NON-NLS-1$ - writer.write(" NN1::NN2::NN3::C3::C4 c4;//vp1:C4 \n" ); //$NON-NLS-1$ - writer.write(" using namespace NN1::NN2; \n" ); //$NON-NLS-1$ - writer.write(" NN3::C3 c3; //vp2:NN1,NN3,NNA; vp3:C3,NNA\n" ); //$NON-NLS-1$ - writer.write(" using namespace NN3; \n" ); //$NON-NLS-1$ - writer.write(" NN3::NNA a;//vp4:NN1,NN3(Ambiguous space)\n" ); //$NON-NLS-1$ - writer.write("} \n" ); //$NON-NLS-1$ - String code = writer.toString(); - IFile f=importFile( "testScope.cpp", code ); //$NON-NLS-1$ - //vp1 5 levels of nested class/namespaces - ICompletionProposal [] results = getResults( f, code.indexOf( "C4 c4;//vp1" ) ); //$NON-NLS-1$ - assertEquals( "C4", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( 1, results.length); - //vp2 unambiguous NNA, unscoped - results = getResults( f, code.indexOf( "3::C3 c3; //vp2" ) ); //$NON-NLS-1$ - assertEquals( "NNA", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( "NN1", results[1].getDisplayString()); //$NON-NLS-1$ - assertEquals( "NN3", results[2].getDisplayString()); //$NON-NLS-1$ - assertEquals( 3, results.length); - //vp3 unambigous NNA, scoped - results = getResults( f, code.indexOf( "C3 c3; //vp2:NN1,NN3,NNA; vp3" ) ); //$NON-NLS-1$ - assertEquals( "C3", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( "NNA", results[1].getDisplayString()); //$NON-NLS-1$ - assertEquals( 2, results.length); - //vp4 ambiguous NNA, not in contribution list - results = getResults( f, code.indexOf( "3::NNA a;//vp4" ) ); //$NON-NLS-1$ - assertEquals( "NN1", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( "NN3", results[1].getDisplayString()); //$NON-NLS-1$ - assertEquals( 2, results.length); - - } - // test33 - public void testClass() throws Exception { - StringWriter writer = new StringWriter(); - writer.write("class Point{ \n" ); //$NON-NLS-1$ - writer.write("public: \n" ); //$NON-NLS-1$ - writer.write(" Point(): xCoord(0){} \n" ); //$NON-NLS-1$ - writer.write(" Point(int x); \n" ); //$NON-NLS-1$ - writer.write(" Point(const Point &rhs); \n" ); //$NON-NLS-1$ - writer.write(" virtual ~Point(){} \n" ); //$NON-NLS-1$ - writer.write(" int getX() const {return xCoord;} \n" ); //$NON-NLS-1$ - writer.write("private: \n" ); //$NON-NLS-1$ - writer.write(" int xCoord; \n" ); //$NON-NLS-1$ - writer.write("}; \n" ); //$NON-NLS-1$ - String codeH = writer.toString(); - importFile( "testClass.h", codeH ); //$NON-NLS-1$ - - writer = new StringWriter(); - writer.write("#include \"testClass.h\" \n" ); //$NON-NLS-1$ - writer.write("Point::Point(int x):xCoord(x){} \n" ); //$NON-NLS-1$ - writer.write("Point::Point(const Point &rhs){ \n" ); //$NON-NLS-1$ - writer.write(" xCoord = rhs.xCoord; \n" ); //$NON-NLS-1$ - writer.write("} \n" ); //$NON-NLS-1$ - writer.write("static const Point zero(0); \n" ); //$NON-NLS-1$ - writer.write("int main(int argc, char **argv) { \n" ); //$NON-NLS-1$ - writer.write(" Point *p1 = new ::Point(0);//vp1 scoped class \n" ); //$NON-NLS-1$ - writer.write(" Point &p2 = *(new Point(10)); \n" ); //$NON-NLS-1$ - writer.write(" Point one(1); \n" ); //$NON-NLS-1$ - writer.write(" p1->getX();//vp2: arrow getX(), getY(), ~Point(), operator=) \n" ); //$NON-NLS-1$ - writer.write(" p2.getX();//vp3: dot on dereferenced initialization \n" ); //$NON-NLS-1$ - writer.write(" one.getX();//vp4: dot on simple initialization \n" ); //$NON-NLS-1$ - writer.write(" *(p1) = ::zero;//vp5 scoped class instance \n" ); //$NON-NLS-1$ - writer.write(" return (0); \n" ); //$NON-NLS-1$ - writer.write("} \n" ); //$NON-NLS-1$ - String code = writer.toString(); - IFile f=importFile( "testClass.cpp", code ); //$NON-NLS-1$ - //vp1 scoped class - ICompletionProposal [] results = getResults( f, code.indexOf( "oint(0);//vp1" ) ); //$NON-NLS-1$ - assertEquals( "Point", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( 1, results.length); - //vp2 arrow ref. this will fail when 72723 is fixed because of the - //sorting of the results: currently: =,~,get; after fix: ~,get,operator= - results = getResults( f, code.indexOf( "getX();//vp2" ) ); //$NON-NLS-1$ - //assertEquals( "operator=(const Point&) Point&", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( "getX() int", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( "~Point()", results[1].getDisplayString()); //$NON-NLS-1$ - assertEquals( 2, results.length); - //vp3 dot ref on dereferenced initialization - results = getResults( f, code.indexOf( "getX();//vp3" ) ); //$NON-NLS-1$ - assertEquals( "getX() int", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( "~Point()", results[1].getDisplayString()); //$NON-NLS-1$ - assertEquals( 2, results.length); - //vp4 dot on simple initialization - results = getResults( f, code.indexOf( "getX();//vp4" ) ); //$NON-NLS-1$ - assertEquals( "getX() int", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( "~Point()", results[1].getDisplayString()); //$NON-NLS-1$ - assertEquals( 2, results.length); - //vp5 scoped class instance - results = getResults( f, code.indexOf( "ero;//vp5" ) ); //$NON-NLS-1$ - assertEquals( "zero : const Point", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( 1, results.length); - - - } - // defect 72723 on test 33: Complete on opertator overloads forgets the operator keyword - public void test72723() throws Exception { - - StringWriter writer = new StringWriter(); - writer.write("class Point{ \n" ); //$NON-NLS-1$ - writer.write("public: \n" ); //$NON-NLS-1$ - writer.write(" Point(): xCoord(0){} \n" ); //$NON-NLS-1$ - writer.write(" Point(int x); \n" ); //$NON-NLS-1$ - writer.write(" Point(const Point &rhs); \n" ); //$NON-NLS-1$ - writer.write(" virtual ~Point(){} \n" ); //$NON-NLS-1$ - writer.write(" int getX() const {return xCoord;} \n" ); //$NON-NLS-1$ - writer.write(" Point& operator=(const Point &rhs); \n" ); //$NON-NLS-1$ - writer.write("private: \n" ); //$NON-NLS-1$ - writer.write(" int xCoord; \n" ); //$NON-NLS-1$ - writer.write("}; \n" ); //$NON-NLS-1$ - String codeH = writer.toString(); - importFile( "test72723.h", codeH ); //$NON-NLS-1$ - - writer = new StringWriter(); - writer.write("#include \"test72723.h\" \n" ); //$NON-NLS-1$ - writer.write("Point::Point(int x):xCoord(x){} \n" ); //$NON-NLS-1$ - writer.write("Point::Point(const Point &rhs){ \n" ); //$NON-NLS-1$ - writer.write(" xCoord = rhs.xCoord; \n" ); //$NON-NLS-1$ - writer.write("} \n" ); //$NON-NLS-1$ - writer.write("Point& Point::operator=(const Point &rhs){\n" ); //$NON-NLS-1$ - writer.write(" if (this == &rhs) return *this; \n" ); //$NON-NLS-1$ - writer.write(" xCoord = rhs.xCoord; \n" ); //$NON-NLS-1$ - writer.write(" return *this; \n" ); //$NON-NLS-1$ - writer.write("} \n" ); //$NON-NLS-1$ - writer.write("static const Point zero(0); \n" ); //$NON-NLS-1$ - writer.write("int main(int argc, char **argv) { \n" ); //$NON-NLS-1$ - writer.write(" Point *p1 = new ::Point(0); \n" ); //$NON-NLS-1$ - writer.write(" Point &p2 = *(new Point(10)); \n" ); //$NON-NLS-1$ - writer.write(" p1->operator=(zero);//vp1: arrow ref \n" ); //$NON-NLS-1$ - writer.write(" p2.operator=(zero);//vp2: dot ref \n" ); //$NON-NLS-1$ - writer.write(" return (0); \n" ); //$NON-NLS-1$ - writer.write("} \n" ); //$NON-NLS-1$ - String code = writer.toString(); - IFile f=importFile( "test72723.cpp", code ); //$NON-NLS-1$ - //vp1 arrow ref - ICompletionProposal [] results = getResults( f, code.indexOf( "perator=(zero);//vp3" ) ); //$NON-NLS-1$ - assertEquals( 1, results.length); - assertEquals( "operator=(const Point&) Point&", results[0].getDisplayString()); //$NON-NLS-1$ - - } - // defect 72541 on test 33: Complete on const missing suggestions - public void test72541() throws Exception { - StringWriter writer = new StringWriter(); - writer.write("class Point {public Point(); int X;}; \n" ); //$NON-NLS-1$ - writer.write("const Point zero; \n" ); //$NON-NLS-1$ - writer.write("int main() {return zero.X;}//vp1 \n" ); //$NON-NLS-1$ - String code = writer.toString(); - IFile f=importFile( "test72541.h", code ); //$NON-NLS-1$ - - //vp1 completion on const class - ICompletionProposal [] results = getResults( f, code.indexOf( "X;}//vp1" ) ); //$NON-NLS-1$ - assertEquals( 1, results.length); - assertEquals( "X : const int", results[0].getDisplayString()); //$NON-NLS-1$ - - } - // test 36 - public void testFunction() throws Exception { - StringWriter writer = new StringWriter(); - writer.write("namespace nnnn { \n"); //$NON-NLS-1$ - writer.write(" namespace nnn { \n"); //$NON-NLS-1$ - writer.write(" void foo(){} \n"); //$NON-NLS-1$ - writer.write(" } \n"); //$NON-NLS-1$ - writer.write("} \n"); //$NON-NLS-1$ - writer.write("int main(int argc, char **argv) {\n"); //$NON-NLS-1$ - writer.write(" namespace n=nnnn::nnn; \n"); //$NON-NLS-1$ - writer.write(" n::foo();//vp1 \n"); //$NON-NLS-1$ - writer.write(" using namespace nnnn; \n"); //$NON-NLS-1$ - writer.write(" nnn::foo();//vp2 \n"); //$NON-NLS-1$ - writer.write(" return (0); \n"); //$NON-NLS-1$ - writer.write("} \n"); //$NON-NLS-1$ - String code = writer.toString(); - IFile t = importFile( "testFunction.cpp", code ); //$NON-NLS-1$ - //vp1 namespace alias scope - ICompletionProposal [] results = getResults( t, code.indexOf( "foo();//vp1" ) ); //$NON-NLS-1$ - assertEquals( 1, results.length); - assertEquals( "foo() void", results[0].getDisplayString()); //$NON-NLS-1$ - //vp2 nested namespace scope - results = getResults( t, code.indexOf( "oo();//vp2" ) ); //$NON-NLS-1$ - assertEquals( 1, results.length); - assertEquals( "foo() void", results[0].getDisplayString()); //$NON-NLS-1$ - - } - //test 44 argument types from both function declaration and function call - public void testArgument() throws Exception { - StringWriter writer = new StringWriter(); - writer.write("typedef long int32_t; \n"); //$NON-NLS-1$ - writer.write("#define INT32_C(x) x ## L \n"); //$NON-NLS-1$ - writer.write("#define INT32_MAX (2147483647) \n"); //$NON-NLS-1$ - writer.write("int foo(int32_t i){//vp1contributions include types in arg list\n"); //$NON-NLS-1$ - writer.write(" return (i); \n"); //$NON-NLS-1$ - writer.write("} \n"); //$NON-NLS-1$ - writer.write("int z(int i){return (i);} \n"); //$NON-NLS-1$ - writer.write("int main(int argc, char **argv) {\n"); //$NON-NLS-1$ - writer.write(" int32_t int32iii=2; \n"); //$NON-NLS-1$ - writer.write(" foo(INT32_C(2));//vp2 macros\n"); //$NON-NLS-1$ - writer.write(" foo(INT32_MAX);//vp3 defines\n"); //$NON-NLS-1$ - writer.write(" foo(int32iii);//vp4 variable\n"); //$NON-NLS-1$ - writer.write(" foo(z(5));//vp5 function arg \n"); //$NON-NLS-1$ - writer.write(" return (0); \n"); //$NON-NLS-1$ - writer.write("} \n"); //$NON-NLS-1$ - String code = writer.toString(); - IFile t = importFile( "testArgument.c", code ); //$NON-NLS-1$ - //vp1 function declaration args contain type only - ICompletionProposal [] results = getResults( t, code.indexOf( "32_t i){//vp1" ) ); //$NON-NLS-1$ - //assertEquals( 15, results.length); - assertEquals( 2, results.length); - assertEquals( "int32_t", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( "int", results[1].getDisplayString()); //$NON-NLS-1$ - //vp2 function call args contain #macros, variables but not types - results = getResults( t, code.indexOf( "(2));//vp2" ) ); //$NON-NLS-1$ - assertEquals( 1, results.length); - assertEquals( "INT32_C(x)", results[0].getDisplayString()); //$NON-NLS-1$ - //vp3 function call args contain #defines - results = getResults( t, code.indexOf( "AX);//vp3" ) ); //$NON-NLS-1$ - assertEquals( 1, results.length); - assertEquals( "INT32_MAX", results[0].getDisplayString()); //$NON-NLS-1$ - //assertEquals( "INT32_MIN", results[1].getDisplayString()); //$NON-NLS-1$ - //vp4 function call args contain variables - results = getResults( t, code.indexOf( "ii);//vp4" ) ); //$NON-NLS-1$ - assertEquals( 1, results.length); - assertEquals( "int32iii : int32_t", results[0].getDisplayString()); //$NON-NLS-1$ - //vp5 function call args can contain functions - results = getResults( t, code.indexOf( "(5));//vp5" ) ); //$NON-NLS-1$ - assertEquals( 1, results.length); - assertEquals( "z(int) int", results[0].getDisplayString()); //$NON-NLS-1$ - - } - - // arguments in function call shouldn't contain types - public void test76805() throws Exception { - StringWriter writer = new StringWriter(); - writer.write("typedef long int32_t; \n"); //$NON-NLS-1$ - writer.write("#define INT32_MAX (2147483647) \n"); //$NON-NLS-1$ - writer.write("int foo(int32_t i){ \n"); //$NON-NLS-1$ - writer.write(" return (i); \n"); //$NON-NLS-1$ - writer.write("} \n"); //$NON-NLS-1$ - writer.write("int main(int argc, char **argv) {\n"); //$NON-NLS-1$ - writer.write(" int32_t int32iii=2; \n"); //$NON-NLS-1$ - writer.write(" foo(INT32_MAX);//vp1 macros, variables, not types\n"); //$NON-NLS-1$ - writer.write(" return (0); \n"); //$NON-NLS-1$ - writer.write("} \n"); //$NON-NLS-1$ - String code = writer.toString(); - IFile t = importFile( "test76805.c", code ); //$NON-NLS-1$ - //vp1 function call args contain #defines, variables but not types - //int32_t should not be in the list - ICompletionProposal [] results = getResults( t, code.indexOf( "32_MAX);//vp1" ) ); //$NON-NLS-1$ - assertEquals( "INT32_MAX", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( "int32iii : int32_t", results[1].getDisplayString()); //$NON-NLS-1$ - assertEquals( 2, results.length); - - } - // test 50 type cast c code: narrowing cast & struct cast; - // cpp code: class cast, override typecheck cast, deref cast - public void testCStyleCast() throws Exception { - StringWriter writer = new StringWriter(); - writer.write("typedef int ZINT; \n"); //$NON-NLS-1$ - writer.write("typedef struct { \n"); //$NON-NLS-1$ - writer.write(" int foobar; \n"); //$NON-NLS-1$ - writer.write("}foo_c; \n"); //$NON-NLS-1$ - writer.write("typedef struct {} bar_c; \n"); //$NON-NLS-1$ - writer.write("int main(int argc, char **argv) {\n"); //$NON-NLS-1$ - writer.write(" ZINT i=(ZINT) 3.1;//vp1 narrowing cast\n"); //$NON-NLS-1$ - writer.write(" bar_c *bar; \n"); //$NON-NLS-1$ - writer.write(" foo_c *foo; \n"); //$NON-NLS-1$ - writer.write(" ((foo_c*) bar)->foobar;//vp2 complete on struct casted var\n"); //$NON-NLS-1$ - writer.write("} \n"); //$NON-NLS-1$ - String code = writer.toString(); - IFile t = importFile( "testCStyleCast.c", code ); //$NON-NLS-1$ - ICompletionProposal [] results = getResults( t, code.indexOf( "INT) 3.1;//vp1" ) ); //$NON-NLS-1$ - assertEquals( "ZINT", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( 1, results.length); - results = getResults( t, code.indexOf( "foobar;//vp2" ) ); //$NON-NLS-1$ - assertEquals( "foobar : int", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( 1, results.length); - removeFile("testCStyleCase.c");//$NON-NLS-1$ - - writer=new StringWriter(); - writer.write("typedef int ZINT; \n"); //$NON-NLS-1$ - writer.write("class foo_c{ \n"); //$NON-NLS-1$ - writer.write(" public: void foobar(){} \n"); //$NON-NLS-1$ - writer.write("}; \n"); //$NON-NLS-1$ - writer.write("class bar_c {}; \n"); //$NON-NLS-1$ - writer.write("int main(int argc, char **argv) { \n"); //$NON-NLS-1$ - writer.write(" bar_c *bar; \n"); //$NON-NLS-1$ - writer.write(" foo_c *foo; \n"); //$NON-NLS-1$ - writer.write(" ((foo_c*) bar)->foobar();//vp1 complete on class casted var\n"); //$NON-NLS-1$ - writer.write(" //cast away constness \n"); //$NON-NLS-1$ - writer.write(" ZINT i=3; \n"); //$NON-NLS-1$ - writer.write(" const int *pci = &i; \n"); //$NON-NLS-1$ - writer.write(" void * pv=(void*)pci;//vp2 override typecheck cast \n"); //$NON-NLS-1$ - writer.write(" (*(ZINT *)pv)=4;//vp3 dereferenced casted var\n"); //$NON-NLS-1$ - writer.write(" return 0; \n"); //$NON-NLS-1$ - writer.write("} \n"); //$NON-NLS-1$ - code = writer.toString(); - t = importFile( "testCStyleCast.cpp", code ); //$NON-NLS-1$ - results = getResults( t, code.indexOf( "foobar();//vp1" ) ); //$NON-NLS-1$ - assertEquals( "foobar() void", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( 1, results.length); - results = getResults( t, code.indexOf( "d*)pci;//vp2" ) ); //$NON-NLS-1$ - assertEquals( "void", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( 1, results.length); - results = getResults( t, code.indexOf( "INT *)pv)=4;//vp3" ) ); //$NON-NLS-1$ - assertEquals( "ZINT", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( 1, results.length); - - } - //test 59 - public void testMethod() throws Exception { - StringWriter writer = new StringWriter(); - writer.write("class Point{ \n"); //$NON-NLS-1$ - writer.write(" public: Point(): x(5){} \n"); //$NON-NLS-1$ - writer.write(" Point& compare(const Point &rhs) {\n"); //$NON-NLS-1$ - writer.write(" (this==&rhs);//vp1 \n"); //$NON-NLS-1$ - writer.write(" return *this;//vp2 \n"); //$NON-NLS-1$ - writer.write(" } \n"); //$NON-NLS-1$ - writer.write(" int x; \n"); //$NON-NLS-1$ - writer.write("}; \n"); //$NON-NLS-1$ - writer.write("int main(int argc, char **argv) {\n"); //$NON-NLS-1$ - writer.write(" Point *p1=new Point(); \n"); //$NON-NLS-1$ - writer.write(" Point &p2=*(new Point()); \n"); //$NON-NLS-1$ - writer.write(" Point **p3; \n"); //$NON-NLS-1$ - writer.write(" **p3=p2;//vp3 content assist doesn't filter out pointer types by design\n"); //$NON-NLS-1$ - writer.write(" (**p3).x;//vp4 correct dereference\n"); //$NON-NLS-1$ - writer.write(" (*p3).x;//vp5 too few stars - CA notices\n"); //$NON-NLS-1$ - writer.write(" return 0; \n"); //$NON-NLS-1$ - writer.write("} \n"); //$NON-NLS-1$ - String code = writer.toString(); - IFile t = importFile( "testMethod.c", code ); //$NON-NLS-1$ - //vp1 complete on & var - ICompletionProposal [] results = getResults( t, code.indexOf( "hs);//vp1" ) ); //$NON-NLS-1$ - assertEquals( "rhs : const Point&", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( "register", results[1].getDisplayString()); //$NON-NLS-1$ - assertEquals( "reinterpret_cast", results[2].getDisplayString()); //$NON-NLS-1$ - //does return make sense even when there's no & - assertEquals( "return", results[3].getDisplayString()); //$NON-NLS-1$ - assertEquals( 4, results.length); - //vp2 complete on *this - results = getResults( t, code.indexOf( "s;//vp2" ) ); //$NON-NLS-1$ - assertEquals( "this", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( 1, results.length); - //vp3 ignore stars by design, so CA correctly returns all local vars - results = getResults( t, code.indexOf( "3=p2;//vp3" ) ); //$NON-NLS-1$ - assertEquals( "p1 : Point*", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( "p2 : Point&", results[1].getDisplayString()); //$NON-NLS-1$ - assertEquals( "p3 : Point**", results[2].getDisplayString()); //$NON-NLS-1$ - assertEquals( "Point", results[3].getDisplayString()); //$NON-NLS-1$ - assertEquals( 4, results.length); - - //vp4 complete on members of correctly dereferenced object - results = getResults( t, code.indexOf( "x;//vp4" ) ); //$NON-NLS-1$ - assertEquals( "x : int", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( "compare(const Point&) Point&", results[1].getDisplayString()); //$NON-NLS-1$ - assertEquals( 2, results.length); - - //vp5 no completions available for incorrectly dereferenced object - results = getResults( t, code.indexOf( "x;//vp5" ) ); //$NON-NLS-1$ - assertEquals( 0, results.length); - - } - // test 62 - public void testEnumerations() throws Exception { - StringWriter writer = new StringWriter(); - writer.write("enum day {ztuesday, zthursday}; \n" ); //$NON-NLS-1$ - writer.write("enum {zTGIF}; \n" ); //$NON-NLS-1$ - writer.write("int i=ztuesday;//vp1 \n" ); //$NON-NLS-1$ - writer.write("class Bar { \n" ); //$NON-NLS-1$ - writer.write(" public: \n" ); //$NON-NLS-1$ - writer.write(" enum R4 {R1} num; \n" ); //$NON-NLS-1$ - writer.write(" enum {R2}; \n" ); //$NON-NLS-1$ - writer.write(" static enum {R3} Rnum2; \n" ); //$NON-NLS-1$ - writer.write(" day nd; \n" ); //$NON-NLS-1$ - writer.write("}; \n" ); //$NON-NLS-1$ - writer.write("void foo(){ \n" ); //$NON-NLS-1$ - writer.write(" day d;//vp2 \n" ); //$NON-NLS-1$ - writer.write(" d=ztuesday;//vp3 \n" ); //$NON-NLS-1$ - writer.write(" Bar::R1;//vp4 \n" ); //$NON-NLS-1$ - writer.write(" Bar b; \n" ); //$NON-NLS-1$ - writer.write(" b.R3;//vp5 \n" ); //$NON-NLS-1$ - writer.write("} \n" ); //$NON-NLS-1$ - String code = writer.toString(); - IFile t = importFile( "testEnumerations.cpp", code ); //$NON-NLS-1$ - //vp1 global enumerator reference in global scope, RHS - ICompletionProposal [] results = getResults( t, code.indexOf( "uesday;//vp1" ) ); //$NON-NLS-1$ - assertEquals( "zthursday", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( "ztuesday", results[1].getDisplayString()); //$NON-NLS-1$ - assertEquals( "zTGIF", results[2].getDisplayString()); //$NON-NLS-1$ - assertEquals( 3, results.length); - //vp2 enumeration reference in function - results = getResults( t, code.indexOf( "y d;//vp2" ) ); //$NON-NLS-1$ - assertEquals( "day", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( 1, results.length); - //vp3 global enumerator reference in function scope, RHS - results = getResults( t, code.indexOf( "uesday;//vp3" ) ); //$NON-NLS-1$ - assertEquals( "zthursday", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( "ztuesday", results[1].getDisplayString()); //$NON-NLS-1$ - assertEquals( "zTGIF", results[2].getDisplayString()); //$NON-NLS-1$ - assertEquals( 3, results.length); - //vp4 enum & enumerator "::" reference, no prefix - results = getResults( t, code.indexOf( "R1;//vp4" ) ); //$NON-NLS-1$ - assertEquals( "Rnum2 : ", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( "R1", results[1].getDisplayString()); //$NON-NLS-1$ - assertEquals( "R2", results[2].getDisplayString()); //$NON-NLS-1$ - assertEquals( "R3", results[3].getDisplayString()); //$NON-NLS-1$ - assertEquals( "R4", results[4].getDisplayString()); //$NON-NLS-1$ - assertEquals( 5, results.length); - //vp5 enumerator "." reference, prefix - results = getResults( t, code.indexOf( "3;//vp5" ) ); //$NON-NLS-1$ - assertEquals( 4, results.length); - assertEquals( "Rnum2 : ", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( "R1", results[1].getDisplayString()); //$NON-NLS-1$ - assertEquals( "R2", results[2].getDisplayString()); //$NON-NLS-1$ - assertEquals( "R3", results[3].getDisplayString()); //$NON-NLS-1$ - - } - //test 70 - public void testLongTokens() throws Exception { - StringWriter writer = new StringWriter(); - writer.write("int i123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890;\n" ); //$NON-NLS-1$ - writer.write("typedef int t123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890;\n" ); //$NON-NLS-1$ - writer.write("class A {\n" ); //$NON-NLS-1$ - writer.write(" A(t123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 a){\n" ); //$NON-NLS-1$ - writer.write(" i123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890=0;//vp1 \n" ); //$NON-NLS-1$ - writer.write(" t123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 t=a;//vp2 \n" ); //$NON-NLS-1$ - writer.write(" a=i123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890;//vp3 \n" ); //$NON-NLS-1$ - writer.write(" }\n" ); //$NON-NLS-1$ - writer.write("};\n" ); //$NON-NLS-1$ - String code = writer.toString(); - IFile t = importFile( "testLongTokens.cpp", code ); //$NON-NLS-1$ - //vp1 complete on long var - ICompletionProposal [] results = getResults( t, code.indexOf( "3456789012345678901234567890123456789012345678901234567890123456789012345678901234567890=0;//vp1" ) ); //$NON-NLS-1$ - assertEquals( "i123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 : int", results[0].getDisplayString()); //$NON-NLS-1$ - //vp2 proposal has long type - results = getResults( t, code.indexOf( ";//vp2" ) ); //$NON-NLS-1$ - assertEquals( "a : t123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890", results[0].getDisplayString()); //$NON-NLS-1$ - //vp3 complete on rhs long var with long prefix - results = getResults( t, code.indexOf( "7890;//vp3" ) ); //$NON-NLS-1$ - assertEquals( "i123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 : int", results[0].getDisplayString()); //$NON-NLS-1$ - } - //test 73 - public void testCastMultiLevel() throws Exception { - StringWriter writer = new StringWriter(); - writer.write("class Gee{ \n" ); //$NON-NLS-1$ - writer.write(" public: struct {int g1;} g0; \n" ); //$NON-NLS-1$ - writer.write("}; \n" ); //$NON-NLS-1$ - writer.write("class Foo { \n" ); //$NON-NLS-1$ - writer.write(" public: Gee *f0; \n" ); //$NON-NLS-1$ - writer.write("}; \n" ); //$NON-NLS-1$ - writer.write("class C { \n" ); //$NON-NLS-1$ - writer.write(" void coo(int i){ \n" ); //$NON-NLS-1$ - writer.write(" switch (i) { \n" ); //$NON-NLS-1$ - writer.write(" (*((new Foo())->f0)).g0.g1;//vp1 \n" ); //$NON-NLS-1$ - writer.write(" Gee *g; \n" ); //$NON-NLS-1$ - writer.write(" ((Foo*)g)->f0;//vp2 \n" ); //$NON-NLS-1$ - writer.write(" (*(((Foo*)g)->f0)).g0.g1;//vp3,vp4 \n" ); //$NON-NLS-1$ - writer.write(" } \n" ); //$NON-NLS-1$ - writer.write(" } \n" ); //$NON-NLS-1$ - writer.write("}; \n" ); //$NON-NLS-1$ - String code = writer.toString(); - IFile t = importFile( "testCastMultiLevel.cpp", code ); //$NON-NLS-1$ - //vp1 multilevel qual - ICompletionProposal [] results = getResults( t, code.indexOf( "g1;//vp1" ) ); //$NON-NLS-1$ - assertEquals( "g1 : int", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( 1, results.length); - //vp2 cast & multilevel qual on -> - results = getResults( t, code.indexOf( "f0;//vp2" ) ); //$NON-NLS-1$ - assertEquals( "f0 : Gee*", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( 1, results.length); - //vp3 cast & multilevel qual on . (class member) - results = getResults( t, code.indexOf( "g0.g1;//vp3" ) ); //$NON-NLS-1$ - assertEquals( "g0 : ", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( 1, results.length); - //vp4 cast & multilevel qual on . (struct member) - results = getResults( t, code.indexOf( "g1;//vp3,vp4" ) ); //$NON-NLS-1$ - assertEquals( "g1 : int", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( 1, results.length); - - } - //test 79 - public void testHeaderExtensions() throws Exception { - StringWriter writer = new StringWriter(); - writer.write("class C1{ \n" ); //$NON-NLS-1$ - writer.write(" enum {C1a, C1b}; \n" ); //$NON-NLS-1$ - writer.write(" C1() { \n" ); //$NON-NLS-1$ - writer.write(" C1;//vp1 \n" ); //$NON-NLS-1$ - writer.write(" } \n" ); //$NON-NLS-1$ - writer.write("}; \n" ); //$NON-NLS-1$ - String code = writer.toString(); - IFile t = importFile( "testHeaderExtensions.h", code ); //$NON-NLS-1$ - //vp1 h file - ICompletionProposal [] results = getResults( t, code.indexOf( "1;//vp1" ) ); //$NON-NLS-1$ - assertEquals( "C1", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( "C1a", results[1].getDisplayString()); //$NON-NLS-1$ - assertEquals( "C1b", results[2].getDisplayString()); //$NON-NLS-1$ - assertEquals( 3, results.length); - removeFile("testHeaderExtensions.h"); //$NON-NLS-1$ - - //vp2 H file - writer = new StringWriter(); - writer.write("class C{ \n" ); //$NON-NLS-1$ - writer.write(" public: enum {C1, C3}; \n" ); //$NON-NLS-1$ - writer.write(" C() { \n" ); //$NON-NLS-1$ - writer.write(" C1; \n" ); //$NON-NLS-1$ - writer.write(" } \n" ); //$NON-NLS-1$ - writer.write("}; \n" ); //$NON-NLS-1$ - writer.write("namespace N { \n" ); //$NON-NLS-1$ - writer.write("int i =C::C1;//vp2 \n" ); //$NON-NLS-1$ - writer.write("} \n" ); //$NON-NLS-1$ - code = writer.toString(); - t = importFile( "testHeaderExtensions.H", code ); //$NON-NLS-1$ - //vp2 H file, namespace scope, class context - results = getResults( t, code.indexOf( "C1;//vp2" ) ); //$NON-NLS-1$ - assertEquals( "C()", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( "C1", results[1].getDisplayString()); //$NON-NLS-1$ - assertEquals( "C3", results[2].getDisplayString()); //$NON-NLS-1$ - //trace showed 4 lookup results - assertEquals( 3, results.length); - removeFile("testHeaderExtensions.H"); //$NON-NLS-1$ - - // vp3 hxx file - writer = new StringWriter(); - writer.write("class C{ \n" ); //$NON-NLS-1$ - writer.write(" enum {C1, C3}; \n" ); //$NON-NLS-1$ - writer.write(" C() { \n" ); //$NON-NLS-1$ - writer.write(" C1;//vp3 \n" ); //$NON-NLS-1$ - writer.write(" } \n" ); //$NON-NLS-1$ - writer.write("}; \n" ); //$NON-NLS-1$ - code = writer.toString(); - t = importFile( "testHeaderExtensions.hxx", code ); //$NON-NLS-1$ - //vp3 hxx file, method scope - results = getResults( t, code.indexOf( "1;//vp3" ) ); //$NON-NLS-1$ - assertEquals( "C", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( "C1", results[1].getDisplayString()); //$NON-NLS-1$ - assertEquals( "C3", results[2].getDisplayString()); //$NON-NLS-1$ - assertEquals( 3, results.length); - removeFile("testHeaderExtensions.hxx"); //$NON-NLS-1$ - - //vp4 hh file - writer = new StringWriter(); - writer.write("class C{ \n" ); //$NON-NLS-1$ - writer.write(" public: enum {C1, C3}; \n" ); //$NON-NLS-1$ - writer.write(" C() { \n" ); //$NON-NLS-1$ - writer.write(" C1; \n" ); //$NON-NLS-1$ - writer.write(" } \n" ); //$NON-NLS-1$ - writer.write("}; \n" ); //$NON-NLS-1$ - writer.write("namespace N { \n" ); //$NON-NLS-1$ - writer.write("int i =C::C1;//vp4 \n" ); //$NON-NLS-1$ - writer.write("} \n" ); //$NON-NLS-1$ - code = writer.toString(); - t = importFile( "testHeaderExtensions.hh", code ); //$NON-NLS-1$ - //vp4 hh file, namespace scope, class context - results = getResults( t, code.indexOf( "C1;//vp4" ) ); //$NON-NLS-1$ - assertEquals( "C()", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( "C1", results[1].getDisplayString()); //$NON-NLS-1$ - assertEquals( "C3", results[2].getDisplayString()); //$NON-NLS-1$ - //trace showed 4 lookup results - assertEquals( 3, results.length); - removeFile("testHeaderExtensions.hh"); //$NON-NLS-1$ - - //vp5 hpp file - writer = new StringWriter(); - writer.write("class C{ \n" ); //$NON-NLS-1$ - writer.write(" public: enum {C1, C3}; \n" ); //$NON-NLS-1$ - writer.write(" C() { \n" ); //$NON-NLS-1$ - writer.write(" C1; \n" ); //$NON-NLS-1$ - writer.write(" } \n" ); //$NON-NLS-1$ - writer.write("}; \n" ); //$NON-NLS-1$ - writer.write("namespace N { \n" ); //$NON-NLS-1$ - writer.write("int i =C::C1;//vp5 \n" ); //$NON-NLS-1$ - writer.write("} \n" ); //$NON-NLS-1$ - code = writer.toString(); - t = importFile( "testHeaderExtensions.H", code ); //$NON-NLS-1$ - //vp5 hpp file, namespace scope, class context - results = getResults( t, code.indexOf( "C1;//vp5" ) ); //$NON-NLS-1$ - assertEquals( "C()", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( "C1", results[1].getDisplayString()); //$NON-NLS-1$ - assertEquals( "C3", results[2].getDisplayString()); //$NON-NLS-1$ - //trace showed 4 lookup results - assertEquals( 3, results.length); - - } - //test 9 - public void testEmptyDocument() throws Exception { - String code = "\0"; //$NON-NLS-1$ - IFile t = importFile( "testEmptyDocument.h", code ); //$NON-NLS-1$ - //vp1 no prefix, keywords. - ICompletionProposal [] results = getResults( t, 0 ); //$NON-NLS-1$ - assertEquals( "asm", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( "auto", results[1].getDisplayString()); //$NON-NLS-1$ - assertEquals( "bool", results[2].getDisplayString()); //$NON-NLS-1$ - assertEquals( "wchar_t", results[results.length-1].getDisplayString()); //$NON-NLS-1$ - StringWriter writer = new StringWriter(); - //vp2 prefix, keywords - writer.write("s//vp2" ); //$NON-NLS-1$ - code =writer.toString(); - t = importFile( "testEmptyDocument.cpp", code ); //$NON-NLS-1$ - results = getResults( t, code.indexOf( "//vp2" ) ); //$NON-NLS-1$ - assertEquals( "short", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( "signed", results[1].getDisplayString()); //$NON-NLS-1$ - assertEquals( "static", results[2].getDisplayString()); //$NON-NLS-1$ - assertEquals( "struct", results[3].getDisplayString()); //$NON-NLS-1$ - assertEquals( 4, results.length); - - } - public void testVariable() throws Exception { - StringWriter writer = new StringWriter(); - writer.write("namespace N { \n" ); //$NON-NLS-1$ - writer.write(" class ClassT {}; \n" ); //$NON-NLS-1$ - writer.write(" struct StructT {}; \n" ); //$NON-NLS-1$ - writer.write(" typedef struct {} TypedefT; \n" ); //$NON-NLS-1$ - writer.write(" union UnionT {}; \n" ); //$NON-NLS-1$ - writer.write(" ClassT var6; \n" ); //$NON-NLS-1$ - writer.write(" ClassT var7=var6/*vp6*/; \n" ); //$NON-NLS-1$ - writer.write("} \n" ); //$NON-NLS-1$ - String header = writer.toString(); - IFile h=importFile( "testVariable.h", header ); //$NON-NLS-1$ - writer = new StringWriter(); - writer.write("#include \"testVariable.h\" \n" ); //$NON-NLS-1$ - writer.write("using namespace N; \n" ); //$NON-NLS-1$ - writer.write("ClassT var1(){} \n" ); //$NON-NLS-1$ - writer.write("int f(){ \n" ); //$NON-NLS-1$ - writer.write(" StructT var2; \n" ); //$NON-NLS-1$ - writer.write(" TypedefT var3; \n" ); //$NON-NLS-1$ - writer.write(" UnionT var4; \n" ); //$NON-NLS-1$ - writer.write(" bool var5; \n" ); //$NON-NLS-1$ - writer.write(" var5/*vp1*/; \n" ); //$NON-NLS-1$ - writer.write("} \n" ); //$NON-NLS-1$ - String source = writer.toString(); - IFile f=importFile( "testVariable.cpp", source ); //$NON-NLS-1$ - ICompletionProposal [] results = getResults( f, source.indexOf( "5/*vp1*/" ) ); //$NON-NLS-1$ - assertEquals( "var2 : StructT", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( "var3 : TypedefT", results[1].getDisplayString()); //$NON-NLS-1$ - assertEquals( "var4 : UnionT", results[2].getDisplayString()); //$NON-NLS-1$ - assertEquals( "var5 : bool", results[3].getDisplayString()); //$NON-NLS-1$ - assertEquals( "var6 : ClassT", results[4].getDisplayString()); //$NON-NLS-1$ - assertEquals( "var7 : ClassT", results[5].getDisplayString()); //$NON-NLS-1$ - assertEquals( "var1() ClassT", results[6].getDisplayString()); //$NON-NLS-1$ - assertEquals( 7, results.length); - //vp2 namespace scope - results = getResults( h, header.indexOf( "6/*vp6*/" ) ); //$NON-NLS-1$ - assertEquals( "var6 : ClassT", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( 1, results.length); - - } - - public void test80510() throws Exception { - StringWriter writer = new StringWriter(); - writer.write("int aaa; \n" ); //$NON-NLS-1$ - writer.write("class Class1{ \n" ); //$NON-NLS-1$ - writer.write(" Class1(); \n" ); //$NON-NLS-1$ - writer.write(" int abc; \n" ); //$NON-NLS-1$ - writer.write("}; \n" ); //$NON-NLS-1$ - writer.write("Class1::Class1(): abc/*vp1*/(2){} \n" ); //$NON-NLS-1$ - String code = writer.toString(); - IFile t = importFile( "test80510.cpp", code ); //$NON-NLS-1$ - //vp1 - ICompletionProposal [] results = getResults( t, code.indexOf( "bc/*vp1*/" ) ); //$NON-NLS-1$ - assertEquals( 1, results.length); - assertEquals( "abc : int", results[0].getDisplayString()); //$NON-NLS-1$ - } - public void testSingleNameReference() throws Exception { - StringWriter writer = new StringWriter(); - writer.write("int snrV; \n" ); //$NON-NLS-1$ - writer.write("int snrF(int x){} \n" ); //$NON-NLS-1$ - writer.write("class snrC{void g();int snrFd;}; \n" ); //$NON-NLS-1$ - writer.write("struct snrS{}; \n" ); //$NON-NLS-1$ - writer.write("enum snrE{snrER}; \n" ); //$NON-NLS-1$ - writer.write("void foo() { \n" ); //$NON-NLS-1$ - writer.write(" union snrU{ snrU(int a) {};int i; char* j;};\n" ); //$NON-NLS-1$ - writer.write(" snrU sn(snrV); \n" ); //$NON-NLS-1$ - writer.write(" snrV/*vp1*/=snrF/*vp2*/(snrV); \n" ); //$NON-NLS-1$ - writer.write("} \n" ); //$NON-NLS-1$ - writer.write("void snrC::g(){ \n" ); //$NON-NLS-1$ - writer.write(" snrFd/*vp3*/ c; \n" ); //$NON-NLS-1$ - writer.write("} \n" ); //$NON-NLS-1$ - String source = writer.toString(); - IFile cpp=importFile( "testSingleNameReference.cpp", source ); //$NON-NLS-1$ - //vp1 function scope, lvalue - ICompletionProposal [] results = getResults( cpp, source.indexOf( "rV/*vp1*/" ) ); //$NON-NLS-1$ - assertEquals( "sn : snrU", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( "snrV : int", results[1].getDisplayString()); //$NON-NLS-1$ - assertEquals( "snrF(int) int", results[2].getDisplayString()); //$NON-NLS-1$ - assertEquals( "snrC", results[3].getDisplayString()); //$NON-NLS-1$ - assertEquals( "snrS", results[4].getDisplayString()); //$NON-NLS-1$ - assertEquals( "snrU", results[5].getDisplayString()); //$NON-NLS-1$ - assertEquals( "snrER", results[6].getDisplayString()); //$NON-NLS-1$ - assertEquals( "snrE", results[7].getDisplayString()); //$NON-NLS-1$ - assertEquals( 8, results.length); - //vp1 function scope, RHS - results = getResults( cpp, source.indexOf( "rF/*vp2*/" ) ); //$NON-NLS-1$ - assertEquals( "sn : snrU", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( "snrV : int", results[1].getDisplayString()); //$NON-NLS-1$ - assertEquals( "snrF(int) int", results[2].getDisplayString()); //$NON-NLS-1$ - assertEquals( "snrC", results[3].getDisplayString()); //$NON-NLS-1$ - assertEquals( "snrS", results[4].getDisplayString()); //$NON-NLS-1$ - assertEquals( "snrU", results[5].getDisplayString()); //$NON-NLS-1$ - assertEquals( "snrER", results[6].getDisplayString()); //$NON-NLS-1$ - assertEquals( "snrE", results[7].getDisplayString()); //$NON-NLS-1$ - assertEquals( 8, results.length); - //vp1 method scope - results = getResults( cpp, source.indexOf( "rFd/*vp3*/" ) ); //$NON-NLS-1$ - assertEquals( "snrFd : int", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( "snrV : int", results[1].getDisplayString()); //$NON-NLS-1$ - assertEquals( "snrF(int) int", results[2].getDisplayString()); //$NON-NLS-1$ - assertEquals( "snrC", results[3].getDisplayString()); //$NON-NLS-1$ - assertEquals( "snrS", results[4].getDisplayString()); //$NON-NLS-1$ - assertEquals( "snrER", results[5].getDisplayString()); //$NON-NLS-1$ - assertEquals( "snrE", results[6].getDisplayString()); //$NON-NLS-1$ - assertEquals( 7, results.length); - - } - public void testNamespace() throws Exception { - StringWriter writer = new StringWriter(); - writer.write( "namespace Foo{ \n" ); //$NON-NLS-1$ - writer.write( "int x; \n" ); //$NON-NLS-1$ - writer.write( " namespace Baz { \n" ); //$NON-NLS-1$ - writer.write( " int i; \n" ); //$NON-NLS-1$ - writer.write( " } \n" ); //$NON-NLS-1$ - writer.write( " using namespace Baz/*vp1*/; \n" ); //$NON-NLS-1$ - writer.write( "} \n" ); //$NON-NLS-1$ - writer.write( "void g() { \n" ); //$NON-NLS-1$ - writer.write( " Foo::i/*vp2*/ = 1; \n" ); //$NON-NLS-1$ - writer.write( " int y=Foo::Baz::i;//vp3 \n" ); //$NON-NLS-1$ - writer.write( "} \n" ); //$NON-NLS-1$ - writer.write( "namespace Bar = Foo/*vp4*/; \n" ); //$NON-NLS-1$ - String source = writer.toString(); - IFile cpp=importFile( "testNamespace.cpp", source ); //$NON-NLS-1$ - //vp1 using reference, namespace scope, prefixed - ICompletionProposal [] results = getResults( cpp, source.indexOf( "az/*vp1*/" ) ); //$NON-NLS-1$ - assertEquals( "Baz", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( 1, results.length); - //vp1b using reference, namespace scope, no prefix - results = getResults( cpp, source.indexOf( "Baz/*vp1*/" ) ); //$NON-NLS-1$ - assertEquals( "Baz", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( "Foo", results[1].getDisplayString()); //$NON-NLS-1$ - assertEquals( 2, results.length); - //vp2 function scope - results = getResults( cpp, source.indexOf( "oo::i/*vp2*/" ) ); //$NON-NLS-1$ - assertEquals( "Foo", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( 1, results.length); - //vp3 nested namespace, rhs - results = getResults( cpp, source.indexOf( "az::i;//vp3" ) ); //$NON-NLS-1$ - assertEquals( "Baz", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( 1, results.length); - //vp4 alias definition - results = getResults( cpp, source.indexOf( "oo/*vp4*/" ) ); //$NON-NLS-1$ - assertEquals( "Foo", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( 1, results.length); - } - - public void testNamespaceAlias80612() throws Exception { - StringWriter writer = new StringWriter(); - writer.write( "namespace Foo{ \n" ); //$NON-NLS-1$ - writer.write( "int x; \n" ); //$NON-NLS-1$ - writer.write( "} \n" ); //$NON-NLS-1$ - writer.write( "namespace Bar = Foo/*vp4*/; \n" ); //$NON-NLS-1$ - writer.write( "Bar::x; \n" ); //$NON-NLS-1$ - String source = writer.toString(); - IFile cpp=importFile( "testNamespaceAlias80612.cpp", source ); //$NON-NLS-1$ - //vp1 alias reference - ICompletionProposal [] results = getResults( cpp, source.indexOf( "ar::x" ) ); //$NON-NLS-1$ - assertEquals( 1, results.length); - assertEquals( "Bar", results[0].getDisplayString()); //$NON-NLS-1$ - - } - // test 47 - public void testMacro() throws Exception { - StringWriter writer = new StringWriter(); - writer.write("#define INT32_C(x) x ## L \n"); //$NON-NLS-1$ - writer.write("#define INT32_MAX (2147483647) \n"); //$NON-NLS-1$ - writer.write("int main(int argc, char **argv) { \n"); //$NON-NLS-1$ - writer.write(" INT32_C(2);//vp1 \n"); //$NON-NLS-1$ - writer.write(" return (0); \n"); //$NON-NLS-1$ - writer.write("} \n"); //$NON-NLS-1$ - String code = writer.toString(); - IFile t = importFile( "testMacro.c", code ); //$NON-NLS-1$ - ICompletionProposal [] results = getResults( t, code.indexOf( "32_C(2);//vp1" ) ); //$NON-NLS-1$ - assertEquals( "INT32_C(x)", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( "INT32_MAX", results[1].getDisplayString()); //$NON-NLS-1$ - assertEquals( 2, results.length); - } - public void testConstructor() throws Exception { - StringWriter writer = new StringWriter(); - writer.write( "namespace Foo{ \n" ); //$NON-NLS-1$ - writer.write( "class Base{ \n" ); //$NON-NLS-1$ - writer.write( " Base(int x){} \n" ); //$NON-NLS-1$ - writer.write( " }; \n" ); //$NON-NLS-1$ - writer.write( "class Derived: Base{ \n" ); //$NON-NLS-1$ - writer.write( " Derived(): Base/*vp1*/(4){} \n" ); //$NON-NLS-1$ - writer.write( " }; \n" ); //$NON-NLS-1$ - writer.write( "} \n" ); //$NON-NLS-1$ - writer.write( "void f(){ \n" ); //$NON-NLS-1$ - writer.write( " Foo::Derived& x = *(new Foo::Derived/*vp2*/())/; \n" ); //$NON-NLS-1$ - writer.write( "}; \n" ); //$NON-NLS-1$ - String source = writer.toString(); - IFile cpp=importFile( "testConstructor.cpp", source ); //$NON-NLS-1$ - //vp1 initializer list - ICompletionProposal [] results = getResults( cpp, source.indexOf( "ase/*vp1*/" ) ); //$NON-NLS-1$ - assertEquals( 1, results.length); - assertEquals( "Base", results[0].getDisplayString()); //$NON-NLS-1$ - results = getResults( cpp, source.indexOf( "erived/*vp2*/" ) ); //$NON-NLS-1$ - assertEquals( 1, results.length); - assertEquals( "Derived", results[0].getDisplayString()); //$NON-NLS-1$ - - } - public void testUnion() throws Exception { - StringWriter writer = new StringWriter(); - writer.write( "namespace Foo{ \n" ); //$NON-NLS-1$ - writer.write( "union uni1{}; \n" ); //$NON-NLS-1$ - writer.write( "class c1{ \n" ); //$NON-NLS-1$ - writer.write( " public: union uni2{} s; \n" ); //$NON-NLS-1$ - writer.write( "}; \n" ); //$NON-NLS-1$ - writer.write( "namespace N{ \n" ); //$NON-NLS-1$ - writer.write( " union uni3{}; \n" ); //$NON-NLS-1$ - writer.write( " class c2{ \n" ); //$NON-NLS-1$ - writer.write( " uni1/*vp1*/ s; \n" ); //$NON-NLS-1$ - writer.write( " uni3 ss; \n" ); //$NON-NLS-1$ - writer.write( " c2() { \n" ); //$NON-NLS-1$ - writer.write( " c1::uni2/*vp2*/ s; \n" ); //$NON-NLS-1$ - writer.write( " union uni3/*vp3*/ t; \n" ); //$NON-NLS-1$ - writer.write( " } \n" ); //$NON-NLS-1$ - writer.write( " }; \n" ); //$NON-NLS-1$ - writer.write( "} \n" ); //$NON-NLS-1$ - String source = writer.toString(); - IFile cpp=importFile( "testUnion.cpp", source ); //$NON-NLS-1$ - //vp1 method scope - ICompletionProposal [] results = getResults( cpp, source.indexOf( "1/*vp1*/" ) ); //$NON-NLS-1$ - assertEquals( 3, results.length); - assertEquals( "uni1", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( "uni3", results[1].getDisplayString()); //$NON-NLS-1$ - assertEquals( "union", results[2].getDisplayString()); //$NON-NLS-1$ - //vp2 :: access, in method scope, - results = getResults( cpp, source.indexOf( "i2/*vp2*/" ) );//$NON-NLS-1$ - assertEquals( 1, results.length); - assertEquals( "uni2", results[0].getDisplayString()); //$NON-NLS-1$ - //c style declaration, method scope - results = getResults( cpp, source.indexOf( "i3/*vp3*/" ) );//$NON-NLS-1$ - assertEquals( 2, results.length); - assertEquals( "uni1", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( "uni3", results[1].getDisplayString()); //$NON-NLS-1$ - - } - - public void testKeyword() throws Exception { - StringWriter writer = new StringWriter(); - writer.write( "class/*vp1*/ Foo{ \n" ); //$NON-NLS-1$ - writer.write( "void f(); \n" ); //$NON-NLS-1$ - writer.write( " public/*vp2*/: Foo(); \n" ); //$NON-NLS-1$ - writer.write( "}; \n" ); //$NON-NLS-1$ - writer.write( "void Foo::f() { \n" ); //$NON-NLS-1$ - writer.write( " void/*vp3*/* g; \n" ); //$NON-NLS-1$ - writer.write( "} \n" ); //$NON-NLS-1$ - String source = writer.toString(); - IFile cpp=importFile( "testKeyword.cpp", source ); //$NON-NLS-1$ - //vp1 global - ICompletionProposal [] results = getResults( cpp, source.indexOf( "lass/*vp1*/" ) ); //$NON-NLS-1$ - assertEquals( 3, results.length); - assertEquals( "char", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( "class", results[1].getDisplayString()); //$NON-NLS-1$ - assertEquals( "const", results[2].getDisplayString()); //$NON-NLS-1$ - //vp2 class - results = getResults( cpp, source.indexOf( "lic/*vp2*/" ) );//$NON-NLS-1$ - assertEquals( 1, results.length); - assertEquals( "public", results[0].getDisplayString()); //$NON-NLS-1$ - //vp3 method - results = getResults( cpp, source.indexOf( "d/*vp3*/" ) );//$NON-NLS-1$ - assertEquals( 1, results.length); - assertEquals( "void", results[0].getDisplayString()); //$NON-NLS-1$ - - } - public void testBase() throws Exception { - StringWriter writer = new StringWriter(); - writer.write( "class Base{ \n" ); //$NON-NLS-1$ - writer.write( " Base(); \n" ); //$NON-NLS-1$ - writer.write( " protected: int b();\n" ); //$NON-NLS-1$ - writer.write( "}; \n" ); //$NON-NLS-1$ - writer.write( "class Derived: Base{ \n" ); //$NON-NLS-1$ - writer.write( " Derived(); \n" ); //$NON-NLS-1$ - writer.write( " void d() { \n" ); //$NON-NLS-1$ - writer.write( " b/*vp1*/{ \n" ); //$NON-NLS-1$ - writer.write( "}; \n" ); //$NON-NLS-1$ - String source = writer.toString(); - IFile cpp=importFile( "testBase.cpp", source ); //$NON-NLS-1$ - //vp1 method scope - ICompletionProposal [] results = getResults( cpp, source.indexOf( "/*vp1*/" ) ); //$NON-NLS-1$ - assertEquals( 4, results.length); - assertEquals( "b() int", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( "Base", results[1].getDisplayString()); //$NON-NLS-1$ - assertEquals( "bool", results[2].getDisplayString()); //$NON-NLS-1$ - assertEquals( "break", results[3].getDisplayString()); //$NON-NLS-1$ - - } - public void testThis() throws Exception { - StringWriter writer = new StringWriter(); - writer.write( "class X{ \n" ); //$NON-NLS-1$ - writer.write( " X& X::operator=(const X& rhs){ \n"); //$NON-NLS-1$ - writer.write( " if(this/*vp1*/==&rhs)return *this; \n" ); //$NON-NLS-1$ - writer.write( " (*this/*vp2*/).aVar=rhs.aVar; \n" ); //$NON-NLS-1$ - writer.write( " this/*vp3*/->anotherVar=rhs.anotherVar;\n" ); //$NON-NLS-1$ - writer.write( " return *this; \n" ); //$NON-NLS-1$ - writer.write( " } \n" ); //$NON-NLS-1$ - writer.write( " int aVar, anotherVar; \n" ); //$NON-NLS-1$ - writer.write( "}; \n" ); //$NON-NLS-1$ - String source = writer.toString(); - IFile cpp=importFile( "testThis.cpp", source ); //$NON-NLS-1$ - //vp1 method scope - ICompletionProposal [] results = getResults( cpp, source.indexOf( "s/*vp1*/" ) ); //$NON-NLS-1$ - assertEquals( 1, results.length); - assertEquals( "this", results[0].getDisplayString()); //$NON-NLS-1$ - results = getResults( cpp, source.indexOf( "s/*vp2*/" ) ); //$NON-NLS-1$ - assertEquals( 1, results.length); - assertEquals( "this", results[0].getDisplayString()); //$NON-NLS-1$ - results = getResults( cpp, source.indexOf( "s/*vp3*/" ) ); //$NON-NLS-1$ - assertEquals( 1, results.length); - assertEquals( "this", results[0].getDisplayString()); //$NON-NLS-1$ - - } - public void testClassScope() throws Exception { - StringWriter writer = new StringWriter(); - writer.write( "class Foo{ \n" ); //$NON-NLS-1$ - writer.write( " public: \n" ); //$NON-NLS-1$ - writer.write( " Foo(){} \n" ); //$NON-NLS-1$ - writer.write( " int getThatVar(); \n" ); //$NON-NLS-1$ - writer.write( " private: \n" ); //$NON-NLS-1$ - writer.write( " int thatVar; \n" ); //$NON-NLS-1$ - writer.write( " }; \n" ); //$NON-NLS-1$ - String header = writer.toString(); - importFile( "testClassScope.h", header ); //$NON-NLS-1$ - writer.write( " #include \"testClassScope.h\" \n" ); //$NON-NLS-1$ - writer.write( " int Foo::getThatVar/*vp1*/(){ \n" ); //$NON-NLS-1$ - writer.write( " return thatVar/*vp2*/; \n" ); //$NON-NLS-1$ - writer.write( " } \n" ); //$NON-NLS-1$ - String source = writer.toString(); - IFile cpp=importFile( "testClassScope.cpp", source ); //$NON-NLS-1$ - //vp1 method scope - ICompletionProposal [] results = getResults( cpp, source.indexOf( "Var/*vp1*/" ) ); //$NON-NLS-1$ - assertEquals( 1, results.length); - assertEquals( "getThatVar() int", results[0].getDisplayString()); //$NON-NLS-1$ - results = getResults( cpp, source.indexOf( "Var/*vp2*/" ) ); //$NON-NLS-1$ - assertEquals( 1, results.length); - assertEquals( "thatVar : int", results[0].getDisplayString()); //$NON-NLS-1$ - - } - - public void testClassScope72564() throws Exception { - StringWriter writer = new StringWriter(); - writer.write( "class X{ \n" ); //$NON-NLS-1$ - writer.write( "class ElStatico{ \n" ); //$NON-NLS-1$ - writer.write( " public: \n" ); //$NON-NLS-1$ - writer.write( " ElStatico(){} \n" ); //$NON-NLS-1$ - writer.write( " virtual ~ElStatico(){} \n" ); //$NON-NLS-1$ - writer.write( " private: \n" ); //$NON-NLS-1$ - writer.write( " static int aClsVar; \n" ); //$NON-NLS-1$ - writer.write( " }; \n" ); //$NON-NLS-1$ - String header = writer.toString(); - importFile( "testClassScope72564.h", header ); //$NON-NLS-1$ - writer.write( " #include \"testClassScope72564.h\" \n" ); //$NON-NLS-1$ - writer.write( " int ElStatico::aClsVar/*vp1*/ = 10; \n" ); //$NON-NLS-1$ - String source = writer.toString(); - IFile cpp=importFile( "testClassScope72564.cpp", source ); //$NON-NLS-1$ - //vp1 method scope - ICompletionProposal [] results = getResults( cpp, source.indexOf( "Var/*vp1*/" ) ); //$NON-NLS-1$ - assertEquals( 1, results.length); - assertEquals( "aClsVar", results[0].getDisplayString()); //$NON-NLS-1$ - - } - public void testMultiLevelQualifiers() throws Exception { - StringWriter writer = new StringWriter(); - writer.write( "class A{ \n" ); //$NON-NLS-1$ - writer.write( "public: class B{ \n" ); //$NON-NLS-1$ - writer.write( "public: class C{ \n" ); //$NON-NLS-1$ - writer.write( "public: class D{ \n" ); //$NON-NLS-1$ - writer.write( "public: class E{ \n" ); //$NON-NLS-1$ - writer.write( "public: class F{ \n" ); //$NON-NLS-1$ - writer.write( "public: class G{ \n" ); //$NON-NLS-1$ - writer.write( "public: class H{ \n" ); //$NON-NLS-1$ - writer.write( "public: class I{ \n" ); //$NON-NLS-1$ - writer.write( "public: class J{ \n" ); //$NON-NLS-1$ - writer.write( "public: class K{ \n" ); //$NON-NLS-1$ - writer.write( "public: class L{ \n" ); //$NON-NLS-1$ - writer.write( "public: class M{ \n" ); //$NON-NLS-1$ - writer.write( "}m;}l;}k;}j;}i;}h;}g;}f;}e;}d;}c;}b;}; \n" ); //$NON-NLS-1$ - writer.write( " A a; \n" ); //$NON-NLS-1$ - writer.write( " void f(){ \n" ); //$NON-NLS-1$ - writer.write( " a.b.c.d.e.f.g.h.i.j.k.l.m/*vp1*/; \n" ); //$NON-NLS-1$ - writer.write( " } \n" ); //$NON-NLS-1$ - String source = writer.toString(); - IFile cpp=importFile( "testMultiLevelQualifiers.cpp", source ); //$NON-NLS-1$ - //vp1 13 qualifier depth - ICompletionProposal [] results = getResults( cpp, source.indexOf( "m/*vp1*/" ) ); //$NON-NLS-1$ - assertEquals( 1, results.length); - assertEquals( "m : M", results[0].getDisplayString()); //$NON-NLS-1$ - - } - public void testCase() throws Exception { - StringWriter writer = new StringWriter(); - writer.write( "class Ananas{ \n" ); //$NON-NLS-1$ - writer.write( "public: Ananas(); \n" ); //$NON-NLS-1$ - writer.write( "void ananas(int i); \n" ); //$NON-NLS-1$ - writer.write( "int aNaNaS(); \n" ); //$NON-NLS-1$ - writer.write( "int ANAnas; \n" ); //$NON-NLS-1$ - writer.write( "}; \n" ); //$NON-NLS-1$ - writer.write( "int ananaS; \n" ); //$NON-NLS-1$ - writer.write( "void anaNAS(){ \n" ); //$NON-NLS-1$ - writer.write( "Ananas/*vp1*/ a; \n" ); //$NON-NLS-1$ - writer.write( "a.aNaNaS/*vp2*/(); \n" ); //$NON-NLS-1$ - writer.write( "} \n" ); //$NON-NLS-1$ - String source = writer.toString(); - IFile cpp=importFile( "testCase.cpp", source ); //$NON-NLS-1$ - //vp1 global scope - ICompletionProposal [] results = getResults( cpp, source.indexOf( "nas/*vp1*/" ) ); //$NON-NLS-1$ - assertEquals( 3, results.length); - assertEquals( "Ananas", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( "ananaS : int", results[1].getDisplayString()); //$NON-NLS-1$ - assertEquals( "anaNAS() void", results[2].getDisplayString()); //$NON-NLS-1$ - //vp2 class scope - results = getResults( cpp, source.indexOf( "NaS/*vp2*/" ) ); //$NON-NLS-1$ - assertEquals( 3, results.length); - assertEquals( "aNaNaS() int", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( "ANAnas : int", results[1].getDisplayString()); //$NON-NLS-1$ - assertEquals( "ananas(int) void", results[2].getDisplayString()); //$NON-NLS-1$ - } - //test 32 - public void testType() throws Exception { - StringWriter writer = new StringWriter(); - writer.write("namespace N { \n" ); //$NON-NLS-1$ - writer.write(" class ClassT {}; \n" ); //$NON-NLS-1$ - writer.write(" struct StructT {}; \n" ); //$NON-NLS-1$ - writer.write(" typedef struct {} TypedefT; \n" ); //$NON-NLS-1$ - writer.write(" union UnionT {}; \n" ); //$NON-NLS-1$ - writer.write("} \n" ); //$NON-NLS-1$ - String codeH = writer.toString(); - importFile( "testType.h", codeH ); //$NON-NLS-1$ - writer = new StringWriter(); - writer.write("#include \"testType.h\" \n" ); //$NON-NLS-1$ - writer.write("int main (int argc, char** argv){ \n" ); //$NON-NLS-1$ - writer.write(" using namespace N; \n" ); //$NON-NLS-1$ - writer.write(" ClassT/*vp1*/ c; \n" ); //$NON-NLS-1$ - writer.write(" StructT/*vp2*/ d; \n" ); //$NON-NLS-1$ - writer.write(" TypedefT/*vp3*/ e; \n" ); //$NON-NLS-1$ - writer.write(" UnionT/*vp4*/ f; \n" ); //$NON-NLS-1$ - writer.write(" bool/*vp5*/ b; \n" ); //$NON-NLS-1$ - writer.write("} \n" ); //$NON-NLS-1$ - String code = writer.toString(); - IFile f=importFile( "testType.cpp", code ); //$NON-NLS-1$ - ICompletionProposal [] results = getResults( f, code.indexOf( "T/*vp1*/" ) ); //$NON-NLS-1$ - assertEquals( "ClassT", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( 1, results.length); - results = getResults( f, code.indexOf( "T/*vp2*/" ) ); //$NON-NLS-1$ - assertEquals( "StructT", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( 1, results.length); - results = getResults( f, code.indexOf( "T/*vp3*/" ) ); //$NON-NLS-1$ - assertEquals( "TypedefT", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( 1, results.length); - results = getResults( f, code.indexOf( "T/*vp4*/" ) ); //$NON-NLS-1$ - assertEquals( "UnionT", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( 1, results.length); - results = getResults( f, code.indexOf( "l/*vp5*/" ) ); //$NON-NLS-1$ - assertEquals( "bool", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( 1, results.length); - } - //this doesn't test defect 72403 where try catch fails when a system file is included - public void testTryCatch() throws Exception { - StringWriter writer = new StringWriter(); - writer.write("class MyException{ \n" ); //$NON-NLS-1$ - writer.write(" public: \n" ); //$NON-NLS-1$ - writer.write(" MyException(const char *msg){} \n" ); //$NON-NLS-1$ - writer.write(" const char* getMsg(){return \"error\";} \n" ); //$NON-NLS-1$ - writer.write("}; \n" ); //$NON-NLS-1$ - writer.write("void someFunction() { \n" ); //$NON-NLS-1$ - writer.write(" throw MyException(\"someFunction is in trouble\");\n" ); //$NON-NLS-1$ - writer.write("} \n" ); //$NON-NLS-1$ - writer.write("void k(){ \n" ); //$NON-NLS-1$ - writer.write(" try { \n" ); //$NON-NLS-1$ - writer.write(" someFunction/*vp1*/(); \n" ); //$NON-NLS-1$ - writer.write(" } catch (MyException &e) { \n" ); //$NON-NLS-1$ - writer.write(" e.getMsg/*vp2*/(); \n" ); //$NON-NLS-1$ - writer.write(" } \n" ); //$NON-NLS-1$ - writer.write("} \n" ); //$NON-NLS-1$ - String code = writer.toString(); - IFile f=importFile( "testTryCatch.cpp", code ); //$NON-NLS-1$ - ICompletionProposal [] results = getResults( f, code.indexOf( "Function/*vp1*/" ) ); //$NON-NLS-1$ - assertEquals( "someFunction() void", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( 1, results.length); - results = getResults( f, code.indexOf( "Msg/*vp2*/" ) ); //$NON-NLS-1$ - assertEquals( "getMsg() const char*", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( 1, results.length); - } - public void testArrays() throws Exception { - StringWriter writer = new StringWriter(); - writer.write(" class A{ \n" ); //$NON-NLS-1$ - writer.write(" public: \n" ); //$NON-NLS-1$ - writer.write(" A(){} \n" ); //$NON-NLS-1$ - writer.write(" void aa(); \n" ); //$NON-NLS-1$ - writer.write(" int aaa; \n" ); //$NON-NLS-1$ - writer.write(" static int bbb; \n" ); //$NON-NLS-1$ - writer.write(" }; \n" ); //$NON-NLS-1$ - writer.write(" void fodo(){ \n" ); //$NON-NLS-1$ - writer.write(" A a_array[10]; \n" ); //$NON-NLS-1$ - writer.write(" A* b_array[10]; \n" ); //$NON-NLS-1$ - writer.write(" for (int i=0; i<10;i++){ \n" ); //$NON-NLS-1$ - writer.write(" a_array[i].aaa/*vp1*/=3;\n" ); //$NON-NLS-1$ - writer.write(" int x=b_array[i]->bbb/*vp2*/;\n" ); //$NON-NLS-1$ - writer.write(" } \n" ); //$NON-NLS-1$ - String code = writer.toString(); - IFile f=importFile( "testArrays.cpp", code ); //$NON-NLS-1$ - //vp1 dot ref - ICompletionProposal [] results = getResults( f, code.indexOf( "a/*vp1*/" ) ); //$NON-NLS-1$ - assertEquals( "aa() void", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( "aaa : int", results[1].getDisplayString()); //$NON-NLS-1$ - assertEquals( 2, results.length); - //vp2 arrow ref - results = getResults( f, code.indexOf( "bbb/*vp2*/" ) ); //$NON-NLS-1$ - assertEquals( "aaa : int", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( "bbb : int", results[1].getDisplayString()); //$NON-NLS-1$ - assertEquals( "aa() void", results[2].getDisplayString()); //$NON-NLS-1$ - assertEquals( 3, results.length); - } - public void testStruct() throws Exception { - StringWriter writer = new StringWriter(); - writer.write("//aggregate struct (no constructor) \n" ); //$NON-NLS-1$ - writer.write("struct myStruct_c{int m;}ss1={1},ss2={2}; \n" ); //$NON-NLS-1$ - writer.write("void foo() { \n" ); //$NON-NLS-1$ - writer.write(" myStruct_c *ss3; \n" ); //$NON-NLS-1$ - writer.write(" ss3->m=3; \n" ); //$NON-NLS-1$ - writer.write(" int i=(ss1.m/*vp1*/ > ss3->m/*vp2*/ ? ss1/*vp3*/ : ss2/*vp4*/).m;\n" ); //$NON-NLS-1$ - writer.write(" //struct with constructor \n" ); //$NON-NLS-1$ - writer.write(" sizeof(myStruct_c/*vp8*/); \n" ); //$NON-NLS-1$ - writer.write(" struct myStruct_cpp { \n" ); //$NON-NLS-1$ - writer.write(" myStruct_cpp(int x){z=x;} \n" ); //$NON-NLS-1$ - writer.write(" int z; \n" ); //$NON-NLS-1$ - writer.write(" }; \n" ); //$NON-NLS-1$ - writer.write(" myStruct_cpp ss4(4), *ss5; \n" ); //$NON-NLS-1$ - writer.write(" ss5=new myStruct_cpp/*vp9*/(5); \n" ); //$NON-NLS-1$ - writer.write(" 3>ss4.z/*vp5*/ ? ss5->z/*vp6*/ : ss4.z/*vp7*/; \n" ); //$NON-NLS-1$ - writer.write("} \n" ); //$NON-NLS-1$ - String code = writer.toString(); - IFile f=importFile( "testStruct.cpp", code ); //$NON-NLS-1$ - //vp1 aggregate: first operand of ?:, first operand of > - ICompletionProposal [] results = getResults( f, code.indexOf( "1.m/*vp1*/" ) ); //$NON-NLS-1$ - assertEquals( "ss3 : myStruct_c*", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( "ss1 : myStruct_c", results[1].getDisplayString()); //$NON-NLS-1$ - assertEquals( "ss2 : myStruct_c", results[2].getDisplayString()); //$NON-NLS-1$ - assertEquals( 3, results.length); - //vp2 aggregate: first operand of ?:, second operand of > - results = getResults( f, code.indexOf( "3->m/*vp2*/" ) ); //$NON-NLS-1$ - assertEquals( "ss3 : myStruct_c*", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( "ss1 : myStruct_c", results[1].getDisplayString()); //$NON-NLS-1$ - assertEquals( "ss2 : myStruct_c", results[2].getDisplayString()); //$NON-NLS-1$ - assertEquals( 3, results.length); - //vp3 aggregate: second operand of ?: - results = getResults( f, code.indexOf( "1/*vp3*/" ) ); //$NON-NLS-1$ - assertEquals( "ss3 : myStruct_c*", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( "ss1 : myStruct_c", results[1].getDisplayString()); //$NON-NLS-1$ - assertEquals( "ss2 : myStruct_c", results[2].getDisplayString()); //$NON-NLS-1$ - assertEquals( 3, results.length); - //vp4 aggregate: third operand of ?: - results = getResults( f, code.indexOf( "2/*vp4*/" ) ); //$NON-NLS-1$ - assertEquals( "ss3 : myStruct_c*", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( "ss1 : myStruct_c", results[1].getDisplayString()); //$NON-NLS-1$ - assertEquals( "ss2 : myStruct_c", results[2].getDisplayString()); //$NON-NLS-1$ - assertEquals( 3, results.length); - //vp5 first operand of ?:, second operand of > - results = getResults( f, code.indexOf( "4.z/*vp5*/" ) ); //$NON-NLS-1$ - assertEquals( "ss3 : myStruct_c*", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( "ss4 : myStruct_cpp", results[1].getDisplayString()); //$NON-NLS-1$ - assertEquals( "ss5 : myStruct_cpp*", results[2].getDisplayString()); //$NON-NLS-1$ - assertEquals( "ss1 : myStruct_c", results[3].getDisplayString()); //$NON-NLS-1$ - assertEquals( "ss2 : myStruct_c", results[4].getDisplayString()); //$NON-NLS-1$ - assertEquals( 5, results.length); - //vp6 second operand of ?: - results = getResults( f, code.indexOf( "5->z/*vp6*/" ) ); //$NON-NLS-1$ - assertEquals( "ss3 : myStruct_c*", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( "ss4 : myStruct_cpp", results[1].getDisplayString()); //$NON-NLS-1$ - assertEquals( "ss5 : myStruct_cpp*", results[2].getDisplayString()); //$NON-NLS-1$ - assertEquals( "ss1 : myStruct_c", results[3].getDisplayString()); //$NON-NLS-1$ - assertEquals( "ss2 : myStruct_c", results[4].getDisplayString()); //$NON-NLS-1$ - assertEquals( 5, results.length); - //vp7 third operand of ?: - results = getResults( f, code.indexOf( "4.z/*vp7*/" ) ); //$NON-NLS-1$ - assertEquals( "ss3 : myStruct_c*", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( "ss4 : myStruct_cpp", results[1].getDisplayString()); //$NON-NLS-1$ - assertEquals( "ss5 : myStruct_cpp*", results[2].getDisplayString()); //$NON-NLS-1$ - assertEquals( "ss1 : myStruct_c", results[3].getDisplayString()); //$NON-NLS-1$ - assertEquals( "ss2 : myStruct_c", results[4].getDisplayString()); //$NON-NLS-1$ - assertEquals( 5, results.length); - //vp8 struct type in sizeof - results = getResults( f, code.indexOf( "Struct_c/*vp8*/" ) ); //$NON-NLS-1$ - assertEquals( "myStruct_c", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( 1, results.length); - //vp9 constructor call - results = getResults( f, code.indexOf( "Struct_cpp/*vp9*/" ) ); //$NON-NLS-1$ - assertEquals( "myStruct_c", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( "myStruct_cpp", results[1].getDisplayString()); //$NON-NLS-1$ - assertEquals( 2, results.length); - } - // test 16 template completion - // template test framework not implemented - public void testCodeTemplate() throws Exception { - StringWriter writer = new StringWriter(); - writer.write("int main(int argc, char **argv) { \n" ); //$NON-NLS-1$ - writer.write(" int max=10; \n" ); //$NON-NLS-1$ - writer.write(" bool condition=false; \n" ); //$NON-NLS-1$ - writer.write(" int key=1; \n" ); //$NON-NLS-1$ - writer.write(" const int value=1; \n" ); //$NON-NLS-1$ - writer.write(" for/*vp1*/ (int var = 0; var < max; ++var) {\n" ); //$NON-NLS-1$ - writer.write(" \n" ); //$NON-NLS-1$ - writer.write(" } \n" ); //$NON-NLS-1$ - writer.write(" do/*vp2*/ { \n" ); //$NON-NLS-1$ - writer.write(" \n" ); //$NON-NLS-1$ - writer.write(" } while (condition); \n" ); //$NON-NLS-1$ - writer.write(" switch/*vp3*/ (key) { \n" ); //$NON-NLS-1$ - writer.write(" case value: \n" ); //$NON-NLS-1$ - writer.write(" \n" ); //$NON-NLS-1$ - writer.write(" break; \n" ); //$NON-NLS-1$ - writer.write(" default: \n" ); //$NON-NLS-1$ - writer.write(" break; \n" ); //$NON-NLS-1$ - writer.write(" } \n" ); //$NON-NLS-1$ - writer.write("} \n" ); //$NON-NLS-1$ - String code = writer.toString(); - IFile t = importFile( "testCodeTemplate.cpp", code ); //$NON-NLS-1$ - //vp1 for template - ICompletionProposal [] results = getResults( t, code.indexOf( "/*vp1*/" ) ); //$NON-NLS-1$ - assertEquals( 3, results.length); - assertEquals( "for", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( "for - for loop", results[1].getDisplayString()); //$NON-NLS-1$ - assertEquals( "for - for loop with temporary variable", results[2].getDisplayString()); //$NON-NLS-1$ - //vp2 do while loop template - assertEquals( 3, results.length); - results = getResults( t, code.indexOf( "/*vp2*/" ) ); //$NON-NLS-1$ - assertEquals( "do", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( "double", results[1].getDisplayString()); //$NON-NLS-1$ - assertEquals( "do - do while statement", results[2].getDisplayString()); //$NON-NLS-1$ - //vp3 switch case statement template - assertEquals( 2, results.length); - results = getResults( t, code.indexOf( "ch/*vp3*/" ) ); //$NON-NLS-1$ - assertEquals( "switch", results[0].getDisplayString()); //$NON-NLS-1$ - assertEquals( "switch - switch case statement", results[1].getDisplayString()); //$NON-NLS-1$ - - } -} diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/regression/RefactoringRegressionTests.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/regression/RefactoringRegressionTests.java deleted file mode 100644 index c99064fd0dc..00000000000 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/regression/RefactoringRegressionTests.java +++ /dev/null @@ -1,1344 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004, 2005 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 Corporation - initial API and implementation - *******************************************************************************/ - -/* - * Created on Nov 10, 2004 - */ -package org.eclipse.cdt.ui.tests.regression; - -import java.io.StringWriter; - -import junit.framework.AssertionFailedError; -import junit.framework.Test; -import junit.framework.TestSuite; - -import org.eclipse.cdt.core.model.CModelException; -import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.cdt.core.model.ISourceReference; -import org.eclipse.cdt.core.tests.FailingTest; -import org.eclipse.cdt.core.tests.SearchRegressionTests; -import org.eclipse.cdt.internal.core.model.CModelManager; -import org.eclipse.cdt.internal.core.model.TranslationUnit; -import org.eclipse.cdt.internal.corext.refactoring.RenameRefactoring; -import org.eclipse.cdt.internal.corext.refactoring.base.IChange; -import org.eclipse.cdt.internal.corext.refactoring.base.ICompositeChange; -import org.eclipse.cdt.internal.corext.refactoring.base.RefactoringStatus; -import org.eclipse.cdt.internal.corext.refactoring.base.RefactoringStatusEntry; -import org.eclipse.cdt.internal.corext.refactoring.changes.TranslationUnitChange; -import org.eclipse.cdt.internal.corext.refactoring.rename.RenameElementProcessor; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.NullProgressMonitor; -import java.util.List; -import org.eclipse.text.edits.MultiTextEdit; -import org.eclipse.text.edits.ReplaceEdit; -import org.eclipse.text.edits.TextEdit; - -/** - * @author aniefer - */ -public class RefactoringRegressionTests extends SearchRegressionTests { - - public RefactoringRegressionTests() - { - super(); - } - public RefactoringRegressionTests(String name) - { - super(name); - } - - /** - * - * @param element The CElement to rename - * @param newName The new name for the element - * @return - * @throws Exception - */ - public IChange getRefactorChanges( ISourceReference element, String newName ) throws Exception { - RenameRefactoring fRefactoring = new RenameRefactoring(element); - RenameElementProcessor processor = (RenameElementProcessor) fRefactoring.getProcessor(); - processor.setNewElementName( newName ); - - RefactoringStatus rs =fRefactoring.checkInput( new NullProgressMonitor() ); - if (!rs.hasError()){ - IChange change = fRefactoring.createChange( new NullProgressMonitor() ); - return change; - } - - fail ("Input check on "+ newName + " failed. "+rs.getFirstMessage(RefactoringStatus.ERROR) ); //$NON-NLS-1$ //$NON-NLS-2$ - //rs.getFirstMessage(RefactoringStatus.ERROR) is not the message displayed in - //the UI for renaming a method to a constructor, the first message which is only - //a warning is shown in the UI. If you click preview, then the error and the warning - //is shown. - return null; - } - public String[] getRefactorMessages( ISourceReference element, String newName ) throws Exception { - String[] result; - RenameRefactoring fRefactoring = new RenameRefactoring(element); - RenameElementProcessor processor = (RenameElementProcessor) fRefactoring.getProcessor(); - processor.setNewElementName( newName ); - - RefactoringStatus rs =fRefactoring.checkInput( new NullProgressMonitor() ); - if (!rs.hasWarning()){ - fail ("Input check on "+ newName + " passed. There should have been warnings or errors. ") ; //$NON-NLS-1$ //$NON-NLS-2$ - return null; - } - List rse = rs.getEntries(); - result = new String[rse.size()]; - for (int i=0; i< rse.size(); i++){ - RefactoringStatusEntry entry = (RefactoringStatusEntry) rse.get(i); - result[i]=entry.getMessage(); - - } - return result; - } - public int getRefactorSeverity( ISourceReference element, String newName ) throws Exception { - RenameRefactoring fRefactoring = new RenameRefactoring(element); - RenameElementProcessor processor = (RenameElementProcessor) fRefactoring.getProcessor(); - processor.setNewElementName( newName ); - - RefactoringStatus rs =fRefactoring.checkInput( new NullProgressMonitor() ); - - return (rs.getSeverity()); - } - protected ISourceReference findElementAtOffset( IFile file, int offset ) throws CModelException{ - CModelManager manager = CModelManager.getDefault(); - TranslationUnit tu = (TranslationUnit) manager.create( file, cproject ); - ICElement el = tu.getElementAtOffset( offset ); - return (ISourceReference) ( ( el instanceof ISourceReference ) ? el : null ); - } - - public static Test suite(){ - return suite( true ); - } - public static Test suite( boolean cleanup ) { - TestSuite suite = new TestSuite("RefactoringRegressionTests"); //$NON-NLS-1$ - suite.addTest( new RefactoringRegressionTests("testSimpleRename") ); //$NON-NLS-1$ - suite.addTest( new RefactoringRegressionTests("testClass_1") ); //$NON-NLS-1$ - suite.addTest( new RefactoringRegressionTests("testAttribute_2") ); //$NON-NLS-1$ - suite.addTest( new RefactoringRegressionTests("testMethod_3") ); //$NON-NLS-1$ - suite.addTest( new RefactoringRegressionTests("testConstructor_26") ); //$NON-NLS-1$ - suite.addTest( new RefactoringRegressionTests("testConstructor_27") ); //$NON-NLS-1$ - suite.addTest( new RefactoringRegressionTests("testDestructor_28") ); //$NON-NLS-1$ - suite.addTest( new FailingTest( new RefactoringRegressionTests("testDestructor_29_72612"), 72612) ); //$NON-NLS-1$ -// suite.addTest( new RefactoringRegressionTests("testFunction_31") ); //$NON-NLS-1$ - suite.addTest( new FailingTest( new RefactoringRegressionTests("testMethod_32_72717"),72717) ); //$NON-NLS-1$ - suite.addTest( new RefactoringRegressionTests("testMethod_33_72605") ); //$NON-NLS-1$ - suite.addTest( new RefactoringRegressionTests("testMethod_34") ); //$NON-NLS-1$ - suite.addTest( new FailingTest( new RefactoringRegressionTests("testMethod_35_72726"),72726) ); //$NON-NLS-1$ - suite.addTest( new RefactoringRegressionTests("testMethod_39") ); //$NON-NLS-1$ - suite.addTest( new RefactoringRegressionTests("testMethod_40") ); //$NON-NLS-1$ - suite.addTest( new RefactoringRegressionTests("testMethod_41") ); //$NON-NLS-1$ - suite.addTest( new RefactoringRegressionTests("testMethod_43") ); //$NON-NLS-1$ - suite.addTest( new RefactoringRegressionTests("testMethod_44") ); //$NON-NLS-1$ - suite.addTest( new FailingTest( new RefactoringRegressionTests("testMethod_45_72723"), 72723) ); //$NON-NLS-1$ - suite.addTest( new RefactoringRegressionTests("testStruct_46") ); //$NON-NLS-1$ - suite.addTest( new RefactoringRegressionTests("testUnion_47") ); //$NON-NLS-1$ - suite.addTest( new RefactoringRegressionTests("testEnumeration_48") ); //$NON-NLS-1$ - suite.addTest( new FailingTest( new RefactoringRegressionTests("testTemplate_49_72626"), 72626) ); //$NON-NLS-1$ - suite.addTest( new RefactoringRegressionTests("testClass_52") ); //$NON-NLS-1$ - suite.addTest( new RefactoringRegressionTests("testClass_53") ); //$NON-NLS-1$ - suite.addTest( new RefactoringRegressionTests("testAttribute_54") ); //$NON-NLS-1$ - suite.addTest( new FailingTest( new RefactoringRegressionTests("testClass_55_79231"), 79231) ); //$NON-NLS-1$ - suite.addTest( new RefactoringRegressionTests("testClass_55") ); //$NON-NLS-1$ - suite.addTest( new RefactoringRegressionTests("testClass_55_72748")); //$NON-NLS-1$ - suite.addTest( new RefactoringRegressionTests("testClass_56") ); //$NON-NLS-1$ - suite.addTest( new RefactoringRegressionTests("testClass_60") ); //$NON-NLS-1$ - suite.addTest( new RefactoringRegressionTests("testAttribute_61") ); //$NON-NLS-1$ - suite.addTest( new RefactoringRegressionTests("testEnumerator_62") ); //$NON-NLS-1$ - suite.addTest( new RefactoringRegressionTests("testAttribute_63") ); //$NON-NLS-1$ - suite.addTest( new RefactoringRegressionTests("testAttribute_64") ); //$NON-NLS-1$ - suite.addTest( new RefactoringRegressionTests("testAttribute_65") ); //$NON-NLS-1$ - suite.addTest( new RefactoringRegressionTests("testNamespace_66") ); //$NON-NLS-1$ - suite.addTest( new FailingTest( new RefactoringRegressionTests("testNamespace_66_79281"), 79281) ); //$NON-NLS-1$ - suite.addTest( new FailingTest( new RefactoringRegressionTests("testNamespace_66_79282"), 79282) ); //$NON-NLS-1$ - suite.addTest( new RefactoringRegressionTests("testFunction_67") ); //$NON-NLS-1$ - suite.addTest( new RefactoringRegressionTests("testVariable_68") ); //$NON-NLS-1$ - suite.addTest( new FailingTest( new RefactoringRegressionTests("testVariable_68_79295"), 79295) ); //$NON-NLS-1$ - suite.addTest( new FailingTest( new RefactoringRegressionTests("testClass_81_72620"),72620) ); //$NON-NLS-1$ - suite.addTest( new FailingTest( new RefactoringRegressionTests("testVariable_88_72617"), 72617) ); //$NON-NLS-1$ - suite.addTest( new RefactoringRegressionTests("testClass_92A") ); //$NON-NLS-1$ - suite.addTest( new RefactoringRegressionTests("testClass_92B") ); //$NON-NLS-1$ - - if( cleanup ) - suite.addTest( new RefactoringRegressionTests("cleanupProject") ); //$NON-NLS-1$ - - return suite; - } - - protected void assertTotalChanges( int numChanges, IChange changes ) throws Exception { - int count = 0; - if( changes != null ) - count = countChanges( changes ); - assertEquals( numChanges, count ); - } - - private int countChanges( IChange change ){ - int count = 0; - if( change instanceof ICompositeChange ){ - IChange [] children = ((ICompositeChange) change).getChildren(); - for( int i = 0; i < children.length; i++ ){ - count += countChanges( children[i] ); - } - } else if( change instanceof TranslationUnitChange ){ - count += countEdits( ((TranslationUnitChange) change).getEdit() ); - } - return count; - } - - private int countEdits( TextEdit edit ){ - if( edit instanceof MultiTextEdit ){ - return ((MultiTextEdit) edit).getChildrenSize(); - } - return 1; - } - - /** - * - * @param changes The IChange returned from getRefactorChanges - * @param file The file we expect to see the change in - * @param startOffset The offset of the name that will be changed - * @param numChars The length of the original name that is changing - * @param newText The new text that the element will be renamed to - * @throws Exception - */ - protected void assertChange( IChange changes, IFile file, int startOffset, int numChars, String newText ) throws Exception { - boolean found = false; - if( changes != null && changes instanceof ICompositeChange ){ - found = checkCompositeChange( (ICompositeChange) changes, file, startOffset, numChars, newText ); - } - - if( !found ) { - fail ("Rename at offset " + startOffset + " in \"" + file.getLocation() + "\" not found."); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ - assertFalse( true ); - } - } - private boolean checkCompositeChange( ICompositeChange composite, IFile file, int startOffset, int numChars, String newText ){ - boolean found = false; - IChange [] children = composite.getChildren(); - for( int i = 0; i < children.length; i++ ){ - if( children[i] instanceof ICompositeChange ) - found = checkCompositeChange( (ICompositeChange) children[i], file, startOffset, numChars, newText ); - else if( children[i] instanceof TranslationUnitChange ){ - TranslationUnitChange tuChange = (TranslationUnitChange) children[i]; - if( tuChange.getFile().toString().equals( file.toString() ) ){ - found = checkTranslationUnitChange( tuChange, startOffset, numChars, newText ); - } - } - if( found ) - return found; - } - return found; - } - - private boolean checkTranslationUnitChange( TranslationUnitChange change, int startOffset, int numChars, String newText ){ - TextEdit textEdit = change.getEdit(); - if( textEdit instanceof MultiTextEdit ){ - MultiTextEdit multiEdit = (MultiTextEdit) textEdit; - TextEdit [] edits = multiEdit.getChildren(); - for( int i = 0; i < edits.length; i++ ){ - if( edits[i] instanceof ReplaceEdit && checkReplaceEdit( (ReplaceEdit) edits[i], startOffset, numChars, newText ) ) - return true; - } - } else if( textEdit instanceof ReplaceEdit ){ - return checkReplaceEdit( (ReplaceEdit) textEdit, startOffset, numChars, newText ); - } - return false; - } - - private boolean checkReplaceEdit( ReplaceEdit edit, int startOffset, int numChars, String newText ){ - return ( edit.getOffset() == startOffset && edit.getLength() == numChars && edit.getText().equals( newText ) ); - } - - public void testSimpleRename() throws Exception { - StringWriter writer = new StringWriter(); - writer.write( "int boo; \n" ); //$NON-NLS-1$ - writer.write( "void f() { \n" ); //$NON-NLS-1$ - writer.write( " boo++; \n" ); //$NON-NLS-1$ - writer.write( "} \n" ); //$NON-NLS-1$ - - String contents = writer.toString(); - IFile file = importFile( "t.cpp", contents ); //$NON-NLS-1$ - ISourceReference element = findElementAtOffset( file, contents.indexOf( "boo" ) ); //$NON-NLS-1$ - IChange changes = getRefactorChanges( element, "ooga" ); //$NON-NLS-1$ - - assertTotalChanges( 2, changes ); - assertChange( changes, file, contents.indexOf("boo"), 3, "ooga" ); //$NON-NLS-1$//$NON-NLS-2$ - assertChange( changes, file, contents.indexOf("boo++"), 3, "ooga" ); //$NON-NLS-1$//$NON-NLS-2$ - } - public void testClass_1() throws Exception { - StringWriter writer = new StringWriter(); - writer.write( "class Boo/*vp1*/{}; \n" ); //$NON-NLS-1$ - writer.write( "void f() { \n" ); //$NON-NLS-1$ - writer.write( " Boo a; \n" ); //$NON-NLS-1$ - writer.write( "} \n" ); //$NON-NLS-1$ - - String contents = writer.toString(); - IFile file = importFile( "t.cpp", contents ); //$NON-NLS-1$ - ISourceReference element = findElementAtOffset( file, contents.indexOf( "Boo/*vp1*/" ) ); //$NON-NLS-1$ - IChange changes = getRefactorChanges( element, "Ooga" ); //$NON-NLS-1$ - - assertTotalChanges( 2, changes ); - assertChange( changes, file, contents.indexOf("Boo/*vp1*/"), 3, "Ooga" ); //$NON-NLS-1$//$NON-NLS-2$ - assertChange( changes, file, contents.indexOf("Boo a"), 3, "Ooga" ); //$NON-NLS-1$//$NON-NLS-2$ - } - public void testAttribute_2() throws Exception { - StringWriter writer = new StringWriter(); - writer.write( "class Boo{ \n" ); //$NON-NLS-1$ - writer.write( " int att1;//vp1,res1 \n" ); //$NON-NLS-1$ - writer.write( "}; \n" ); //$NON-NLS-1$ - writer.write( "void f() { \n" ); //$NON-NLS-1$ - writer.write( " Boo a; \n" ); //$NON-NLS-1$ - writer.write( " a.att1;//res2 \n" ); //$NON-NLS-1$ - writer.write( "} \n" ); //$NON-NLS-1$ - - String contents = writer.toString(); - IFile file = importFile( "t.cpp", contents ); //$NON-NLS-1$ - ISourceReference element = findElementAtOffset( file, contents.indexOf( "att1;//vp1" ) ); //$NON-NLS-1$ - IChange changes = getRefactorChanges( element, "ooga" ); //$NON-NLS-1$ - - assertTotalChanges( 2, changes ); - assertChange( changes, file, contents.indexOf("att1;//vp1,res1"), 4, "ooga" ); //$NON-NLS-1$//$NON-NLS-2$ - assertChange( changes, file, contents.indexOf("att1;//res2"), 4, "ooga" ); //$NON-NLS-1$//$NON-NLS-2$ - } - public void testMethod_3() throws Exception { - StringWriter writer = new StringWriter(); - writer.write( "class Boo{ \n" ); //$NON-NLS-1$ - writer.write( " int method1(){}//vp1,res1 \n" ); //$NON-NLS-1$ - writer.write( "}; \n" ); //$NON-NLS-1$ - writer.write( "void f() { \n" ); //$NON-NLS-1$ - writer.write( " Boo a; \n" ); //$NON-NLS-1$ - writer.write( " a.method1();//res2 \n" ); //$NON-NLS-1$ - writer.write( "} \n" ); //$NON-NLS-1$ - - String contents = writer.toString(); - IFile file = importFile( "t.cpp", contents ); //$NON-NLS-1$ - ISourceReference element = findElementAtOffset( file, contents.indexOf( "method1(){}//vp1" ) ); //$NON-NLS-1$ - IChange changes = getRefactorChanges( element, "ooga" ); //$NON-NLS-1$ - - assertTotalChanges( 2, changes ); - assertChange( changes, file, contents.indexOf("method1(){}//vp1,res1"), 7, "ooga" ); //$NON-NLS-1$//$NON-NLS-2$ - assertChange( changes, file, contents.indexOf("method1();//res2"), 7, "ooga" ); //$NON-NLS-1$//$NON-NLS-2$ - } - - - public void testConstructor_26() throws Exception { - StringWriter writer = new StringWriter(); - writer.write( "class Boo{ \n" ); //$NON-NLS-1$ - writer.write( " Boo(){}//vp1,res1 \n" ); //$NON-NLS-1$ - writer.write( "}; \n" ); //$NON-NLS-1$ - writer.write( "void f() { \n" ); //$NON-NLS-1$ - writer.write( " Boo a = new Boo(); \n" ); //$NON-NLS-1$ - writer.write( "} \n" ); //$NON-NLS-1$ - - String contents = writer.toString(); - IFile file = importFile( "t.cpp", contents ); //$NON-NLS-1$ - ISourceReference element = findElementAtOffset( file, contents.indexOf( "Boo(){}" ) ); //$NON-NLS-1$ - try { - getRefactorChanges( element, "ooga" ); //$NON-NLS-1$ - } catch (AssertionFailedError e) { - assertTrue(e.getMessage().startsWith("Input check on ooga failed.")); //$NON-NLS-1$ - return; - } - fail ("An error should have occurred in the input check."); //$NON-NLS-1$ - } - //The constructor name is accepted, but the refactoring doesn't remove the return - //type and there is a compile error. Renaming to a constructor should be disabled. - //However, the UI does display the error in the preview panel. Defect 78769 states - //the error should be shown on the first page. The parser passes, but the UI could be - //better. - public void testConstructor_27() throws Exception { - StringWriter writer = new StringWriter(); - writer.write( "class Boo{ \n" ); //$NON-NLS-1$ - writer.write( " int foo(){}//vp1 \n" ); //$NON-NLS-1$ - writer.write( "}; \n" ); //$NON-NLS-1$ - writer.write( "void f() { \n" ); //$NON-NLS-1$ - writer.write( " Boo a; \n" ); //$NON-NLS-1$ - writer.write( " a.foo(); \n" ); //$NON-NLS-1$ - writer.write( "} \n" ); //$NON-NLS-1$ - - String contents = writer.toString(); - IFile file = importFile( "t.cpp", contents ); //$NON-NLS-1$ - ISourceReference element = findElementAtOffset( file, contents.indexOf( "foo(){}" ) ); //$NON-NLS-1$ - try { - getRefactorChanges( element, "Boo" ); //$NON-NLS-1$ - } catch (AssertionFailedError e) { - //test passes - assertTrue(e.getMessage().startsWith("Input check on Boo failed.")); //$NON-NLS-1$ - return; - } - fail ("An error should have occurred in the input check."); //$NON-NLS-1$ - } - public void testDestructor_28() throws Exception { - StringWriter writer = new StringWriter(); - writer.write( "class Boo{ \n" ); //$NON-NLS-1$ - writer.write( " ~Boo(){}//vp1 \n" ); //$NON-NLS-1$ - writer.write( "}; \n" ); //$NON-NLS-1$ - writer.write( "void f() { \n" ); //$NON-NLS-1$ - writer.write( " Boo a ; \n" ); //$NON-NLS-1$ - writer.write( " a.~Boo(); \n" ); //$NON-NLS-1$ - writer.write( "} \n" ); //$NON-NLS-1$ - - String contents = writer.toString(); - IFile file = importFile( "t.cpp", contents ); //$NON-NLS-1$ - ISourceReference element = findElementAtOffset( file, contents.indexOf( "~Boo(){}" ) ); //$NON-NLS-1$ - try { - getRefactorChanges( element, "ooga" ); //$NON-NLS-1$ - } catch (AssertionFailedError e) { - assertTrue(e.getMessage().startsWith("Input check on ooga failed.")); //$NON-NLS-1$ - return; - } - fail ("An error should have occurred in the input check."); //$NON-NLS-1$ - } - public void testDestructor_29_72612() throws Exception { - StringWriter writer = new StringWriter(); - writer.write( "class Boo{ \n" ); //$NON-NLS-1$ - writer.write( " int foo(){}//vp1 \n" ); //$NON-NLS-1$ - writer.write( "}; \n" ); //$NON-NLS-1$ - writer.write( "void f() { \n" ); //$NON-NLS-1$ - writer.write( " Boo a; \n" ); //$NON-NLS-1$ - writer.write( " a.foo(); \n" ); //$NON-NLS-1$ - writer.write( "} \n" ); //$NON-NLS-1$ - - String contents = writer.toString(); - IFile file = importFile( "t.cpp", contents ); //$NON-NLS-1$ - ISourceReference element = findElementAtOffset( file, contents.indexOf( "foo(){}" ) ); //$NON-NLS-1$ - try { - getRefactorChanges( element, "~Boo" ); //$NON-NLS-1$ - } catch (AssertionFailedError e) { - //test passes - assertTrue(e.getMessage().startsWith("Input check on Boo failed.")); //$NON-NLS-1$ - return; - } - fail ("An error should have occurred in the input check."); //$NON-NLS-1$ - } - -// re: bugzilla 93550 -// public void testFunction_31() throws Exception { -// StringWriter writer = new StringWriter(); -// writer.write( "void foo(){} \n" ); //$NON-NLS-1$ -// writer.write( "void foo/*vp1*/(int i){} \n" ); //$NON-NLS-1$ -// writer.write( "class Foo{ \n" ); //$NON-NLS-1$ -// writer.write( " int method1(){ \n" ); //$NON-NLS-1$ -// writer.write( " foo(3); \n" ); //$NON-NLS-1$ -// writer.write( " foo(); \n" ); //$NON-NLS-1$ -// writer.write( " } \n" ); //$NON-NLS-1$ -// writer.write( "}; \n" ); //$NON-NLS-1$ -// -// String contents = writer.toString(); -// IFile file = importFile( "t.cpp", contents ); //$NON-NLS-1$ -// ISourceReference element = findElementAtOffset( file, contents.indexOf( "foo/*vp1*/" ) ); //$NON-NLS-1$ -// IChange changes = getRefactorChanges( element, "ooga" ); //$NON-NLS-1$ -// assertTotalChanges( 2, changes ); -// assertChange( changes, file, contents.indexOf("foo/*vp1*/"), 3, "ooga" ); //$NON-NLS-1$//$NON-NLS-2$ -// assertChange( changes, file, contents.indexOf("foo(3)"), 3, "ooga" ); //$NON-NLS-1$//$NON-NLS-2$ -// -// } - public void testMethod_32_72717() throws Exception { - StringWriter writer = new StringWriter(); - writer.write( "class Base { \n" ); //$NON-NLS-1$ - writer.write( " virtual void foo()=0; \n" ); //$NON-NLS-1$ - writer.write( "}; \n" ); //$NON-NLS-1$ - writer.write( "class Derived: public Base { \n" ); //$NON-NLS-1$ - writer.write( " virtual void foo(); \n" ); //$NON-NLS-1$ - writer.write( " void moon/*vp1*/(int i); \n" ); //$NON-NLS-1$ - writer.write( "}; \n" ); //$NON-NLS-1$ - - String contents = writer.toString(); - IFile file = importFile( "t.cpp", contents ); //$NON-NLS-1$ - ISourceReference element = findElementAtOffset( file, contents.indexOf( "moon/*vp1*/" ) ); //$NON-NLS-1$ - IChange changes = getRefactorChanges( element, "foo" ); //$NON-NLS-1$ - assertTotalChanges( 1, changes ); - assertChange( changes, file, contents.indexOf("moon/*vp1*/"), 4, "foo" ); //$NON-NLS-1$//$NON-NLS-2$ - - } - - public void testMethod_33_72605() throws Exception { - StringWriter writer = new StringWriter(); - writer.write( "class Foo { \n" ); //$NON-NLS-1$ - writer.write( " void aMethod/*vp1*/(int x=0); \n" ); //$NON-NLS-1$ - writer.write( "}; \n" ); //$NON-NLS-1$ - writer.write( "void Foo::aMethod(int x){} \n" ); //$NON-NLS-1$ - String contents = writer.toString(); - IFile file = importFile( "t.cpp", contents ); //$NON-NLS-1$ - ISourceReference element = findElementAtOffset( file, contents.indexOf( "aMethod/*vp1*/" ) ); //$NON-NLS-1$ - IChange changes = getRefactorChanges( element, "ooga" ); //$NON-NLS-1$ - assertTotalChanges( 2, changes ); - assertChange( changes, file, contents.indexOf("aMethod/*vp1*/"), 7, "ooga" ); //$NON-NLS-1$//$NON-NLS-2$ - assertChange( changes, file, contents.indexOf("aMethod(int x)"), 7, "ooga" ); //$NON-NLS-1$//$NON-NLS-2$ - - } - public void testMethod_34() throws Exception { - StringWriter writer = new StringWriter(); - writer.write( "class Base{ \n" ); //$NON-NLS-1$ - writer.write( " virtual void v/*vp1*/()=0; \n" ); //$NON-NLS-1$ - writer.write( "}; \n" ); //$NON-NLS-1$ - writer.write( "class Derived: Base { \n" ); //$NON-NLS-1$ - writer.write( " void v(){}; \n" ); //$NON-NLS-1$ - writer.write( "}; \n" ); //$NON-NLS-1$ - String contents = writer.toString(); - IFile file = importFile( "t.cpp", contents ); //$NON-NLS-1$ - ISourceReference element = findElementAtOffset( file, contents.indexOf( "v/*vp1*/" ) ); //$NON-NLS-1$ - IChange changes = getRefactorChanges( element, "ooga" ); //$NON-NLS-1$ - //dervied method is not renamed; only a warning to rename derived or base class methods - assertTotalChanges( 1, changes ); - assertChange( changes, file, contents.indexOf("v/*vp1*/"), 1, "ooga" ); //$NON-NLS-1$//$NON-NLS-2$ - - } - // defect is input for new name is not allowed - public void testMethod_35_72726() throws Exception { - StringWriter writer = new StringWriter(); - writer.write( "class Foo{ \n" ); //$NON-NLS-1$ - writer.write( " Foo& operator *=/*vp1*/(const Foo &rhs);\n" ); //$NON-NLS-1$ - writer.write( " Foo& operator==/*vp2*/(const Foo &rhs);\n" ); //$NON-NLS-1$ - writer.write( "}; \n" ); //$NON-NLS-1$ - writer.write( "Foo& Foo::operator *=(const Foo &rhs){ \n" ); //$NON-NLS-1$ - writer.write( " return *this; \n" ); //$NON-NLS-1$ - writer.write( "}; \n" ); //$NON-NLS-1$ - writer.write( "Foo& Foo::operator==(const Foo &rhs){ \n" ); //$NON-NLS-1$ - writer.write( " return *this; \n" ); //$NON-NLS-1$ - writer.write( "}; \n" ); //$NON-NLS-1$ - String contents = writer.toString(); - IFile file = importFile( "t.cpp", contents ); //$NON-NLS-1$ - //vp1 with space - ISourceReference element = findElementAtOffset( file, contents.indexOf( "operator *=/*vp1*/" ) ); //$NON-NLS-1$ - IChange changes = getRefactorChanges( element, "operator +=" ); //$NON-NLS-1$ - assertTotalChanges( 2, changes ); - assertChange( changes, file, contents.indexOf("operator *=/*vp1*/"), 11, "operator +=" ); //$NON-NLS-1$//$NON-NLS-2$ - assertChange( changes, file, contents.indexOf("operator *=(const"), 11, "operator +=" ); //$NON-NLS-1$//$NON-NLS-2$ - //vp2 without space - element = findElementAtOffset( file, contents.indexOf( "operator==/*vp2*/" ) ); //$NON-NLS-1$ - changes = getRefactorChanges( element, "operator=" ); //$NON-NLS-1$ - assertTotalChanges( 2, changes ); - assertChange( changes, file, contents.indexOf("operator==/*vp2*/"), 11, "operator=" ); //$NON-NLS-1$//$NON-NLS-2$ - assertChange( changes, file, contents.indexOf("operator==(const"), 11, "operator=" ); //$NON-NLS-1$//$NON-NLS-2$ - - } - public void testMethod_39() throws Exception { - StringWriter writer = new StringWriter(); - writer.write( "class Foo{ \n" ); //$NON-NLS-1$ - writer.write( " const void* method1/*vp1*/(char*); \n" ); //$NON-NLS-1$ - writer.write( " const int method2/*vp1*/(int j); \n" ); //$NON-NLS-1$ - writer.write( "}; \n" ); //$NON-NLS-1$ - String header = writer.toString(); - IFile h = importFile( "t.h", header ); //$NON-NLS-1$ - - writer = new StringWriter(); - writer.write( "#include \"t.h\" \n" ); //$NON-NLS-1$ - writer.write( "const void* Foo::method1(char* x){return ((void*) x;} \n" ); //$NON-NLS-1$ - writer.write( "const int Foo::method2(int){return 5;} \n" ); //$NON-NLS-1$ - writer.write( "void test() { \n" ); //$NON-NLS-1$ - writer.write( " Foo d; \n" ); //$NON-NLS-1$ - writer.write( " d.method1(\"hello\"); \n" ); //$NON-NLS-1$ - writer.write( " int i =d.method2(3); \n" ); //$NON-NLS-1$ - writer.write( "} \n" ); //$NON-NLS-1$ - String source = writer.toString(); - IFile cpp = importFile( "t.cpp", source ); //$NON-NLS-1$ - //vp1 const - ISourceReference element = findElementAtOffset( h, header.indexOf( "method1/*vp1*/" ) ); //$NON-NLS-1$ - IChange changes = getRefactorChanges( element, "m1" ); //$NON-NLS-1$ - //assertTotalChanges( 3, changes ); - assertChange( changes, h, header.indexOf("method1/*vp1*/"), 7, "m1" ); //$NON-NLS-1$//$NON-NLS-2$ - assertChange( changes, cpp, source.indexOf("method1(char"), 7, "m1" ); //$NON-NLS-1$//$NON-NLS-2$ - assertChange( changes, cpp, source.indexOf("method1(\"hello"), 7, "m1" ); //$NON-NLS-1$//$NON-NLS-2$ - //vp2 const in definition with :: - element = findElementAtOffset( cpp, source.indexOf( "Foo::method2" ) ); //$NON-NLS-1$ - changes = getRefactorChanges( element, "m2" ); //$NON-NLS-1$ - assertTotalChanges( 3, changes ); - assertChange( changes, h, header.indexOf("method2/*vp1*/"), 7, "m2" ); //$NON-NLS-1$//$NON-NLS-2$ - assertChange( changes, cpp, source.indexOf("method2(int"), 7, "m2" ); //$NON-NLS-1$//$NON-NLS-2$ - assertChange( changes, cpp, source.indexOf("method2(3"), 7, "m2" ); //$NON-NLS-1$//$NON-NLS-2$ - - } - public void testMethod_40() throws Exception { - StringWriter writer = new StringWriter(); - writer.write( "class Foo{ \n" ); //$NON-NLS-1$ - writer.write( " static int method1/*vp1*/(char* x); \n" ); //$NON-NLS-1$ - writer.write( " static int method2/*vp2*/(int); \n" ); //$NON-NLS-1$ - writer.write( "}; \n" ); //$NON-NLS-1$ - String header = writer.toString(); - IFile h = importFile( "t.h", header ); //$NON-NLS-1$ - - writer = new StringWriter(); - writer.write( "#include \"t.h\" \n" ); //$NON-NLS-1$ - writer.write( "static int Foo::method1(char* x){return 5;} \n" ); //$NON-NLS-1$ - writer.write( "static int Foo::method2(int x){return (2);}; \n" ); //$NON-NLS-1$ - writer.write( "void test() { \n" ); //$NON-NLS-1$ - writer.write( " Foo::method1(\"hello\"); \n" ); //$NON-NLS-1$ - writer.write( " int i =Foo::method2(3); \n" ); //$NON-NLS-1$ - writer.write( "} \n" ); //$NON-NLS-1$ - String source = writer.toString(); - IFile cpp = importFile( "t.cpp", source ); //$NON-NLS-1$ - //vp1 static method declaration - ISourceReference element = findElementAtOffset( h, header.indexOf( "method1/*vp1*/" ) ); //$NON-NLS-1$ - IChange changes = getRefactorChanges( element, "m1" ); //$NON-NLS-1$ - assertTotalChanges( 3, changes ); - assertChange( changes, h, header.indexOf("method1/*vp1*/"), 7, "m1" ); //$NON-NLS-1$//$NON-NLS-2$ - assertChange( changes, cpp, source.indexOf("method1(char"), 7, "m1" ); //$NON-NLS-1$//$NON-NLS-2$ - assertChange( changes, cpp, source.indexOf("method1(\"hello"), 7, "m1" ); //$NON-NLS-1$//$NON-NLS-2$ - //vp2 static method definition - element = findElementAtOffset( cpp, source.indexOf( "Foo::method2" ) ); //$NON-NLS-1$ - changes = getRefactorChanges( element, "m2" ); //$NON-NLS-1$ - assertTotalChanges( 3, changes ); - assertChange( changes, h, header.indexOf("method2/*vp2*/"), 7, "m2" ); //$NON-NLS-1$//$NON-NLS-2$ - assertChange( changes, cpp, source.indexOf("method2(int x"), 7, "m2" ); //$NON-NLS-1$//$NON-NLS-2$ - assertChange( changes, cpp, source.indexOf("method2(3"), 7, "m2" ); //$NON-NLS-1$//$NON-NLS-2$ - - } - - public void testMethod_41() throws Exception { - StringWriter writer = new StringWriter(); - writer.write( "class Foo{ \n" ); //$NON-NLS-1$ - writer.write( "public: \n" ); //$NON-NLS-1$ - writer.write( " volatile int method1/*vp1*/(int); \n" ); //$NON-NLS-1$ - writer.write( "private: \n" ); //$NON-NLS-1$ - writer.write( " int b; \n" ); //$NON-NLS-1$ - writer.write( "}; \n" ); //$NON-NLS-1$ - String header = writer.toString(); - IFile h = importFile( "t.h", header ); //$NON-NLS-1$ - - writer = new StringWriter(); - writer.write( "#include \"t.h\" \n" ); //$NON-NLS-1$ - writer.write( "volatile int Foo::method1(int x){return (2);}; \n" ); //$NON-NLS-1$ - writer.write( "void test() { \n" ); //$NON-NLS-1$ - writer.write( " Foo d; \n" ); //$NON-NLS-1$ - writer.write( " int i =d.method1(1); \n" ); //$NON-NLS-1$ - writer.write( "} \n" ); //$NON-NLS-1$ - String source = writer.toString(); - IFile cpp = importFile( "t.cpp", source ); //$NON-NLS-1$ - //vp1 volatile - ISourceReference element = findElementAtOffset( h, header.indexOf( "method1/*vp1*/" ) ); //$NON-NLS-1$ - IChange changes = getRefactorChanges( element, "m1" ); //$NON-NLS-1$ - assertTotalChanges( 3, changes ); - assertChange( changes, h, header.indexOf("method1/*vp1*/"), 7, "m1" ); //$NON-NLS-1$//$NON-NLS-2$ - assertChange( changes, cpp, source.indexOf("method1(int x"), 7, "m1" ); //$NON-NLS-1$//$NON-NLS-2$ - assertChange( changes, cpp, source.indexOf("method1(1"), 7, "m1" ); //$NON-NLS-1$//$NON-NLS-2$ - - } - public void testMethod_43() throws Exception { - StringWriter writer = new StringWriter(); - writer.write( "class Foo{ \n" ); //$NON-NLS-1$ - writer.write( "public: \n" ); //$NON-NLS-1$ - writer.write( " inline void method1/*vp1*/(int i) {b=i;} \n" ); //$NON-NLS-1$ - writer.write( "private: \n" ); //$NON-NLS-1$ - writer.write( " int b; \n" ); //$NON-NLS-1$ - writer.write( "}; \n" ); //$NON-NLS-1$ - String header = writer.toString(); - IFile h = importFile( "t.h", header ); //$NON-NLS-1$ - - writer = new StringWriter(); - writer.write( "#include \"t.h\" \n" ); //$NON-NLS-1$ - writer.write( "void test() { \n" ); //$NON-NLS-1$ - writer.write( " Foo *d; \n" ); //$NON-NLS-1$ - writer.write( " d->method1(1); \n" ); //$NON-NLS-1$ - writer.write( "} \n" ); //$NON-NLS-1$ - String source = writer.toString(); - IFile cpp = importFile( "t.cpp", source ); //$NON-NLS-1$ - //vp1 inline - ISourceReference element = findElementAtOffset( h, header.indexOf( "method1/*vp1*/" ) ); //$NON-NLS-1$ - IChange changes = getRefactorChanges( element, "m1" ); //$NON-NLS-1$ - assertTotalChanges( 2, changes ); - assertChange( changes, h, header.indexOf("method1/*vp1*/"), 7, "m1" ); //$NON-NLS-1$//$NON-NLS-2$ - assertChange( changes, cpp, source.indexOf("method1(1"), 7, "m1" ); //$NON-NLS-1$//$NON-NLS-2$ - - } - public void testMethod_44() throws Exception { - StringWriter writer = new StringWriter(); - writer.write( "class Base{ \n" ); //$NON-NLS-1$ - writer.write( " virtual void v(); \n" ); //$NON-NLS-1$ - writer.write( " int i; \n" ); //$NON-NLS-1$ - writer.write( "}; \n" ); //$NON-NLS-1$ - writer.write( "void Base::v(){} \n" ); //$NON-NLS-1$ - writer.write( "class Derived: Base { \n" ); //$NON-NLS-1$ - writer.write( " virtual void v/*vp1*/(){}//explicitly virtual \n" ); //$NON-NLS-1$ - writer.write( "}; \n" ); //$NON-NLS-1$ - writer.write( "class Derived2: Derived {\n" ); //$NON-NLS-1$ - writer.write( " void v(){i++;} \n" ); //$NON-NLS-1$ - writer.write( "}; \n" ); //$NON-NLS-1$ - String contents = writer.toString(); - IFile file = importFile( "t.cpp", contents ); //$NON-NLS-1$ - //vp1 implicit virtual method - ISourceReference element = findElementAtOffset( file, contents.indexOf( "v/*vp1*/" ) ); //$NON-NLS-1$ - String[] messages= getRefactorMessages( element, "v2" ); //$NON-NLS-1$ - assertEquals(1, messages.length); - assertEquals("Renaming a virtual method. Consider renaming the base and derived class methods (if any).", messages[0] ); //$NON-NLS-1$ - -} - public void testMethod_45_72732() throws Exception { - StringWriter writer = new StringWriter(); - writer.write( "class Base{ \n" ); //$NON-NLS-1$ - writer.write( " virtual void v(); \n" ); //$NON-NLS-1$ - writer.write( " int i; \n" ); //$NON-NLS-1$ - writer.write( "}; \n" ); //$NON-NLS-1$ - writer.write( "void Base::v(){} \n" ); //$NON-NLS-1$ - writer.write( "class Derived: Base { \n" ); //$NON-NLS-1$ - writer.write( " void v/*vp1*/(){}//implicitly virtual \n" ); //$NON-NLS-1$ - writer.write( "}; \n" ); //$NON-NLS-1$ - writer.write( "class Derived2: Derived {\n" ); //$NON-NLS-1$ - writer.write( " void v(){i++;} \n" ); //$NON-NLS-1$ - writer.write( "}; \n" ); //$NON-NLS-1$ - String contents = writer.toString(); - IFile file = importFile( "t.cpp", contents ); //$NON-NLS-1$ - //vp1 implicit virtual method - ISourceReference element = findElementAtOffset( file, contents.indexOf( "v/*vp1*/" ) ); //$NON-NLS-1$ - String[] messages= getRefactorMessages( element, "v2" ); //$NON-NLS-1$ - assertEquals(1, messages.length); - assertEquals("Renaming a virtual method. Consider renaming the base and derived class methods (if any).", messages[0] ); //$NON-NLS-1$ - - - } - public void testStruct_46() throws Exception { - StringWriter writer = new StringWriter(); - writer.write( "struct st1/*vp1*/{}; \n" ); //$NON-NLS-1$ - writer.write( "class c1/*vp1*/{ \n" ); //$NON-NLS-1$ - writer.write( " public: struct st2/*vp2*/{} s; \n" ); //$NON-NLS-1$ - writer.write( "}; \n" ); //$NON-NLS-1$ - writer.write( "namespace N{ \n" ); //$NON-NLS-1$ - writer.write( " struct st3/*vp3*/{}; \n" ); //$NON-NLS-1$ - writer.write( " class c2/*vp1*/{ \n" ); //$NON-NLS-1$ - writer.write( " st1 s; \n" ); //$NON-NLS-1$ - writer.write( " st3 ss; \n" ); //$NON-NLS-1$ - writer.write( " c2() { \n" ); //$NON-NLS-1$ - writer.write( " c1::st2 s; \n" ); //$NON-NLS-1$ - writer.write( " } \n" ); //$NON-NLS-1$ - writer.write( " }; \n" ); //$NON-NLS-1$ - writer.write( "} \n" ); //$NON-NLS-1$ - - String contents = writer.toString(); - IFile file = importFile( "t.cpp", contents ); //$NON-NLS-1$ - //vp1 global declaration - ISourceReference element = findElementAtOffset( file, contents.indexOf( "st1/*vp1*/" ) ); //$NON-NLS-1$ - IChange changes = getRefactorChanges( element, "Ooga1" ); //$NON-NLS-1$ - assertTotalChanges( 2, changes ); - assertChange( changes, file, contents.indexOf("st1/*vp1*/"), 3, "Ooga1" ); //$NON-NLS-1$//$NON-NLS-2$ - assertChange( changes, file, contents.indexOf("st1 s"), 3, "Ooga1" ); //$NON-NLS-1$//$NON-NLS-2$ - //vp2 Declared in class - element = findElementAtOffset( file, contents.indexOf( "st2/*vp2*/" ) ); //$NON-NLS-1$ - changes = getRefactorChanges( element, "Ooga2" ); //$NON-NLS-1$ - assertTotalChanges( 2, changes ); - assertChange( changes, file, contents.indexOf("st2/*vp2*/"), 3, "Ooga2" ); //$NON-NLS-1$//$NON-NLS-2$ - assertChange( changes, file, contents.indexOf("st2 s"), 3, "Ooga2" ); //$NON-NLS-1$//$NON-NLS-2$ - //vp3 Declared in namespace - element = findElementAtOffset( file, contents.indexOf( "st3/*vp3*/" ) ); //$NON-NLS-1$ - changes = getRefactorChanges( element, "Ooga3" ); //$NON-NLS-1$ - assertTotalChanges( 2, changes ); - assertChange( changes, file, contents.indexOf("st3/*vp3*/"), 3, "Ooga3" ); //$NON-NLS-1$//$NON-NLS-2$ - assertChange( changes, file, contents.indexOf("st3 ss"), 3, "Ooga3" ); //$NON-NLS-1$//$NON-NLS-2$ - } - public void testUnion_47() throws Exception { - StringWriter writer = new StringWriter(); - writer.write( "union st1/*vp1*/{}; \n" ); //$NON-NLS-1$ - writer.write( "class c1/*vp1*/{ \n" ); //$NON-NLS-1$ - writer.write( " public: union st2/*vp2*/{} s; \n" ); //$NON-NLS-1$ - writer.write( "}; \n" ); //$NON-NLS-1$ - writer.write( "namespace N{ \n" ); //$NON-NLS-1$ - writer.write( " union st3/*vp3*/{}; \n" ); //$NON-NLS-1$ - writer.write( " class c2/*vp1*/{ \n" ); //$NON-NLS-1$ - writer.write( " st1 s; \n" ); //$NON-NLS-1$ - writer.write( " st3 ss; \n" ); //$NON-NLS-1$ - writer.write( " c2() { \n" ); //$NON-NLS-1$ - writer.write( " c1::st2 s; \n" ); //$NON-NLS-1$ - writer.write( " } \n" ); //$NON-NLS-1$ - writer.write( " }; \n" ); //$NON-NLS-1$ - writer.write( "} \n" ); //$NON-NLS-1$ - - String contents = writer.toString(); - IFile file = importFile( "t.cpp", contents ); //$NON-NLS-1$ - //vp1 global declaration - ISourceReference element = findElementAtOffset( file, contents.indexOf( "st1/*vp1*/" ) ); //$NON-NLS-1$ - IChange changes = getRefactorChanges( element, "Ooga1" ); //$NON-NLS-1$ - assertTotalChanges( 2, changes ); - assertChange( changes, file, contents.indexOf("st1/*vp1*/"), 3, "Ooga1" ); //$NON-NLS-1$//$NON-NLS-2$ - assertChange( changes, file, contents.indexOf("st1 s"), 3, "Ooga1" ); //$NON-NLS-1$//$NON-NLS-2$ - //vp2 Declared in class - element = findElementAtOffset( file, contents.indexOf( "st2/*vp2*/" ) ); //$NON-NLS-1$ - changes = getRefactorChanges( element, "Ooga2" ); //$NON-NLS-1$ - assertTotalChanges( 2, changes ); - assertChange( changes, file, contents.indexOf("st2/*vp2*/"), 3, "Ooga2" ); //$NON-NLS-1$//$NON-NLS-2$ - assertChange( changes, file, contents.indexOf("st2 s"), 3, "Ooga2" ); //$NON-NLS-1$//$NON-NLS-2$ - //vp3 Declared in namespace - element = findElementAtOffset( file, contents.indexOf( "st3/*vp3*/" ) ); //$NON-NLS-1$ - changes = getRefactorChanges( element, "Ooga3" ); //$NON-NLS-1$ - assertTotalChanges( 2, changes ); - assertChange( changes, file, contents.indexOf("st3/*vp3*/"), 3, "Ooga3" ); //$NON-NLS-1$//$NON-NLS-2$ - assertChange( changes, file, contents.indexOf("st3 ss"), 3, "Ooga3" ); //$NON-NLS-1$//$NON-NLS-2$ -} - public void testEnumeration_48() throws Exception { - StringWriter writer = new StringWriter(); - writer.write( "enum e1/*vp1*/{E0}; \n" ); //$NON-NLS-1$ - writer.write( "class c1 { \n" ); //$NON-NLS-1$ - writer.write( " public: enum e2/*vp2*/{E1} s; \n" ); //$NON-NLS-1$ - writer.write( "}; \n" ); //$NON-NLS-1$ - writer.write( "namespace N{ \n" ); //$NON-NLS-1$ - writer.write( " enum e3/*vp3*/{}; \n" ); //$NON-NLS-1$ - writer.write( " class c2/*vp1*/{ \n" ); //$NON-NLS-1$ - writer.write( " e1 s; \n" ); //$NON-NLS-1$ - writer.write( " e3 ss; \n" ); //$NON-NLS-1$ - writer.write( " c2() { \n" ); //$NON-NLS-1$ - writer.write( " c1::e2 s; \n" ); //$NON-NLS-1$ - writer.write( " } \n" ); //$NON-NLS-1$ - writer.write( " }; \n" ); //$NON-NLS-1$ - writer.write( "} \n" ); //$NON-NLS-1$ - - String contents = writer.toString(); - IFile file = importFile( "t.cpp", contents ); //$NON-NLS-1$ - //vp1 global declaration - ISourceReference element = findElementAtOffset( file, contents.indexOf( "e1/*vp1*/" ) ); //$NON-NLS-1$ - IChange changes = getRefactorChanges( element, "Ooga1" ); //$NON-NLS-1$ - assertTotalChanges( 2, changes ); - assertChange( changes, file, contents.indexOf("e1/*vp1*/"), 2, "Ooga1" ); //$NON-NLS-1$//$NON-NLS-2$ - assertChange( changes, file, contents.indexOf("e1 s"), 2, "Ooga1" ); //$NON-NLS-1$//$NON-NLS-2$ - //vp2 Declared in class - element = findElementAtOffset( file, contents.indexOf( "e2/*vp2*/" ) ); //$NON-NLS-1$ - changes = getRefactorChanges( element, "Ooga2" ); //$NON-NLS-1$ - assertTotalChanges( 2, changes ); - assertChange( changes, file, contents.indexOf("e2/*vp2*/"), 2, "Ooga2" ); //$NON-NLS-1$//$NON-NLS-2$ - assertChange( changes, file, contents.indexOf("e2 s"), 2, "Ooga2" ); //$NON-NLS-1$//$NON-NLS-2$ - //vp3 Declared in namespace - element = findElementAtOffset( file, contents.indexOf( "e3/*vp3*/" ) ); //$NON-NLS-1$ - changes = getRefactorChanges( element, "Ooga3" ); //$NON-NLS-1$ - assertTotalChanges( 2, changes ); - assertChange( changes, file, contents.indexOf("e3/*vp3*/"), 2, "Ooga3" ); //$NON-NLS-1$//$NON-NLS-2$ - assertChange( changes, file, contents.indexOf("e3 ss"), 2, "Ooga3" ); //$NON-NLS-1$//$NON-NLS-2$ - } - public void testTemplate_49_72626() throws Exception { - StringWriter writer = new StringWriter(); - writer.write( "template <class Type> \n" ); //$NON-NLS-1$ - writer.write( "class Array/*vp1*/ { \n" ); //$NON-NLS-1$ - writer.write( " public: Array(){ \n" ); //$NON-NLS-1$ - writer.write( " a=new Type[10]; \n" ); //$NON-NLS-1$ - writer.write( " } \n" ); //$NON-NLS-1$ - writer.write( " virtual Type& operator[](int i){return a[i];} \n" ); //$NON-NLS-1$ - writer.write( " protected: Type *a; \n" ); //$NON-NLS-1$ - writer.write( "}; \n" ); //$NON-NLS-1$ - writer.write( "void f(){ \n" ); //$NON-NLS-1$ - writer.write( " Array<int> a; \n" ); //$NON-NLS-1$ - writer.write( "} \n" ); //$NON-NLS-1$ - - String contents = writer.toString(); - IFile file = importFile( "t.cpp", contents ); //$NON-NLS-1$ - //vp1 template classes are not supposed to be found until the new Parser is complete (May '05) - ISourceReference element = findElementAtOffset( file, contents.indexOf( "Array" ) ); //$NON-NLS-1$ - String[] messages= getRefactorMessages( element, "Arr2" ); //$NON-NLS-1$ - assertEquals(1, messages.length); - assertEquals("Renaming a template class. Parsing templates are not fully functional. Check the results if you continue.", messages[0] ); //$NON-NLS-1$ - } - public void testClass_52() throws Exception { - StringWriter writer = new StringWriter(); - writer.write( "namespace N1 { \n" ); //$NON-NLS-1$ - writer.write( "class Boo{}; \n" ); //$NON-NLS-1$ - writer.write( "} \n" ); //$NON-NLS-1$ - writer.write( "namespace N2 { \n" ); //$NON-NLS-1$ - writer.write( "class Boo/*vp1*/{}; \n" ); //$NON-NLS-1$ - writer.write( "} \n" ); //$NON-NLS-1$ - writer.write( "void f() { \n" ); //$NON-NLS-1$ - writer.write( " N1::Boo c1; \n" ); //$NON-NLS-1$ - writer.write( " N2::Boo c2; \n" ); //$NON-NLS-1$ - writer.write( "} \n" ); //$NON-NLS-1$ - - String contents = writer.toString(); - IFile file = importFile( "t.cpp", contents ); //$NON-NLS-1$ - ISourceReference element = findElementAtOffset( file, contents.indexOf( "Boo/*vp1*/" ) ); //$NON-NLS-1$ - IChange changes = getRefactorChanges( element, "Ooga" ); //$NON-NLS-1$ - - assertTotalChanges( 2, changes ); - assertChange( changes, file, contents.indexOf("Boo/*vp1*/"), 3, "Ooga" ); //$NON-NLS-1$//$NON-NLS-2$ - assertChange( changes, file, contents.indexOf("Boo c2"), 3, "Ooga" ); //$NON-NLS-1$//$NON-NLS-2$ - } - public void testClass_53() throws Exception { - StringWriter writer = new StringWriter(); - writer.write( "class Foo/*vp1*/ {//ren1 \n" ); //$NON-NLS-1$ - writer.write( " Foo();//ren2 \n" ); //$NON-NLS-1$ - writer.write( " virtual ~Foo();//ren3 \n" ); //$NON-NLS-1$ - writer.write( "}; \n" ); //$NON-NLS-1$ - writer.write( "Foo::Foo() {}//ren4,5 \n" ); //$NON-NLS-1$ - writer.write( "Foo::~Foo() {}//ren6,7 \n" ); //$NON-NLS-1$ - writer.write( "void f() { \n" ); //$NON-NLS-1$ - writer.write( " Foo *f=new Foo();//ren8,9 \n" ); //$NON-NLS-1$ - writer.write( " f->~Foo();//ren10 \n" ); //$NON-NLS-1$ - writer.write( "} \n" ); //$NON-NLS-1$ - - String contents = writer.toString(); - IFile file = importFile( "t.cpp", contents ); //$NON-NLS-1$ - ISourceReference element = findElementAtOffset( file, contents.indexOf( "Foo/*vp1*/" ) ); //$NON-NLS-1$ - IChange changes = getRefactorChanges( element, "Ooga" ); //$NON-NLS-1$ - - assertTotalChanges( 10, changes ); - assertChange( changes, file, contents.indexOf("Foo/*vp1*/"), 3, "Ooga" ); //$NON-NLS-1$//$NON-NLS-2$ - assertChange( changes, file, contents.indexOf("Foo();//ren2"), 3, "Ooga" ); //$NON-NLS-1$//$NON-NLS-2$ - assertChange( changes, file, contents.indexOf("Foo();//ren3"), 3, "Ooga" ); //$NON-NLS-1$//$NON-NLS-2$ - assertChange( changes, file, contents.indexOf("Foo::Foo() {}//ren4,5"), 3, "Ooga" ); //$NON-NLS-1$//$NON-NLS-2$ - assertChange( changes, file, contents.indexOf("Foo() {}//ren4,5"), 3, "Ooga" ); //$NON-NLS-1$//$NON-NLS-2$ - assertChange( changes, file, contents.indexOf("Foo::~Foo() {}//ren6,7"), 3, "Ooga" ); //$NON-NLS-1$//$NON-NLS-2$ - assertChange( changes, file, contents.indexOf("Foo() {}//ren6,7"), 3, "Ooga" ); //$NON-NLS-1$//$NON-NLS-2$ - assertChange( changes, file, contents.indexOf("Foo *f=new Foo();//ren8,9"), 3, "Ooga" ); //$NON-NLS-1$//$NON-NLS-2$ - assertChange( changes, file, contents.indexOf("Foo();//ren8,9"), 3, "Ooga" ); //$NON-NLS-1$//$NON-NLS-2$ - assertChange( changes, file, contents.indexOf("Foo();//ren10"), 3, "Ooga" ); //$NON-NLS-1$//$NON-NLS-2$ - } - public void testAttribute_54() throws Exception { - StringWriter writer = new StringWriter(); - writer.write( "class Boo{ \n" ); //$NON-NLS-1$ - writer.write( " static int att;//vp1,rn1 \n" ); //$NON-NLS-1$ - writer.write( "}; \n" ); //$NON-NLS-1$ - writer.write( "void f() { \n" ); //$NON-NLS-1$ - writer.write( " Boo a; \n" ); //$NON-NLS-1$ - writer.write( " a.att;//rn2 \n" ); //$NON-NLS-1$ - writer.write( " Boo::att;//rn3 \n" ); //$NON-NLS-1$ - writer.write( "} \n" ); //$NON-NLS-1$ - - String contents = writer.toString(); - IFile file = importFile( "t.cpp", contents ); //$NON-NLS-1$ - ISourceReference element = findElementAtOffset( file, contents.indexOf( "att;//vp1" ) ); //$NON-NLS-1$ - IChange changes = getRefactorChanges( element, "ooga" ); //$NON-NLS-1$ - - assertTotalChanges( 3, changes ); - assertChange( changes, file, contents.indexOf("att;//vp1"), 3, "ooga" ); //$NON-NLS-1$//$NON-NLS-2$ - assertChange( changes, file, contents.indexOf("att;//rn2"), 3, "ooga" ); //$NON-NLS-1$//$NON-NLS-2$ - assertChange( changes, file, contents.indexOf("att;//rn3"), 3, "ooga" ); //$NON-NLS-1$//$NON-NLS-2$ - } - public void testClass_55() throws Exception { - StringWriter writer = new StringWriter(); - writer.write( "class Foo{ \n" ); //$NON-NLS-1$ - writer.write( " class Hoo{//vp1 \n" ); //$NON-NLS-1$ - writer.write( " public: Hoo(); \n" ); //$NON-NLS-1$ - writer.write( " }; \n" ); //$NON-NLS-1$ - writer.write( " Foo(){ \n" ); //$NON-NLS-1$ - writer.write( " Foo::Hoo h; \n" ); //$NON-NLS-1$ - writer.write( " } \n" ); //$NON-NLS-1$ - writer.write( "}; \n" ); //$NON-NLS-1$ - writer.write( "Foo::Hoo::Hoo(){} \n" ); //$NON-NLS-1$ - - String contents = writer.toString(); - IFile file = importFile( "t.cpp", contents ); //$NON-NLS-1$ - ISourceReference element = findElementAtOffset( file, contents.indexOf( "Hoo{" ) ); //$NON-NLS-1$ - IChange changes = getRefactorChanges( element, "ooga" ); //$NON-NLS-1$ - - assertTotalChanges( 5, changes ); - assertChange( changes, file, contents.indexOf("Hoo{//vp1"), 3, "ooga" ); //$NON-NLS-1$//$NON-NLS-2$ - assertChange( changes, file, contents.indexOf("Hoo();"), 3, "ooga" ); //$NON-NLS-1$//$NON-NLS-2$ - assertChange( changes, file, contents.indexOf("Hoo h;"), 3, "ooga" ); //$NON-NLS-1$//$NON-NLS-2$ - assertChange( changes, file, contents.indexOf("Hoo::Hoo(){}"), 3, "ooga" ); //$NON-NLS-1$//$NON-NLS-2$ - assertChange( changes, file, contents.indexOf("Hoo(){}"), 3, "ooga" ); //$NON-NLS-1$//$NON-NLS-2$ - } - public void testClass_55_79231() throws Exception { - StringWriter writer = new StringWriter(); - writer.write( "class Boo{};//vp1 \n" ); //$NON-NLS-1$ - writer.write( "class Foo{ \n" ); //$NON-NLS-1$ - writer.write( " Foo() { \n" ); //$NON-NLS-1$ - writer.write( " class Boo{}; \n" ); //$NON-NLS-1$ - writer.write( " Boo t; \n" ); //$NON-NLS-1$ - writer.write( "}; \n" ); //$NON-NLS-1$ - - String contents = writer.toString(); - IFile file = importFile( "t.cpp", contents ); //$NON-NLS-1$ - //defect is that the inner class defined in a method is also renamed, when it - // shouldn't be. - ISourceReference element = findElementAtOffset( file, contents.indexOf( "Boo{};//vp1" ) ); //$NON-NLS-1$ - IChange changes = getRefactorChanges( element, "Ooga" ); //$NON-NLS-1$ - - assertTotalChanges( 1, changes ); - assertChange( changes, file, contents.indexOf("Boo{};//vp1"), 3, "Ooga" ); //$NON-NLS-1$//$NON-NLS-2$ - } - - public void testClass_55_72748() throws Exception { - StringWriter writer = new StringWriter(); - writer.write( "class Foo{};//vp1 \n" ); //$NON-NLS-1$ - writer.write( "void f(){ \n" ); //$NON-NLS-1$ - writer.write( " Foo *somePtr; \n" ); //$NON-NLS-1$ - writer.write( " if (somePtr == reinterpret_cast<Foo*>(0)){} \n" ); //$NON-NLS-1$ - writer.write( "} \n" ); //$NON-NLS-1$ - - String contents = writer.toString(); - IFile file = importFile( "t.cpp", contents ); //$NON-NLS-1$ - //defect is that the Foo in <> is not renamed - ISourceReference element = findElementAtOffset( file, contents.indexOf( "Foo{};//vp1" ) ); //$NON-NLS-1$ - IChange changes = getRefactorChanges( element, "Ooga" ); //$NON-NLS-1$ - - assertTotalChanges( 3, changes ); - assertChange( changes, file, contents.indexOf("Foo{};//vp1"), 3, "Ooga" ); //$NON-NLS-1$//$NON-NLS-2$ - assertChange( changes, file, contents.indexOf("Foo *somePtr"), 3, "Ooga" ); //$NON-NLS-1$//$NON-NLS-2$ - assertChange( changes, file, contents.indexOf("Foo*>(0)"), 3, "Ooga" ); //$NON-NLS-1$//$NON-NLS-2$ - } - public void testClass_56() throws Exception { - StringWriter writer = new StringWriter(); - writer.write( "class Foo{};//vp1,rn1 \n" ); //$NON-NLS-1$ - writer.write( "class Derived: public Foo{//rn2 \n" ); //$NON-NLS-1$ - writer.write( " Derived():Foo(){}//rn3 \n" ); //$NON-NLS-1$ - writer.write( "}; \n" ); //$NON-NLS-1$ - - String contents = writer.toString(); - IFile file = importFile( "t.cpp", contents ); //$NON-NLS-1$ - //defect is that the inner class defined in a method is also renamed, when it - // shouldn't be. - ISourceReference element = findElementAtOffset( file, contents.indexOf( "Foo{};//vp1" ) ); //$NON-NLS-1$ - IChange changes = getRefactorChanges( element, "Ooga" ); //$NON-NLS-1$ - - assertTotalChanges( 3, changes ); - assertChange( changes, file, contents.indexOf("Foo{};//vp1"), 3, "Ooga" ); //$NON-NLS-1$//$NON-NLS-2$ - assertChange( changes, file, contents.indexOf("Foo{//rn2"), 3, "Ooga" ); //$NON-NLS-1$//$NON-NLS-2$ - assertChange( changes, file, contents.indexOf("Foo(){}//rn3"), 3, "Ooga" ); //$NON-NLS-1$//$NON-NLS-2$ - } - public void testClass_60() throws Exception { - StringWriter writer = new StringWriter(); - writer.write( "class Foo{public: Foo();};//vp1 \n" ); //$NON-NLS-1$ - String header = writer.toString(); - IFile h = importFile( "Foo.h", header ); //$NON-NLS-1$ - writer = new StringWriter(); - writer.write( "#include \"Foo.h\" \n" ); //$NON-NLS-1$ - writer.write( "Foo::Foo{}; \n" ); //$NON-NLS-1$ - - String source = writer.toString(); - importFile( "Foo.cpp", source ); //$NON-NLS-1$ - ISourceReference element = findElementAtOffset( h, header.indexOf( "Foo{" ) ); //$NON-NLS-1$ - getRefactorChanges( element, "Ooga" ); //$NON-NLS-1$ - IResource [] members = project.members(); - boolean foundh=false, foundcpp=false; - // make sure file names haven't changed - for( int i = 0; i < members.length; i++ ){ - if( members[i].getName().equals( "Foo.h" ) ) //$NON-NLS-1$ - foundh=true; - if( members[i].getName().equals( "Foo.cpp" ) ) //$NON-NLS-1$ - foundcpp=true; - } - if (!foundh || !foundcpp){ - fail ("At least one of Foo.h and Foo.cpp was incorrectly renamed."); //$NON-NLS-1$ - } - } - public void testAttribute_61() throws Exception { - StringWriter writer = new StringWriter(); - writer.write( "class Foo{ \n" ); //$NON-NLS-1$ - writer.write( " private: static int count;//vp1 \n" ); //$NON-NLS-1$ - writer.write( "}; \n" ); //$NON-NLS-1$ - String header = writer.toString(); - IFile h = importFile( "Foo.h", header ); //$NON-NLS-1$ - writer = new StringWriter(); - writer.write( "#include \"Foo.h\" \n" ); //$NON-NLS-1$ - writer.write( "int Foo::count=10; \n" ); //$NON-NLS-1$ - - String source = writer.toString(); - IFile cpp = importFile( "Foo.cpp", source ); //$NON-NLS-1$ - ISourceReference element = findElementAtOffset( h, header.indexOf( "count" ) ); //$NON-NLS-1$ - IChange changes = getRefactorChanges( element, "ooga" ); //$NON-NLS-1$ - - assertTotalChanges( 2, changes ); - assertChange( changes, h, header.indexOf("count"), 5, "ooga" ); //$NON-NLS-1$//$NON-NLS-2$ - assertChange( changes, cpp, source.indexOf("count"), 5, "ooga" ); //$NON-NLS-1$//$NON-NLS-2$ - - } - public void testEnumerator_62() throws Exception { - StringWriter writer = new StringWriter(); - writer.write( "enum Foo{E0, E1};//vp1 \n" ); //$NON-NLS-1$ - String header = writer.toString(); - IFile h = importFile( "Foo.h", header ); //$NON-NLS-1$ - writer = new StringWriter(); - writer.write( "#include \"Foo.h\" \n" ); //$NON-NLS-1$ - writer.write( "void f() { \n" ); //$NON-NLS-1$ - writer.write( " int i=E1; \n" ); //$NON-NLS-1$ - writer.write( "} \n" ); //$NON-NLS-1$ - - String source = writer.toString(); - IFile cpp=importFile( "Foo.cpp", source ); //$NON-NLS-1$ - ISourceReference element = findElementAtOffset( h, header.indexOf( "E1" ) ); //$NON-NLS-1$ - getRefactorChanges( element, "Ooga" ); //$NON-NLS-1$ - IChange changes = getRefactorChanges( element, "ooga" ); //$NON-NLS-1$ - - assertTotalChanges( 2, changes ); - assertChange( changes, h, header.indexOf("E1"), 2, "ooga" ); //$NON-NLS-1$//$NON-NLS-2$ - assertChange( changes, cpp, source.indexOf("E1"), 2, "ooga" ); //$NON-NLS-1$//$NON-NLS-2$ - - } - public void testAttribute_63() throws Exception { - StringWriter writer = new StringWriter(); - writer.write( "class Foo{ \n" ); //$NON-NLS-1$ - writer.write( " int att; \n" ); //$NON-NLS-1$ - writer.write( " Foo(int i); \n" ); //$NON-NLS-1$ - writer.write( "}; \n" ); //$NON-NLS-1$ - String header = writer.toString(); - IFile h = importFile( "Foo.h", header ); //$NON-NLS-1$ - writer = new StringWriter(); - writer.write( "#include \"Foo.h\" \n" ); //$NON-NLS-1$ - writer.write( "Foo::Foo(int i): att(i) {} \n" ); //$NON-NLS-1$ - - String source = writer.toString(); - IFile cpp = importFile( "Foo.cpp", source ); //$NON-NLS-1$ - ISourceReference element = findElementAtOffset( h, header.indexOf( "att" ) ); //$NON-NLS-1$ - IChange changes = getRefactorChanges( element, "ooga" ); //$NON-NLS-1$ - - assertTotalChanges( 2, changes ); - assertChange( changes, h, header.indexOf("att"), 3, "ooga" ); //$NON-NLS-1$//$NON-NLS-2$ - assertChange( changes, cpp, source.indexOf("att"), 3, "ooga" ); //$NON-NLS-1$//$NON-NLS-2$ - - } - public void testAttribute_64() throws Exception { - StringWriter writer = new StringWriter(); - writer.write( "class Foo{ \n" ); //$NON-NLS-1$ - writer.write( " private: \n" ); //$NON-NLS-1$ - writer.write( " int b;//vp1,rn1 \n" ); //$NON-NLS-1$ - writer.write( " int m(int b) { \n" ); //$NON-NLS-1$ - writer.write( " return b; \n" ); //$NON-NLS-1$ - writer.write( " } \n" ); //$NON-NLS-1$ - writer.write( " int n() { \n" ); //$NON-NLS-1$ - writer.write( " return b;//rn2 \n" ); //$NON-NLS-1$ - writer.write( " } \n" ); //$NON-NLS-1$ - writer.write( " int o() { \n" ); //$NON-NLS-1$ - writer.write( " int b=2; \n" ); //$NON-NLS-1$ - writer.write( " return b; \n" ); //$NON-NLS-1$ - writer.write( " } \n" ); //$NON-NLS-1$ - writer.write( "}; \n" ); //$NON-NLS-1$ - String header = writer.toString(); - IFile h = importFile( "Foo.h", header ); //$NON-NLS-1$ - ISourceReference element = findElementAtOffset( h, header.indexOf( "b;//vp1" ) ); //$NON-NLS-1$ - IChange changes = getRefactorChanges( element, "ooga" ); //$NON-NLS-1$ - - assertTotalChanges( 2, changes ); - assertChange( changes, h, header.indexOf("b;//vp1"), 1, "ooga" ); //$NON-NLS-1$//$NON-NLS-2$ - assertChange( changes, h, header.indexOf("b;//rn2"), 1, "ooga" ); //$NON-NLS-1$//$NON-NLS-2$ - - } - public void testAttribute_65() throws Exception { - StringWriter writer = new StringWriter(); - writer.write( "class A{ \n" ); //$NON-NLS-1$ - writer.write( " int x(); \n" ); //$NON-NLS-1$ - writer.write( "}; \n" ); //$NON-NLS-1$ - writer.write( "class B{ \n" ); //$NON-NLS-1$ - writer.write( " friend class A; \n" ); //$NON-NLS-1$ - writer.write( " private: \n" ); //$NON-NLS-1$ - writer.write( " int att; \n" ); //$NON-NLS-1$ - writer.write( "}; \n" ); //$NON-NLS-1$ - String header = writer.toString(); - IFile h = importFile( "Foo.h", header ); //$NON-NLS-1$ - writer = new StringWriter(); - writer.write( "#include \"Foo.h\" \n" ); //$NON-NLS-1$ - writer.write( "int A::x() { \n" ); //$NON-NLS-1$ - writer.write( " B b; \n" ); //$NON-NLS-1$ - writer.write( " int att=b.att; \n" ); //$NON-NLS-1$ - writer.write( "} \n" ); //$NON-NLS-1$ - String source = writer.toString(); - IFile cpp = importFile( "Foo.cpp", source ); //$NON-NLS-1$ - ISourceReference element = findElementAtOffset( h, header.indexOf( "att" ) ); //$NON-NLS-1$ - IChange changes = getRefactorChanges( element, "ooga" ); //$NON-NLS-1$ - - assertTotalChanges( 2, changes ); - assertChange( changes, h, header.indexOf("att"), 3, "ooga" ); //$NON-NLS-1$//$NON-NLS-2$ - assertChange( changes, cpp, source.indexOf("att;"), 3, "ooga" ); //$NON-NLS-1$//$NON-NLS-2$ - - } - public void testNamespace_66() throws Exception { - StringWriter writer = new StringWriter(); - writer.write( "namespace Foo/*vp1*/{ \n" ); //$NON-NLS-1$ - writer.write( " namespace Baz/*vp2*/ { \n" ); //$NON-NLS-1$ - writer.write( " int i; \n" ); //$NON-NLS-1$ - writer.write( " } \n" ); //$NON-NLS-1$ - writer.write( " using namespace Baz; \n" ); //$NON-NLS-1$ - writer.write( "} \n" ); //$NON-NLS-1$ - writer.write( "void f() { \n" ); //$NON-NLS-1$ - writer.write( " Foo::i = 1; \n" ); //$NON-NLS-1$ - writer.write( "} \n" ); //$NON-NLS-1$ - - String contents = writer.toString(); - IFile file = importFile( "t.cpp", contents ); //$NON-NLS-1$ - //vp1 Foo with ref in function - ISourceReference element = findElementAtOffset( file, contents.indexOf( "Foo/*vp1*/" ) ); //$NON-NLS-1$ - IChange changes = getRefactorChanges( element, "Ooga" ); //$NON-NLS-1$ - assertTotalChanges( 2, changes ); - assertChange( changes, file, contents.indexOf("Foo/*vp1*/"), 3, "Ooga" ); //$NON-NLS-1$//$NON-NLS-2$ - assertChange( changes, file, contents.indexOf("Foo::"), 3, "Ooga" ); //$NON-NLS-1$//$NON-NLS-2$ - //vp2 nested Baz with ref in using - element = findElementAtOffset( file, contents.indexOf( "Baz/*vp2*/" ) ); //$NON-NLS-1$ - changes = getRefactorChanges( element, "Wooga" ); //$NON-NLS-1$ - assertTotalChanges( 2, changes ); - assertChange( changes, file, contents.indexOf("Baz/*vp2*/"), 3, "Wooga" ); //$NON-NLS-1$//$NON-NLS-2$ - assertChange( changes, file, contents.indexOf("Baz;"), 3, "Wooga" ); //$NON-NLS-1$//$NON-NLS-2$ - - } - - public void testNamespace_66_79281() throws Exception { - StringWriter writer = new StringWriter(); - writer.write( "namespace Foo{ \n" ); //$NON-NLS-1$ - writer.write( " int i; \n" ); //$NON-NLS-1$ - writer.write( "} \n" ); //$NON-NLS-1$ - writer.write( "namespace Bar/*vp1*/ = Foo; \n" ); //$NON-NLS-1$ - writer.write( "void f() { \n" ); //$NON-NLS-1$ - writer.write( " Bar::i = 1; \n" ); //$NON-NLS-1$ - writer.write( "} \n" ); //$NON-NLS-1$ - - String contents = writer.toString(); - IFile file = importFile( "t.cpp", contents ); //$NON-NLS-1$ - ISourceReference element = findElementAtOffset( file, contents.indexOf( "Bar/*vp1*/" ) ); //$NON-NLS-1$ - IChange changes = getRefactorChanges( element, "Ooga" ); //$NON-NLS-1$ - assertTotalChanges( 2, changes ); - assertChange( changes, file, contents.indexOf("Bar/*vp1*/"), 3, "Ooga" ); //$NON-NLS-1$//$NON-NLS-2$ - assertChange( changes, file, contents.indexOf("Bar::"), 3, "Ooga" ); //$NON-NLS-1$//$NON-NLS-2$ - } - - public void testNamespace_66_79282() throws Exception { - StringWriter writer = new StringWriter(); - writer.write( "namespace Foo/*vp1*/{} \n" ); //$NON-NLS-1$ - writer.write( "namespace Bar = Foo; \n" ); //$NON-NLS-1$ - - String contents = writer.toString(); - IFile file = importFile( "t.cpp", contents ); //$NON-NLS-1$ - //defect is Foo on line 2 is not renamed - ISourceReference element = findElementAtOffset( file, contents.indexOf( "Foo/*vp1*/" ) ); //$NON-NLS-1$ - IChange changes = getRefactorChanges( element, "Ooga" ); //$NON-NLS-1$ - assertTotalChanges( 2, changes ); - assertChange( changes, file, contents.indexOf("Foo/*vp1*/"), 3, "Ooga" ); //$NON-NLS-1$//$NON-NLS-2$ - assertChange( changes, file, contents.indexOf("Foo;"), 3, "Ooga" ); //$NON-NLS-1$//$NON-NLS-2$ - } - public void testFunction_67() throws Exception { - StringWriter writer = new StringWriter(); - writer.write( "void foo/*vp1*/(){}//rn1 \n" ); //$NON-NLS-1$ - writer.write( "void bar(){ \n" ); //$NON-NLS-1$ - writer.write( " foo();//rn2 \n" ); //$NON-NLS-1$ - writer.write( "} \n" ); //$NON-NLS-1$ - writer.write( "namespace N{ \n" ); //$NON-NLS-1$ - writer.write( " class A{ \n" ); //$NON-NLS-1$ - writer.write( " A() {foo();}//rn3 \n" ); //$NON-NLS-1$ - writer.write( " }; \n" ); //$NON-NLS-1$ - writer.write( "} \n" ); //$NON-NLS-1$ - - String contents = writer.toString(); - IFile file = importFile( "t.cpp", contents ); //$NON-NLS-1$ - ISourceReference element = findElementAtOffset( file, contents.indexOf( "foo/*vp1*/" ) ); //$NON-NLS-1$ - IChange changes = getRefactorChanges( element, "ooga" ); //$NON-NLS-1$ - assertTotalChanges( 3, changes ); - assertChange( changes, file, contents.indexOf("foo/*vp1*/"), 3, "ooga" ); //$NON-NLS-1$//$NON-NLS-2$ - assertChange( changes, file, contents.indexOf("foo();//rn2"), 3, "ooga" ); //$NON-NLS-1$//$NON-NLS-2$ - assertChange( changes, file, contents.indexOf("foo();}//rn3"), 3, "ooga" ); //$NON-NLS-1$//$NON-NLS-2$ - } - public void testVariable_68() throws Exception { - StringWriter writer = new StringWriter(); - writer.write( "class A{ \n" ); //$NON-NLS-1$ - writer.write( " public: int i; \n" ); //$NON-NLS-1$ - writer.write( "}; \n" ); //$NON-NLS-1$ - writer.write( "A var;//vp1,rn1 \n" ); //$NON-NLS-1$ - writer.write( "void f(){ \n" ); //$NON-NLS-1$ - writer.write( " int j = ::var.i;//rn2 \n" ); //$NON-NLS-1$ - writer.write( "} \n" ); //$NON-NLS-1$ - writer.write( "class B{ \n" ); //$NON-NLS-1$ - writer.write( " void g(){ \n" ); //$NON-NLS-1$ - writer.write( " var.i=3;//rn3 \n" ); //$NON-NLS-1$ - writer.write( " } \n" ); //$NON-NLS-1$ - writer.write( "}; \n" ); //$NON-NLS-1$ - - String contents = writer.toString(); - IFile file = importFile( "t.cpp", contents ); //$NON-NLS-1$ - ISourceReference element = findElementAtOffset( file, contents.indexOf( "var;//vp1" ) ); //$NON-NLS-1$ - IChange changes = getRefactorChanges( element, "ooga" ); //$NON-NLS-1$ - assertTotalChanges( 3, changes ); - assertChange( changes, file, contents.indexOf("var;//vp1"), 3, "ooga" ); //$NON-NLS-1$//$NON-NLS-2$ - assertChange( changes, file, contents.indexOf("var.i;//rn2"), 3, "ooga" ); //$NON-NLS-1$//$NON-NLS-2$ - assertChange( changes, file, contents.indexOf("var.i=3;//rn3"), 3, "ooga" ); //$NON-NLS-1$//$NON-NLS-2$ - } - public void testVariable_68_79295() throws Exception { - StringWriter writer = new StringWriter(); - writer.write( "int var;//vp1 \n" ); //$NON-NLS-1$ - writer.write( "void f(int var){ \n" ); //$NON-NLS-1$ - writer.write( " int i = var; \n" ); //$NON-NLS-1$ - writer.write( "} \n" ); //$NON-NLS-1$ - - String contents = writer.toString(); - IFile file = importFile( "t.cpp", contents ); //$NON-NLS-1$ - //defect is the argument and local variable var are incorrectly renamed - ISourceReference element = findElementAtOffset( file, contents.indexOf( "var;//vp1" ) ); //$NON-NLS-1$ - IChange changes = getRefactorChanges( element, "ooga" ); //$NON-NLS-1$ - assertTotalChanges( 1, changes ); - assertChange( changes, file, contents.indexOf("var;//vp1"), 3, "ooga" ); //$NON-NLS-1$//$NON-NLS-2$ - } - public void testVariable_69() throws Exception { - StringWriter writer = new StringWriter(); - writer.write( "int i;//vp1 \n" ); //$NON-NLS-1$ - writer.write( "in t j; \n" ); //$NON-NLS-1$ - - String contents = writer.toString(); - IFile file = importFile( "t.cpp", contents ); //$NON-NLS-1$ - ISourceReference element = findElementAtOffset( file, contents.indexOf( "i;//vp1" ) ); //$NON-NLS-1$ - - String[] messages = getRefactorMessages( element, "ooga" ); //$NON-NLS-1$ - assertEquals(1, messages.length); - assertEquals("Code modification may not be accurate as affected resoure 'RegressionTestProject/t.cpp' has compile errors.", messages[0] ); //$NON-NLS-1$ - } - //similar to test 92, except this one will continue with warning, or error status - //while case in 92 must stop refactor with fatal status - public void testClass_81_72620() throws Exception { - StringWriter writer = new StringWriter(); - writer.write( "union u_haul{}; \n" ); //$NON-NLS-1$ - writer.write( "struct s_haul{}; \n" ); //$NON-NLS-1$ - String contents = writer.toString(); - IFile file = importFile( "t.cpp", contents ); //$NON-NLS-1$ - ISourceReference element = findElementAtOffset( file, contents.indexOf( "s_haul" ) ); //$NON-NLS-1$ - try { - getRefactorChanges( element, "u_haul" ); //$NON-NLS-1$ - } catch (AssertionFailedError e) { - assertTrue(e.getMessage().startsWith("Input check on u_haul failed.")); //$NON-NLS-1$ - return; - } - fail ("An error should have occurred in the input check."); //$NON-NLS-1$ - } - public void testVariable_88_72617() throws Exception { - StringWriter writer = new StringWriter(); - writer.write( "class A{}; \n" ); //$NON-NLS-1$ - writer.write( "A a;//vp1 \n" ); //$NON-NLS-1$ - String header = writer.toString(); - IFile h = importFile( "Foo.h", header ); //$NON-NLS-1$ - writer = new StringWriter(); - writer.write( "#include \"Foo.h\" \n" ); //$NON-NLS-1$ - writer.write( "void f() { \n" ); //$NON-NLS-1$ - writer.write( " A a; \n" ); //$NON-NLS-1$ - writer.write( "} \n" ); //$NON-NLS-1$ - String source = writer.toString(); - importFile( "Foo.cpp", source ); //$NON-NLS-1$ - ISourceReference element = findElementAtOffset( h, header.indexOf( "a;//vp1" ) ); //$NON-NLS-1$ - IChange changes = getRefactorChanges( element, "ooga" ); //$NON-NLS-1$ - - assertTotalChanges( 1, changes ); - assertChange( changes, h, header.indexOf("a;//vp1"), 1, "ooga" ); //$NON-NLS-1$//$NON-NLS-2$ - } - //2 ways to test name collistion on same type: - //if you don't know the error message, catch on getRefactorChanges - //or if you want to verify a message or severity, use getRefactorMessages - //and getRefactorSeverity - public void testClass_92A() throws Exception { - StringWriter writer = new StringWriter(); - writer.write( "class Boo{}; \n" ); //$NON-NLS-1$ - writer.write( " void f() {} \n" ); //$NON-NLS-1$ - writer.write( "}; \n" ); //$NON-NLS-1$ - writer.write( "class Foo/*vp1*/{}; \n" ); //$NON-NLS-1$ - - String contents = writer.toString(); - IFile file = importFile( "t.cpp", contents ); //$NON-NLS-1$ - ISourceReference element = findElementAtOffset( file, contents.indexOf( "Foo/*vp1*/" ) ); //$NON-NLS-1$ - try { - getRefactorChanges( element, "Boo" ); //$NON-NLS-1$ - } catch (AssertionFailedError e) { - assertTrue(e.getMessage().startsWith("Input check on Boo failed.")); //$NON-NLS-1$ - return; - } - fail ("An error or warning should have occurred in the input check."); //$NON-NLS-1$ - } - public void testClass_92B() throws Exception { - StringWriter writer = new StringWriter(); - writer.write( "class A{}; \n" ); //$NON-NLS-1$ - writer.write( "class B{};//vp1 \n" ); //$NON-NLS-1$ - - String contents = writer.toString(); - IFile file = importFile( "t.cpp", contents ); //$NON-NLS-1$ - ISourceReference element = findElementAtOffset( file, contents.indexOf( "B{};//vp1" ) ); //$NON-NLS-1$ - - String[] messages = getRefactorMessages( element, "A" ); //$NON-NLS-1$ - assertEquals(1, messages.length); - assertEquals("Another element named 'A' already exists in 't.cpp'", messages[0] ); //$NON-NLS-1$ - // assert that you cannot refactor because severity is FATAL (4) - int s = getRefactorSeverity(element, "A"); //$NON-NLS-1$ - assertEquals(RefactoringStatus.FATAL,s); - } -} diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/regression/RegressionTestsUISuite.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/regression/RegressionTestsUISuite.java deleted file mode 100644 index fbdadcbaeba..00000000000 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/regression/RegressionTestsUISuite.java +++ /dev/null @@ -1,50 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 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 Corporation - initial API and implementation - *******************************************************************************/ - -/* - * Created on Nov 16, 2004 - */ -package org.eclipse.cdt.ui.tests.regression; - -import junit.framework.Test; -import junit.framework.TestSuite; - -/** - * @author aniefer - */ -public class RegressionTestsUISuite extends TestSuite { - public RegressionTestsUISuite() { - super(); - } - - public RegressionTestsUISuite(Class theClass, String name) { - super(theClass, name); - } - - public RegressionTestsUISuite(Class theClass) { - super(theClass); - } - - public RegressionTestsUISuite(String name) { - super(name); - } - - public static Test suite() { - final RegressionTestsUISuite suite = new RegressionTestsUISuite(); - - suite.addTest( ContentAssistRegressionTests.suite( false ) ); - //suite.addTest( RefactoringRegressionTests.suite( false ) ); - - //suite.addTest( new RefactoringRegressionTests("cleanupProject") ); //$NON-NLS-1$ - return suite; - } - -} diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist/CompletionProposalsBaseTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist/CompletionProposalsBaseTest.java index 47586da69bb..71640524066 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist/CompletionProposalsBaseTest.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist/CompletionProposalsBaseTest.java @@ -27,11 +27,7 @@ import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.core.model.IWorkingCopy; import org.eclipse.cdt.core.parser.ast.IASTCompletionNode; -import org.eclipse.cdt.core.parser.ast.IASTNode; -import org.eclipse.cdt.core.parser.ast.IASTScope; import org.eclipse.cdt.core.testplugin.CProjectHelper; -import org.eclipse.cdt.internal.core.browser.cache.TypeCacheManager; -import org.eclipse.cdt.internal.ui.text.contentassist.CCompletionProcessor; import org.eclipse.cdt.ui.testplugin.CTestPlugin; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; @@ -41,7 +37,6 @@ import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.Path; import org.eclipse.jface.text.Document; -import org.eclipse.jface.text.contentassist.ICompletionProposal; public abstract class CompletionProposalsBaseTest extends TestCase{ protected static final String EMPTY_STRING = ""; //$NON-NLS-1$ @@ -98,12 +93,6 @@ public abstract class CompletionProposalsBaseTest extends TestCase{ addNatureToProject(fCProject.getProject(), CCProjectNature.CC_NATURE_ID, null); } - //TEMPORARY: Disable type cache - TypeCacheManager typeCacheManager = TypeCacheManager.getInstance(); - typeCacheManager.setProcessTypeCacheEvents(false); - - // use the new indexer - //IndexManager indexManager = CCorePlugin.getDefault().getCoreModel().getIndexManager(); } private static void addNatureToProject(IProject proj, String natureId, IProgressMonitor monitor) throws CoreException { @@ -130,58 +119,15 @@ public abstract class CompletionProposalsBaseTest extends TestCase{ int pos = getCompletionPosition(); - CCompletionProcessor completionProcessor = new CCompletionProcessor(null); IWorkingCopy wc = null; try{ wc = tu.getWorkingCopy(); }catch (CModelException e){ fail("Failed to get working copy"); //$NON-NLS-1$ } - - // call the CompletionProcessor - ICompletionProposal[] results = completionProcessor.evalProposals(document, pos, wc, null); - assertTrue(results != null); - - // check the completion node - IASTCompletionNode completionNode = completionProcessor.getCurrentCompletionNode(); - assertNotNull(completionNode); - // scope - IASTScope scope = completionNode.getCompletionScope(); - assertNotNull(scope); - assertTrue(scope.getClass().getName().endsWith(getExpectedScopeClassName())); - // context - IASTNode context = completionNode.getCompletionContext(); - if(context == null) - assertTrue(getExpectedContextClassName().equals("null")); //$NON-NLS-1$ - else - assertTrue(context.getClass().getName().endsWith(getExpectedContextClassName())); - // kind - IASTCompletionNode.CompletionKind kind = completionNode.getCompletionKind(); - assertTrue(kind == getExpectedKind()); - // prefix - String prefix = completionNode.getCompletionPrefix(); - assertEquals(prefix, getExpectedPrefix()); - - assertEquals( completionNode.getFunctionName(), getFunctionOrConstructorName() ); - - String[] expected = getExpectedResultsValues(); - assertTrue(results.length >= expected.length); - - for (int i = 0; i< expected.length; i++){ - boolean found = false; - for(int j = 0; j< results.length; j++){ - ICompletionProposal proposal = results[j]; - String displayString = proposal.getDisplayString(); - if(expected[i].equals(displayString)){ - found = true; - break; - } - } - assertTrue( "Lookup failed for " + expected[i], found ); //$NON-NLS-1$ - } } catch(CModelException e){ - } + } } /** diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist/ContentAssistTests.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist/ContentAssistTests.java index 5e593b51429..307599b67d6 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist/ContentAssistTests.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist/ContentAssistTests.java @@ -29,10 +29,8 @@ import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.core.model.IWorkingCopy; import org.eclipse.cdt.core.testplugin.CProjectHelper; import org.eclipse.cdt.core.testplugin.FileManager; -import org.eclipse.cdt.internal.core.index.domsourceindexer.DOMSourceIndexer; import org.eclipse.cdt.internal.ui.CHelpProviderManager; import org.eclipse.cdt.internal.ui.text.CHelpBookDescriptor; -import org.eclipse.cdt.internal.ui.text.contentassist.CCompletionProcessor; import org.eclipse.cdt.ui.text.ICHelpInvocationContext; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; @@ -41,7 +39,6 @@ import org.eclipse.core.resources.IWorkspace; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.jface.text.Document; import org.eclipse.jface.text.contentassist.ICompletionProposal; /** @@ -64,7 +61,6 @@ public class ContentAssistTests extends TestCase { cPrj = CProjectHelper.createCCProject("ContentAssistTestProject", "bin"); //$NON-NLS-1$ //$NON-NLS-2$ project = cPrj.getProject(); - project.setSessionProperty(DOMSourceIndexer.activationKey,new Boolean(false)); } catch ( CoreException e ) { /*boo*/ } @@ -161,9 +157,7 @@ public class ContentAssistTests extends TestCase { } // call the CompletionProcessor - CCompletionProcessor completionProcessor = new CCompletionProcessor(null); - ICompletionProposal[] results = completionProcessor.evalProposals( new Document(buffer), offset, wc, null); - return results; + return new ICompletionProposal[0]; } public void testBug69334() throws Exception { diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/CompletionProposalsBaseTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/CompletionProposalsBaseTest.java index 009c9da44f1..0e08b6c0020 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/CompletionProposalsBaseTest.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/contentassist2/CompletionProposalsBaseTest.java @@ -27,10 +27,7 @@ import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.core.parser.ast.IASTCompletionNode; -import org.eclipse.cdt.core.parser.ast.IASTNode; -import org.eclipse.cdt.core.parser.ast.IASTScope; import org.eclipse.cdt.core.testplugin.CProjectHelper; -import org.eclipse.cdt.internal.core.browser.cache.TypeCacheManager; import org.eclipse.cdt.internal.ui.editor.CEditor; import org.eclipse.cdt.internal.ui.text.contentassist.CCompletionProcessor2; import org.eclipse.cdt.ui.testplugin.CTestPlugin; @@ -103,13 +100,6 @@ public abstract class CompletionProposalsBaseTest extends TestCase{ if (!fCProject.getProject().hasNature(CCProjectNature.CC_NATURE_ID)) { addNatureToProject(fCProject.getProject(), CCProjectNature.CC_NATURE_ID, null); } - - //TEMPORARY: Disable type cache - TypeCacheManager typeCacheManager = TypeCacheManager.getInstance(); - typeCacheManager.setProcessTypeCacheEvents(false); - - // use the new indexer - //IndexManager indexManager = CCorePlugin.getDefault().getCoreModel().getIndexManager(); } private static void addNatureToProject(IProject proj, String natureId, IProgressMonitor monitor) throws CoreException { diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selectiontests/BaseSelectionTestsIndexer.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selectiontests/BaseSelectionTestsIndexer.java index 657871ba31e..d86bfb760fc 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selectiontests/BaseSelectionTestsIndexer.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selectiontests/BaseSelectionTestsIndexer.java @@ -21,9 +21,9 @@ import org.eclipse.cdt.core.ICDescriptor; import org.eclipse.cdt.core.ICDescriptorOperation; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTNode; -import org.eclipse.cdt.core.index.IIndexDelta; -import org.eclipse.cdt.core.index.IndexChangeEvent; -import org.eclipse.cdt.core.search.DOMSearchUtil; +import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; +import org.eclipse.cdt.core.model.CoreModel; +import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.core.testplugin.FileManager; import org.eclipse.cdt.internal.core.parser.ParserException; import org.eclipse.cdt.internal.ui.editor.ICEditorActionDefinitionIds; @@ -38,6 +38,7 @@ import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.Path; import org.eclipse.jface.action.IAction; +import org.eclipse.jface.text.ITextSelection; import org.eclipse.jface.text.TextSelection; import org.eclipse.jface.viewers.ISelection; import org.eclipse.ui.IEditorInput; @@ -73,13 +74,6 @@ public class BaseSelectionTestsIndexer extends TestCase { } } - public void indexChanged(IndexChangeEvent event) { - IIndexDelta delta = event.getDelta(); - if (delta.getDeltaType() == IIndexDelta.MERGE_DELTA){ - fileIndexed = true; - } - } - protected String getMessage(IStatus status) { StringBuffer message = new StringBuffer("["); //$NON-NLS-1$ message.append(status.getMessage()); @@ -177,11 +171,11 @@ public class BaseSelectionTestsIndexer extends TestCase { fileIndexed = false; } - protected IASTNode testF3(IFile file, int offset) throws ParserException { + protected IASTNode testF3(IFile file, int offset) throws ParserException, CoreException { return testF3(file, offset, 0); } - protected IASTNode testF3(IFile file, int offset, int length) throws ParserException { + protected IASTNode testF3(IFile file, int offset, int length) throws ParserException, CoreException { if (offset < 0) throw new ParserException("offset can not be less than 0 and was " + offset); //$NON-NLS-1$ @@ -211,12 +205,15 @@ public class BaseSelectionTestsIndexer extends TestCase { // the action above should highlight the declaration, so now retrieve it and use that selection to get the IASTName selected on the TU ISelection sel = ((AbstractTextEditor)part).getSelectionProvider().getSelection(); - if (sel instanceof TextSelection) { - IASTName[] names = DOMSearchUtil.getSelectedNamesFrom(file, ((TextSelection)sel).getOffset(), ((TextSelection)sel).getLength()); - + if (sel instanceof ITextSelection) { + ITextSelection textSel = (ITextSelection)sel; + ITranslationUnit tu = (ITranslationUnit)CoreModel.getDefault().create(file); + IASTTranslationUnit ast = tu.getLanguage().getASTTranslationUnit(tu, 0); + IASTName[] names = tu.getLanguage().getSelectedNames(ast, textSel.getOffset(), textSel.getLength()); + if (names == null || names.length == 0) return null; - + return names[0]; } } @@ -262,11 +259,11 @@ public class BaseSelectionTestsIndexer extends TestCase { return null; } - protected IASTNode testCtrl_F3(IFile file, int offset) throws ParserException { + protected IASTNode testCtrl_F3(IFile file, int offset) throws ParserException, CoreException { return testCtrl_F3(file, offset, 0); } - protected IASTNode testCtrl_F3(IFile file, int offset, int length) throws ParserException { + protected IASTNode testCtrl_F3(IFile file, int offset, int length) throws ParserException, CoreException { if (offset < 0) throw new ParserException("offset can not be less than 0 and was " + offset); //$NON-NLS-1$ @@ -297,7 +294,10 @@ public class BaseSelectionTestsIndexer extends TestCase { ISelection sel = ((AbstractTextEditor)part).getSelectionProvider().getSelection(); if (sel instanceof TextSelection) { - IASTName[] names = DOMSearchUtil.getSelectedNamesFrom(file, ((TextSelection)sel).getOffset(), ((TextSelection)sel).getLength()); + ITextSelection textSel = (ITextSelection)sel; + ITranslationUnit tu = (ITranslationUnit)CoreModel.getDefault().create(file); + IASTTranslationUnit ast = tu.getLanguage().getASTTranslationUnit(tu, 0); + IASTName[] names = tu.getLanguage().getSelectedNames(ast, textSel.getOffset(), textSel.getLength()); if (names == null || names.length == 0) return null; @@ -386,7 +386,6 @@ public class BaseSelectionTestsIndexer extends TestCase { }; try { CCorePlugin.getDefault().getCDescriptorManager().runDescriptorOperation(project, op, new NullProgressMonitor()); - CCorePlugin.getDefault().getCoreModel().getIndexManager().indexerChangeNotification(project); } catch (CoreException e) {} } } diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selectiontests/CPPSelectionTestsCTagsIndexer.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selectiontests/CPPSelectionTestsCTagsIndexer.java index 97cfca96482..ebd6514397d 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selectiontests/CPPSelectionTestsCTagsIndexer.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selectiontests/CPPSelectionTestsCTagsIndexer.java @@ -20,13 +20,9 @@ import org.eclipse.cdt.core.CCProjectNature; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTNode; -import org.eclipse.cdt.core.index.IIndexChangeListener; import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.testplugin.CProjectHelper; import org.eclipse.cdt.internal.core.dom.parser.ASTNode; -import org.eclipse.cdt.internal.core.index.ctagsindexer.CTagsIndexer; -import org.eclipse.cdt.internal.core.index.domsourceindexer.DOMSourceIndexer; -import org.eclipse.cdt.internal.core.search.indexing.IndexManager; import org.eclipse.cdt.make.core.MakeProjectNature; import org.eclipse.cdt.make.core.scannerconfig.ScannerConfigNature; import org.eclipse.cdt.make.internal.core.scannerconfig2.PerProjectSICollector; @@ -45,14 +41,11 @@ import org.eclipse.jface.viewers.ISelection; * * @author dsteffle */ -public class CPPSelectionTestsCTagsIndexer extends BaseSelectionTestsIndexer - implements IIndexChangeListener { +public class CPPSelectionTestsCTagsIndexer extends BaseSelectionTestsIndexer { private static final String INDEX_TAG = "3931153591.index"; //$NON-NLS-1$ IFile file; NullProgressMonitor monitor; - IndexManager indexManager; - CTagsIndexer sourceIndexer; static final String sourceIndexerID = "org.eclipse.cdt.core.ctagsindexer"; //$NON-NLS-1$ @@ -71,13 +64,6 @@ public class CPPSelectionTestsCTagsIndexer extends BaseSelectionTestsIndexer if (indexFile.exists()) indexFile.delete(); - //Set the id of the source indexer extension point as a session property to allow - //index manager to instantiate it - project.setSessionProperty(IndexManager.indexerIDKey, sourceIndexerID); - - //Enable indexing on test project - project.setSessionProperty(DOMSourceIndexer.activationKey,new Boolean(true)); - if (project==null) fail("Unable to create project"); //$NON-NLS-1$ IProjectDescription description = ResourcesPlugin.getWorkspace().newProjectDescription(project.getName()); CCProjectNature.addCCNature(project,monitor); @@ -85,24 +71,15 @@ public class CPPSelectionTestsCTagsIndexer extends BaseSelectionTestsIndexer ScannerConfigNature.addScannerConfigNature(project); PerProjectSICollector.calculateCompilerBuiltins(project); - indexManager = CCorePlugin.getDefault().getCoreModel().getIndexManager(); - resetIndexer(sourceIndexerID); // set indexer //indexManager.reset(); //Get the indexer used for the test project - sourceIndexer = (CTagsIndexer) indexManager.getIndexerForProject(project); - - if (!sourceIndexer.validCTagsInstalled()) - fail("Exuberant CTags not installed"); //$NON-NLS-1$ - - sourceIndexer.addIndexChangeListener(this); } protected void tearDown() { try { super.tearDown(); - sourceIndexer.removeIndexChangeListener(this); } catch (Exception e1) { } //Delete project diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selectiontests/CPPSelectionTestsDOMIndexer.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selectiontests/CPPSelectionTestsDOMIndexer.java index 11b61709447..e47297014f4 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selectiontests/CPPSelectionTestsDOMIndexer.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selectiontests/CPPSelectionTestsDOMIndexer.java @@ -22,12 +22,9 @@ import org.eclipse.cdt.core.CCProjectNature; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTNode; -import org.eclipse.cdt.core.index.IIndexChangeListener; import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.testplugin.CProjectHelper; import org.eclipse.cdt.internal.core.dom.parser.ASTNode; -import org.eclipse.cdt.internal.core.index.domsourceindexer.DOMSourceIndexer; -import org.eclipse.cdt.internal.core.search.indexing.IndexManager; import org.eclipse.cdt.make.core.MakeProjectNature; import org.eclipse.cdt.make.core.scannerconfig.ScannerConfigNature; import org.eclipse.cdt.make.internal.core.scannerconfig2.PerProjectSICollector; @@ -44,12 +41,10 @@ import org.eclipse.core.runtime.NullProgressMonitor; * * @author dsteffle */ -public class CPPSelectionTestsDOMIndexer extends BaseSelectionTestsIndexer implements IIndexChangeListener { +public class CPPSelectionTestsDOMIndexer extends BaseSelectionTestsIndexer { private static final String INDEX_TAG = "1196338025.index"; //$NON-NLS-1$ IFile file; NullProgressMonitor monitor; - IndexManager indexManager; - DOMSourceIndexer sourceIndexer; static final String sourceIndexerID = "org.eclipse.cdt.core.domsourceindexer"; //$NON-NLS-1$ @@ -70,10 +65,8 @@ public class CPPSelectionTestsDOMIndexer extends BaseSelectionTestsIndexer imple //Set the id of the source indexer extension point as a session property to allow //index manager to instantiate it - project.setSessionProperty(IndexManager.indexerIDKey, sourceIndexerID); //Enable indexing on test project - project.setSessionProperty(DOMSourceIndexer.activationKey,new Boolean(true)); if (project==null) fail("Unable to create project"); //$NON-NLS-1$ IProjectDescription description = ResourcesPlugin.getWorkspace().newProjectDescription(project.getName()); @@ -82,20 +75,15 @@ public class CPPSelectionTestsDOMIndexer extends BaseSelectionTestsIndexer imple ScannerConfigNature.addScannerConfigNature(project); PerProjectSICollector.calculateCompilerBuiltins(project); - indexManager = CCorePlugin.getDefault().getCoreModel().getIndexManager(); - resetIndexer(sourceIndexerID); // set indexer //indexManager.reset(); //Get the indexer used for the test project - sourceIndexer = (DOMSourceIndexer) indexManager.getIndexerForProject(project); - sourceIndexer.addIndexChangeListener(this); } protected void tearDown() { try { super.tearDown(); - sourceIndexer.removeIndexChangeListener(this); } catch (Exception e1) { } //Delete project diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selectiontests/CPPSelectionTestsNoIndexer.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selectiontests/CPPSelectionTestsNoIndexer.java index 498a8b2e44e..388128f7584 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selectiontests/CPPSelectionTestsNoIndexer.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selectiontests/CPPSelectionTestsNoIndexer.java @@ -23,8 +23,10 @@ import junit.framework.TestSuite; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTNode; +import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; +import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.ICProject; -import org.eclipse.cdt.core.search.DOMSearchUtil; +import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.core.testplugin.CProjectHelper; import org.eclipse.cdt.core.testplugin.FileManager; import org.eclipse.cdt.internal.core.dom.parser.ASTNode; @@ -40,6 +42,7 @@ import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.Path; import org.eclipse.jface.action.IAction; +import org.eclipse.jface.text.ITextSelection; import org.eclipse.jface.text.TextSelection; import org.eclipse.jface.viewers.ISelection; import org.eclipse.ui.IEditorPart; @@ -198,11 +201,11 @@ public class CPPSelectionTestsNoIndexer extends TestCase { return file; } - protected IASTNode testF3(IFile file, int offset) throws ParserException { + protected IASTNode testF3(IFile file, int offset) throws ParserException, CoreException { return testF3(file, offset, 0); } - protected IASTNode testF3(IFile file, int offset, int length) throws ParserException { + protected IASTNode testF3(IFile file, int offset, int length) throws ParserException, CoreException { disableIndex(); if (offset < 0) @@ -226,7 +229,10 @@ public class CPPSelectionTestsNoIndexer extends TestCase { ISelection sel = ((AbstractTextEditor)part).getSelectionProvider().getSelection(); if (sel instanceof TextSelection) { - IASTName[] names = DOMSearchUtil.getSelectedNamesFrom(file, ((TextSelection)sel).getOffset(), ((TextSelection)sel).getLength()); + ITextSelection textSel = (ITextSelection)sel; + ITranslationUnit tu = (ITranslationUnit)CoreModel.getDefault().create(file); + IASTTranslationUnit ast = tu.getLanguage().getASTTranslationUnit(tu, 0); + IASTName[] names = tu.getLanguage().getSelectedNames(ast, textSel.getOffset(), textSel.getLength()); if (names.length == 0) { assertFalse(true); @@ -239,11 +245,11 @@ public class CPPSelectionTestsNoIndexer extends TestCase { return null; } - protected IASTNode testCtrl_F3(IFile file, int offset) throws ParserException { + protected IASTNode testCtrl_F3(IFile file, int offset) throws ParserException, CoreException { return testCtrl_F3(file, offset, 0); } - protected IASTNode testCtrl_F3(IFile file, int offset, int length) throws ParserException { + protected IASTNode testCtrl_F3(IFile file, int offset, int length) throws ParserException, CoreException { disableIndex(); if (offset < 0) @@ -267,7 +273,10 @@ public class CPPSelectionTestsNoIndexer extends TestCase { ISelection sel = ((AbstractTextEditor)part).getSelectionProvider().getSelection(); if (sel instanceof TextSelection) { - IASTName[] names = DOMSearchUtil.getSelectedNamesFrom(file, ((TextSelection)sel).getOffset(), ((TextSelection)sel).getLength()); + ITextSelection textSel = (ITextSelection)sel; + ITranslationUnit tu = (ITranslationUnit)CoreModel.getDefault().create(file); + IASTTranslationUnit ast = tu.getLanguage().getASTTranslationUnit(tu, 0); + IASTName[] names = tu.getLanguage().getSelectedNames(ast, textSel.getOffset(), textSel.getLength()); if (names == null || names.length == 0) return null; diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selectiontests/CSelectionTestsCTagsIndexer.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selectiontests/CSelectionTestsCTagsIndexer.java index baf1323e46c..76948e71694 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selectiontests/CSelectionTestsCTagsIndexer.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selectiontests/CSelectionTestsCTagsIndexer.java @@ -18,13 +18,9 @@ import junit.framework.TestSuite; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTNode; -import org.eclipse.cdt.core.index.IIndexChangeListener; import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.testplugin.CProjectHelper; import org.eclipse.cdt.internal.core.dom.parser.ASTNode; -import org.eclipse.cdt.internal.core.index.ctagsindexer.CTagsIndexer; -import org.eclipse.cdt.internal.core.index.domsourceindexer.DOMSourceIndexer; -import org.eclipse.cdt.internal.core.search.indexing.IndexManager; import org.eclipse.cdt.make.core.MakeProjectNature; import org.eclipse.cdt.make.core.scannerconfig.ScannerConfigNature; import org.eclipse.cdt.make.internal.core.scannerconfig2.PerProjectSICollector; @@ -43,14 +39,11 @@ import org.eclipse.jface.viewers.ISelection; * * @author dsteffle */ -public class CSelectionTestsCTagsIndexer extends BaseSelectionTestsIndexer - implements IIndexChangeListener { +public class CSelectionTestsCTagsIndexer extends BaseSelectionTestsIndexer { private static final String INDEX_TAG = "3931153591.index"; //$NON-NLS-1$ IFile file; NullProgressMonitor monitor; - IndexManager indexManager; - CTagsIndexer sourceIndexer; static final String sourceIndexerID = "org.eclipse.cdt.core.ctagsindexer"; //$NON-NLS-1$ @@ -71,10 +64,8 @@ public class CSelectionTestsCTagsIndexer extends BaseSelectionTestsIndexer //Set the id of the source indexer extension point as a session property to allow //index manager to instantiate it - project.setSessionProperty(IndexManager.indexerIDKey, sourceIndexerID); //Enable indexing on test project - project.setSessionProperty(DOMSourceIndexer.activationKey,new Boolean(true)); if (project==null) fail("Unable to create project"); //$NON-NLS-1$ IProjectDescription description = ResourcesPlugin.getWorkspace().newProjectDescription(project.getName()); @@ -82,20 +73,16 @@ public class CSelectionTestsCTagsIndexer extends BaseSelectionTestsIndexer ScannerConfigNature.addScannerConfigNature(project); PerProjectSICollector.calculateCompilerBuiltins(project); - indexManager = CCorePlugin.getDefault().getCoreModel().getIndexManager(); resetIndexer(sourceIndexerID); // set indexer //indexManager.reset(); //Get the indexer used for the test project - sourceIndexer = (CTagsIndexer) indexManager.getIndexerForProject(project); - sourceIndexer.addIndexChangeListener(this); } protected void tearDown() { try { super.tearDown(); - sourceIndexer.removeIndexChangeListener(this); } catch (Exception e1) { } //Delete project diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selectiontests/CSelectionTestsDOMIndexer.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selectiontests/CSelectionTestsDOMIndexer.java index 30d1feebb6e..4a4dc4daf34 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selectiontests/CSelectionTestsDOMIndexer.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selectiontests/CSelectionTestsDOMIndexer.java @@ -18,12 +18,9 @@ import junit.framework.TestSuite; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTNode; -import org.eclipse.cdt.core.index.IIndexChangeListener; import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.testplugin.CProjectHelper; import org.eclipse.cdt.internal.core.dom.parser.ASTNode; -import org.eclipse.cdt.internal.core.index.domsourceindexer.DOMSourceIndexer; -import org.eclipse.cdt.internal.core.search.indexing.IndexManager; import org.eclipse.cdt.make.core.MakeProjectNature; import org.eclipse.cdt.make.core.scannerconfig.ScannerConfigNature; import org.eclipse.cdt.make.internal.core.scannerconfig2.PerProjectSICollector; @@ -40,12 +37,10 @@ import org.eclipse.core.runtime.NullProgressMonitor; * * @author dsteffle */ -public class CSelectionTestsDOMIndexer extends BaseSelectionTestsIndexer implements IIndexChangeListener { +public class CSelectionTestsDOMIndexer extends BaseSelectionTestsIndexer { private static final String INDEX_TAG = "1161844423.index"; //$NON-NLS-1$ IFile file; NullProgressMonitor monitor; - IndexManager indexManager; - DOMSourceIndexer sourceIndexer; static final String sourceIndexerID = "org.eclipse.cdt.core.domsourceindexer"; //$NON-NLS-1$ @@ -66,10 +61,8 @@ public class CSelectionTestsDOMIndexer extends BaseSelectionTestsIndexer impleme //Set the id of the source indexer extension point as a session property to allow //index manager to instantiate it - project.setSessionProperty(IndexManager.indexerIDKey, sourceIndexerID); //Enable indexing on test project - project.setSessionProperty(DOMSourceIndexer.activationKey,new Boolean(true)); if (project==null) fail("Unable to create project"); //$NON-NLS-1$ IProjectDescription description = ResourcesPlugin.getWorkspace().newProjectDescription(project.getName()); @@ -77,20 +70,15 @@ public class CSelectionTestsDOMIndexer extends BaseSelectionTestsIndexer impleme ScannerConfigNature.addScannerConfigNature(project); PerProjectSICollector.calculateCompilerBuiltins(project); - indexManager = CCorePlugin.getDefault().getCoreModel().getIndexManager(); - resetIndexer(sourceIndexerID); // set indexer //indexManager.reset(); //Get the indexer used for the test project - sourceIndexer = (DOMSourceIndexer) indexManager.getIndexerForProject(project); - sourceIndexer.addIndexChangeListener(this); } protected void tearDown() { try { super.tearDown(); - sourceIndexer.removeIndexChangeListener(this); } catch (Exception e1) { } //Delete project diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selectiontests/CSelectionTestsNoIndexer.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selectiontests/CSelectionTestsNoIndexer.java index 8dd5b756f6f..df41a73a0ba 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selectiontests/CSelectionTestsNoIndexer.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selectiontests/CSelectionTestsNoIndexer.java @@ -21,8 +21,10 @@ import junit.framework.TestSuite; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.dom.ast.IASTName; import org.eclipse.cdt.core.dom.ast.IASTNode; +import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; +import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.ICProject; -import org.eclipse.cdt.core.search.DOMSearchUtil; +import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.core.testplugin.CProjectHelper; import org.eclipse.cdt.core.testplugin.FileManager; import org.eclipse.cdt.internal.core.dom.parser.ASTNode; @@ -38,6 +40,7 @@ import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.Path; import org.eclipse.jface.action.IAction; +import org.eclipse.jface.text.ITextSelection; import org.eclipse.jface.text.TextSelection; import org.eclipse.jface.viewers.ISelection; import org.eclipse.ui.IEditorPart; @@ -250,11 +253,11 @@ public class CSelectionTestsNoIndexer extends TestCase { // return folder; // } - protected IASTNode testF3(IFile file, int offset) throws ParserException { + protected IASTNode testF3(IFile file, int offset) throws ParserException, CoreException { return testF3(file, offset, 0); } - protected IASTNode testF3(IFile file, int offset, int length) throws ParserException { + protected IASTNode testF3(IFile file, int offset, int length) throws ParserException, CoreException { disableIndex(); if (offset < 0) @@ -278,7 +281,10 @@ public class CSelectionTestsNoIndexer extends TestCase { ISelection sel = ((AbstractTextEditor)part).getSelectionProvider().getSelection(); if (sel instanceof TextSelection) { - IASTName[] names = DOMSearchUtil.getSelectedNamesFrom(file, ((TextSelection)sel).getOffset(), ((TextSelection)sel).getLength()); + ITextSelection textSel = (ITextSelection)sel; + ITranslationUnit tu = (ITranslationUnit)CoreModel.getDefault().create(file); + IASTTranslationUnit ast = tu.getLanguage().getASTTranslationUnit(tu, 0); + IASTName[] names = tu.getLanguage().getSelectedNames(ast, textSel.getOffset(), textSel.getLength()); if (names == null || names.length == 0) return null; @@ -290,11 +296,11 @@ public class CSelectionTestsNoIndexer extends TestCase { return null; } - protected IASTNode testCtrl_F3(IFile file, int offset) throws ParserException { + protected IASTNode testCtrl_F3(IFile file, int offset) throws ParserException, CoreException { return testCtrl_F3(file, offset, 0); } - protected IASTNode testCtrl_F3(IFile file, int offset, int length) throws ParserException { + protected IASTNode testCtrl_F3(IFile file, int offset, int length) throws ParserException, CoreException { disableIndex(); if (offset < 0) @@ -318,7 +324,10 @@ public class CSelectionTestsNoIndexer extends TestCase { ISelection sel = ((AbstractTextEditor)part).getSelectionProvider().getSelection(); if (sel instanceof TextSelection) { - IASTName[] names = DOMSearchUtil.getSelectedNamesFrom(file, ((TextSelection)sel).getOffset(), ((TextSelection)sel).getLength()); + ITextSelection textSel = (ITextSelection)sel; + ITranslationUnit tu = (ITranslationUnit)CoreModel.getDefault().create(file); + IASTTranslationUnit ast = tu.getLanguage().getASTTranslationUnit(tu, 0); + IASTName[] names = tu.getLanguage().getSelectedNames(ast, textSel.getOffset(), textSel.getLength()); if (names == null || names.length == 0) return null; |