From 0db9a0a9139f5259e237cfef3be74d341fe43b86 Mon Sep 17 00:00:00 2001 From: Anton Leherbauer Date: Fri, 11 May 2012 12:45:04 +0200 Subject: [PATCH] Bug 298668 - Folding gets confused when there are identical foldable lines inside methods in different classes. --- .../cdt/ui/tests/text/BasicCEditorTest.java | 12 ++++----- .../DefaultCFoldingStructureProvider.java | 25 +++++++++++++++---- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/BasicCEditorTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/BasicCEditorTest.java index ca4b727ed4d..f30cdf90b58 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/BasicCEditorTest.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/BasicCEditorTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2011 Wind River Systems, Inc. and others. + * Copyright (c) 2006, 2012 Wind River Systems, Inc. and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -209,7 +209,7 @@ public class BasicCEditorTest extends BaseUITestCase { content= fDocument.get(); assertEquals("Save failed", newContent, content); // check reconciler - ITranslationUnit tUnit= (ITranslationUnit)fEditor.getInputCElement(); + ITranslationUnit tUnit= fEditor.getInputCElement(); ICElement[] children= tUnit.getChildren(); assertEquals(2, children.length); setCaret(content.length()); @@ -287,7 +287,7 @@ public class BasicCEditorTest extends BaseUITestCase { content= fDocument.get().trim(); assertEquals("Save failed", newContent, content); // check reconciler - ITranslationUnit tUnit= (ITranslationUnit)fEditor.getInputCElement(); + ITranslationUnit tUnit= fEditor.getInputCElement(); ICElement[] children= tUnit.getChildren(); assertEquals(4, children.length); setCaret(content.length()); @@ -349,7 +349,7 @@ public class BasicCEditorTest extends BaseUITestCase { content= fDocument.get(); assertEquals("Save failed", newContent, content); // check reconciler - ITranslationUnit tUnit= (ITranslationUnit)fEditor.getInputCElement(); + ITranslationUnit tUnit= fEditor.getInputCElement(); ICElement[] children= tUnit.getChildren(); assertEquals(2, children.length); setCaret(content.length()); @@ -390,7 +390,7 @@ public class BasicCEditorTest extends BaseUITestCase { content= fDocument.get(); assertEquals("Save failed", newContent, content); // check reconciler - ITranslationUnit tUnit= (ITranslationUnit)fEditor.getInputCElement(); + ITranslationUnit tUnit= fEditor.getInputCElement(); ICElement[] children= tUnit.getChildren(); assertEquals(2, children.length); setCaret(content.length()); @@ -459,7 +459,7 @@ public class BasicCEditorTest extends BaseUITestCase { int ngc = 10; while (ref.get() != null && ngc-- > 0) { System.gc(); - Thread.sleep(200); + EditorTestHelper.runEventQueue(200); } assertNull("CEditor instance seems to be leaking after close", ref.get()); } 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 65deb449507..20c7adb0de4 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 @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2010 IBM Corporation and others. + * Copyright (c) 2000, 2012 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -55,7 +55,9 @@ import org.eclipse.ui.texteditor.ITextEditor; import org.eclipse.cdt.core.dom.ast.ASTVisitor; import org.eclipse.cdt.core.dom.ast.IASTBreakStatement; import org.eclipse.cdt.core.dom.ast.IASTCaseStatement; +import org.eclipse.cdt.core.dom.ast.IASTCompositeTypeSpecifier; import org.eclipse.cdt.core.dom.ast.IASTCompoundStatement; +import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier; import org.eclipse.cdt.core.dom.ast.IASTDeclaration; import org.eclipse.cdt.core.dom.ast.IASTDefaultStatement; import org.eclipse.cdt.core.dom.ast.IASTDoStatement; @@ -73,6 +75,7 @@ import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIfdefStatement; import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIfndefStatement; import org.eclipse.cdt.core.dom.ast.IASTPreprocessorStatement; import org.eclipse.cdt.core.dom.ast.IASTProblem; +import org.eclipse.cdt.core.dom.ast.IASTSimpleDeclaration; import org.eclipse.cdt.core.dom.ast.IASTStatement; import org.eclipse.cdt.core.dom.ast.IASTSwitchStatement; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; @@ -121,7 +124,7 @@ public class DefaultCFoldingStructureProvider implements ICFoldingStructureProvi } private final Stack fStatements; int fLevel= 0; - String fFunction= ""; //$NON-NLS-1$ + Stack fScope= new Stack(); private StatementVisitor(Stack statements) { fStatements = statements; @@ -239,9 +242,14 @@ public class DefaultCFoldingStructureProvider implements ICFoldingStructureProvi if (declaration instanceof IASTFunctionDefinition) { final IASTFunctionDeclarator declarator = ((IASTFunctionDefinition)declaration).getDeclarator(); if (declarator != null) { - fFunction= new String(ASTQueries.findInnermostDeclarator(declarator).getName().toCharArray()); + fScope.push(new String(ASTQueries.findInnermostDeclarator(declarator).getName().toCharArray())); fLevel= 0; } + } else if (declaration instanceof IASTSimpleDeclaration) { + IASTDeclSpecifier declSpecifier = ((IASTSimpleDeclaration) declaration).getDeclSpecifier(); + if (declSpecifier instanceof IASTCompositeTypeSpecifier) { + fScope.push(new String(((IASTCompositeTypeSpecifier) declSpecifier).getName().toCharArray())); + } } return PROCESS_CONTINUE; } @@ -249,13 +257,20 @@ public class DefaultCFoldingStructureProvider implements ICFoldingStructureProvi @Override public int leave(IASTDeclaration declaration) { if (declaration instanceof IASTFunctionDefinition) { - fFunction= ""; //$NON-NLS-1$ + if (!fScope.isEmpty()) + fScope.pop(); + } else if (declaration instanceof IASTSimpleDeclaration) { + IASTDeclSpecifier declSpecifier = ((IASTSimpleDeclaration) declaration).getDeclSpecifier(); + if (declSpecifier instanceof IASTCompositeTypeSpecifier) { + if (!fScope.isEmpty()) + fScope.pop(); + } } return PROCESS_CONTINUE; } private StatementRegion createRegion() { - return new StatementRegion(fFunction, fLevel); + return new StatementRegion(fScope.toString(), fLevel); } }