/
SarlBatchCompilerModule.java
142 lines (121 loc) · 4.93 KB
/
SarlBatchCompilerModule.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/*
* $Id$
*
* SARL is an general-purpose agent programming language.
* More details on http://www.sarl.io
*
* Copyright (C) 2014-2018 the original authors or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.sarl.lang.sarlc.modules.general;
import java.io.File;
import java.util.Map.Entry;
import com.google.inject.AbstractModule;
import com.google.inject.Injector;
import com.google.inject.Provider;
import com.google.inject.Provides;
import com.google.inject.Singleton;
import org.eclipse.xtext.diagnostics.Severity;
import org.eclipse.xtext.util.Strings;
import io.sarl.lang.compiler.batch.SarlBatchCompiler;
import io.sarl.lang.compiler.batch.SarlBatchCompiler.IssueMessageFormatter;
import io.sarl.lang.sarlc.configs.SarlConfig;
import io.sarl.lang.sarlc.configs.subconfigs.CompilerConfig;
import io.sarl.lang.sarlc.configs.subconfigs.ValidatorConfig;
import io.sarl.lang.sarlc.tools.SARLBootClasspathProvider;
/** Module for creating the SARL batch compiler with the configuration provided by bootique modules.
*
* @author $Author: sgalland$
* @version $FullVersion$
* @mavengroupid $GroupId$
* @mavenartifactid $ArtifactId$
* @since 0.8
*/
public class SarlBatchCompilerModule extends AbstractModule {
@Override
protected void configure() {
//
}
/** Replies the formatter of the issue messages.
*
* @return the formatter
*/
@SuppressWarnings("static-method")
@Provides
@Singleton
public IssueMessageFormatter provideIssueMessageFormatter() {
return (issue, uriToProblem) -> {
// Use the default formatter.
return null;
};
}
/** Replies the SARL batch compiler.
*
* @param injector the current injector.
* @param config the configuration for the paths.
* @param defaultBootClasspath the SARL boot class path that must be used by default.
* @param issueMessageFormater the formatter of the issue messages.
* @return the SARL batch compiler
*/
@SuppressWarnings({"static-method", "checkstyle:npathcomplexity"})
@Provides
@Singleton
public SarlBatchCompiler provideSarlBatchCompiler(
Injector injector, Provider<SarlConfig> config, Provider<SARLBootClasspathProvider> defaultBootClasspath,
Provider<IssueMessageFormatter> issueMessageFormater) {
final SarlConfig cfg = config.get();
final CompilerConfig compilerConfig = cfg.getCompiler();
final ValidatorConfig validatorConfig = cfg.getValidator();
final SarlBatchCompiler compiler = new SarlBatchCompiler();
injector.injectMembers(compiler);
String fullClassPath = cfg.getBootClasspath();
if (Strings.isEmpty(fullClassPath)) {
fullClassPath = defaultBootClasspath.get().getClasspath();
}
final String userClassPath = cfg.getClasspath();
if (!Strings.isEmpty(userClassPath) && !Strings.isEmpty(fullClassPath)) {
fullClassPath = fullClassPath + File.pathSeparator + userClassPath;
}
compiler.setClassPath(fullClassPath);
if (!Strings.isEmpty(cfg.getJavaBootClasspath())) {
compiler.setBootClassPath(cfg.getJavaBootClasspath());
}
if (!Strings.isEmpty(compilerConfig.getFileEncoding())) {
compiler.setFileEncoding(compilerConfig.getFileEncoding());
}
if (!Strings.isEmpty(compilerConfig.getJavaVersion())) {
compiler.setJavaSourceVersion(compilerConfig.getJavaVersion());
}
compiler.setJavaPostCompilationEnable(compilerConfig.getJavaCompiler());
compiler.setWriteTraceFiles(compilerConfig.getOutputTraceFiles());
compiler.setWriteStorageFiles(compilerConfig.getOutputTraceFiles());
compiler.setGenerateInlineAnnotation(compilerConfig.getGenerateInlines());
compiler.setUseExpressionInterpreterForInlineAnnotation(compilerConfig.getCompressInlineExpressions());
compiler.setGeneratePureAnnotation(compilerConfig.getGeneratePures());
compiler.setGenerateEqualityTestFunctions(compilerConfig.getGenerateEqualityTests());
compiler.setGenerateToStringFunctions(compilerConfig.getGenerateToString());
compiler.setGenerateCloneFunctions(compilerConfig.getGenerateClone());
compiler.setGenerateSerialNumberFields(compilerConfig.getGenerateSerialIds());
if (validatorConfig.getAllErrors()) {
compiler.setAllWarningSeverities(Severity.ERROR);
} else if (validatorConfig.getIgnoreWarnings()) {
compiler.setAllWarningSeverities(Severity.IGNORE);
}
for (final Entry<String, Severity> entry : validatorConfig.getWarningLevels().entrySet()) {
compiler.setWarningSeverity(entry.getKey(), entry.getValue());
}
compiler.setIssueMessageFormatter(issueMessageFormater.get());
return compiler;
}
}