Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: bump spoon version #886

Merged
merged 10 commits into from
Mar 5, 2020

Conversation

danglotb
Copy link
Member

No description provided.

@danglotb
Copy link
Member Author

Looks like there are problems with
CompilationUnit cu = this.getFactory().CompilationUnit().getOrCreate(element); in JavaOutputProcessor when printing a java file with Spoon.

@monperrus
Copy link
Member

We're still stabilizing 7.6. Let's wait a little bit.

@monperrus monperrus changed the title misc: update to spoon 7.6 bump spoon version Dec 10, 2019
@monperrus
Copy link
Member

conflict?

@danglotb danglotb force-pushed the update-to-spoon-7.6 branch from acd5241 to 16904bf Compare December 11, 2019 11:38
@monperrus
Copy link
Member

ping @danglotb

@danglotb
Copy link
Member Author

danglotb commented Feb 5, 2020

Hello, there are still issues with the CompilationUnit. It seems that it returns the original version of the class when I try to print it with :

public static void printCtTypeToGivenDirectory(CtType<?> type, File directory, boolean autoImports) {
         try {
            Factory factory = type.getFactory();
            Environment env = factory.getEnvironment();
            env.setAutoImports(autoImports);
            env.setNoClasspath(true);
            env.setCommentEnabled(DSpotUtils.withComment);
            JavaOutputProcessor processor = new JavaOutputProcessor(new DefaultJavaPrettyPrinter(env));
            processor.setFactory(factory);
            processor.getEnvironment().setSourceOutputDirectory(directory);
            processor.createJavaFile(type);
            env.setAutoImports(false);
        } catch (Exception e) {
            printCtTypUsingToStringToGivenDirectory(type, directory);
        }

In processor#createJavaFile(CtElement) there is:

CompilationUnit cu = this.getFactory().CompilationUnit().getOrCreate(element);

And this CompilationUnit still point on the original class and not the one that I want to print, i.e. the element gave in parameter.

I tried to create a new Factory (kind of messy & ugly but uh), as follow:

try {
            //Factory factory = type.getFactory();
            Environment env = type.getFactory().getEnvironment();
            Factory factory = new FactoryImpl(new DefaultCoreFactory(), env);
            CtPackage packageOfTestClass = factory.Package().getOrCreate(type.getPackage().getQualifiedName());
            packageOfTestClass.addType(type);
            env.setAutoImports(autoImports);
            env.setNoClasspath(true);
            env.setCommentEnabled(DSpotUtils.withComment);
            JavaOutputProcessor processor = new JavaOutputProcessor(new DefaultJavaPrettyPrinter(env));
            processor.setFactory(factory);
            processor.getEnvironment().setSourceOutputDirectory(directory);
            processor.createJavaFile(type);
            env.setAutoImports(false);
        } catch (Exception e) {
            printCtTypUsingToStringToGivenDirectory(type, directory);
        }

But still the same behaviour. It looks like Spoon is using the original java file to print it, instead of the loaded CtType.

@monperrus
Copy link
Member

monperrus commented Feb 6, 2020 via email

@danglotb
Copy link
Member Author

danglotb commented Feb 6, 2020

Hello @monperrus

Yes, I'll do that ASAP. Thank you :)

@monperrus
Copy link
Member

updated to 8.1.0-SNAPSHOT

@danglotb
Copy link
Member Author

It looks like we have still the same issue.

Spoon is printing the old class (before modification) instead of the one given in parameter.

BTW, DSpot looks into the public snapshot repository at maven.inria.fr for the snapshot of Spoon

However, the last updated is :

8.1.0-SNAPSHOT/ 06-Nov-2019 15:51 -

Is the latest SNAPSHOT available somewhere else ?

I'll look at providing a new test as pull request on the spoon repository to capture the problem.

The cause in DSpot is the following method:

public static void printCtTypeToGivenDirectory(CtType<?> type, File directory, boolean autoImports) {
        Environment env = type.getFactory().getEnvironment();
        Factory factory = new FactoryImpl(new DefaultCoreFactory(), env);
        try {
            //Factory factory = type.getFactory();
            CtPackage packageOfTestClass = factory.Package().create(factory.Package().getRootPackage(), type.getPackage().getQualifiedName());
            packageOfTestClass.addType(type.clone());
            env.setAutoImports(autoImports);
            env.setNoClasspath(true);
            env.setCommentEnabled(DSpotUtils.withComment);
            JavaOutputProcessor processor = new JavaOutputProcessor(new DefaultJavaPrettyPrinter(env));
            processor.setFactory(factory);
            processor.getEnvironment().setSourceOutputDirectory(directory);
            processor.createJavaFile(type);
            env.setAutoImports(false);
        } catch (Exception e) {
            printCtTypUsingToStringToGivenDirectory(type, directory);
        }
    }

Thank you very much.

@monperrus
Copy link
Member

DSpot looks into the public snapshot repository at maven.inria.fr for the snapshot of Spoon

Yes, and the last update is from Feb 26, if you look into the 8.1.0-SNAPSHOT folder:
http://maven.inria.fr/artifactory/spoon-public-snapshot/fr/inria/gforge/spoon/spoon-core/8.1.0-SNAPSHOT/

@danglotb danglotb force-pushed the update-to-spoon-7.6 branch from 61e92e0 to 4d10fa3 Compare March 4, 2020 17:37
@danglotb danglotb force-pushed the update-to-spoon-7.6 branch from 4d10fa3 to 299f80b Compare March 4, 2020 17:53
@coveralls
Copy link

Pull Request Test Coverage Report for Build 2502

  • 34 of 35 (97.14%) changed or added relevant lines in 9 files are covered.
  • 24 unchanged lines in 3 files lost coverage.
  • Overall coverage decreased (-0.1%) to 83.302%

Changes Missing Coverage Covered Lines Changed/Added Lines %
dspot/src/main/java/eu/stamp_project/dspot/common/report/output/selector/TestSelectorElementReportImpl.java 2 3 66.67%
Files with Coverage Reduction New Missed Lines %
dspot/src/main/java/eu/stamp_project/dspot/common/test_framework/implementations/AssertJTestFramework.java 1 50.0%
dspot/src/main/java/eu/stamp_project/dspot/common/miscellaneous/DSpotUtils.java 7 77.52%
dspot/src/main/java/eu/stamp_project/dspot/amplifier/SimpleInputAmplDistributor.java 16 75.76%
Totals Coverage Status
Change from base Build 2498: -0.1%
Covered Lines: 4914
Relevant Lines: 5899

💛 - Coveralls

@monperrus monperrus changed the title bump spoon version chore: bump spoon version Mar 5, 2020
@monperrus monperrus merged commit 81bd760 into STAMP-project:master Mar 5, 2020
@monperrus
Copy link
Member

Thanks a lot @danglotb !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants