diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CMacroCompareViewer.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CMacroCompareViewer.java index 4e2ffd22053..9bb17b057dc 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CMacroCompareViewer.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CMacroCompareViewer.java @@ -172,7 +172,7 @@ class CMacroCompareViewer extends CMergeViewer { */ public void setMacroExpansionInput(CMacroExpansionInput input) { fInput= input; - fPrefixLength= fInput.getPrefix().length(); + fPrefixLength= 0; } /* diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CMacroExpansionExplorationControl.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CMacroExpansionExplorationControl.java index 5c2f8346a0e..87abf68345a 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CMacroExpansionExplorationControl.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CMacroExpansionExplorationControl.java @@ -242,24 +242,23 @@ public class CMacroExpansionExplorationControl extends AbstractCompareViewerInfo } protected final void gotoMacroDefinition() { - if (fIndex < getStepCount()) { - final IMacroExpansionStep step= fInput.fExplorer.getExpansionStep(fIndex); - IASTFileLocation fileLocation= step.getLocationOfExpandedMacroDefinition(); - if (fileLocation != null) { - final IPath path= new Path(fileLocation.getFileName()); - final int offset= fileLocation.getNodeOffset(); - final int length= fileLocation.getNodeLength(); - IEditorPart editor; - try { - editor = EditorUtility.openInEditor(path, null); - if (editor instanceof ITextEditor) { - ITextEditor textEditor = (ITextEditor)editor; - textEditor.selectAndReveal(offset, length); - } - dispose(); - } catch (PartInitException exc) { - CUIPlugin.getDefault().log(exc); + int index= fIndex < getStepCount() ? fIndex : 0; + final IMacroExpansionStep step= fInput.fExplorer.getExpansionStep(index); + IASTFileLocation fileLocation= step.getLocationOfExpandedMacroDefinition(); + if (fileLocation != null) { + final IPath path= new Path(fileLocation.getFileName()); + final int offset= fileLocation.getNodeOffset(); + final int length= fileLocation.getNodeLength(); + IEditorPart editor; + try { + editor = EditorUtility.openInEditor(path, null); + if (editor instanceof ITextEditor) { + ITextEditor textEditor = (ITextEditor)editor; + textEditor.selectAndReveal(offset, length); } + dispose(); + } catch (PartInitException exc) { + CUIPlugin.getDefault().log(exc); } } } @@ -397,12 +396,10 @@ public class CMacroExpansionExplorationControl extends AbstractCompareViewerInfo expansionStep= fInput.fExplorer.getFullExpansion(); } final String text; - final String prefix = fInput.getPrefix(); - final String postfix = fInput.getPostfix(); if (before) { - text= prefix + expansionStep.getCodeBeforeStep() + postfix; + text= expansionStep.getCodeBeforeStep(); } else { - text= prefix + expansionStep.getCodeAfterStep() + postfix; + text= expansionStep.getCodeAfterStep(); } final Document doc= new Document(text); CUIPlugin.getDefault().getTextTools().setupCDocument(doc); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CMacroExpansionHover.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CMacroExpansionHover.java index 05d437847b8..630878d6722 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CMacroExpansionHover.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CMacroExpansionHover.java @@ -44,7 +44,6 @@ public class CMacroExpansionHover extends AbstractCEditorTextHover implements II if (input == null) { return null; } - input.fStartWithFullExpansion= true; fCache= new SoftReference(input); String result= input.fExplorer.getFullExpansion().getCodeAfterStep(); if (result.length() == 0) { @@ -93,7 +92,6 @@ public class CMacroExpansionHover extends AbstractCEditorTextHover implements II ITextSelection textSelection= (ITextSelection) selection; IRegion region= new Region(textSelection.getOffset(), textSelection.getLength()); input= CMacroExpansionInput.create(editor, region, true); - input.fStartWithFullExpansion= true; } } } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CMacroExpansionInput.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CMacroExpansionInput.java index 9cb6eb6dead..bb22b7b784f 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CMacroExpansionInput.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/c/hover/CMacroExpansionInput.java @@ -200,10 +200,6 @@ public class CMacroExpansionInput { IRegion region= getExpansionRegion(); if (region != null) { fExplorer= MacroExpansionExplorer.create(ast, region); - int length= fExplorer.getExpansionStep(0).getCodeAfterStep().length(); - if (region.getLength() < length) { - region= new Region(region.getOffset(), length); - } fExpansionRegion= region; } } @@ -280,33 +276,12 @@ public class CMacroExpansionInput { MacroExpansionExplorer fExplorer; IDocument fDocument; IRegion fRegion; - boolean fStartWithFullExpansion; - - private int fPrefixLength; - private int fPostfixLength; + boolean fStartWithFullExpansion= true; private CMacroExpansionInput() { // forbidden } - String getPrefix() { - try { - return fDocument.get(fRegion.getOffset() - fPrefixLength, fPrefixLength); - } catch (BadLocationException exc) { - fPrefixLength= 0; - return ""; //$NON-NLS-1$ - } - } - - String getPostfix() { - try { - return fDocument.get(fRegion.getOffset() + fRegion.getLength(), fPostfixLength); - } catch (BadLocationException exc) { - fPostfixLength= 0; - return ""; //$NON-NLS-1$ - } - } - public static CMacroExpansionInput create(IEditorPart editor, IRegion hoverRegion, boolean allowSelection) { if (editor == null || !(editor instanceof ITextEditor)) { return null; @@ -340,10 +315,6 @@ public class CMacroExpansionInput { input.fDocument= document; input.fRegion= region; - // add context lines -// IRegion contextRegion= expandRegion(region, document, 2); -// input.fPrefixLength= region.getOffset() - contextRegion.getOffset(); -// input.fPostfixLength= contextRegion.getOffset() + contextRegion.getLength() - (region.getOffset() + region.getLength()); return input; }