-
-
Notifications
You must be signed in to change notification settings - Fork 342
/
UnicodeBugTest.java
46 lines (39 loc) · 1.52 KB
/
UnicodeBugTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package spoon.test.literal;
import spoon.reflect.code.CtBinaryOperator;
import spoon.reflect.code.CtCodeElement;
import spoon.reflect.code.CtLiteral;
import spoon.reflect.declaration.CtField;
import spoon.Launcher;
import spoon.processing.AbstractProcessor;
import spoon.reflect.visitor.filter.TypeFilter;
import spoon.reflect.CtModel;
import spoon.support.compiler.VirtualFile;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
// bug case kindly provided by @Banbury
// in https://github.com/INRIA/spoon/issues/3203
public class UnicodeBugTest {
@Test
public void testUnicodeBug() {
Launcher launcher = new Launcher();
launcher.addInputResource(new VirtualFile("class A { String s = \"Hellö \" + \"Wörld!\"; }"));
launcher.buildModel();
launcher.addProcessor(new StringConcatProcessor());
launcher.process();
CtModel model = launcher.getModel();
CtField<?> field = model.getElements(new TypeFilter<>(CtField.class)).get(0);
assertEquals(field.toString(), "java.lang.String s = \"Hellö Wörld!\";");
}
private class StringConcatProcessor extends AbstractProcessor<CtLiteral<?>> {
@Override
public boolean isToBeProcessed(CtLiteral<?> candidate) {
return candidate.getType().isSubtypeOf(getFactory().Type().stringType()) &&
candidate.getParent() instanceof CtBinaryOperator;
}
@Override
public void process(CtLiteral<?> element) {
CtCodeElement s = ((CtBinaryOperator<?>) element.getParent()).partiallyEvaluate();
element.getParent().replace(s);
}
}
}