Comments (5)
Hey,
For a CtElement
with a position you can use element.getPosition().getFile()
. Providing a reproduction example or instruction what you are doing is necessary for us to debug this.
from spoon.
My coworker managed to reproduce the issue during my holidays, the solution we implemented is to use a variable to store the instance of the new HashMap
Problem
package com.demo;
import java.util.HashMap;
import java.util.Map;
public class TestClass {
private final Map<String, Object> testMap;
public TestClass() {
this.testMap = Map.of("TEST", true);
}
public Boolean myTest() {
var redirectView = Boolean.TRUE;
return test(redirectView, new HashMap<>(testMap));
}
private Boolean test(final Boolean redirectView, final Map<String, Object> params) {
params.put("TEST", "TEST");
return redirectView;
}
}
Solution
public Boolean myTest() {
var redirectView = Boolean.TRUE;
var solution = new HashMap<>(testMap);
return test(redirectView, solution);
}
from spoon.
Do you mean that JLSViolation
error occurred when the code you provided was analyzed by spoon?
Could you also provide the spoon code used for the analysis?
from spoon.
Yes, I've extracted the code of the launcher
String path = "src/test/java";
String basedir = new File(path).getAbsolutePath();
Launcher launcher = new Launcher();
launcher.getEnvironment().setNoClasspath(true);
launcher.addInputResource(basedir);
launcher.buildModel();
And here is the complete stack
spoon.JLSViolation: Not allowed javaletter or keyword in identifier found. See JLS for correct identifier. Identifier: K'
at spoon.JLSViolation.throwIfSyntaxErrorsAreNotIgnored(JLSViolation.java:38)
at spoon.support.reflect.reference.CtReferenceImpl.checkIdentifierForJLSCorrectness(CtReferenceImpl.java:114)
at spoon.support.reflect.reference.CtReferenceImpl.setSimpleName(CtReferenceImpl.java:57)
at spoon.support.compiler.jdt.ReferenceBuilder.getTypeReferenceFromTypeVariableBinding(ReferenceBuilder.java:1026)
at spoon.support.compiler.jdt.ReferenceBuilder.getTypeReference(ReferenceBuilder.java:863)
at spoon.support.compiler.jdt.ReferenceBuilder.getTypeReference(ReferenceBuilder.java:842)
at spoon.support.compiler.jdt.ReferenceBuilder.getTypeReferenceFromWildcardBinding(ReferenceBuilder.java:1107)
at spoon.support.compiler.jdt.ReferenceBuilder.getTypeReference(ReferenceBuilder.java:867)
at spoon.support.compiler.jdt.ReferenceBuilder.getTypeReference(ReferenceBuilder.java:842)
at spoon.support.compiler.jdt.ReferenceBuilder.getTypeReferenceFromTypeArgument(ReferenceBuilder.java:976)
at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
at java.base/java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:992)
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921)
at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:682)
at spoon.support.compiler.jdt.ReferenceBuilder.getTypeArguments(ReferenceBuilder.java:961)
at spoon.support.compiler.jdt.ReferenceBuilder.getParameterizedTypeReference(ReferenceBuilder.java:948)
at spoon.support.compiler.jdt.ReferenceBuilder.getTypeReference(ReferenceBuilder.java:857)
at spoon.support.compiler.jdt.ReferenceBuilder.getExecutableReference(ReferenceBuilder.java:475)
at spoon.support.compiler.jdt.ReferenceBuilder.getExecutableReference(ReferenceBuilder.java:414)
at spoon.support.compiler.jdt.ReferenceBuilder.getExecutableReference(ReferenceBuilder.java:493)
at spoon.support.compiler.jdt.JDTTreeBuilder.visit(JDTTreeBuilder.java:880)
at org.eclipse.jdt.internal.compiler.ast.AllocationExpression.traverse(AllocationExpression.java:727)
at org.eclipse.jdt.internal.compiler.ast.MessageSend.traverse(MessageSend.java:1176)
at org.eclipse.jdt.internal.compiler.ast.ReturnStatement.traverse(ReturnStatement.java:392)
at org.eclipse.jdt.internal.compiler.ast.MethodDeclaration.traverse(MethodDeclaration.java:437)
at org.eclipse.jdt.internal.compiler.ast.TypeDeclaration.traverse(TypeDeclaration.java:1700)
at org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration.traverse(CompilationUnitDeclaration.java:829)
at org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration.traverse(CompilationUnitDeclaration.java:790)
at spoon.support.compiler.jdt.JDTBasedSpoonCompiler.traverseUnitDeclaration(JDTBasedSpoonCompiler.java:481)
at spoon.support.compiler.jdt.JDTBasedSpoonCompiler.lambda$buildModel$0(JDTBasedSpoonCompiler.java:438)
at spoon.support.compiler.jdt.JDTBasedSpoonCompiler.forEachCompilationUnit(JDTBasedSpoonCompiler.java:465)
at spoon.support.compiler.jdt.JDTBasedSpoonCompiler.buildModel(JDTBasedSpoonCompiler.java:436)
at spoon.support.compiler.jdt.JDTBasedSpoonCompiler.buildUnitsAndModel(JDTBasedSpoonCompiler.java:373)
at spoon.support.compiler.jdt.JDTBasedSpoonCompiler.buildSources(JDTBasedSpoonCompiler.java:336)
at spoon.support.compiler.jdt.JDTBasedSpoonCompiler.build(JDTBasedSpoonCompiler.java:117)
at spoon.support.compiler.jdt.JDTBasedSpoonCompiler.build(JDTBasedSpoonCompiler.java:100)
at spoon.Launcher.buildModel(Launcher.java:781)
from spoon.
Does the src/test/java
folder containing TestClass
cause the error?
I could not reproduce it.
Could you provide a minimal example that reproduces the problem? Please also try the approach that MartinWitt commented on.
from spoon.
Related Issues (20)
- Move or delete spoon testing package from src/main HOT 1
- Delete old unused javadoc package HOT 2
- [Bug]: Under multithreading, using the isOverriding method will lead to incorrect results of the getElements method
- [Bug]: How to correctly recognize the signature of invoked methods in lambda expression?
- Java Compatibility with Older Versions of Spoon HOT 1
- [Bug]: CtReferenceImpl.isSpecialType throws an exception
- [Bug]: Bug adding comment in AST of lambda HOT 2
- Update a method calls reference
- java 22 HOT 1
- [Bug]: Control Flow graph missing edge for implicit default case in switch
- [Bug]: Control Flow Graph doesn't handle cases with multiple expressions
- Spotless for imports HOT 2
- [Bug]: Spoon inserts incorrect break in enhanced switch block
- [Feature Request]: Minimize Parens in `DefaultJavaPrettyPrinter` should use operator precedence (`(a == b) || (b == c)` could be `a == b || b == c`) HOT 2
- [Bug]: Javadoc of class missing HOT 1
- improve reproducible build architecture for Spoon HOT 2
- Unable to start JavaFX UI
- How to Implement Angelic Value with Spoon for APR
- Processing import Statements HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from spoon.