Giter Site home page Giter Site logo

Comments (5)

MartinWitt avatar MartinWitt commented on May 29, 2024

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.

callain-mirakl avatar callain-mirakl commented on May 29, 2024

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.

tenax66 avatar tenax66 commented on May 29, 2024

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.

callain-mirakl avatar callain-mirakl commented on May 29, 2024

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.

tenax66 avatar tenax66 commented on May 29, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.