mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Bug 298668 - Folding gets confused when there are identical foldable lines inside methods in different classes.
This commit is contained in:
parent
1193dcc379
commit
0db9a0a913
2 changed files with 26 additions and 11 deletions
|
@ -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
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -209,7 +209,7 @@ public class BasicCEditorTest extends BaseUITestCase {
|
||||||
content= fDocument.get();
|
content= fDocument.get();
|
||||||
assertEquals("Save failed", newContent, content);
|
assertEquals("Save failed", newContent, content);
|
||||||
// check reconciler
|
// check reconciler
|
||||||
ITranslationUnit tUnit= (ITranslationUnit)fEditor.getInputCElement();
|
ITranslationUnit tUnit= fEditor.getInputCElement();
|
||||||
ICElement[] children= tUnit.getChildren();
|
ICElement[] children= tUnit.getChildren();
|
||||||
assertEquals(2, children.length);
|
assertEquals(2, children.length);
|
||||||
setCaret(content.length());
|
setCaret(content.length());
|
||||||
|
@ -287,7 +287,7 @@ public class BasicCEditorTest extends BaseUITestCase {
|
||||||
content= fDocument.get().trim();
|
content= fDocument.get().trim();
|
||||||
assertEquals("Save failed", newContent, content);
|
assertEquals("Save failed", newContent, content);
|
||||||
// check reconciler
|
// check reconciler
|
||||||
ITranslationUnit tUnit= (ITranslationUnit)fEditor.getInputCElement();
|
ITranslationUnit tUnit= fEditor.getInputCElement();
|
||||||
ICElement[] children= tUnit.getChildren();
|
ICElement[] children= tUnit.getChildren();
|
||||||
assertEquals(4, children.length);
|
assertEquals(4, children.length);
|
||||||
setCaret(content.length());
|
setCaret(content.length());
|
||||||
|
@ -349,7 +349,7 @@ public class BasicCEditorTest extends BaseUITestCase {
|
||||||
content= fDocument.get();
|
content= fDocument.get();
|
||||||
assertEquals("Save failed", newContent, content);
|
assertEquals("Save failed", newContent, content);
|
||||||
// check reconciler
|
// check reconciler
|
||||||
ITranslationUnit tUnit= (ITranslationUnit)fEditor.getInputCElement();
|
ITranslationUnit tUnit= fEditor.getInputCElement();
|
||||||
ICElement[] children= tUnit.getChildren();
|
ICElement[] children= tUnit.getChildren();
|
||||||
assertEquals(2, children.length);
|
assertEquals(2, children.length);
|
||||||
setCaret(content.length());
|
setCaret(content.length());
|
||||||
|
@ -390,7 +390,7 @@ public class BasicCEditorTest extends BaseUITestCase {
|
||||||
content= fDocument.get();
|
content= fDocument.get();
|
||||||
assertEquals("Save failed", newContent, content);
|
assertEquals("Save failed", newContent, content);
|
||||||
// check reconciler
|
// check reconciler
|
||||||
ITranslationUnit tUnit= (ITranslationUnit)fEditor.getInputCElement();
|
ITranslationUnit tUnit= fEditor.getInputCElement();
|
||||||
ICElement[] children= tUnit.getChildren();
|
ICElement[] children= tUnit.getChildren();
|
||||||
assertEquals(2, children.length);
|
assertEquals(2, children.length);
|
||||||
setCaret(content.length());
|
setCaret(content.length());
|
||||||
|
@ -459,7 +459,7 @@ public class BasicCEditorTest extends BaseUITestCase {
|
||||||
int ngc = 10;
|
int ngc = 10;
|
||||||
while (ref.get() != null && ngc-- > 0) {
|
while (ref.get() != null && ngc-- > 0) {
|
||||||
System.gc();
|
System.gc();
|
||||||
Thread.sleep(200);
|
EditorTestHelper.runEventQueue(200);
|
||||||
}
|
}
|
||||||
assertNull("CEditor instance seems to be leaking after close", ref.get());
|
assertNull("CEditor instance seems to be leaking after close", ref.get());
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* 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.ASTVisitor;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTBreakStatement;
|
import org.eclipse.cdt.core.dom.ast.IASTBreakStatement;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTCaseStatement;
|
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.IASTCompoundStatement;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTDeclSpecifier;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
import org.eclipse.cdt.core.dom.ast.IASTDeclaration;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDefaultStatement;
|
import org.eclipse.cdt.core.dom.ast.IASTDefaultStatement;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTDoStatement;
|
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.IASTPreprocessorIfndefStatement;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorStatement;
|
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorStatement;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTProblem;
|
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.IASTStatement;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTSwitchStatement;
|
import org.eclipse.cdt.core.dom.ast.IASTSwitchStatement;
|
||||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||||
|
@ -121,7 +124,7 @@ public class DefaultCFoldingStructureProvider implements ICFoldingStructureProvi
|
||||||
}
|
}
|
||||||
private final Stack<StatementRegion> fStatements;
|
private final Stack<StatementRegion> fStatements;
|
||||||
int fLevel= 0;
|
int fLevel= 0;
|
||||||
String fFunction= ""; //$NON-NLS-1$
|
Stack<String> fScope= new Stack<String>();
|
||||||
|
|
||||||
private StatementVisitor(Stack<StatementRegion> statements) {
|
private StatementVisitor(Stack<StatementRegion> statements) {
|
||||||
fStatements = statements;
|
fStatements = statements;
|
||||||
|
@ -239,9 +242,14 @@ public class DefaultCFoldingStructureProvider implements ICFoldingStructureProvi
|
||||||
if (declaration instanceof IASTFunctionDefinition) {
|
if (declaration instanceof IASTFunctionDefinition) {
|
||||||
final IASTFunctionDeclarator declarator = ((IASTFunctionDefinition)declaration).getDeclarator();
|
final IASTFunctionDeclarator declarator = ((IASTFunctionDefinition)declaration).getDeclarator();
|
||||||
if (declarator != null) {
|
if (declarator != null) {
|
||||||
fFunction= new String(ASTQueries.findInnermostDeclarator(declarator).getName().toCharArray());
|
fScope.push(new String(ASTQueries.findInnermostDeclarator(declarator).getName().toCharArray()));
|
||||||
fLevel= 0;
|
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;
|
return PROCESS_CONTINUE;
|
||||||
}
|
}
|
||||||
|
@ -249,13 +257,20 @@ public class DefaultCFoldingStructureProvider implements ICFoldingStructureProvi
|
||||||
@Override
|
@Override
|
||||||
public int leave(IASTDeclaration declaration) {
|
public int leave(IASTDeclaration declaration) {
|
||||||
if (declaration instanceof IASTFunctionDefinition) {
|
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;
|
return PROCESS_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
private StatementRegion createRegion() {
|
private StatementRegion createRegion() {
|
||||||
return new StatementRegion(fFunction, fLevel);
|
return new StatementRegion(fScope.toString(), fLevel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue