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) {
|
public void setMacroExpansionInput(CMacroExpansionInput input) {
|
||||||
fInput= input;
|
fInput= input;
|
||||||
fPrefixLength= fInput.getPrefix().length();
|
fPrefixLength= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -242,8 +242,8 @@ public class CMacroExpansionExplorationControl extends AbstractCompareViewerInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
protected final void gotoMacroDefinition() {
|
protected final void gotoMacroDefinition() {
|
||||||
if (fIndex < getStepCount()) {
|
int index= fIndex < getStepCount() ? fIndex : 0;
|
||||||
final IMacroExpansionStep step= fInput.fExplorer.getExpansionStep(fIndex);
|
final IMacroExpansionStep step= fInput.fExplorer.getExpansionStep(index);
|
||||||
IASTFileLocation fileLocation= step.getLocationOfExpandedMacroDefinition();
|
IASTFileLocation fileLocation= step.getLocationOfExpandedMacroDefinition();
|
||||||
if (fileLocation != null) {
|
if (fileLocation != null) {
|
||||||
final IPath path= new Path(fileLocation.getFileName());
|
final IPath path= new Path(fileLocation.getFileName());
|
||||||
|
@ -262,7 +262,6 @@ public class CMacroExpansionExplorationControl extends AbstractCompareViewerInfo
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
protected final void forward() {
|
protected final void forward() {
|
||||||
fIndex= fixIndex(fIndex + 1);
|
fIndex= fixIndex(fIndex + 1);
|
||||||
|
@ -397,12 +396,10 @@ public class CMacroExpansionExplorationControl extends AbstractCompareViewerInfo
|
||||||
expansionStep= fInput.fExplorer.getFullExpansion();
|
expansionStep= fInput.fExplorer.getFullExpansion();
|
||||||
}
|
}
|
||||||
final String text;
|
final String text;
|
||||||
final String prefix = fInput.getPrefix();
|
|
||||||
final String postfix = fInput.getPostfix();
|
|
||||||
if (before) {
|
if (before) {
|
||||||
text= prefix + expansionStep.getCodeBeforeStep() + postfix;
|
text= expansionStep.getCodeBeforeStep();
|
||||||
} else {
|
} else {
|
||||||
text= prefix + expansionStep.getCodeAfterStep() + postfix;
|
text= expansionStep.getCodeAfterStep();
|
||||||
}
|
}
|
||||||
final Document doc= new Document(text);
|
final Document doc= new Document(text);
|
||||||
CUIPlugin.getDefault().getTextTools().setupCDocument(doc);
|
CUIPlugin.getDefault().getTextTools().setupCDocument(doc);
|
||||||
|
|
|
@ -44,7 +44,6 @@ public class CMacroExpansionHover extends AbstractCEditorTextHover implements II
|
||||||
if (input == null) {
|
if (input == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
input.fStartWithFullExpansion= true;
|
|
||||||
fCache= new SoftReference(input);
|
fCache= new SoftReference(input);
|
||||||
String result= input.fExplorer.getFullExpansion().getCodeAfterStep();
|
String result= input.fExplorer.getFullExpansion().getCodeAfterStep();
|
||||||
if (result.length() == 0) {
|
if (result.length() == 0) {
|
||||||
|
@ -93,7 +92,6 @@ public class CMacroExpansionHover extends AbstractCEditorTextHover implements II
|
||||||
ITextSelection textSelection= (ITextSelection) selection;
|
ITextSelection textSelection= (ITextSelection) selection;
|
||||||
IRegion region= new Region(textSelection.getOffset(), textSelection.getLength());
|
IRegion region= new Region(textSelection.getOffset(), textSelection.getLength());
|
||||||
input= CMacroExpansionInput.create(editor, region, true);
|
input= CMacroExpansionInput.create(editor, region, true);
|
||||||
input.fStartWithFullExpansion= true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -200,10 +200,6 @@ public class CMacroExpansionInput {
|
||||||
IRegion region= getExpansionRegion();
|
IRegion region= getExpansionRegion();
|
||||||
if (region != null) {
|
if (region != null) {
|
||||||
fExplorer= MacroExpansionExplorer.create(ast, region);
|
fExplorer= MacroExpansionExplorer.create(ast, region);
|
||||||
int length= fExplorer.getExpansionStep(0).getCodeAfterStep().length();
|
|
||||||
if (region.getLength() < length) {
|
|
||||||
region= new Region(region.getOffset(), length);
|
|
||||||
}
|
|
||||||
fExpansionRegion= region;
|
fExpansionRegion= region;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -280,33 +276,12 @@ public class CMacroExpansionInput {
|
||||||
MacroExpansionExplorer fExplorer;
|
MacroExpansionExplorer fExplorer;
|
||||||
IDocument fDocument;
|
IDocument fDocument;
|
||||||
IRegion fRegion;
|
IRegion fRegion;
|
||||||
boolean fStartWithFullExpansion;
|
boolean fStartWithFullExpansion= true;
|
||||||
|
|
||||||
private int fPrefixLength;
|
|
||||||
private int fPostfixLength;
|
|
||||||
|
|
||||||
private CMacroExpansionInput() {
|
private CMacroExpansionInput() {
|
||||||
// forbidden
|
// 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) {
|
public static CMacroExpansionInput create(IEditorPart editor, IRegion hoverRegion, boolean allowSelection) {
|
||||||
if (editor == null || !(editor instanceof ITextEditor)) {
|
if (editor == null || !(editor instanceof ITextEditor)) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -340,10 +315,6 @@ public class CMacroExpansionInput {
|
||||||
input.fDocument= document;
|
input.fDocument= document;
|
||||||
input.fRegion= region;
|
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;
|
return input;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue