You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AjCompilerOptions.java 15KB

21 jaren geleden
21 jaren geleden
21 jaren geleden
21 jaren geleden
19 jaren geleden
14 jaren geleden
10 jaren geleden
19 jaren geleden
21 jaren geleden
19 jaren geleden
19 jaren geleden
21 jaren geleden
21 jaren geleden
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. /* *******************************************************************
  2. * Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC).
  3. * All rights reserved.
  4. * This program and the accompanying materials are made available
  5. * under the terms of the Eclipse Public License v 2.0
  6. * which accompanies this distribution and is available at
  7. * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt
  8. *
  9. * Contributors:
  10. * PARC initial implementation
  11. * ******************************************************************/
  12. package org.aspectj.ajdt.internal.core.builder;
  13. import java.util.Map;
  14. import org.aspectj.org.eclipse.jdt.internal.compiler.ast.ASTNode;
  15. import org.aspectj.org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
  16. import org.aspectj.org.eclipse.jdt.internal.compiler.impl.IrritantSet;
  17. import org.aspectj.weaver.Constants;
  18. /**
  19. * Compiler options used by Eclipse integration (AJDT)
  20. */
  21. public class AjCompilerOptions extends CompilerOptions {
  22. // AspectJ Lint options
  23. public static final String OPTION_ReportInvalidAbsoluteTypeName = "org.aspectj.ajdt.core.compiler.lint.InvalidAbsoluteTypeName";
  24. public static final String OPTION_ReportInvalidWildcardTypeName = "org.aspectj.ajdt.core.compiler.lint.WildcardTypeName";
  25. public static final String OPTION_ReportUnresolvableMember = "org.aspectj.ajdt.core.compiler.lint.UnresolvableMember";
  26. public static final String OPTION_ReportTypeNotExposedToWeaver = "org.aspectj.ajdt.core.compiler.lint.TypeNotExposedToWeaver";
  27. public static final String OPTION_ReportShadowNotInStructure = "org.aspectj.ajdt.core.compiler.lint.ShadowNotInStructure";
  28. public static final String OPTION_ReportUnmatchedSuperTypeInCall = "org.aspectj.ajdt.core.compiler.list.UnmatchedSuperTypeInCall";
  29. public static final String OPTION_ReportCannotImplementLazyTJP = "org.aspectj.ajdt.core.compiler.lint.CannotImplementLazyTJP";
  30. public static final String OPTION_ReportNeedSerialVersionUIDField = "org.aspectj.ajdt.core.compiler.lint.NeedSerialVersionUIDField";
  31. public static final String OPTION_ReportIncompatibleSerialVersion = "org.aspectj.ajdt.core.compiler.lint.BrokeSerialVersionCompatibility";
  32. // General AspectJ Compiler options (excludes paths etc, these are handled separately)
  33. public static final String OPTION_TerminateAfterCompilation = "org.aspectj.ajdt.core.compiler.weaver.TerminateAfterCompilation";
  34. public static final String OPTION_XSerializableAspects = "org.aspectj.ajdt.core.compiler.weaver.XSerializableAspects";
  35. public static final String OPTION_XLazyThisJoinPoint = "org.aspectj.ajdt.core.compiler.weaver.XLazyThisJoinPoint";
  36. public static final String OPTION_XNoInline = "org.aspectj.ajdt.core.compiler.weaver.XNoInline";
  37. public static final String OPTION_XNotReweavable = "org.aspectj.ajdt.core.compiler.weaver.XNotReweavable";
  38. public static final String OPTION_XHasMember = "org.aspectj.ajdt.core.compiler.weaver.XHasMember";
  39. public static final String OPTION_XdevPinpoint = "org.aspectj.ajdt.core.compiler.weaver.XdevPinpoint";
  40. // these next four not exposed by IDEs
  41. public static final String OPTION_XDevNoAtAspectJProcessing = "org.aspectj.ajdt.core.compiler.ast.NoAtAspectJProcessing";
  42. public static final String OPTION_GenerateModel = "org.aspectj.ajdt.core.compiler.model.GenerateModel";
  43. public static final String OPTION_GenerateJavaDocsInModel = "org.aspectj.ajdt.core.compiler.model.GenerateJavaDocsInModel";
  44. public static final String OPTION_Emacssym = "org.aspectj.ajdt.core.compiler.model.Emacssym";
  45. // constants for irritant levels
  46. public static final int InvalidAbsoluteTypeName = IrritantSet.GROUP3 | ASTNode.Bit1;
  47. public static final int InvalidWildCardTypeName = IrritantSet.GROUP3 | ASTNode.Bit2;
  48. public static final int UnresolvableMember = IrritantSet.GROUP3 | ASTNode.Bit3;
  49. public static final int TypeNotExposedToWeaver = IrritantSet.GROUP3 | ASTNode.Bit4;
  50. public static final int ShadowNotInStructure = IrritantSet.GROUP3 | ASTNode.Bit5;
  51. public static final int UnmatchedSuperTypeInCall = IrritantSet.GROUP3 | ASTNode.Bit6;
  52. public static final int CannotImplementLazyTJP = IrritantSet.GROUP3 | ASTNode.Bit7;
  53. public static final int NeedSerialVersionUIDField = IrritantSet.GROUP3 | ASTNode.Bit8;
  54. public static final int IncompatibleSerialVersion = IrritantSet.GROUP3 | ASTNode.Bit9;
  55. public boolean terminateAfterCompilation = false;
  56. public boolean xSerializableAspects = false;
  57. public boolean xLazyThisJoinPoint = false;
  58. public boolean xNoInline = false;
  59. public boolean xNotReweavable = false;
  60. public boolean xHasMember = false;
  61. public boolean xdevPinpoint = false;
  62. public boolean showWeavingInformation = false;
  63. public String xOptionalJoinpoints = null;
  64. // If true - autoboxing behaves differently ...
  65. public boolean behaveInJava5Way = true;
  66. public boolean timing = false;
  67. // Specifies the level of the aspectjrt.jar we are targetting
  68. public String targetAspectjRuntimeLevel = Constants.RUNTIME_LEVEL_DEFAULT;
  69. public String xConfigurationInfo;
  70. public boolean addSerialVerUID = false;
  71. public boolean xmlConfigured = false;
  72. public boolean makeReflectable = false;
  73. // these next four not exposed by IDEs
  74. public boolean generateModel = false;
  75. public boolean generateJavaDocsInModel = false;
  76. public boolean generateEmacsSymFiles = false;
  77. public boolean noAtAspectJProcessing = false;
  78. /**
  79. * Generates a map of cross references based on information in the structure model.
  80. */
  81. public boolean generateCrossRefs = false;
  82. // Check aspectjrt*.jar exists and within it the version number is right (see AjBuildManager.checkRtJar())
  83. public boolean checkRuntimeVersion = true;
  84. public boolean proceedOnError = false;
  85. /**
  86. * Initializing the compiler options with defaults
  87. */
  88. public AjCompilerOptions() {
  89. super();
  90. setAspectJWarningDefaults();
  91. }
  92. public AjCompilerOptions(Map<String,String> settings) {
  93. setAspectJWarningDefaults();
  94. if (settings == null) {
  95. return;
  96. }
  97. set(settings);
  98. }
  99. @Override
  100. public Map<String,String> getMap() {
  101. Map<String,String> map = super.getMap();
  102. // now add AspectJ additional options
  103. map.put(OPTION_ReportInvalidAbsoluteTypeName, getSeverityString(InvalidAbsoluteTypeName));
  104. map.put(OPTION_ReportInvalidWildcardTypeName, getSeverityString(InvalidWildCardTypeName));
  105. map.put(OPTION_ReportUnresolvableMember, getSeverityString(UnresolvableMember));
  106. map.put(OPTION_ReportTypeNotExposedToWeaver, getSeverityString(TypeNotExposedToWeaver));
  107. map.put(OPTION_ReportShadowNotInStructure, getSeverityString(ShadowNotInStructure));
  108. map.put(OPTION_ReportUnmatchedSuperTypeInCall, getSeverityString(UnmatchedSuperTypeInCall));
  109. map.put(OPTION_ReportCannotImplementLazyTJP, getSeverityString(CannotImplementLazyTJP));
  110. map.put(OPTION_ReportNeedSerialVersionUIDField, getSeverityString(NeedSerialVersionUIDField));
  111. map.put(OPTION_ReportIncompatibleSerialVersion, getSeverityString(IncompatibleSerialVersion));
  112. map.put(CompilerOptions.OPTION_ReportSwallowedExceptionInCatchBlock,
  113. getSeverityString(CompilerOptions.SwallowedExceptionInCatchBlock));
  114. map.put(OPTION_TerminateAfterCompilation, this.terminateAfterCompilation ? ENABLED : DISABLED);
  115. map.put(OPTION_XSerializableAspects, this.xSerializableAspects ? ENABLED : DISABLED);
  116. map.put(OPTION_XLazyThisJoinPoint, this.xLazyThisJoinPoint ? ENABLED : DISABLED);
  117. map.put(OPTION_XNoInline, this.xNoInline ? ENABLED : DISABLED);
  118. map.put(OPTION_XNotReweavable, this.xNotReweavable ? ENABLED : DISABLED);
  119. map.put(OPTION_XHasMember, this.xHasMember ? ENABLED : DISABLED);
  120. map.put(OPTION_XdevPinpoint, this.xdevPinpoint ? ENABLED : DISABLED);
  121. map.put(OPTION_GenerateModel, this.generateModel ? ENABLED : DISABLED);
  122. map.put(OPTION_GenerateJavaDocsInModel, this.generateJavaDocsInModel ? ENABLED : DISABLED);
  123. map.put(OPTION_Emacssym, this.generateEmacsSymFiles ? ENABLED : DISABLED);
  124. map.put(OPTION_XDevNoAtAspectJProcessing, this.noAtAspectJProcessing ? ENABLED : DISABLED);
  125. return map;
  126. }
  127. @Override
  128. public void set(Map<String,String> optionsMap) {
  129. super.set(optionsMap);
  130. Object optionValue;
  131. if ((optionValue = optionsMap.get(OPTION_ReportUnusedPrivateMember)) != null) {
  132. updateSeverity(UnusedPrivateMember, optionValue);
  133. }
  134. if ((optionValue = optionsMap.get(OPTION_ReportInvalidAbsoluteTypeName)) != null) {
  135. updateSeverity(InvalidAbsoluteTypeName, optionValue);
  136. }
  137. if ((optionValue = optionsMap.get(OPTION_ReportInvalidWildcardTypeName)) != null) {
  138. updateSeverity(InvalidWildCardTypeName, optionValue);
  139. }
  140. if ((optionValue = optionsMap.get(OPTION_ReportUnresolvableMember)) != null) {
  141. updateSeverity(UnresolvableMember, optionValue);
  142. }
  143. if ((optionValue = optionsMap.get(OPTION_ReportTypeNotExposedToWeaver)) != null) {
  144. updateSeverity(TypeNotExposedToWeaver, optionValue);
  145. }
  146. if ((optionValue = optionsMap.get(OPTION_ReportShadowNotInStructure)) != null) {
  147. updateSeverity(ShadowNotInStructure, optionValue);
  148. }
  149. if ((optionValue = optionsMap.get(OPTION_ReportUnmatchedSuperTypeInCall)) != null) {
  150. updateSeverity(UnmatchedSuperTypeInCall, optionValue);
  151. }
  152. if ((optionValue = optionsMap.get(OPTION_ReportCannotImplementLazyTJP)) != null) {
  153. updateSeverity(CannotImplementLazyTJP, optionValue);
  154. }
  155. if ((optionValue = optionsMap.get(OPTION_ReportNeedSerialVersionUIDField)) != null) {
  156. updateSeverity(NeedSerialVersionUIDField, optionValue);
  157. }
  158. if ((optionValue = optionsMap.get(OPTION_ReportIncompatibleSerialVersion)) != null) {
  159. updateSeverity(IncompatibleSerialVersion, optionValue);
  160. }
  161. if ((optionValue = optionsMap.get(CompilerOptions.OPTION_ReportSwallowedExceptionInCatchBlock)) != null) {
  162. updateSeverity(CompilerOptions.SwallowedExceptionInCatchBlock, optionValue);
  163. }
  164. if ((optionValue = optionsMap.get(OPTION_TerminateAfterCompilation)) != null) {
  165. if (ENABLED.equals(optionValue)) {
  166. this.terminateAfterCompilation = true;
  167. } else if (DISABLED.equals(optionValue)) {
  168. this.terminateAfterCompilation = false;
  169. }
  170. }
  171. if ((optionValue = optionsMap.get(OPTION_XSerializableAspects)) != null) {
  172. if (ENABLED.equals(optionValue)) {
  173. this.xSerializableAspects = true;
  174. } else if (DISABLED.equals(optionValue)) {
  175. this.xSerializableAspects = false;
  176. }
  177. }
  178. if ((optionValue = optionsMap.get(OPTION_XLazyThisJoinPoint)) != null) {
  179. if (ENABLED.equals(optionValue)) {
  180. this.xLazyThisJoinPoint = true;
  181. } else if (DISABLED.equals(optionValue)) {
  182. this.xLazyThisJoinPoint = false;
  183. }
  184. }
  185. if ((optionValue = optionsMap.get(OPTION_XNoInline)) != null) {
  186. if (ENABLED.equals(optionValue)) {
  187. this.xNoInline = true;
  188. } else if (DISABLED.equals(optionValue)) {
  189. this.xNoInline = false;
  190. }
  191. }
  192. if ((optionValue = optionsMap.get(OPTION_XNotReweavable)) != null) {
  193. if (ENABLED.equals(optionValue)) {
  194. this.xNotReweavable = true;
  195. } else if (DISABLED.equals(optionValue)) {
  196. this.xNotReweavable = false;
  197. }
  198. }
  199. /*
  200. * if ((optionValue = optionsMap.get(OPTION_XReweavableCompress)) != null) { if (ENABLED.equals(optionValue)) {
  201. * this.xReweavableCompress = true; } else if (DISABLED.equals(optionValue)) { this.xReweavableCompress = false; } }
  202. */
  203. if ((optionValue = optionsMap.get(OPTION_XHasMember)) != null) {
  204. if (ENABLED.equals(optionValue)) {
  205. this.xHasMember = true;
  206. } else if (DISABLED.equals(optionValue)) {
  207. this.xHasMember = false;
  208. }
  209. }
  210. if ((optionValue = optionsMap.get(OPTION_XdevPinpoint)) != null) {
  211. if (ENABLED.equals(optionValue)) {
  212. this.xdevPinpoint = true;
  213. } else if (DISABLED.equals(optionValue)) {
  214. this.xdevPinpoint = false;
  215. }
  216. }
  217. if ((optionValue = optionsMap.get(OPTION_GenerateModel)) != null) {
  218. if (ENABLED.equals(optionValue)) {
  219. this.generateModel = true;
  220. } else if (DISABLED.equals(optionValue)) {
  221. this.generateModel = false;
  222. }
  223. }
  224. if ((optionValue = optionsMap.get(OPTION_GenerateJavaDocsInModel)) != null) {
  225. if (ENABLED.equals(optionValue)) {
  226. this.generateJavaDocsInModel = true;
  227. } else if (DISABLED.equals(optionValue)) {
  228. this.generateJavaDocsInModel = false;
  229. }
  230. }
  231. if ((optionValue = optionsMap.get(OPTION_Emacssym)) != null) {
  232. if (ENABLED.equals(optionValue)) {
  233. this.generateEmacsSymFiles = true;
  234. } else if (DISABLED.equals(optionValue)) {
  235. this.generateEmacsSymFiles = false;
  236. }
  237. }
  238. if ((optionValue = optionsMap.get(OPTION_XDevNoAtAspectJProcessing)) != null) {
  239. if (ENABLED.equals(optionValue)) {
  240. this.noAtAspectJProcessing = true;
  241. } else if (DISABLED.equals(optionValue)) {
  242. this.noAtAspectJProcessing = false;
  243. }
  244. }
  245. }
  246. /**
  247. * Add these warnings to the default set...
  248. */
  249. private void setAspectJWarningDefaults() {
  250. super.warningThreshold = new IrritantSet(super.warningThreshold);
  251. super.warningThreshold.set(InvalidAbsoluteTypeName | UnresolvableMember | TypeNotExposedToWeaver
  252. | UnmatchedSuperTypeInCall | CannotImplementLazyTJP);
  253. super.warningThreshold.set(CompilerOptions.SwallowedExceptionInCatchBlock);
  254. }
  255. @Override
  256. public String toString() {
  257. StringBuilder buf = new StringBuilder(super.toString());
  258. // now add AspectJ additional options
  259. buf.append("\n\tAspectJ Specific Options:");
  260. buf.append("\n\t- terminate after compilation: ").append(this.terminateAfterCompilation ? ENABLED : DISABLED); //$NON-NLS-1$
  261. buf.append("\n\t- no inline (X option): ").append(this.xNoInline ? ENABLED : DISABLED); //$NON-NLS-1$
  262. buf.append("\n\t- generate serializable aspects (X option): ").append(this.xSerializableAspects ? ENABLED : DISABLED); //$NON-NLS-1$
  263. buf.append("\n\t- lazy thisJoinPoint (X option): ").append(this.xLazyThisJoinPoint ? ENABLED : DISABLED); //$NON-NLS-1$
  264. buf.append("\n\t- generate non-reweavable class files (X option): ").append(this.xNotReweavable ? ENABLED : DISABLED); //$NON-NLS-1$
  265. buf.append("\n\t- has member support (X option): ").append(this.xHasMember ? ENABLED : DISABLED); //$NON-NLS-1$
  266. buf.append("\n\t- generate AJDE model: ").append(this.generateModel ? ENABLED : DISABLED); //$NON-NLS-1$
  267. buf.append("\n\t- generate Javadocs in AJDE model: ").append(this.generateJavaDocsInModel ? ENABLED : DISABLED); //$NON-NLS-1$
  268. buf.append("\n\t- generate Emacs symbol files: ").append(this.generateEmacsSymFiles ? ENABLED : DISABLED); //$NON-NLS-1$
  269. buf.append("\n\t- suppress @AspectJ processing: ").append(this.noAtAspectJProcessing ? ENABLED : DISABLED); //$NON-NLS-1$
  270. buf.append("\n\t- invalid absolute type name (XLint): ").append(getSeverityString(InvalidAbsoluteTypeName)); //$NON-NLS-1$
  271. buf.append("\n\t- invalid wildcard type name (XLint): ").append(getSeverityString(InvalidWildCardTypeName)); //$NON-NLS-1$
  272. buf.append("\n\t- unresolvable member (XLint): ").append(getSeverityString(UnresolvableMember)); //$NON-NLS-1$
  273. buf.append("\n\t- type not exposed to weaver (XLint): ").append(getSeverityString(TypeNotExposedToWeaver)); //$NON-NLS-1$
  274. buf.append("\n\t- shadow not in structure (XLint): ").append(getSeverityString(ShadowNotInStructure)); //$NON-NLS-1$
  275. buf.append("\n\t- unmatched super type in call (XLint): ").append(getSeverityString(UnmatchedSuperTypeInCall)); //$NON-NLS-1$
  276. buf.append("\n\t- cannot implement lazy thisJoinPoint (XLint): ").append(getSeverityString(CannotImplementLazyTJP)); //$NON-NLS-1$
  277. buf.append("\n\t- need serialVersionUID field (XLint): ").append(getSeverityString(NeedSerialVersionUIDField)); //$NON-NLS-1$
  278. buf.append("\n\t- incompatible serial version (XLint): ").append(getSeverityString(IncompatibleSerialVersion)); //$NON-NLS-1$
  279. buf.append("\n\t- swallowed exception in catch block (XLint): ").append(getSeverityString(CompilerOptions.SwallowedExceptionInCatchBlock)); //$NON-NLS-1$
  280. return buf.toString();
  281. }
  282. }