From e6e17610e5da6745d60ed85df7147cd70524cb66 Mon Sep 17 00:00:00 2001 From: Alain Magloire Date: Mon, 8 Sep 2003 04:59:14 +0000 Subject: [PATCH] Work on code completion and hover. --- .../make/internal/ui/MakeResources.properties | 16 ++ .../ui/editor/MakefileContentOutlinePage.java | 21 +- .../ui/editor/MakefileDocumentProvider.java | 1 + .../internal/ui/editor/MakefileEditor.java | 73 +++++- .../MakefileEditorActionContributor.java | 65 ++++-- ...akefileEditorTogglePresentationAction.java | 21 +- ....java => MakefileSourceConfiguration.java} | 39 +++- .../IMakefileColorManager.java | 2 +- .../MakefileColorManager.java | 2 +- .../internal/ui/text/WordPartDetector.java | 61 ++++++ .../makefile}/MakefileCodeScanner.java | 4 +- .../makefile/MakefileCompletionProcessor.java | 207 ++++++++++++++++++ .../makefile}/MakefileMacroScanner.java | 2 +- .../makefile}/MakefilePartitionScanner.java | 2 +- .../makefile}/MakefileSimpleMacroRule.java | 2 +- .../makefile}/MakefileWordDetector.java | 2 +- 16 files changed, 449 insertions(+), 71 deletions(-) rename build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/editor/{MakefileEditorConfiguration.java => MakefileSourceConfiguration.java} (64%) rename build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/{editor => text}/IMakefileColorManager.java (96%) rename build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/{editor => text}/MakefileColorManager.java (96%) create mode 100644 build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/text/WordPartDetector.java rename build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/{editor => text/makefile}/MakefileCodeScanner.java (98%) create mode 100644 build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/text/makefile/MakefileCompletionProcessor.java rename build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/{editor => text/makefile}/MakefileMacroScanner.java (98%) rename build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/{editor => text/makefile}/MakefilePartitionScanner.java (99%) rename build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/{editor => text/makefile}/MakefileSimpleMacroRule.java (96%) rename build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/{editor => text/makefile}/MakefileWordDetector.java (95%) diff --git a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/MakeResources.properties b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/MakeResources.properties index cd4f46d4fa5..add42d72fce 100644 --- a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/MakeResources.properties +++ b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/MakeResources.properties @@ -67,3 +67,19 @@ BuildPropertyCommon.label.addVar=Add BuildPropertyCommon.label.message=Value: BuildPropertyCommon.label.browse=Browse... BuildPropertyCommon.label.configs=Defined configurations: + +# Makefile Editor messages +ContentAssistProposal.label=Content Assist@Ctrl+SPACE +ContentAssistProposal.tooltip=Content Assist +ContentAssistProposal.image= +ContentAssistProposal.description=Content Assist + +ContentAssistTip.label=Content Tip@Ctrl+SHIFT+SPACE +ContentAssistTip.tooltip=Content Tip +ContentAssistTip.image= +ContentAssistTip.description=Content Tip + +TogglePresentation.label=Change Presentation +TogglePresentation.tooltip=Enable/Disable Segmented Source Viewer +TogglePresentation.description=Enable/Disable Segmented Source Viewer + diff --git a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/editor/MakefileContentOutlinePage.java b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/editor/MakefileContentOutlinePage.java index 46e959cb5ae..c2448a6f8fd 100644 --- a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/editor/MakefileContentOutlinePage.java +++ b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/editor/MakefileContentOutlinePage.java @@ -10,9 +10,6 @@ ***********************************************************************/ package org.eclipse.cdt.make.internal.ui.editor; -import java.io.IOException; -import java.io.Reader; -import java.io.StringReader; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -23,7 +20,7 @@ import org.eclipse.cdt.make.core.makefile.IMakefile; import org.eclipse.cdt.make.core.makefile.IRule; import org.eclipse.cdt.make.core.makefile.IStatement; import org.eclipse.cdt.make.core.makefile.ITargetRule; -import org.eclipse.cdt.make.internal.core.makefile.posix.PosixMakefile; +import org.eclipse.cdt.make.internal.core.makefile.NullMakefile; import org.eclipse.cdt.make.internal.ui.MakeUIImages; import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.IDocument; @@ -54,6 +51,7 @@ public class MakefileContentOutlinePage extends ContentOutlinePage implements IC protected boolean showInferenceRule = true; protected IMakefile makefile; + protected IMakefile nullMakefile = new NullMakefile(); /* (non-Javadoc) * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object) @@ -109,21 +107,12 @@ public class MakefileContentOutlinePage extends ContentOutlinePage implements IC */ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { if (oldInput != null) { - //IDocument document= fDocumentProvider.getDocument(oldInput); - //if (document != null) { - //} + makefile = nullMakefile; } if (newInput != null) { - IDocument document = fDocumentProvider.getDocument(newInput); - if (document != null) { - try { - String content = document.get(); - Reader r = new StringReader(content); - makefile = new PosixMakefile(r); - } catch (IOException e) { - } - } + IDocument document= fDocumentProvider.getDocument(newInput); + makefile = fEditor.getMakefile(document); } } diff --git a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/editor/MakefileDocumentProvider.java b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/editor/MakefileDocumentProvider.java index 9df28c86caf..5f700f59af3 100644 --- a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/editor/MakefileDocumentProvider.java +++ b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/editor/MakefileDocumentProvider.java @@ -10,6 +10,7 @@ ***********************************************************************/ package org.eclipse.cdt.make.internal.ui.editor; +import org.eclipse.cdt.make.internal.ui.text.makefile.MakefilePartitionScanner; import org.eclipse.core.runtime.CoreException; import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.IDocumentPartitioner; diff --git a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/editor/MakefileEditor.java b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/editor/MakefileEditor.java index dce8e47fc30..34761231077 100644 --- a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/editor/MakefileEditor.java +++ b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/editor/MakefileEditor.java @@ -10,9 +10,24 @@ ***********************************************************************/ package org.eclipse.cdt.make.internal.ui.editor; +import java.io.IOException; +import java.io.Reader; +import java.io.StringReader; +import java.util.ResourceBundle; + +import org.eclipse.cdt.make.core.makefile.IMakefile; +import org.eclipse.cdt.make.internal.core.makefile.NullMakefile; +import org.eclipse.cdt.make.internal.core.makefile.posix.PosixMakefile; +import org.eclipse.cdt.make.internal.ui.MakeUIPlugin; +import org.eclipse.cdt.make.internal.ui.text.MakefileColorManager; import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.source.ISourceViewer; import org.eclipse.ui.editors.text.TextEditor; import org.eclipse.ui.texteditor.DefaultRangeIndicator; +import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds; +import org.eclipse.ui.texteditor.TextOperationAction; import org.eclipse.ui.views.contentoutline.IContentOutlinePage; public class MakefileEditor extends TextEditor { @@ -25,8 +40,35 @@ public class MakefileEditor extends TextEditor { * The page that shows the outline. */ protected MakefileContentOutlinePage page; + protected IMakefile makefile; + private MakefileContentOutlinePage getOutlinePage() { + if (page == null) { + page = new MakefileContentOutlinePage(getDocumentProvider(), this); + page.setInput(getEditorInput()); + } + return page; + } + public IMakefile getMakefile() { + IDocument document = getDocumentProvider().getDocument(getEditorInput()); + return getMakefile(document); + } + + public IMakefile getMakefile(IDocument document) { + if (document != null) { + if (makefile == null || isDirty()) { + try { + String content = document.get(); + Reader r = new StringReader(content); + makefile = new PosixMakefile(r); + } catch (IOException e) { + makefile = new NullMakefile(); + } + } + } + return makefile; + } public MakefileEditor() { super(); @@ -38,7 +80,7 @@ public class MakefileEditor extends TextEditor { */ protected void initializeEditor() { - setSourceViewerConfiguration(new MakefileEditorConfiguration(new MakefileColorManager())); + setSourceViewerConfiguration(new MakefileSourceConfiguration(new MakefileColorManager(), this)); setRangeIndicator(new DefaultRangeIndicator()); setEditorContextMenuId("#MakefileEditorContext"); //$NON-NLS-1$ setRulerContextMenuId("#MakefileRulerContext"); //$NON-NLS-1$ @@ -55,15 +97,6 @@ public class MakefileEditor extends TextEditor { return super.getAdapter(key); } - private MakefileContentOutlinePage getOutlinePage() { - if (page == null) { - page= new MakefileContentOutlinePage(getDocumentProvider(), this); - //page.addPostSelectionChangedListener(selectionChangedListener); - page.setInput(getEditorInput()); - } - return page; - } - /* (non-Javadoc) * @see org.eclipse.ui.ISaveablePart#doSave(org.eclipse.core.runtime.IProgressMonitor) */ @@ -74,4 +107,24 @@ public class MakefileEditor extends TextEditor { } } + /** + * Method to install the editor actions. + * + * @see org.eclipse.ui.texteditor.AbstractTextEditor#createActions() + */ + protected void createActions() { + super.createActions(); + + ResourceBundle bundle = MakeUIPlugin.getDefault().getResourceBundle(); + + IAction a = new TextOperationAction(bundle, "ContentAssistProposal.", this, ISourceViewer.CONTENTASSIST_PROPOSALS); //$NON-NLS-1$ + a.setActionDefinitionId(ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS); + setAction("ContentAssistProposal", a); //$NON-NLS-1$ + + a = new TextOperationAction(bundle, "ContentAssistTip.", this, ISourceViewer.CONTENTASSIST_CONTEXT_INFORMATION); //$NON-NLS-1$ + a.setActionDefinitionId(ITextEditorActionDefinitionIds.CONTENT_ASSIST_CONTEXT_INFORMATION); + setAction("ContentAssistTip", a); //$NON-NLS-1$ + + } + } diff --git a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/editor/MakefileEditorActionContributor.java b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/editor/MakefileEditorActionContributor.java index 9577ac6f845..b3344ab36bd 100644 --- a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/editor/MakefileEditorActionContributor.java +++ b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/editor/MakefileEditorActionContributor.java @@ -10,24 +10,36 @@ ***********************************************************************/ package org.eclipse.cdt.make.internal.ui.editor; +import org.eclipse.cdt.make.internal.ui.MakeUIPlugin; +import org.eclipse.jface.action.IMenuManager; import org.eclipse.jface.action.IToolBarManager; +import org.eclipse.jface.action.Separator; import org.eclipse.ui.IActionBars; import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.IWorkbenchActionConstants; import org.eclipse.ui.texteditor.BasicTextEditorActionContributor; import org.eclipse.ui.texteditor.ITextEditor; +import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds; +import org.eclipse.ui.texteditor.RetargetTextEditorAction; /** */ public class MakefileEditorActionContributor extends BasicTextEditorActionContributor { - private MakefileEditorTogglePresentationAction togglePresentationAction; - private static final String TOGGLE_PRESENTATION = "makefile_toggle_presentation"; //$NON-NLS-1$ + + private MakefileEditorTogglePresentationAction fTogglePresentation; + protected RetargetTextEditorAction fContentAssistProposal; + protected RetargetTextEditorAction fContentAssistTip; /** * Constructor for MakefileEditorActionContributor. */ public MakefileEditorActionContributor() { super(); - togglePresentationAction = new MakefileEditorTogglePresentationAction(); + fContentAssistProposal = new RetargetTextEditorAction(MakeUIPlugin.getDefault().getResourceBundle(), "ContentAssistProposal."); //$NON-NLS-1$ + fContentAssistProposal.setActionDefinitionId(ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS); + fContentAssistTip = new RetargetTextEditorAction(MakeUIPlugin.getDefault().getResourceBundle(), "ContentAssistTip."); //$NON-NLS-1$ + fContentAssistTip.setActionDefinitionId(ITextEditorActionDefinitionIds.CONTENT_ASSIST_CONTEXT_INFORMATION); + fTogglePresentation = new MakefileEditorTogglePresentationAction(); } /** @@ -35,11 +47,30 @@ public class MakefileEditorActionContributor extends BasicTextEditorActionContri */ public void setActiveEditor(IEditorPart targetEditor) { super.setActiveEditor(targetEditor); - ITextEditor textEditor = null; - if (targetEditor instanceof ITextEditor) - textEditor = (ITextEditor) targetEditor; + doSetActiveEditor(targetEditor); + } - togglePresentationAction.setEditor(textEditor); + private void doSetActiveEditor(IEditorPart part) { + super.setActiveEditor(part); + + ITextEditor editor = null; + if (part instanceof ITextEditor) { + editor = (ITextEditor) part; + } + + fContentAssistProposal.setAction(getAction(editor, "ContentAssistProposal")); //$NON-NLS-1$ + fContentAssistTip.setAction(getAction(editor, "ContentAssistTip")); //$NON-NLS-1$ + + fTogglePresentation.setEditor(editor); + fTogglePresentation.update(); + } + + /* + * @see IEditorActionBarContributor#dispose() + */ + public void dispose() { + doSetActiveEditor(null); + super.dispose(); } /** @@ -47,15 +78,19 @@ public class MakefileEditorActionContributor extends BasicTextEditorActionContri */ public void init(IActionBars bars) { super.init(bars); - bars.setGlobalActionHandler(TOGGLE_PRESENTATION, togglePresentationAction); - } + IMenuManager menuManager = bars.getMenuManager(); + IMenuManager editMenu = menuManager.findMenuUsingPath(IWorkbenchActionConstants.M_EDIT); + if (editMenu != null) { + editMenu.add(new Separator()); + editMenu.add(fContentAssistProposal); + editMenu.add(fContentAssistTip); + } - /** - * @see org.eclipse.ui.part.EditorActionBarContributor#contributeToToolBar(IToolBarManager) - */ - public void contributeToToolBar(IToolBarManager toolBarManager) { - super.contributeToToolBar(toolBarManager); - toolBarManager.add(togglePresentationAction); + IToolBarManager toolBarManager = bars.getToolBarManager(); + if (toolBarManager != null) { + toolBarManager.add(new Separator()); + toolBarManager.add(fTogglePresentation); + } } } diff --git a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/editor/MakefileEditorTogglePresentationAction.java b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/editor/MakefileEditorTogglePresentationAction.java index 6926b355e9f..1d1137e1481 100644 --- a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/editor/MakefileEditorTogglePresentationAction.java +++ b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/editor/MakefileEditorTogglePresentationAction.java @@ -19,18 +19,11 @@ import org.eclipse.ui.texteditor.TextEditorAction; */ public class MakefileEditorTogglePresentationAction extends TextEditorAction { - private final static String ACTION_ID = "org.eclipse.cdt.make.ui.MakefileEditorTogglePresentationAction"; //$NON-NLS-1$ /** * Constructor for MakefileEditorTogglePresentationAction. - * @param bundle - * @param prefix - * @param editor */ public MakefileEditorTogglePresentationAction() { - super(MakeUIPlugin.getDefault().getResourceBundle(), "MakefileEditorTogglePresentationAction.", null); //$NON-NLS-1$ - - setToolTipText("MakefileEditorTogglePresentationAction.tooltip"); //$NON-NLS-1$ - setActionDefinitionId(ACTION_ID); + super(MakeUIPlugin.getDefault().getResourceBundle(), "MakefileEditorTogglePresentation.", null); //$NON-NLS-1$ MakeUIImages.setImageDescriptors(this, MakeUIImages.T_TOOL, MakeUIImages.IMG_TOOLS_MAKEFILE_SEGMENT_EDIT); update(); } @@ -50,16 +43,8 @@ public class MakefileEditorTogglePresentationAction extends TextEditorAction { * @see org.eclipse.ui.texteditor.IUpdate#update() */ public void update() { - setChecked(isChecked()); - setEnabled(isEnabled()); - } - - /** - * @see org.eclipse.ui.texteditor.TextEditorAction#setEditor(ITextEditor) - */ - public void setEditor(ITextEditor editor) { - super.setEditor(editor); - update(); + setChecked(getTextEditor() != null && getTextEditor().showsHighlightRangeOnly()); + setEnabled(true); } } diff --git a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/editor/MakefileEditorConfiguration.java b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/editor/MakefileSourceConfiguration.java similarity index 64% rename from build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/editor/MakefileEditorConfiguration.java rename to build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/editor/MakefileSourceConfiguration.java index 1ed5b9dd129..54d9c4f9ec1 100644 --- a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/editor/MakefileEditorConfiguration.java +++ b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/editor/MakefileSourceConfiguration.java @@ -10,8 +10,15 @@ ***********************************************************************/ package org.eclipse.cdt.make.internal.ui.editor; +import org.eclipse.cdt.make.internal.ui.text.IMakefileColorManager; +import org.eclipse.cdt.make.internal.ui.text.MakefileColorManager; +import org.eclipse.cdt.make.internal.ui.text.makefile.MakefileCodeScanner; +import org.eclipse.cdt.make.internal.ui.text.makefile.MakefileCompletionProcessor; +import org.eclipse.cdt.make.internal.ui.text.makefile.MakefilePartitionScanner; import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.TextAttribute; +import org.eclipse.jface.text.contentassist.ContentAssistant; +import org.eclipse.jface.text.contentassist.IContentAssistant; import org.eclipse.jface.text.presentation.IPresentationReconciler; import org.eclipse.jface.text.presentation.PresentationReconciler; import org.eclipse.jface.text.rules.BufferedRuleBasedScanner; @@ -19,11 +26,13 @@ import org.eclipse.jface.text.rules.DefaultDamagerRepairer; import org.eclipse.jface.text.rules.Token; import org.eclipse.jface.text.source.ISourceViewer; import org.eclipse.jface.text.source.SourceViewerConfiguration; +import org.eclipse.swt.graphics.RGB; -public class MakefileEditorConfiguration extends SourceViewerConfiguration { +public class MakefileSourceConfiguration extends SourceViewerConfiguration { - private IMakefileColorManager colorManager = null; - private MakefileCodeScanner codeScanner = null; + private IMakefileColorManager colorManager; + private MakefileCodeScanner codeScanner; + private MakefileEditor fEditor; /** * Single token scanner. @@ -37,8 +46,9 @@ public class MakefileEditorConfiguration extends SourceViewerConfiguration { /** * Constructor for MakeConfiguration */ - public MakefileEditorConfiguration(IMakefileColorManager colorManager) { + public MakefileSourceConfiguration(IMakefileColorManager colorManager, MakefileEditor editor) { super(); + fEditor = editor; this.colorManager = colorManager; } @@ -51,10 +61,29 @@ public class MakefileEditorConfiguration extends SourceViewerConfiguration { MakefileEditor.MAKE_COMMENT, MakefileEditor.MAKE_KEYWORD, MakefileEditor.MAKE_MACRO_VAR, - MakefileEditor.MAKE_META_DATA }; + MakefileEditor.MAKE_META_DATA + }; } + /** + * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getContentAssistant(ISourceViewer) + */ + public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) { + ContentAssistant assistant = new ContentAssistant(); + assistant.setContentAssistProcessor(new MakefileCompletionProcessor(fEditor), IDocument.DEFAULT_CONTENT_TYPE); + assistant.setContentAssistProcessor(new MakefileCompletionProcessor(fEditor), MakefileEditor.MAKE_MACRO_VAR); + assistant.enableAutoActivation(true); + assistant.setAutoActivationDelay(500); + assistant.setProposalPopupOrientation(IContentAssistant.CONTEXT_INFO_BELOW); + assistant.setContextInformationPopupOrientation(IContentAssistant.CONTEXT_INFO_BELOW); + //Set to Carolina blue + assistant.setContextInformationPopupBackground(getColorManager().getColor(new RGB(0, 191, 255))); + + return assistant; + } + + protected IMakefileColorManager getColorManager() { if (null == colorManager) colorManager = new MakefileColorManager(); diff --git a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/editor/IMakefileColorManager.java b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/text/IMakefileColorManager.java similarity index 96% rename from build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/editor/IMakefileColorManager.java rename to build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/text/IMakefileColorManager.java index 5cc102c3270..588f4b11d08 100644 --- a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/editor/IMakefileColorManager.java +++ b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/text/IMakefileColorManager.java @@ -8,7 +8,7 @@ * Contributors: * QNX Software Systems - Initial API and implementation ***********************************************************************/ -package org.eclipse.cdt.make.internal.ui.editor; +package org.eclipse.cdt.make.internal.ui.text; import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Color; diff --git a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/editor/MakefileColorManager.java b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/text/MakefileColorManager.java similarity index 96% rename from build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/editor/MakefileColorManager.java rename to build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/text/MakefileColorManager.java index e68d71b004f..40f133748c5 100644 --- a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/editor/MakefileColorManager.java +++ b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/text/MakefileColorManager.java @@ -8,7 +8,7 @@ * Contributors: * QNX Software Systems - Initial API and implementation ***********************************************************************/ -package org.eclipse.cdt.make.internal.ui.editor; +package org.eclipse.cdt.make.internal.ui.text; import java.util.HashMap; import java.util.Iterator; diff --git a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/text/WordPartDetector.java b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/text/WordPartDetector.java new file mode 100644 index 00000000000..bbf971743cf --- /dev/null +++ b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/text/WordPartDetector.java @@ -0,0 +1,61 @@ +/* + * "The Java Developer's Guide to Eclipse" + * by Shavor, D'Anjou, Fairbrother, Kehn, Kellerman, McCarthy + * + * (C) Copyright International Business Machines Corporation, 2003. + * All Rights Reserved. + * + * Code or samples provided herein are provided without warranty of any kind. + */ +package org.eclipse.cdt.make.internal.ui.text; + +import org.eclipse.jface.text.BadLocationException; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.ITextViewer; + +/** + * Used to scan and detect for SQL keywords + */ +public class WordPartDetector { + String wordPart = ""; + int offset; + + /** + * Method WordPartDetector. + * @param viewer is a text viewer + * @param documentOffset into the SQL document + */ + public WordPartDetector(ITextViewer viewer, int documentOffset) { + offset = documentOffset - 1; + int endOffset = documentOffset; + try { + IDocument doc = viewer.getDocument(); + int bottom = viewer.getBottomIndexEndOffset(); + int top = viewer.getTopIndexStartOffset(); + while (offset >= top && Character.isLetterOrDigit(doc.getChar(offset))) { + offset--; + } + while (endOffset < bottom && Character.isLetterOrDigit(doc.getChar(endOffset))) { + endOffset++; + } + //we've been one step too far : increase the offset + offset++; + wordPart = viewer.getDocument().get(offset, endOffset - offset); + } catch (BadLocationException e) { + // do nothing + } + } + + /** + * Method getString. + * @return String + */ + public String getString() { + return wordPart; + } + + public int getOffset() { + return offset; + } + +} diff --git a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/editor/MakefileCodeScanner.java b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/text/makefile/MakefileCodeScanner.java similarity index 98% rename from build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/editor/MakefileCodeScanner.java rename to build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/text/makefile/MakefileCodeScanner.java index ed687f3975e..d09bf686ef9 100644 --- a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/editor/MakefileCodeScanner.java +++ b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/text/makefile/MakefileCodeScanner.java @@ -8,11 +8,12 @@ * Contributors: * QNX Software Systems - Initial API and implementation ***********************************************************************/ -package org.eclipse.cdt.make.internal.ui.editor; +package org.eclipse.cdt.make.internal.ui.text.makefile; import java.util.ArrayList; import java.util.List; +import org.eclipse.cdt.make.internal.ui.text.IMakefileColorManager; import org.eclipse.jface.text.TextAttribute; import org.eclipse.jface.text.rules.EndOfLineRule; import org.eclipse.jface.text.rules.ICharacterScanner; @@ -158,6 +159,7 @@ public class MakefileCodeScanner extends RuleBasedScanner { return Token.UNDEFINED; } + /** * Returns the characters in the buffer to the scanner. * diff --git a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/text/makefile/MakefileCompletionProcessor.java b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/text/makefile/MakefileCompletionProcessor.java new file mode 100644 index 00000000000..c36f2e894b3 --- /dev/null +++ b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/text/makefile/MakefileCompletionProcessor.java @@ -0,0 +1,207 @@ +/********************************************************************** + * Copyright (c) 2002,2003 QNX Software Systems and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * QNX Software Systems - Initial API and implementation +***********************************************************************/ +package org.eclipse.cdt.make.internal.ui.text.makefile; + +import java.util.ArrayList; + +import org.eclipse.cdt.make.core.makefile.IMacroDefinition; +import org.eclipse.cdt.make.core.makefile.IMakefile; +import org.eclipse.cdt.make.core.makefile.IRule; +import org.eclipse.cdt.make.core.makefile.IStatement; +import org.eclipse.cdt.make.internal.ui.MakeUIImages; +import org.eclipse.cdt.make.internal.ui.editor.MakefileEditor; +import org.eclipse.cdt.make.internal.ui.text.WordPartDetector; +import org.eclipse.jface.text.BadLocationException; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.ITextViewer; +import org.eclipse.jface.text.TextPresentation; +import org.eclipse.jface.text.contentassist.CompletionProposal; +import org.eclipse.jface.text.contentassist.ContextInformation; +import org.eclipse.jface.text.contentassist.ICompletionProposal; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.text.contentassist.IContextInformation; +import org.eclipse.jface.text.contentassist.IContextInformationPresenter; +import org.eclipse.jface.text.contentassist.IContextInformationValidator; +import org.eclipse.swt.graphics.Image; + +/** + * MakefileCompletionProcessor + */ +public class MakefileCompletionProcessor implements IContentAssistProcessor { + + /** + * Simple content assist tip closer. The tip is valid in a range + * of 5 characters around its popup location. + */ + protected static class Validator implements IContextInformationValidator, IContextInformationPresenter { + + protected int fInstallOffset; + + /* + * @see IContextInformationValidator#isContextInformationValid(int) + */ + public boolean isContextInformationValid(int offset) { + return Math.abs(fInstallOffset - offset) < 5; + } + + /* + * @see IContextInformationValidator#install(IContextInformation, ITextViewer, int) + */ + public void install(IContextInformation info, ITextViewer viewer, int offset) { + fInstallOffset = offset; + } + + /* + * @see org.eclipse.jface.text.contentassist.IContextInformationPresenter#updatePresentation(int, TextPresentation) + */ + public boolean updatePresentation(int documentPosition, TextPresentation presentation) { + return false; + } + } + + protected IContextInformationValidator fValidator = new Validator(); + protected Image imageMacro = MakeUIImages.getImage(MakeUIImages.IMG_OBJS_MAKEFILE_MACRO); + protected Image imageTarget = MakeUIImages.getImage(MakeUIImages.IMG_OBJS_MAKEFILE_TARGET_RULE); + protected MakefileEditor fEditor; + + public MakefileCompletionProcessor(MakefileEditor editor) { + fEditor = editor; + } + + /* (non-Javadoc) + * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#computeCompletionProposals(org.eclipse.jface.text.ITextViewer, int) + */ + public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int documentOffset) { + boolean macro = inMacro(viewer, documentOffset); + IMakefile makefile = fEditor.getMakefile(viewer.getDocument()); + IStatement[] statements = null; + if (macro) { + statements = makefile.getMacroDefinitions(); + } else { + statements = makefile.getTargetRules(); + } + + ArrayList proposalList = new ArrayList(statements.length); + WordPartDetector wordPart = new WordPartDetector(viewer, documentOffset); + + // iterate over all the different categories + for (int i = 0; i < statements.length; i++) { + String name = null; + Image image = null; + String infoString = "";//getContentInfoString(name); + if (statements[i] instanceof IMacroDefinition) { + name = ((IMacroDefinition) statements[i]).getName(); + image = imageMacro; + infoString = ((IMacroDefinition)statements[i]).getValue(); + } else if (statements[i] instanceof IRule) { + name = ((IRule) statements[i]).getTarget().toString(); + image = imageTarget; + infoString = name; + } + if (name != null && name.startsWith(wordPart.getString())) { + IContextInformation info = new ContextInformation(name, infoString); + ICompletionProposal result = + new CompletionProposal( + name, + wordPart.getOffset(), + wordPart.getString().length(), + name.length(), + image, + name, + info, + infoString); + proposalList.add(result); + } + } + return (ICompletionProposal[]) proposalList.toArray(new ICompletionProposal[0]); + } + + /* (non-Javadoc) + * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#computeContextInformation(org.eclipse.jface.text.ITextViewer, int) + */ + public IContextInformation[] computeContextInformation(ITextViewer viewer, int documentOffset) { + WordPartDetector wordPart = new WordPartDetector(viewer, documentOffset); + boolean macro = inMacro(viewer, documentOffset); + IMakefile makefile = fEditor.getMakefile(viewer.getDocument()); + ArrayList contextList = new ArrayList(); + if (macro) { + IStatement[] statements = makefile.getMacroDefinitions(); + for (int i = 0; i < statements.length; i++) { + if (statements[i] instanceof IMacroDefinition) { + String name = ((IMacroDefinition) statements[i]).getName(); + if (name != null && name.equals(wordPart.getString())) { + String value = ((IMacroDefinition) statements[i]).getValue(); + if (value != null && value.length() > 0) { + contextList.add(value); + } + } + } + } + } + + IContextInformation[] result = new IContextInformation[contextList.size()]; + for (int i = 0; i < result.length; i++) { + String context = (String)contextList.get(i); + result[i] = new ContextInformation(imageMacro, wordPart.getString(), context); + } + return result; + + } + + /* (non-Javadoc) + * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#getCompletionProposalAutoActivationCharacters() + */ + public char[] getCompletionProposalAutoActivationCharacters() { + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#getContextInformationAutoActivationCharacters() + */ + public char[] getContextInformationAutoActivationCharacters() { + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#getErrorMessage() + */ + public String getErrorMessage() { + return null; + } + + /* (non-Javadoc) + * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#getContextInformationValidator() + */ + public IContextInformationValidator getContextInformationValidator() { + return fValidator; + } + + private boolean inMacro(ITextViewer viewer, int offset) { + boolean isMacro = false; + IDocument document = viewer.getDocument(); + // Try to figure out if we are in a Macro. + try { + for (int index = offset - 1; index >= 0; index--) { + char c; + c = document.getChar(index); + if (c == '$') { + isMacro = true; + break; + } else if (Character.isWhitespace(c)) { + break; + } + } + } catch (BadLocationException e) { + } + return isMacro; + } + +} diff --git a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/editor/MakefileMacroScanner.java b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/text/makefile/MakefileMacroScanner.java similarity index 98% rename from build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/editor/MakefileMacroScanner.java rename to build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/text/makefile/MakefileMacroScanner.java index d80c85d4f8b..4d70025b4d9 100644 --- a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/editor/MakefileMacroScanner.java +++ b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/text/makefile/MakefileMacroScanner.java @@ -8,7 +8,7 @@ * Contributors: * QNX Software Systems - Initial API and implementation ***********************************************************************/ -package org.eclipse.cdt.make.internal.ui.editor; +package org.eclipse.cdt.make.internal.ui.text.makefile; import java.util.ArrayList; import java.util.List; diff --git a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/editor/MakefilePartitionScanner.java b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/text/makefile/MakefilePartitionScanner.java similarity index 99% rename from build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/editor/MakefilePartitionScanner.java rename to build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/text/makefile/MakefilePartitionScanner.java index bf39286d115..2f7d4ca6c19 100644 --- a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/editor/MakefilePartitionScanner.java +++ b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/text/makefile/MakefilePartitionScanner.java @@ -8,7 +8,7 @@ * Contributors: * QNX Software Systems - Initial API and implementation ***********************************************************************/ -package org.eclipse.cdt.make.internal.ui.editor; +package org.eclipse.cdt.make.internal.ui.text.makefile; import java.util.ArrayList; import java.util.List; diff --git a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/editor/MakefileSimpleMacroRule.java b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/text/makefile/MakefileSimpleMacroRule.java similarity index 96% rename from build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/editor/MakefileSimpleMacroRule.java rename to build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/text/makefile/MakefileSimpleMacroRule.java index aca8061d71a..a49c1da44b2 100644 --- a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/editor/MakefileSimpleMacroRule.java +++ b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/text/makefile/MakefileSimpleMacroRule.java @@ -8,7 +8,7 @@ * Contributors: * QNX Software Systems - Initial API and implementation ***********************************************************************/ -package org.eclipse.cdt.make.internal.ui.editor; +package org.eclipse.cdt.make.internal.ui.text.makefile; import org.eclipse.jface.text.rules.ICharacterScanner; import org.eclipse.jface.text.rules.IToken; diff --git a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/editor/MakefileWordDetector.java b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/text/makefile/MakefileWordDetector.java similarity index 95% rename from build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/editor/MakefileWordDetector.java rename to build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/text/makefile/MakefileWordDetector.java index fc2cdf22b74..05f7b300006 100644 --- a/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/editor/MakefileWordDetector.java +++ b/build/org.eclipse.cdt.make.ui/src/org/eclipse/cdt/make/internal/ui/text/makefile/MakefileWordDetector.java @@ -8,7 +8,7 @@ * Contributors: * QNX Software Systems - Initial API and implementation ***********************************************************************/ -package org.eclipse.cdt.make.internal.ui.editor; +package org.eclipse.cdt.make.internal.ui.text.makefile; import org.eclipse.jface.text.rules.IWordDetector;