mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Macro explorer fixes and cleanup
This commit is contained in:
parent
bf2aafaf4b
commit
7c5c048c7b
4 changed files with 20 additions and 54 deletions
|
@ -172,7 +172,7 @@ class CMacroCompareViewer extends CMergeViewer {
|
|||
*/
|
||||
public void setMacroExpansionInput(CMacroExpansionInput input) {
|
||||
fInput= input;
|
||||
fPrefixLength= fInput.getPrefix().length();
|
||||
fPrefixLength= 0;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -242,8 +242,8 @@ public class CMacroExpansionExplorationControl extends AbstractCompareViewerInfo
|
|||
}
|
||||
|
||||
protected final void gotoMacroDefinition() {
|
||||
if (fIndex < getStepCount()) {
|
||||
final IMacroExpansionStep step= fInput.fExplorer.getExpansionStep(fIndex);
|
||||
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());
|
||||
|
@ -262,7 +262,6 @@ public class CMacroExpansionExplorationControl extends AbstractCompareViewerInfo
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected final void forward() {
|
||||
fIndex= fixIndex(fIndex + 1);
|
||||
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue