Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnton Leherbauer2008-03-14 13:53:47 +0000
committerAnton Leherbauer2008-03-14 13:53:47 +0000
commitdbbd26805c676f6d0e53f74ab0f10310c034a8cf (patch)
treed96cb38cd677dca06c5a931552770ac5f2c33f72
parentf9ddd200f88eea28e9c97931c7c3df45aee77cd7 (diff)
downloadorg.eclipse.cdt-dbbd26805c676f6d0e53f74ab0f10310c034a8cf.tar.gz
org.eclipse.cdt-dbbd26805c676f6d0e53f74ab0f10310c034a8cf.tar.xz
org.eclipse.cdt-dbbd26805c676f6d0e53f74ab0f10310c034a8cf.zip
Fix folding initialization if no AST required
-rw-r--r--core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/FoldingTest.java39
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/folding/DefaultCFoldingStructureProvider.java9
2 files changed, 37 insertions, 11 deletions
diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/FoldingTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/FoldingTest.java
index 47866ad719d..ce3aaeccb7e 100644
--- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/FoldingTest.java
+++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/FoldingTest.java
@@ -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);
+ }
+
}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/folding/DefaultCFoldingStructureProvider.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/folding/DefaultCFoldingStructureProvider.java
index 928ffb62997..fd275b84c6b 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/folding/DefaultCFoldingStructureProvider.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/folding/DefaultCFoldingStructureProvider.java
@@ -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 {

Back to the top