| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
package org.mozilla.javascript; |
| 8 |
|
| 9 |
import java.util.Set; |
| 10 |
|
| 11 |
import org.mozilla.javascript.ast.ErrorCollector; |
| 12 |
|
| 13 |
public class CompilerEnvirons |
| 14 |
{ |
| 15 |
public CompilerEnvirons() |
| 16 |
{ |
| 17 |
errorReporter = DefaultErrorReporter.instance; |
| 18 |
languageVersion = Context.VERSION_DEFAULT; |
| 19 |
generateDebugInfo = true; |
| 20 |
reservedKeywordAsIdentifier = true; |
| 21 |
allowMemberExprAsFunctionName = false; |
| 22 |
xmlAvailable = true; |
| 23 |
optimizationLevel = 0; |
| 24 |
generatingSource = true; |
| 25 |
strictMode = false; |
| 26 |
warningAsError = false; |
| 27 |
generateObserverCount = false; |
| 28 |
allowSharpComments = false; |
| 29 |
} |
| 30 |
|
| 31 |
public void initFromContext(Context cx) |
| 32 |
{ |
| 33 |
setErrorReporter(cx.getErrorReporter()); |
| 34 |
languageVersion = cx.getLanguageVersion(); |
| 35 |
generateDebugInfo = (!cx.isGeneratingDebugChanged() |
| 36 |
|| cx.isGeneratingDebug()); |
| 37 |
reservedKeywordAsIdentifier |
| 38 |
= cx.hasFeature(Context.FEATURE_RESERVED_KEYWORD_AS_IDENTIFIER); |
| 39 |
allowMemberExprAsFunctionName |
| 40 |
= cx.hasFeature(Context.FEATURE_MEMBER_EXPR_AS_FUNCTION_NAME); |
| 41 |
strictMode |
| 42 |
= cx.hasFeature(Context.FEATURE_STRICT_MODE); |
| 43 |
warningAsError = cx.hasFeature(Context.FEATURE_WARNING_AS_ERROR); |
| 44 |
xmlAvailable |
| 45 |
= cx.hasFeature(Context.FEATURE_E4X); |
| 46 |
|
| 47 |
optimizationLevel = cx.getOptimizationLevel(); |
| 48 |
|
| 49 |
generatingSource = cx.isGeneratingSource(); |
| 50 |
activationNames = cx.activationNames; |
| 51 |
|
| 52 |
|
| 53 |
generateObserverCount = cx.generateObserverCount; |
| 54 |
} |
| 55 |
|
| 56 |
public final ErrorReporter getErrorReporter() |
| 57 |
{ |
| 58 |
return errorReporter; |
| 59 |
} |
| 60 |
|
| 61 |
public void setErrorReporter(ErrorReporter errorReporter) |
| 62 |
{ |
| 63 |
if (errorReporter == null) throw new IllegalArgumentException(); |
| 64 |
this.errorReporter = errorReporter; |
| 65 |
} |
| 66 |
|
| 67 |
public final int getLanguageVersion() |
| 68 |
{ |
| 69 |
return languageVersion; |
| 70 |
} |
| 71 |
|
| 72 |
public void setLanguageVersion(int languageVersion) |
| 73 |
{ |
| 74 |
Context.checkLanguageVersion(languageVersion); |
| 75 |
this.languageVersion = languageVersion; |
| 76 |
} |
| 77 |
|
| 78 |
public final boolean isGenerateDebugInfo() |
| 79 |
{ |
| 80 |
return generateDebugInfo; |
| 81 |
} |
| 82 |
|
| 83 |
public void setGenerateDebugInfo(boolean flag) |
| 84 |
{ |
| 85 |
this.generateDebugInfo = flag; |
| 86 |
} |
| 87 |
|
| 88 |
public final boolean isReservedKeywordAsIdentifier() |
| 89 |
{ |
| 90 |
return reservedKeywordAsIdentifier; |
| 91 |
} |
| 92 |
|
| 93 |
public void setReservedKeywordAsIdentifier(boolean flag) |
| 94 |
{ |
| 95 |
reservedKeywordAsIdentifier = flag; |
| 96 |
} |
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
public final boolean isAllowMemberExprAsFunctionName() |
| 103 |
{ |
| 104 |
return allowMemberExprAsFunctionName; |
| 105 |
} |
| 106 |
|
| 107 |
public void setAllowMemberExprAsFunctionName(boolean flag) |
| 108 |
{ |
| 109 |
allowMemberExprAsFunctionName = flag; |
| 110 |
} |
| 111 |
|
| 112 |
public final boolean isXmlAvailable() |
| 113 |
{ |
| 114 |
return xmlAvailable; |
| 115 |
} |
| 116 |
|
| 117 |
public void setXmlAvailable(boolean flag) |
| 118 |
{ |
| 119 |
xmlAvailable = flag; |
| 120 |
} |
| 121 |
|
| 122 |
public final int getOptimizationLevel() |
| 123 |
{ |
| 124 |
return optimizationLevel; |
| 125 |
} |
| 126 |
|
| 127 |
public void setOptimizationLevel(int level) |
| 128 |
{ |
| 129 |
Context.checkOptimizationLevel(level); |
| 130 |
this.optimizationLevel = level; |
| 131 |
} |
| 132 |
|
| 133 |
public final boolean isGeneratingSource() |
| 134 |
{ |
| 135 |
return generatingSource; |
| 136 |
} |
| 137 |
|
| 138 |
public boolean getWarnTrailingComma() { |
| 139 |
return warnTrailingComma; |
| 140 |
} |
| 141 |
|
| 142 |
public void setWarnTrailingComma(boolean warn) { |
| 143 |
warnTrailingComma = warn; |
| 144 |
} |
| 145 |
|
| 146 |
public final boolean isStrictMode() |
| 147 |
{ |
| 148 |
return strictMode; |
| 149 |
} |
| 150 |
|
| 151 |
public void setStrictMode(boolean strict) |
| 152 |
{ |
| 153 |
strictMode = strict; |
| 154 |
} |
| 155 |
|
| 156 |
public final boolean reportWarningAsError() |
| 157 |
{ |
| 158 |
return warningAsError; |
| 159 |
} |
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
public void setGeneratingSource(boolean generatingSource) |
| 171 |
{ |
| 172 |
this.generatingSource = generatingSource; |
| 173 |
} |
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
public boolean isGenerateObserverCount() { |
| 180 |
return generateObserverCount; |
| 181 |
} |
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
public void setGenerateObserverCount(boolean generateObserverCount) { |
| 195 |
this.generateObserverCount = generateObserverCount; |
| 196 |
} |
| 197 |
|
| 198 |
public boolean isRecordingComments() { |
| 199 |
return recordingComments; |
| 200 |
} |
| 201 |
|
| 202 |
public void setRecordingComments(boolean record) { |
| 203 |
recordingComments = record; |
| 204 |
} |
| 205 |
|
| 206 |
public boolean isRecordingLocalJsDocComments() { |
| 207 |
return recordingLocalJsDocComments; |
| 208 |
} |
| 209 |
|
| 210 |
public void setRecordingLocalJsDocComments(boolean record) { |
| 211 |
recordingLocalJsDocComments = record; |
| 212 |
} |
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
public void setRecoverFromErrors(boolean recover) { |
| 220 |
recoverFromErrors = recover; |
| 221 |
} |
| 222 |
|
| 223 |
public boolean recoverFromErrors() { |
| 224 |
return recoverFromErrors; |
| 225 |
} |
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
public void setIdeMode(boolean ide) { |
| 232 |
ideMode = ide; |
| 233 |
} |
| 234 |
|
| 235 |
public boolean isIdeMode() { |
| 236 |
return ideMode; |
| 237 |
} |
| 238 |
|
| 239 |
public Set<String> getActivationNames() { |
| 240 |
return activationNames; |
| 241 |
} |
| 242 |
|
| 243 |
public void setActivationNames(Set<String> activationNames) { |
| 244 |
this.activationNames = activationNames; |
| 245 |
} |
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
public void setAllowSharpComments(boolean allow) { |
| 251 |
allowSharpComments = allow; |
| 252 |
} |
| 253 |
|
| 254 |
public boolean getAllowSharpComments() { |
| 255 |
return allowSharpComments; |
| 256 |
} |
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
public static CompilerEnvirons ideEnvirons() { |
| 264 |
CompilerEnvirons env = new CompilerEnvirons(); |
| 265 |
env.setRecoverFromErrors(true); |
| 266 |
env.setRecordingComments(true); |
| 267 |
env.setStrictMode(true); |
| 268 |
env.setWarnTrailingComma(true); |
| 269 |
env.setLanguageVersion(170); |
| 270 |
env.setReservedKeywordAsIdentifier(true); |
| 271 |
env.setIdeMode(true); |
| 272 |
env.setErrorReporter(new ErrorCollector()); |
| 273 |
return env; |
| 274 |
} |
| 275 |
|
| 276 |
private ErrorReporter errorReporter; |
| 277 |
|
| 278 |
private int languageVersion; |
| 279 |
private boolean generateDebugInfo; |
| 280 |
private boolean reservedKeywordAsIdentifier; |
| 281 |
private boolean allowMemberExprAsFunctionName; |
| 282 |
private boolean xmlAvailable; |
| 283 |
private int optimizationLevel; |
| 284 |
private boolean generatingSource; |
| 285 |
private boolean strictMode; |
| 286 |
private boolean warningAsError; |
| 287 |
private boolean generateObserverCount; |
| 288 |
private boolean recordingComments; |
| 289 |
private boolean recordingLocalJsDocComments; |
| 290 |
private boolean recoverFromErrors; |
| 291 |
private boolean warnTrailingComma; |
| 292 |
private boolean ideMode; |
| 293 |
private boolean allowSharpComments; |
| 294 |
Set<String> activationNames; |
| 295 |
} |