mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-08 18:26: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();
|
||||
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_INACTIVE_CODE);
|
||||
store.setToDefault(PreferenceConstants.EDITOR_FOLDING_HEADERS);
|
||||
|
@ -175,21 +176,19 @@ public class FoldingTest extends TestCase {
|
|||
}
|
||||
|
||||
protected Position[] getFoldingPositions() {
|
||||
List positions= new ArrayList();
|
||||
List<Position> positions= new ArrayList<Position>();
|
||||
ProjectionAnnotationModel model= (ProjectionAnnotationModel)fEditor.getAdapter(ProjectionAnnotationModel.class);
|
||||
assertNotNull(model);
|
||||
for (Iterator iter= model.getAnnotationIterator(); iter.hasNext(); ) {
|
||||
for (Iterator<Annotation> iter= model.getAnnotationIterator(); iter.hasNext(); ) {
|
||||
Annotation ann= (Annotation)iter.next();
|
||||
Position pos= model.getPosition(ann);
|
||||
positions.add(pos);
|
||||
}
|
||||
Collections.sort(positions, new Comparator() {
|
||||
public int compare(Object arg0, Object arg1) {
|
||||
Position p0= (Position)arg0;
|
||||
Position p1= (Position)arg1;
|
||||
Collections.sort(positions, new Comparator<Position>() {
|
||||
public int compare(Position p0, Position p1) {
|
||||
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 {
|
||||
|
@ -268,4 +267,30 @@ public class FoldingTest extends TestCase {
|
|||
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;
|
||||
} catch (Exception e) {
|
||||
CUIPlugin.getDefault().log(e);
|
||||
CUIPlugin.log(e);
|
||||
return PROCESS_ABORT;
|
||||
}
|
||||
}
|
||||
|
@ -1248,7 +1248,8 @@ public class DefaultCFoldingStructureProvider implements ICFoldingStructureProvi
|
|||
// ignore
|
||||
}
|
||||
}
|
||||
if (fPreprocessorBranchFoldingEnabled || fStatementsFoldingEnabled) {
|
||||
final boolean needAST= fPreprocessorBranchFoldingEnabled || fStatementsFoldingEnabled;
|
||||
if (needAST) {
|
||||
IASTTranslationUnit ast= ctx.getAST();
|
||||
if (ast != null) {
|
||||
computeFoldingStructure(ast, ctx);
|
||||
|
@ -1265,11 +1266,11 @@ public class DefaultCFoldingStructureProvider implements ICFoldingStructureProvi
|
|||
}
|
||||
});
|
||||
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;
|
||||
IParent parent= (IParent) fInput;
|
||||
try {
|
||||
|
|
Loading…
Add table
Reference in a new issue