我向项目添加了简单的注释驱动方面,而IntelliJ无法对其进行编译:

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


请注意,应该在何处配置编译级别(在项目设置中,整个项目和所有模块的Java 6都应设置为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
+}

最佳答案

尝试

source="1.5"


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

08-26 14:42