View | Details | Raw Unified | Return to bug 308754
Collapse All | Expand All

(-)dom/org/eclipse/jdt/internal/core/dom/rewrite/ASTRewriteAnalyzer.java (-1 / +10 lines)
Lines 1503-1509 Link Here
1503
		if (invertType) {
1503
		if (invertType) {
1504
			try {
1504
			try {
1505
				int typeToken= isInterface ? TerminalTokens.TokenNameinterface : TerminalTokens.TokenNameclass;
1505
				int typeToken= isInterface ? TerminalTokens.TokenNameinterface : TerminalTokens.TokenNameclass;
1506
				getScanner().readToToken(typeToken, node.getStartPosition());
1506
				int startPosition = node.getStartPosition();
1507
				if (apiLevel >= AST.JLS3) {
1508
					List modifiers = node.modifiers();
1509
					final int size = modifiers.size();
1510
					if (size != 0) {
1511
						ASTNode modifierNode = (ASTNode) modifiers.get(size - 1);
1512
						startPosition = modifierNode.getStartPosition() + modifierNode.getLength();
1513
					}
1514
				}
1515
				getScanner().readToToken(typeToken, startPosition);
1507
1516
1508
				String str= isInterface ? "class" : "interface"; //$NON-NLS-1$ //$NON-NLS-2$
1517
				String str= isInterface ? "class" : "interface"; //$NON-NLS-1$ //$NON-NLS-2$
1509
				int start= getScanner().getCurrentStartOffset();
1518
				int start= getScanner().getCurrentStartOffset();
(-)src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingTypeDeclTest.java (+49 lines)
Lines 153-159 Link Here
153
		assertEqualString(preview, buf.toString());
153
		assertEqualString(preview, buf.toString());
154
154
155
	}
155
	}
156
	//https://bugs.eclipse.org/bugs/show_bug.cgi?id=308754
157
	public void testTypeDeclarationChange() throws Exception {
158
		IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
159
		StringBuffer buf= new StringBuffer();
160
		buf.append("package test1;\n");
161
		buf.append("public class C {}");
162
		ICompilationUnit cu= pack1.createCompilationUnit("C.java", buf.toString(), false, null);
163
164
		CompilationUnit astRoot= createAST(cu);
165
		ASTRewrite rewrite= ASTRewrite.create(astRoot.getAST());
166
		{
167
			// change to interface
168
			TypeDeclaration type= findTypeDeclaration(astRoot, "C");
169
170
			astRoot.recordModifications();
171
			// change to interface
172
			rewrite.set(type, TypeDeclaration.INTERFACE_PROPERTY, Boolean.TRUE, null);
173
		}
174
		String preview= evaluateRewrite(cu, rewrite);
156
175
176
		buf= new StringBuffer();
177
		buf.append("package test1;\n");
178
		buf.append("public interface C {}");
179
		assertEqualString(preview, buf.toString());
180
	}
181
	//https://bugs.eclipse.org/bugs/show_bug.cgi?id=308754
182
	public void testTypeDeclarationChange2() throws Exception {
183
		IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
184
		StringBuffer buf= new StringBuffer();
185
		buf.append("package test1;\n");
186
		buf.append("@A(X.class) public class C {}");
187
		ICompilationUnit cu= pack1.createCompilationUnit("C.java", buf.toString(), false, null);
188
189
		CompilationUnit astRoot= createAST3(cu);
190
		ASTRewrite rewrite= ASTRewrite.create(astRoot.getAST());
191
		{
192
			// change to interface
193
			TypeDeclaration type= findTypeDeclaration(astRoot, "C");
194
195
			astRoot.recordModifications();
196
			// change to interface
197
			rewrite.set(type, TypeDeclaration.INTERFACE_PROPERTY, Boolean.TRUE, null);
198
		}
199
		String preview= evaluateRewrite(cu, rewrite);
200
201
		buf= new StringBuffer();
202
		buf.append("package test1;\n");
203
		buf.append("@A(X.class) public interface C {}");
204
		assertEqualString(preview, buf.toString());
205
	}
157
	public void testTypeDeclChanges2() throws Exception {
206
	public void testTypeDeclChanges2() throws Exception {
158
		IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
207
		IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null);
159
		StringBuffer buf= new StringBuffer();
208
		StringBuffer buf= new StringBuffer();
(-)src/org/eclipse/jdt/core/tests/rewrite/modifying/ASTRewritingModifyingOtherTest.java (-46 / +57 lines)
Lines 16-23 Link Here
16
16
17
import org.eclipse.jdt.core.ICompilationUnit;
17
import org.eclipse.jdt.core.ICompilationUnit;
18
import org.eclipse.jdt.core.IPackageFragment;
18
import org.eclipse.jdt.core.IPackageFragment;
19
19
import org.eclipse.jdt.core.dom.AST;
20
import org.eclipse.jdt.core.dom.*;
20
import org.eclipse.jdt.core.dom.ASTVisitor;
21
import org.eclipse.jdt.core.dom.CompilationUnit;
22
import org.eclipse.jdt.core.dom.ImportDeclaration;
23
import org.eclipse.jdt.core.dom.Name;
24
import org.eclipse.jdt.core.dom.TypeDeclaration;
21
25
22
public class ASTRewritingModifyingOtherTest extends ASTRewritingModifyingTest {
26
public class ASTRewritingModifyingOtherTest extends ASTRewritingModifyingTest {
23
	private static final Class THIS = ASTRewritingModifyingOtherTest.class;
27
	private static final Class THIS = ASTRewritingModifyingOtherTest.class;
Lines 186-234 Link Here
186
		buf.append("}\n");
190
		buf.append("}\n");
187
		assertEqualString(preview, buf.toString());
191
		assertEqualString(preview, buf.toString());
188
	}
192
	}
193
	//https://bugs.eclipse.org/bugs/show_bug.cgi?id=308754
194
	public void test0005() throws Exception {
195
		IPackageFragment pack1= this.sourceFolder.createPackageFragment("test0005", false, null);
196
		StringBuffer buf= new StringBuffer();
197
		buf.append("package test0005;\n");
198
		buf.append("@A(X.class) public class C {}");
199
		ICompilationUnit cu= pack1.createCompilationUnit("C.java", buf.toString(), false, null);
200
201
		CompilationUnit astRoot= createCU(cu, true, AST.JLS3);
202
		astRoot.recordModifications();
203
		{
204
			// change to interface
205
			astRoot.accept(new ASTVisitor() {
206
				public boolean visit(TypeDeclaration node) {
207
					node.setInterface(true);
208
					return false;
209
				}
210
			});
211
		}
212
		String preview= evaluateRewrite(cu, astRoot);
213
214
		buf= new StringBuffer();
215
		buf.append("package test0005;\n");
216
		buf.append("@A(X.class) public interface C {}");
217
		assertEqualString(preview, buf.toString());
218
	}
219
	//https://bugs.eclipse.org/bugs/show_bug.cgi?id=308754
220
	public void test0006() throws Exception {
221
		IPackageFragment pack1= this.sourceFolder.createPackageFragment("test0006", false, null);
222
		StringBuffer buf= new StringBuffer();
223
		buf.append("package test0006;\n");
224
		buf.append("public @A(X.class) class C {}");
225
		ICompilationUnit cu= pack1.createCompilationUnit("C.java", buf.toString(), false, null);
226
227
		CompilationUnit astRoot= createCU(cu, true, AST.JLS3);
228
		astRoot.recordModifications();
229
		{
230
			// change to interface
231
			astRoot.accept(new ASTVisitor() {
232
				public boolean visit(TypeDeclaration node) {
233
					node.setInterface(true);
234
					return false;
235
				}
236
			});
237
		}
238
		String preview= evaluateRewrite(cu, astRoot);
189
239
190
//	public void _test000X() throws Exception {
240
		buf= new StringBuffer();
191
//		IPackageFragment pack1= fSourceFolder.createPackageFragment("test0004", false, null);
241
		buf.append("package test0006;\n");
192
//		StringBuffer buf= new StringBuffer();
242
		buf.append("public @A(X.class) interface C {}");
193
//		buf.append("package test0004;\n");
243
		assertEqualString(preview, buf.toString());
194
//		buf.append("\n");
244
	}
195
//		buf.append("public class X {\n");
196
//		buf.append("    void foo(){\n");
197
//		buf.append("        //rien\n");
198
//		buf.append("    \n");
199
//		buf.append("    \n");
200
//		buf.append("    \n");
201
//		buf.append("    \n");
202
//		buf.append("    }\n");
203
//		buf.append("}\n");
204
//		ICompilationUnit cu= pack1.createCompilationUnit("X.java", buf.toString(), false, null);
205
//
206
//		CompilationUnit astRoot= parseCompilationUnit(cu, false);
207
//
208
//		astRoot.recordModifications();
209
//
210
//		AST a = astRoot.getAST();
211
//
212
//		Comment[] comments = astRoot.getCommentTable();
213
//		Comment comment1 = comments[0];
214
//		Comment comment2 = a.newBlockComment();
215
//		comment2.setSourceRange(comment1.getStartPosition(), comment1.getLength() - 2);
216
//		comments[0] = comment2;
217
//
218
//		String preview = evaluateRewrite(cu, astRoot);
219
//
220
//		buf= new StringBuffer();
221
//		buf.append("package test0004;\n");
222
//		buf.append("\n");
223
//		buf.append("public class X {\n");
224
//		buf.append("\n");
225
//		buf.append("}\n");
226
//		buf.append("class Y {\n");
227
//		buf.append("\n");
228
//		buf.append("}\n");
229
//		buf.append("class Z {\n");
230
//		buf.append("\n");
231
//		buf.append("}\n");
232
//		assertEqualString(preview, buf.toString());
233
//	}
234
}
245
}

Return to bug 308754