mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-09 02:36:01 +02:00
Fix folding initialization if no AST required
This commit is contained in:
parent
f9ddd200f8
commit
dbbd26805c
2 changed files with 37 additions and 11 deletions
|
@ -99,6 +99,7 @@ public class FoldingTest extends TestCase {
|
||||||
|
|
||||||
IPreferenceStore store= CUIPlugin.getDefault().getPreferenceStore();
|
IPreferenceStore store= CUIPlugin.getDefault().getPreferenceStore();
|
||||||
store.setToDefault(PreferenceConstants.EDITOR_FOLDING_ENABLED);
|
store.setToDefault(PreferenceConstants.EDITOR_FOLDING_ENABLED);
|
||||||
|
store.setToDefault(PreferenceConstants.EDITOR_FOLDING_STATEMENTS);
|
||||||
store.setToDefault(PreferenceConstants.EDITOR_FOLDING_PREPROCESSOR_BRANCHES_ENABLED);
|
store.setToDefault(PreferenceConstants.EDITOR_FOLDING_PREPROCESSOR_BRANCHES_ENABLED);
|
||||||
store.setToDefault(PreferenceConstants.EDITOR_FOLDING_INACTIVE_CODE);
|
store.setToDefault(PreferenceConstants.EDITOR_FOLDING_INACTIVE_CODE);
|
||||||
store.setToDefault(PreferenceConstants.EDITOR_FOLDING_HEADERS);
|
store.setToDefault(PreferenceConstants.EDITOR_FOLDING_HEADERS);
|
||||||
|
@ -175,21 +176,19 @@ public class FoldingTest extends TestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Position[] getFoldingPositions() {
|
protected Position[] getFoldingPositions() {
|
||||||
List positions= new ArrayList();
|
List<Position> positions= new ArrayList<Position>();
|
||||||
ProjectionAnnotationModel model= (ProjectionAnnotationModel)fEditor.getAdapter(ProjectionAnnotationModel.class);
|
ProjectionAnnotationModel model= (ProjectionAnnotationModel)fEditor.getAdapter(ProjectionAnnotationModel.class);
|
||||||
assertNotNull(model);
|
assertNotNull(model);
|
||||||
for (Iterator iter= model.getAnnotationIterator(); iter.hasNext(); ) {
|
for (Iterator<Annotation> iter= model.getAnnotationIterator(); iter.hasNext(); ) {
|
||||||
Annotation ann= (Annotation)iter.next();
|
Annotation ann= (Annotation)iter.next();
|
||||||
Position pos= model.getPosition(ann);
|
Position pos= model.getPosition(ann);
|
||||||
positions.add(pos);
|
positions.add(pos);
|
||||||
}
|
}
|
||||||
Collections.sort(positions, new Comparator() {
|
Collections.sort(positions, new Comparator<Position>() {
|
||||||
public int compare(Object arg0, Object arg1) {
|
public int compare(Position p0, Position p1) {
|
||||||
Position p0= (Position)arg0;
|
|
||||||
Position p1= (Position)arg1;
|
|
||||||
return p0.offset - p1.offset;
|
return p0.offset - p1.offset;
|
||||||
}});
|
}});
|
||||||
return (Position[]) positions.toArray(new Position[positions.size()]);
|
return positions.toArray(new Position[positions.size()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testInitialFolding() throws BadLocationException {
|
public void testInitialFolding() throws BadLocationException {
|
||||||
|
@ -268,4 +267,30 @@ public class FoldingTest extends TestCase {
|
||||||
assertEqualPositions(expected, actual);
|
assertEqualPositions(expected, actual);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testToggleFoldingNoASTRequired() throws BadLocationException {
|
||||||
|
fEditor.getAction("FoldingToggle").run();
|
||||||
|
IPreferenceStore store= CUIPlugin.getDefault().getPreferenceStore();
|
||||||
|
store.setValue(PreferenceConstants.EDITOR_FOLDING_STATEMENTS, false);
|
||||||
|
store.setValue(PreferenceConstants.EDITOR_FOLDING_PREPROCESSOR_BRANCHES_ENABLED, false);
|
||||||
|
fEditor.getAction("FoldingToggle").run();
|
||||||
|
|
||||||
|
Position[] actual= getFoldingPositions();
|
||||||
|
Position[] expected= new Position[] {
|
||||||
|
createPosition(0, 2, 1),
|
||||||
|
createPosition(4, 7),
|
||||||
|
createPosition(29, 31, 30),
|
||||||
|
createPosition(35, 40),
|
||||||
|
createPosition(42, 46),
|
||||||
|
createPosition(48, 55),
|
||||||
|
createPosition(51, 53),
|
||||||
|
createPosition(57, 59),
|
||||||
|
createPosition(61, 63),
|
||||||
|
createPosition(65, 67),
|
||||||
|
createPosition(70, 104, 71),
|
||||||
|
createPosition(106, 110),
|
||||||
|
};
|
||||||
|
assertEquals(toString(expected), toString(actual));
|
||||||
|
assertEqualPositions(expected, actual);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -211,7 +211,7 @@ public class DefaultCFoldingStructureProvider implements ICFoldingStructureProvi
|
||||||
}
|
}
|
||||||
return PROCESS_CONTINUE;
|
return PROCESS_CONTINUE;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
CUIPlugin.getDefault().log(e);
|
CUIPlugin.log(e);
|
||||||
return PROCESS_ABORT;
|
return PROCESS_ABORT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1248,7 +1248,8 @@ public class DefaultCFoldingStructureProvider implements ICFoldingStructureProvi
|
||||||
// ignore
|
// ignore
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (fPreprocessorBranchFoldingEnabled || fStatementsFoldingEnabled) {
|
final boolean needAST= fPreprocessorBranchFoldingEnabled || fStatementsFoldingEnabled;
|
||||||
|
if (needAST) {
|
||||||
IASTTranslationUnit ast= ctx.getAST();
|
IASTTranslationUnit ast= ctx.getAST();
|
||||||
if (ast != null) {
|
if (ast != null) {
|
||||||
computeFoldingStructure(ast, ctx);
|
computeFoldingStructure(ast, ctx);
|
||||||
|
@ -1265,11 +1266,11 @@ public class DefaultCFoldingStructureProvider implements ICFoldingStructureProvi
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (status.matches(IStatus.ERROR)) {
|
if (status.matches(IStatus.ERROR)) {
|
||||||
CUIPlugin.getDefault().log(status);
|
CUIPlugin.log(status);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ctx.getAST() != null && isConsistent(fInput)) {
|
if (!needAST || ctx.getAST() != null) {
|
||||||
fInitialReconcilePending= false;
|
fInitialReconcilePending= false;
|
||||||
IParent parent= (IParent) fInput;
|
IParent parent= (IParent) fInput;
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Add table
Reference in a new issue