0

我在项目中添加了简单的注释驱动方面,而 IntelliJ 无法编译它:

annotation type patterns are only supported at Java 5 compliance level or above

请告知,应该在哪里配置编译级别(在项目设置中,整个项目和所有模块都设置为 Java 6),在 settings->aspectj weaver 中只能启用 weaver 并查看方面列表。

UPD问题与 OpenJDK 有关,因为 aspectJ weaver 插件无法正确识别它的版本。补丁已提交给维护者。

--- src/common/se/expertsystem/intellij/PluginUtils.java.orig   2012-04-11 14:03:35.000000000 +0300
+++ src/common/se/expertsystem/intellij/PluginUtils.java    2012-04-11 14:47:11.000000000 +0300
@@ -31,32 +31,34 @@
  */
 package se.expertsystem.intellij;

+import com.intellij.openapi.application.ApplicationInfo;
+import com.intellij.openapi.application.ApplicationManager;
+import com.intellij.openapi.diagnostic.Logger;
 import com.intellij.openapi.module.Module;
 import com.intellij.openapi.module.ModuleManager;
-import com.intellij.openapi.roots.ModuleRootManager;
-import com.intellij.openapi.roots.OrderRootType;
-import com.intellij.openapi.util.io.FileUtil;
-import com.intellij.openapi.diagnostic.Logger;
 import com.intellij.openapi.progress.ProgressIndicator;
 import com.intellij.openapi.progress.ProgressManager;
 import com.intellij.openapi.project.Project;
-import com.intellij.openapi.application.ApplicationInfo;
-import com.intellij.openapi.application.ApplicationManager;
-import com.intellij.openapi.vfs.VirtualFile;
+import com.intellij.openapi.roots.ModuleRootManager;
+import com.intellij.openapi.roots.OrderRootType;
+import com.intellij.openapi.util.io.FileUtil;
 import com.intellij.openapi.vfs.VfsUtil;
+import com.intellij.openapi.vfs.VirtualFile;
 import com.intellij.util.ActionRunner;

-import java.util.List;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.io.IOException;
 import java.io.File;
-import java.lang.reflect.Method;
+import java.io.IOException;
 import java.lang.reflect.InvocationTargetException;
-import java.net.URL;
+import java.lang.reflect.Method;
+import java.net.MalformedURLException;
 import java.net.URI;
 import java.net.URISyntaxException;
-import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;

 /**
  * Class containing useful utility methods for IntelliJ IDEA plugins.
@@ -68,6 +70,8 @@

   private static final Class[] NO_PARAMETERS = new Class[] {};

+  private static final Pattern jdkVersionResolver = Pattern.compile("(java|openjdk)\\s+version\\s+\"(\\d+)\\.(\\d+)");
+
   /**
    * Find classpath for module. Returns list of <code>File</code>s.
    * @param project Project to get classpath for.
@@ -296,13 +300,21 @@
    */
   public static boolean isJava5(Module module) {
     final String versionString = getJdkVersionString(module);  // Example: java version "1.5.0_07"
-    if(versionString.startsWith("java version \"1.") && versionString.length() > "java version \"1.".length())
-      return versionString.charAt("java version \"1.".length()) >= '5';
-    LOG.error("Unparsable version string: " + versionString);
-    return false;
+    final Matcher versionMatcher = jdkVersionResolver.matcher(versionString);
+    if (!versionMatcher.find()) {
+      LOG.error("Unparsable version string (regex failed): " + versionString);
+      return false;
+    } else if (!("1".equals(versionMatcher.group(2)) 
+                && versionMatcher.group(3).charAt(0) >= '5')) {
+      LOG.error("Version invalid: major "+versionMatcher.group(2)+
+        " , minor "+versionMatcher.group(3));
+      return false;
+    }
+    LOG.info("Detected JDK: "+versionString);
+    return true;
   }

-  /////////////////////////////////////////////////////////////////////////////
+    /////////////////////////////////////////////////////////////////////////////
   // Methods for progress indication
   /////////////////////////////////////////////////////////////////////////////

@@ -382,4 +394,4 @@
       return modules;
     }
   }
-}
\ No newline at end of file
+}
4

2 回答 2

1

尝试

source="1.5"

插入到 build.xml 中的 iajc 任务中

于 2012-04-11T11:12:17.137 回答
0

我通过升级 aspectjweaver jar 解决了现有的合规级别。利用aspectjweaver-1.7.3.jar

于 2015-04-30T06:34:58.140 回答