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.

JavaOptions.java 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /********************************************************************
  2. * Copyright (c) 2007 Contributors. All rights reserved.
  3. * This program and the accompanying materials are made available
  4. * under the terms of the Eclipse Public License v 2.0
  5. * which accompanies this distribution and is available at
  6. * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt
  7. *
  8. * Contributors: IBM Corporation - initial API and implementation
  9. * Helen Hawkins - initial version (bug 148190)
  10. *******************************************************************/
  11. package org.aspectj.ajde.core;
  12. import java.util.HashMap;
  13. import java.util.Map;
  14. import org.aspectj.org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
  15. /**
  16. * Class containing the current custom java options
  17. */
  18. public final class JavaOptions {
  19. public static final String COMPLIANCE_LEVEL = CompilerOptions.OPTION_Compliance;
  20. public static final String SOURCE_COMPATIBILITY_LEVEL = CompilerOptions.OPTION_Source;
  21. public static final String TARGET_COMPATIBILITY_LEVEL = CompilerOptions.OPTION_TargetPlatform;
  22. // Version constants
  23. public static final String VERSION_13 = CompilerOptions.VERSION_1_3;
  24. public static final String VERSION_14 = CompilerOptions.VERSION_1_4;
  25. public static final String VERSION_15 = CompilerOptions.VERSION_1_5;
  26. public static final String VERSION_16 = CompilerOptions.VERSION_1_6;
  27. // by default will use the platform default encoding
  28. public static final String CHARACTER_ENCODING = CompilerOptions.OPTION_Encoding;
  29. // indicates if unused/optimizable local variables need to be preserved (debugging purpose)
  30. public static final String PRESERVE_ALL_LOCALS = CompilerOptions.OPTION_PreserveUnusedLocal;
  31. public static final String PRESERVE = CompilerOptions.PRESERVE;
  32. public static final String OPTIMIZE = CompilerOptions.OPTIMIZE_OUT;
  33. // Warning constants
  34. public static final String WARN_METHOD_WITH_CONSTRUCTOR_NAME = CompilerOptions.OPTION_ReportMethodWithConstructorName;
  35. public static final String WARN_OVERRIDING_PACKAGE_DEFAULT_METHOD = CompilerOptions.OPTION_ReportOverridingPackageDefaultMethod;
  36. public static final String WARN_DEPRECATION = CompilerOptions.OPTION_ReportDeprecation;
  37. public static final String WARN_HIDDEN_CATCH_BLOCKS = CompilerOptions.OPTION_ReportHiddenCatchBlock;
  38. public static final String WARN_UNUSED_LOCALS = CompilerOptions.OPTION_ReportUnusedLocal;
  39. public static final String WARN_UNUSED_PARAMETER = CompilerOptions.OPTION_ReportUnusedParameter;
  40. public static final String WARN_UNUSED_IMPORTS = CompilerOptions.OPTION_ReportUnusedImport;
  41. public static final String WARN_SYNTHETIC_ACCESS = CompilerOptions.OPTION_ReportSyntheticAccessEmulation;
  42. public static final String WARN_ASSERT_IDENITIFIER = CompilerOptions.OPTION_ReportAssertIdentifier;
  43. public static final String WARN_NON_NLS = CompilerOptions.OPTION_ReportNonExternalizedStringLiteral;
  44. // warning option constants
  45. public static final String IGNORE = CompilerOptions.IGNORE;
  46. public static final String WARNING = CompilerOptions.WARNING;
  47. // Debug constants
  48. public static final String DEBUG_SOURCE = CompilerOptions.OPTION_SourceFileAttribute;
  49. public static final String DEBUG_LINES = CompilerOptions.OPTION_LocalVariableAttribute;
  50. public static final String DEBUG_VARS = CompilerOptions.OPTION_LineNumberAttribute;
  51. // Debug option constants
  52. public static final String GENERATE = CompilerOptions.GENERATE;
  53. public static final String DO_NOT_GENERATE = CompilerOptions.DO_NOT_GENERATE;
  54. private static Map<String,String> defaultOptionsMap;
  55. /**
  56. * @return the java options map with the default settings
  57. */
  58. public static Map<String,String> getDefaultJavaOptions() {
  59. if (defaultOptionsMap != null) return defaultOptionsMap;
  60. defaultOptionsMap = new HashMap<>();
  61. defaultOptionsMap.put(COMPLIANCE_LEVEL, VERSION_14);
  62. defaultOptionsMap.put(SOURCE_COMPATIBILITY_LEVEL, VERSION_13);
  63. defaultOptionsMap.put(PRESERVE_ALL_LOCALS, OPTIMIZE);
  64. defaultOptionsMap.put(WARN_METHOD_WITH_CONSTRUCTOR_NAME, IGNORE);
  65. defaultOptionsMap.put(WARN_OVERRIDING_PACKAGE_DEFAULT_METHOD, IGNORE);
  66. defaultOptionsMap.put(WARN_DEPRECATION, IGNORE);
  67. defaultOptionsMap.put(WARN_HIDDEN_CATCH_BLOCKS, IGNORE);
  68. defaultOptionsMap.put(WARN_UNUSED_LOCALS, IGNORE);
  69. defaultOptionsMap.put(WARN_UNUSED_PARAMETER, IGNORE);
  70. defaultOptionsMap.put(WARN_UNUSED_IMPORTS, IGNORE);
  71. defaultOptionsMap.put(WARN_SYNTHETIC_ACCESS, IGNORE);
  72. defaultOptionsMap.put(WARN_ASSERT_IDENITIFIER, IGNORE);
  73. defaultOptionsMap.put(WARN_NON_NLS, IGNORE);
  74. defaultOptionsMap.put(DEBUG_SOURCE, GENERATE);
  75. defaultOptionsMap.put(DEBUG_LINES, GENERATE);
  76. defaultOptionsMap.put(DEBUG_VARS, DO_NOT_GENERATE);
  77. return defaultOptionsMap;
  78. }
  79. /**
  80. * @return true if the given value is a valid JVM version
  81. * (JavaOptions.VERSION_13, JavaOptions.VERSION_134, JavaOptions.VERSION_15,
  82. * JavaOptions.VERSION_16) and false otherwise
  83. */
  84. public static boolean isValidJvmVersion(String value) {
  85. return VERSION_13.equals(value) || VERSION_14.equals(value)
  86. || VERSION_15.equals(value) || VERSION_16.equals(value);
  87. }
  88. /**
  89. * @return true if the given option is JavaOptions.PRESERVE or
  90. * JavaOptions.OPTIMIZE and false otherwise
  91. */
  92. public static boolean isValidPreserveAllLocalsOption(String option) {
  93. return PRESERVE.equals(option) || OPTIMIZE.equals(option);
  94. }
  95. /**
  96. * @return true if the given option is JavaOptions.IGNORE or
  97. * JavaOptions.WARNING and false otherwise
  98. */
  99. public static boolean isIgnoreOrWarning(String option) {
  100. return IGNORE.equals(option) || WARNING.equals(option);
  101. }
  102. /**
  103. * @return true if the given option is JavaOptions.GENERATE or
  104. * JavaOptions.DO_NOT_GENERATE and false otherwise
  105. */
  106. public static boolean isGenerateOrNot(String option) {
  107. return GENERATE.equals(option) || DO_NOT_GENERATE.equals(option);
  108. }
  109. }