mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Folding bugs 248613 and 248716
This commit is contained in:
parent
9bccca7417
commit
02dd15386f
3 changed files with 58 additions and 21 deletions
|
@ -72,7 +72,7 @@ int
|
||||||
main(int argc,
|
main(int argc,
|
||||||
char *argv[])
|
char *argv[])
|
||||||
{
|
{
|
||||||
int MyI = 0,j = 0;
|
int MyI = 0,j = 0;
|
||||||
if (0==0) {
|
if (0==0) {
|
||||||
puts("Wow ");
|
puts("Wow ");
|
||||||
} else {
|
} else {
|
||||||
|
@ -109,3 +109,20 @@ enum E {
|
||||||
e2,
|
e2,
|
||||||
e3
|
e3
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// http://bugs.eclipse.org/248613
|
||||||
|
jungle::Monkey_ptr
|
||||||
|
jungle::MonkeyImpl::
|
||||||
|
Initialize()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
// http://bugs.eclipse.org/248716
|
||||||
|
void foo() {
|
||||||
|
if (1
|
||||||
|
&& 2)
|
||||||
|
{
|
||||||
|
} else if (3
|
||||||
|
|| 4)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -75,6 +75,7 @@ public class FoldingTest extends TestCase {
|
||||||
super(name);
|
super(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected void setUp() throws Exception {
|
protected void setUp() throws Exception {
|
||||||
super.setUp();
|
super.setUp();
|
||||||
fCProject= EditorTestHelper.createCProject(PROJECT, LINKED_FOLDER);
|
fCProject= EditorTestHelper.createCProject(PROJECT, LINKED_FOLDER);
|
||||||
|
@ -91,6 +92,7 @@ public class FoldingTest extends TestCase {
|
||||||
assertTrue(EditorTestHelper.joinReconciler(fSourceViewer, 0, 10000, 300));
|
assertTrue(EditorTestHelper.joinReconciler(fSourceViewer, 0, 10000, 300));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
protected void tearDown () throws Exception {
|
protected void tearDown () throws Exception {
|
||||||
EditorTestHelper.closeEditor(fEditor);
|
EditorTestHelper.closeEditor(fEditor);
|
||||||
|
|
||||||
|
@ -180,7 +182,7 @@ public class FoldingTest extends TestCase {
|
||||||
ProjectionAnnotationModel model= (ProjectionAnnotationModel)fEditor.getAdapter(ProjectionAnnotationModel.class);
|
ProjectionAnnotationModel model= (ProjectionAnnotationModel)fEditor.getAdapter(ProjectionAnnotationModel.class);
|
||||||
assertNotNull(model);
|
assertNotNull(model);
|
||||||
for (Iterator<Annotation> iter= model.getAnnotationIterator(); iter.hasNext(); ) {
|
for (Iterator<Annotation> iter= model.getAnnotationIterator(); iter.hasNext(); ) {
|
||||||
Annotation ann= (Annotation)iter.next();
|
Annotation ann= iter.next();
|
||||||
Position pos= model.getPosition(ann);
|
Position pos= model.getPosition(ann);
|
||||||
positions.add(pos);
|
positions.add(pos);
|
||||||
}
|
}
|
||||||
|
@ -227,6 +229,10 @@ public class FoldingTest extends TestCase {
|
||||||
createPosition(95, 97),
|
createPosition(95, 97),
|
||||||
createPosition(99, 102),
|
createPosition(99, 102),
|
||||||
createPosition(106, 110),
|
createPosition(106, 110),
|
||||||
|
createPosition(113, 117, 115),
|
||||||
|
createPosition(119, 127),
|
||||||
|
createPosition(120, 122),
|
||||||
|
createPosition(123, 126),
|
||||||
};
|
};
|
||||||
assertEquals(toString(expected), toString(actual));
|
assertEquals(toString(expected), toString(actual));
|
||||||
assertEqualPositions(expected, actual);
|
assertEqualPositions(expected, actual);
|
||||||
|
@ -262,6 +268,10 @@ public class FoldingTest extends TestCase {
|
||||||
createPosition(95, 97),
|
createPosition(95, 97),
|
||||||
createPosition(99, 102),
|
createPosition(99, 102),
|
||||||
createPosition(106, 110),
|
createPosition(106, 110),
|
||||||
|
createPosition(113, 117, 115),
|
||||||
|
createPosition(119, 127),
|
||||||
|
createPosition(120, 122),
|
||||||
|
createPosition(123, 126),
|
||||||
};
|
};
|
||||||
assertEquals(toString(expected), toString(actual));
|
assertEquals(toString(expected), toString(actual));
|
||||||
assertEqualPositions(expected, actual);
|
assertEqualPositions(expected, actual);
|
||||||
|
@ -288,6 +298,8 @@ public class FoldingTest extends TestCase {
|
||||||
createPosition(65, 67),
|
createPosition(65, 67),
|
||||||
createPosition(70, 104, 71),
|
createPosition(70, 104, 71),
|
||||||
createPosition(106, 110),
|
createPosition(106, 110),
|
||||||
|
createPosition(113, 117, 115),
|
||||||
|
createPosition(119, 127),
|
||||||
};
|
};
|
||||||
assertEquals(toString(expected), toString(actual));
|
assertEquals(toString(expected), toString(actual));
|
||||||
assertEqualPositions(expected, actual);
|
assertEqualPositions(expected, actual);
|
||||||
|
|
|
@ -109,7 +109,7 @@ import org.eclipse.cdt.internal.ui.text.ICReconcilingListener;
|
||||||
public class DefaultCFoldingStructureProvider implements ICFoldingStructureProvider {
|
public class DefaultCFoldingStructureProvider implements ICFoldingStructureProvider {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A visitor to collect compund statement positions.
|
* A visitor to collect compound statement positions.
|
||||||
*
|
*
|
||||||
* @since 5.0
|
* @since 5.0
|
||||||
*/
|
*/
|
||||||
|
@ -140,25 +140,31 @@ public class DefaultCFoldingStructureProvider implements ICFoldingStructureProvi
|
||||||
fl = ifstmt.getFileLocation();
|
fl = ifstmt.getFileLocation();
|
||||||
if (fl==null) return PROCESS_CONTINUE;
|
if (fl==null) return PROCESS_CONTINUE;
|
||||||
int ifOffset= fl.getNodeOffset();
|
int ifOffset= fl.getNodeOffset();
|
||||||
IASTStatement tmp;
|
IASTStatement thenStmt;
|
||||||
mr = createRegion();
|
mr = createRegion();
|
||||||
tmp = ifstmt.getThenClause();
|
thenStmt = ifstmt.getThenClause();
|
||||||
if (tmp==null) return PROCESS_CONTINUE;
|
if (thenStmt==null) return PROCESS_CONTINUE;
|
||||||
fl = tmp.getFileLocation();
|
fl = thenStmt.getFileLocation();
|
||||||
mr.setLength(fl.getNodeOffset() + fl.getNodeLength() - ifOffset);
|
mr.setLength(fl.getNodeOffset() + fl.getNodeLength() - ifOffset);
|
||||||
mr.setOffset(ifOffset);
|
mr.setOffset(ifOffset);
|
||||||
mr.inclusive = !(tmp instanceof IASTCompoundStatement);
|
mr.inclusive = !(thenStmt instanceof IASTCompoundStatement);
|
||||||
tmp = ifstmt.getElseClause();
|
IASTStatement elseStmt;
|
||||||
if (tmp==null || tmp instanceof IASTIfStatement) {
|
elseStmt = ifstmt.getElseClause();
|
||||||
|
if (elseStmt == null) {
|
||||||
mr.inclusive = true;
|
mr.inclusive = true;
|
||||||
fStatements.push(mr);
|
fStatements.push(mr);
|
||||||
return PROCESS_CONTINUE;
|
return PROCESS_CONTINUE;
|
||||||
}
|
}
|
||||||
|
IASTFileLocation elseStmtLocation = elseStmt.getFileLocation();
|
||||||
|
mr.inclusive = mr.inclusive || fl.getEndingLineNumber() < elseStmtLocation.getStartingLineNumber();
|
||||||
|
if (elseStmt instanceof IASTIfStatement) {
|
||||||
|
fStatements.push(mr);
|
||||||
|
return PROCESS_CONTINUE;
|
||||||
|
}
|
||||||
fStatements.push(mr);
|
fStatements.push(mr);
|
||||||
mr = createRegion();
|
mr = createRegion();
|
||||||
fl = tmp.getFileLocation();
|
mr.setLength(elseStmtLocation.getNodeLength());
|
||||||
mr.setLength(fl.getNodeLength());
|
mr.setOffset(elseStmtLocation.getNodeOffset());
|
||||||
mr.setOffset(fl.getNodeOffset());
|
|
||||||
mr.inclusive = true;
|
mr.inclusive = true;
|
||||||
fStatements.push(mr);
|
fStatements.push(mr);
|
||||||
return PROCESS_CONTINUE;
|
return PROCESS_CONTINUE;
|
||||||
|
@ -658,7 +664,7 @@ public class DefaultCFoldingStructureProvider implements ICFoldingStructureProvi
|
||||||
* @see org.eclipse.jface.text.source.projection.IProjectionPosition#computeFoldingRegions(org.eclipse.jface.text.IDocument)
|
* @see org.eclipse.jface.text.source.projection.IProjectionPosition#computeFoldingRegions(org.eclipse.jface.text.IDocument)
|
||||||
*/
|
*/
|
||||||
public IRegion[] computeProjectionRegions(IDocument document) throws BadLocationException {
|
public IRegion[] computeProjectionRegions(IDocument document) throws BadLocationException {
|
||||||
int nameStart= offset;
|
int captionOffset= offset;
|
||||||
try {
|
try {
|
||||||
/* The member's name range may not be correct. However,
|
/* The member's name range may not be correct. However,
|
||||||
* reconciling would trigger another element delta which would
|
* reconciling would trigger another element delta which would
|
||||||
|
@ -668,7 +674,9 @@ public class DefaultCFoldingStructureProvider implements ICFoldingStructureProvi
|
||||||
if (fElement instanceof ISourceReference) {
|
if (fElement instanceof ISourceReference) {
|
||||||
ISourceRange sourceRange= ((ISourceReference) fElement).getSourceRange();
|
ISourceRange sourceRange= ((ISourceReference) fElement).getSourceRange();
|
||||||
if (sourceRange != null) {
|
if (sourceRange != null) {
|
||||||
nameStart= sourceRange.getIdStartPos();
|
// Use end of name range for the caption offset
|
||||||
|
// in case a qualified name is split on multiple lines (bug 248613).
|
||||||
|
captionOffset= sourceRange.getIdStartPos() + sourceRange.getIdLength() - 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (CModelException e) {
|
} catch (CModelException e) {
|
||||||
|
@ -676,7 +684,7 @@ public class DefaultCFoldingStructureProvider implements ICFoldingStructureProvi
|
||||||
}
|
}
|
||||||
|
|
||||||
int firstLine= document.getLineOfOffset(offset);
|
int firstLine= document.getLineOfOffset(offset);
|
||||||
int captionLine= document.getLineOfOffset(nameStart);
|
int captionLine= document.getLineOfOffset(captionOffset);
|
||||||
int lastLine= document.getLineOfOffset(offset + length);
|
int lastLine= document.getLineOfOffset(offset + length);
|
||||||
|
|
||||||
/* see comment above - adjust the caption line to be inside the
|
/* see comment above - adjust the caption line to be inside the
|
||||||
|
@ -717,15 +725,15 @@ public class DefaultCFoldingStructureProvider implements ICFoldingStructureProvi
|
||||||
* @see org.eclipse.jface.text.source.projection.IProjectionPosition#computeCaptionOffset(org.eclipse.jface.text.IDocument)
|
* @see org.eclipse.jface.text.source.projection.IProjectionPosition#computeCaptionOffset(org.eclipse.jface.text.IDocument)
|
||||||
*/
|
*/
|
||||||
public int computeCaptionOffset(IDocument document) throws BadLocationException {
|
public int computeCaptionOffset(IDocument document) throws BadLocationException {
|
||||||
int nameStart= offset;
|
int captionOffset= offset;
|
||||||
try {
|
try {
|
||||||
// need a reconcile here?
|
// need a reconcile here?
|
||||||
if (fElement instanceof ISourceReference) {
|
if (fElement instanceof ISourceReference) {
|
||||||
ISourceRange sourceRange= ((ISourceReference) fElement).getSourceRange();
|
ISourceRange sourceRange= ((ISourceReference) fElement).getSourceRange();
|
||||||
if (sourceRange != null) {
|
if (sourceRange != null) {
|
||||||
nameStart= sourceRange.getIdStartPos();
|
captionOffset= sourceRange.getIdStartPos() + sourceRange.getIdLength() - 1;
|
||||||
if (nameStart < offset) {
|
if (captionOffset < offset) {
|
||||||
nameStart= offset;
|
captionOffset= offset;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -733,7 +741,7 @@ public class DefaultCFoldingStructureProvider implements ICFoldingStructureProvi
|
||||||
// ignore and use default
|
// ignore and use default
|
||||||
}
|
}
|
||||||
|
|
||||||
return nameStart - offset;
|
return captionOffset - offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue