Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 162313 Details for
Bug 293558
[quick assist] "Invert if statement" fails when comment follows
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Proposed fix + regression tests
patch_293558.txt (text/plain), 5.53 KB, created by
Olivier Thomann
on 2010-03-17 12:18:16 EDT
(
hide
)
Description:
Proposed fix + regression tests
Filename:
MIME Type:
Creator:
Olivier Thomann
Created:
2010-03-17 12:18:16 EDT
Size:
5.53 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jdt.core >Index: dom/org/eclipse/jdt/internal/core/dom/rewrite/ASTRewriteAnalyzer.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/rewrite/ASTRewriteAnalyzer.java,v >retrieving revision 1.70 >diff -u -r1.70 ASTRewriteAnalyzer.java >--- dom/org/eclipse/jdt/internal/core/dom/rewrite/ASTRewriteAnalyzer.java 17 Mar 2010 16:09:16 -0000 1.70 >+++ dom/org/eclipse/jdt/internal/core/dom/rewrite/ASTRewriteAnalyzer.java 17 Mar 2010 16:17:36 -0000 >@@ -764,8 +764,22 @@ > } > case RewriteEvent.REPLACED: { > ASTNode node= (ASTNode) event.getOriginalValue(); >+ boolean insertNewLine = false; > if (endPos == -1) { >+ int previousEnd = node.getStartPosition() + node.getLength(); > endPos= getExtendedEnd(node); >+ if (endPos != previousEnd) { >+ // check if the end is a comment >+ int token = TokenScanner.END_OF_FILE; >+ try { >+ token = getScanner().readNext(previousEnd, false); >+ } catch(CoreException e) { >+ // ignore >+ } >+ if (token == TerminalTokens.TokenNameCOMMENT_LINE) { >+ insertNewLine = true; >+ } >+ } > } > TextEditGroup editGroup= getEditGroup(event); > int nodeLen= endPos - offset; >@@ -775,7 +789,11 @@ > doTextRemoveAndVisit(offset, nodeLen, node, editGroup); > > String prefix= strings[0]; >- doTextInsert(offset, prefix, editGroup); >+ String insertedPrefix = prefix; >+ if (insertNewLine) { >+ insertedPrefix = getLineDelimiter() + this.formatter.createIndentString(indent) + insertedPrefix.trim() + ' '; >+ } >+ doTextInsert(offset, insertedPrefix, editGroup); > String lineInPrefix= getCurrentLine(prefix, prefix.length()); > if (prefix.length() != lineInPrefix.length()) { > // prefix contains a new line: update the indent to the one used in the prefix >@@ -793,7 +811,6 @@ > } > return pos; > } >- > private int rewriteOptionalQualifier(ASTNode parent, StructuralPropertyDescriptor property, int startPos) { > RewriteEvent event= getEvent(parent, property); > if (event != null) { >#P org.eclipse.jdt.core.tests.model >Index: src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingStatementsTest.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingStatementsTest.java,v >retrieving revision 1.31 >diff -u -r1.31 ASTRewritingStatementsTest.java >--- src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingStatementsTest.java 29 Sep 2009 15:46:39 -0000 1.31 >+++ src/org/eclipse/jdt/core/tests/rewrite/describing/ASTRewritingStatementsTest.java 17 Mar 2010 16:17:37 -0000 >@@ -3060,6 +3060,67 @@ > > } > >+ public void testIfStatementReplaceElse5() throws Exception { >+ IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null); >+ StringBuffer buf= new StringBuffer(); >+ buf.append("package test1;\n"); >+ buf.append("public class E {\n"); >+ buf.append(" public void foo(int i) {\n"); >+ buf.append(" if (i == 0) {\n"); >+ buf.append(" System.beep();\n"); >+ buf.append(" } else {\n"); >+ buf.append(" System.beep();\n"); >+ buf.append(" System.beep();\n"); >+ buf.append(" }\n"); >+ buf.append(" // comment\n"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ ICompilationUnit cu= pack1.createCompilationUnit("E.java", buf.toString(), false, null); >+ >+ CompilationUnit astRoot= createAST(cu); >+ AST ast= astRoot.getAST(); >+ ASTRewrite rewrite= ASTRewrite.create(ast); >+ >+ assertTrue("Parse errors", (astRoot.getFlags() & ASTNode.MALFORMED) == 0); >+ TypeDeclaration type= findTypeDeclaration(astRoot, "E"); >+ MethodDeclaration methodDecl= findMethodDeclaration(type, "foo"); >+ Block block= methodDecl.getBody(); >+ List statements= block.statements(); >+ assertTrue("Number of statements not 1", statements.size() == 1); >+ >+ { >+ // replace then statement by block , replace else with if statement (block) >+ IfStatement ifStatement= (IfStatement) statements.get(0); >+ >+ Statement thenStatement= ifStatement.getThenStatement(); >+ Statement elseStatement= ifStatement.getElseStatement(); >+ >+ Statement newElseStatement= (Statement) rewrite.createMoveTarget(thenStatement); >+ Statement newThenStatement= (Statement) rewrite.createMoveTarget(elseStatement); >+ >+ rewrite.set(ifStatement, IfStatement.THEN_STATEMENT_PROPERTY, newThenStatement, null); >+ rewrite.set(ifStatement, IfStatement.ELSE_STATEMENT_PROPERTY, newElseStatement, null); >+ } >+ String preview= evaluateRewrite(cu, rewrite); >+ >+ buf= new StringBuffer(); >+ buf.append("package test1;\n"); >+ buf.append("public class E {\n"); >+ buf.append(" public void foo(int i) {\n"); >+ buf.append(" if (i == 0) {\n"); >+ buf.append(" System.beep();\n"); >+ buf.append(" System.beep();\n"); >+ buf.append(" }\n"); >+ buf.append(" // comment\n"); >+ buf.append(" else {\n"); >+ buf.append(" System.beep();\n"); >+ buf.append(" }\n"); >+ buf.append(" }\n"); >+ buf.append("}\n"); >+ assertEqualString(preview, buf.toString()); >+ >+ } >+ > public void testLabeledStatement() throws Exception { > IPackageFragment pack1= this.sourceFolder.createPackageFragment("test1", false, null); > StringBuffer buf= new StringBuffer();
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 293558
: 162313