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 16KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  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 v1.0
  6. * which accompanies this distribution and is available at
  7. * http://www.eclipse.org/legal/epl-v10.html
  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.GROUP2 | ASTNode.Bit8;
  47. public static final int InvalidWildCardTypeName = IrritantSet.GROUP2 | ASTNode.Bit9;
  48. public static final int UnresolvableMember = IrritantSet.GROUP2 | ASTNode.Bit10;
  49. public static final int TypeNotExposedToWeaver = IrritantSet.GROUP2 | ASTNode.Bit11;
  50. public static final int ShadowNotInStructure = IrritantSet.GROUP2 | ASTNode.Bit12;
  51. public static final int UnmatchedSuperTypeInCall = IrritantSet.GROUP2 | ASTNode.Bit13;
  52. public static final int CannotImplementLazyTJP = IrritantSet.GROUP2 | ASTNode.Bit14;
  53. public static final int NeedSerialVersionUIDField = IrritantSet.GROUP2 | ASTNode.Bit15;
  54. public static final int IncompatibleSerialVersion = IrritantSet.GROUP2 | ASTNode.Bit16;
  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 = false;
  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. /**
  93. * Initializing the compiler options with external settings
  94. *
  95. * @param settings
  96. */
  97. public AjCompilerOptions(Map settings) {
  98. setAspectJWarningDefaults();
  99. if (settings == null) {
  100. return;
  101. }
  102. set(settings);
  103. }
  104. /*
  105. * (non-Javadoc)
  106. *
  107. * @see org.eclipse.jdt.internal.compiler.impl.CompilerOptions#getMap()
  108. */
  109. public Map getMap() {
  110. Map map = super.getMap();
  111. // now add AspectJ additional options
  112. map.put(OPTION_ReportInvalidAbsoluteTypeName, getSeverityString(InvalidAbsoluteTypeName));
  113. map.put(OPTION_ReportInvalidWildcardTypeName, getSeverityString(InvalidWildCardTypeName));
  114. map.put(OPTION_ReportUnresolvableMember, getSeverityString(UnresolvableMember));
  115. map.put(OPTION_ReportTypeNotExposedToWeaver, getSeverityString(TypeNotExposedToWeaver));
  116. map.put(OPTION_ReportShadowNotInStructure, getSeverityString(ShadowNotInStructure));
  117. map.put(OPTION_ReportUnmatchedSuperTypeInCall, getSeverityString(UnmatchedSuperTypeInCall));
  118. map.put(OPTION_ReportCannotImplementLazyTJP, getSeverityString(CannotImplementLazyTJP));
  119. map.put(OPTION_ReportNeedSerialVersionUIDField, getSeverityString(NeedSerialVersionUIDField));
  120. map.put(OPTION_ReportIncompatibleSerialVersion, getSeverityString(IncompatibleSerialVersion));
  121. map.put(CompilerOptions.OPTION_ReportSwallowedExceptionInCatchBlock,
  122. getSeverityString(CompilerOptions.SwallowedExceptionInCatchBlock));
  123. map.put(OPTION_TerminateAfterCompilation, this.terminateAfterCompilation ? ENABLED : DISABLED);
  124. map.put(OPTION_XSerializableAspects, this.xSerializableAspects ? ENABLED : DISABLED);
  125. map.put(OPTION_XLazyThisJoinPoint, this.xLazyThisJoinPoint ? ENABLED : DISABLED);
  126. map.put(OPTION_XNoInline, this.xNoInline ? ENABLED : DISABLED);
  127. map.put(OPTION_XNotReweavable, this.xNotReweavable ? ENABLED : DISABLED);
  128. map.put(OPTION_XHasMember, this.xHasMember ? ENABLED : DISABLED);
  129. map.put(OPTION_XdevPinpoint, this.xdevPinpoint ? ENABLED : DISABLED);
  130. map.put(OPTION_GenerateModel, this.generateModel ? ENABLED : DISABLED);
  131. map.put(OPTION_GenerateJavaDocsInModel, this.generateJavaDocsInModel ? ENABLED : DISABLED);
  132. map.put(OPTION_Emacssym, this.generateEmacsSymFiles ? ENABLED : DISABLED);
  133. map.put(OPTION_XDevNoAtAspectJProcessing, this.noAtAspectJProcessing ? ENABLED : DISABLED);
  134. return map;
  135. }
  136. /*
  137. * (non-Javadoc)
  138. *
  139. * @see org.eclipse.jdt.internal.compiler.impl.CompilerOptions#set(java.util.Map)
  140. */
  141. public void set(Map optionsMap) {
  142. super.set(optionsMap);
  143. Object optionValue;
  144. if ((optionValue = optionsMap.get(OPTION_ReportUnusedPrivateMember)) != null) {
  145. updateSeverity(UnusedPrivateMember, optionValue);
  146. }
  147. if ((optionValue = optionsMap.get(OPTION_ReportInvalidAbsoluteTypeName)) != null) {
  148. updateSeverity(InvalidAbsoluteTypeName, optionValue);
  149. }
  150. if ((optionValue = optionsMap.get(OPTION_ReportInvalidWildcardTypeName)) != null) {
  151. updateSeverity(InvalidWildCardTypeName, optionValue);
  152. }
  153. if ((optionValue = optionsMap.get(OPTION_ReportUnresolvableMember)) != null) {
  154. updateSeverity(UnresolvableMember, optionValue);
  155. }
  156. if ((optionValue = optionsMap.get(OPTION_ReportTypeNotExposedToWeaver)) != null) {
  157. updateSeverity(TypeNotExposedToWeaver, optionValue);
  158. }
  159. if ((optionValue = optionsMap.get(OPTION_ReportShadowNotInStructure)) != null) {
  160. updateSeverity(ShadowNotInStructure, optionValue);
  161. }
  162. if ((optionValue = optionsMap.get(OPTION_ReportUnmatchedSuperTypeInCall)) != null) {
  163. updateSeverity(UnmatchedSuperTypeInCall, optionValue);
  164. }
  165. if ((optionValue = optionsMap.get(OPTION_ReportCannotImplementLazyTJP)) != null) {
  166. updateSeverity(CannotImplementLazyTJP, optionValue);
  167. }
  168. if ((optionValue = optionsMap.get(OPTION_ReportNeedSerialVersionUIDField)) != null) {
  169. updateSeverity(NeedSerialVersionUIDField, optionValue);
  170. }
  171. if ((optionValue = optionsMap.get(OPTION_ReportIncompatibleSerialVersion)) != null) {
  172. updateSeverity(IncompatibleSerialVersion, optionValue);
  173. }
  174. if ((optionValue = optionsMap.get(CompilerOptions.OPTION_ReportSwallowedExceptionInCatchBlock)) != null) {
  175. updateSeverity(CompilerOptions.SwallowedExceptionInCatchBlock, optionValue);
  176. }
  177. if ((optionValue = optionsMap.get(OPTION_TerminateAfterCompilation)) != null) {
  178. if (ENABLED.equals(optionValue)) {
  179. this.terminateAfterCompilation = true;
  180. } else if (DISABLED.equals(optionValue)) {
  181. this.terminateAfterCompilation = false;
  182. }
  183. }
  184. if ((optionValue = optionsMap.get(OPTION_XSerializableAspects)) != null) {
  185. if (ENABLED.equals(optionValue)) {
  186. this.xSerializableAspects = true;
  187. } else if (DISABLED.equals(optionValue)) {
  188. this.xSerializableAspects = false;
  189. }
  190. }
  191. if ((optionValue = optionsMap.get(OPTION_XLazyThisJoinPoint)) != null) {
  192. if (ENABLED.equals(optionValue)) {
  193. this.xLazyThisJoinPoint = true;
  194. } else if (DISABLED.equals(optionValue)) {
  195. this.xLazyThisJoinPoint = false;
  196. }
  197. }
  198. if ((optionValue = optionsMap.get(OPTION_XNoInline)) != null) {
  199. if (ENABLED.equals(optionValue)) {
  200. this.xNoInline = true;
  201. } else if (DISABLED.equals(optionValue)) {
  202. this.xNoInline = false;
  203. }
  204. }
  205. if ((optionValue = optionsMap.get(OPTION_XNotReweavable)) != null) {
  206. if (ENABLED.equals(optionValue)) {
  207. this.xNotReweavable = true;
  208. } else if (DISABLED.equals(optionValue)) {
  209. this.xNotReweavable = false;
  210. }
  211. }
  212. /*
  213. * if ((optionValue = optionsMap.get(OPTION_XReweavableCompress)) != null) { if (ENABLED.equals(optionValue)) {
  214. * this.xReweavableCompress = true; } else if (DISABLED.equals(optionValue)) { this.xReweavableCompress = false; } }
  215. */
  216. if ((optionValue = optionsMap.get(OPTION_XHasMember)) != null) {
  217. if (ENABLED.equals(optionValue)) {
  218. this.xHasMember = true;
  219. } else if (DISABLED.equals(optionValue)) {
  220. this.xHasMember = false;
  221. }
  222. }
  223. if ((optionValue = optionsMap.get(OPTION_XdevPinpoint)) != null) {
  224. if (ENABLED.equals(optionValue)) {
  225. this.xdevPinpoint = true;
  226. } else if (DISABLED.equals(optionValue)) {
  227. this.xdevPinpoint = false;
  228. }
  229. }
  230. if ((optionValue = optionsMap.get(OPTION_GenerateModel)) != null) {
  231. if (ENABLED.equals(optionValue)) {
  232. this.generateModel = true;
  233. } else if (DISABLED.equals(optionValue)) {
  234. this.generateModel = false;
  235. }
  236. }
  237. if ((optionValue = optionsMap.get(OPTION_GenerateJavaDocsInModel)) != null) {
  238. if (ENABLED.equals(optionValue)) {
  239. this.generateJavaDocsInModel = true;
  240. } else if (DISABLED.equals(optionValue)) {
  241. this.generateJavaDocsInModel = false;
  242. }
  243. }
  244. if ((optionValue = optionsMap.get(OPTION_Emacssym)) != null) {
  245. if (ENABLED.equals(optionValue)) {
  246. this.generateEmacsSymFiles = true;
  247. } else if (DISABLED.equals(optionValue)) {
  248. this.generateEmacsSymFiles = false;
  249. }
  250. }
  251. if ((optionValue = optionsMap.get(OPTION_XDevNoAtAspectJProcessing)) != null) {
  252. if (ENABLED.equals(optionValue)) {
  253. this.noAtAspectJProcessing = true;
  254. } else if (DISABLED.equals(optionValue)) {
  255. this.noAtAspectJProcessing = false;
  256. }
  257. }
  258. }
  259. /**
  260. * Add these warnings to the default set...
  261. */
  262. private void setAspectJWarningDefaults() {
  263. super.warningThreshold = new IrritantSet(super.warningThreshold);
  264. super.warningThreshold.set(InvalidAbsoluteTypeName | UnresolvableMember | TypeNotExposedToWeaver
  265. | UnmatchedSuperTypeInCall | CannotImplementLazyTJP | CompilerOptions.SwallowedExceptionInCatchBlock);
  266. }
  267. /*
  268. * (non-Javadoc)
  269. *
  270. * @see java.lang.Object#toString()
  271. */
  272. public String toString() {
  273. StringBuffer buf = new StringBuffer(super.toString());
  274. // now add AspectJ additional options
  275. buf.append("\n\tAspectJ Specific Options:");
  276. buf.append("\n\t- terminate after compilation: ").append(this.terminateAfterCompilation ? ENABLED : DISABLED); //$NON-NLS-1$
  277. buf.append("\n\t- no inline (X option): ").append(this.xNoInline ? ENABLED : DISABLED); //$NON-NLS-1$
  278. buf.append("\n\t- generate serializable aspects (X option): ").append(this.xSerializableAspects ? ENABLED : DISABLED); //$NON-NLS-1$
  279. buf.append("\n\t- lazy thisJoinPoint (X option): ").append(this.xLazyThisJoinPoint ? ENABLED : DISABLED); //$NON-NLS-1$
  280. buf.append("\n\t- generate non-reweavable class files (X option): ").append(this.xNotReweavable ? ENABLED : DISABLED); //$NON-NLS-1$
  281. buf.append("\n\t- has member support (X option): ").append(this.xHasMember ? ENABLED : DISABLED); //$NON-NLS-1$
  282. buf.append("\n\t- generate AJDE model: ").append(this.generateModel ? ENABLED : DISABLED); //$NON-NLS-1$
  283. buf.append("\n\t- generate Javadocs in AJDE model: ").append(this.generateJavaDocsInModel ? ENABLED : DISABLED); //$NON-NLS-1$
  284. buf.append("\n\t- generate Emacs symbol files: ").append(this.generateEmacsSymFiles ? ENABLED : DISABLED); //$NON-NLS-1$
  285. buf.append("\n\t- suppress @AspectJ processing: ").append(this.noAtAspectJProcessing ? ENABLED : DISABLED); //$NON-NLS-1$
  286. buf.append("\n\t- invalid absolute type name (XLint): ").append(getSeverityString(InvalidAbsoluteTypeName)); //$NON-NLS-1$
  287. buf.append("\n\t- invalid wildcard type name (XLint): ").append(getSeverityString(InvalidWildCardTypeName)); //$NON-NLS-1$
  288. buf.append("\n\t- unresolvable member (XLint): ").append(getSeverityString(UnresolvableMember)); //$NON-NLS-1$
  289. buf.append("\n\t- type not exposed to weaver (XLint): ").append(getSeverityString(TypeNotExposedToWeaver)); //$NON-NLS-1$
  290. buf.append("\n\t- shadow not in structure (XLint): ").append(getSeverityString(ShadowNotInStructure)); //$NON-NLS-1$
  291. buf.append("\n\t- unmatched super type in call (XLint): ").append(getSeverityString(UnmatchedSuperTypeInCall)); //$NON-NLS-1$
  292. buf.append("\n\t- cannot implement lazy thisJoinPoint (XLint): ").append(getSeverityString(CannotImplementLazyTJP)); //$NON-NLS-1$
  293. buf.append("\n\t- need serialVersionUID field (XLint): ").append(getSeverityString(NeedSerialVersionUIDField)); //$NON-NLS-1$
  294. buf.append("\n\t- incompatible serial version (XLint): ").append(getSeverityString(IncompatibleSerialVersion)); //$NON-NLS-1$
  295. buf
  296. .append("\n\t- swallowed exception in catch block (XLint): ").append(getSeverityString(CompilerOptions.SwallowedExceptionInCatchBlock)); //$NON-NLS-1$
  297. return buf.toString();
  298. }
  299. }