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

review: feat: Add Environment#setFactory #1671

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/main/java/spoon/compiler/Environment.java
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,11 @@ void report(Processor<?> processor, Level level,
*/
Factory getFactory();

/**
* Sets the factory of the environment
*/
void setFactory(Factory factory);

/**
* Gets the level of loggers asked by the user.
*/
Expand Down
1 change: 1 addition & 0 deletions src/main/java/spoon/reflect/factory/FactoryImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ public QueryFactory Query() {
*/
public FactoryImpl(CoreFactory coreFactory, Environment environment, Factory parentFactory) {
this.environment = environment;
this.environment.setFactory(this);
this.core = coreFactory;
this.core.setMainFactory(this);
this.parentFactory = parentFactory;
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/spoon/support/StandardEnvironment.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ public Factory getFactory() {
return factory;
}

@Override
public void setFactory(Factory factory) {
this.factory = factory;
}

@Override
public Level getLevel() {
return this.level;
Expand Down
7 changes: 7 additions & 0 deletions src/test/java/spoon/test/factory/FactoryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -201,4 +201,11 @@ public void specificationCoreFactoryCreate() throws Exception {
}
}

@Test
public void testEnvGetFactoryIsNotNull() {
// contract: env.getFactory() should not return null

Launcher launcher = new Launcher();
assertNotNull(launcher.getEnvironment().getFactory());
}
}