Lines 41-46
Link Here
|
41 |
package org.netbeans.api.java.source.gen; |
41 |
package org.netbeans.api.java.source.gen; |
42 |
|
42 |
|
43 |
import com.sun.source.tree.*; |
43 |
import com.sun.source.tree.*; |
|
|
44 |
import com.sun.source.util.TreePath; |
44 |
import static com.sun.source.tree.Tree.*; |
45 |
import static com.sun.source.tree.Tree.*; |
45 |
import java.io.File; |
46 |
import java.io.File; |
46 |
import org.netbeans.api.java.source.*; |
47 |
import org.netbeans.api.java.source.*; |
Lines 286-291
Link Here
|
286 |
return make.Unary(Kind.LOGICAL_COMPLEMENT, make.Parenthesized(input)); |
287 |
return make.Unary(Kind.LOGICAL_COMPLEMENT, make.Parenthesized(input)); |
287 |
} |
288 |
} |
288 |
} |
289 |
} |
|
|
290 |
|
291 |
public void testUnary158150() throws Exception { |
292 |
String test = "public class Test { void m(int x) { int y = - |- x; } }"; |
293 |
String golden = "public class Test { void m(int x) { int y = +x; } }"; |
294 |
testFile = new File(getWorkDir(), "Test.java"); |
295 |
final int index = test.indexOf("|"); |
296 |
assertTrue(index != -1); |
297 |
TestUtilities.copyStringToFile(testFile, test.replace("|", "")); |
298 |
JavaSource src = getJavaSource(testFile); |
299 |
Task<WorkingCopy> task = new Task<WorkingCopy>() { |
300 |
|
301 |
public void run(WorkingCopy copy) throws Exception { |
302 |
if (copy.toPhase(Phase.RESOLVED).compareTo(Phase.RESOLVED) < 0) { |
303 |
return; |
304 |
} |
305 |
TreePath node = copy.getTreeUtilities().pathFor(index); |
306 |
assertEquals(Kind.UNARY_MINUS, node.getLeaf().getKind()); |
307 |
UnaryTree original = (UnaryTree) node.getLeaf(); |
308 |
System.out.println("original: " + original); |
309 |
TreeMaker make = copy.getTreeMaker(); |
310 |
UnaryTree modified = make.Unary(Kind.UNARY_PLUS, original.getExpression()); |
311 |
System.out.println("modified: " + modified); |
312 |
copy.rewrite(original, modified); |
313 |
} |
314 |
}; |
315 |
src.runModificationTask(task).commit(); |
316 |
String res = TestUtilities.copyFileToString(testFile); |
317 |
assertEquals(golden, res); |
318 |
} |
289 |
|
319 |
|
290 |
String getGoldenPckg() { |
320 |
String getGoldenPckg() { |
291 |
return ""; |
321 |
return ""; |