1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

fix behaviour when commenting methods preceded by a macro

This commit is contained in:
Andrew Ferguson 2008-03-13 11:32:53 +00:00
parent 2ee490ecf3
commit 83b3470a9e
3 changed files with 52 additions and 23 deletions

View file

@ -41,7 +41,7 @@ import org.eclipse.cdt.internal.ui.text.CTextTools;
* Testing the auto indent strategies. * Testing the auto indent strategies.
*/ */
public class DefaultCCommentAutoEditStrategyTest extends AbstractAutoEditTest { public class DefaultCCommentAutoEditStrategyTest extends AbstractAutoEditTest {
private HashMap fOptions; private HashMap<String,String> fOptions;
/** /**
* @param name * @param name
@ -522,6 +522,19 @@ public class DefaultCCommentAutoEditStrategyTest extends AbstractAutoEditTest {
public void testFollowingDeclaration9() { public void testFollowingDeclaration9() {
assertDeclarationFollowingX("void baz(int x) {}"); assertDeclarationFollowingX("void baz(int x) {}");
} }
// #define STATIC static
//
// class D {
// public:
// X
// STATIC void D::foo(int x) {
//
// }
// };
public void testFollowingDeclaration13() throws CoreException {
assertDeclarationFollowingX("STATIC void D::foo(int x) {\n \n }");
}
// #define MM void foo() // #define MM void foo()
// X // X

View file

@ -13,8 +13,6 @@
package org.eclipse.cdt.ui.tests.text.doctools.doxygen; package org.eclipse.cdt.ui.tests.text.doctools.doxygen;
import java.util.HashMap;
import junit.framework.Test; import junit.framework.Test;
import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFile;
@ -23,7 +21,6 @@ import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.Document; import org.eclipse.jface.text.Document;
import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.IDocument;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.ICProject;
@ -45,7 +42,6 @@ import org.eclipse.cdt.internal.ui.text.CTextTools;
* Testing the auto indent strategies. * Testing the auto indent strategies.
*/ */
public class DoxygenCCommentAutoEditStrategyTest extends DefaultCCommentAutoEditStrategyTest { public class DoxygenCCommentAutoEditStrategyTest extends DefaultCCommentAutoEditStrategyTest {
private HashMap fOptions;
protected ICProject fCProject; protected ICProject fCProject;
/** /**
@ -62,7 +58,6 @@ public class DoxygenCCommentAutoEditStrategyTest extends DefaultCCommentAutoEdit
protected void setUp() throws Exception { protected void setUp() throws Exception {
super.setUp(); super.setUp();
fCProject= CProjectHelper.createCCProject("test"+System.currentTimeMillis(), null); fCProject= CProjectHelper.createCCProject("test"+System.currentTimeMillis(), null);
fOptions= CCorePlugin.getOptions();
} }
/* /*
@ -70,7 +65,6 @@ public class DoxygenCCommentAutoEditStrategyTest extends DefaultCCommentAutoEdit
*/ */
protected void tearDown() throws Exception { protected void tearDown() throws Exception {
CProjectHelper.delete(fCProject); CProjectHelper.delete(fCProject);
CCorePlugin.setOptions(fOptions);
super.tearDown(); super.tearDown();
} }
@ -332,6 +326,32 @@ public class DoxygenCCommentAutoEditStrategyTest extends DefaultCCommentAutoEdit
assertAutoEditBehaviour(); assertAutoEditBehaviour();
} }
// #define STATIC static
//
// class D {
// public:
// /**X
// STATIC void D::foo(int x) {
//
// }
// };
// #define STATIC static
//
// class D {
// public:
// /**
// * X
// * @param x
// */
// STATIC void D::foo(int x) {
//
// }
// };
public void testAutoDocCommentContent17() throws CoreException {
assertAutoEditBehaviour();
}
protected void assertAutoEditBehaviour() throws CoreException { protected void assertAutoEditBehaviour() throws CoreException {
CTextTools textTools = CUIPlugin.getDefault().getTextTools(); CTextTools textTools = CUIPlugin.getDefault().getTextTools();
final IDocument doc = new Document(); final IDocument doc = new Document();

View file

@ -189,23 +189,19 @@ public class DefaultMultilineCommentAutoEditStrategy implements IAutoEditStrateg
IASTDeclaration stopWhenLeaving; IASTDeclaration stopWhenLeaving;
public int visit(IASTDeclaration declaration) { public int visit(IASTDeclaration declaration) {
IASTNodeLocation[] locs= declaration.getNodeLocations(); IASTNodeLocation loc= declaration.getFileLocation();
if(locs.length>0) { if(loc != null) {
for(int i=0; i<locs.length; i++) { int candidateOffset= loc.getNodeOffset();
IASTNodeLocation loc= locs[i]; int candidateEndOffset= candidateOffset+loc.getNodeLength();
int candidateOffset= loc.getNodeOffset(); if(offset <= candidateOffset) {
int candidateEndOffset= candidateOffset+loc.getNodeLength(); dec[0]= declaration;
return PROCESS_ABORT;
if(offset <= candidateOffset) { }
dec[0]= declaration;
return PROCESS_ABORT; boolean candidateEnclosesOffset= (offset >= candidateOffset) && (offset < candidateEndOffset);
} if(candidateEnclosesOffset) {
stopWhenLeaving= declaration;
boolean candidateEnclosesOffset= (offset >= candidateOffset) && (offset < candidateEndOffset);
if(candidateEnclosesOffset) {
stopWhenLeaving= declaration;
}
} }
} }
return PROCESS_CONTINUE; return PROCESS_CONTINUE;