diff options
author | Reinier Zwitserloot <reinier@zwitserloot.com> | 2013-03-24 19:14:10 +0100 |
---|---|---|
committer | Reinier Zwitserloot <reinier@zwitserloot.com> | 2013-05-23 21:25:30 +0200 |
commit | 4152eee126bcb6a0403d3e7a79fe336944031268 (patch) | |
tree | a255c5d4815752ca2a31c1e9eba7dd1a888b2f34 /src/utils/lombok | |
parent | ffb3527daa05c966f40cccb3bbd93133b5775c7b (diff) | |
download | lombok-4152eee126bcb6a0403d3e7a79fe336944031268.tar.gz lombok-4152eee126bcb6a0403d3e7a79fe336944031268.tar.bz2 lombok-4152eee126bcb6a0403d3e7a79fe336944031268.zip |
Added a method to obtain latest java language spec supported by host
platform and implemented it for javac BUT NOT FOR ECJ!
Diffstat (limited to 'src/utils/lombok')
-rw-r--r-- | src/utils/lombok/javac/CommentCatcher.java | 4 | ||||
-rw-r--r-- | src/utils/lombok/javac/Javac.java | 20 |
2 files changed, 21 insertions, 3 deletions
diff --git a/src/utils/lombok/javac/CommentCatcher.java b/src/utils/lombok/javac/CommentCatcher.java index 474dc43d..2825cd30 100644 --- a/src/utils/lombok/javac/CommentCatcher.java +++ b/src/utils/lombok/javac/CommentCatcher.java @@ -62,7 +62,7 @@ public class CommentCatcher { private static void registerCommentsCollectingScannerFactory(Context context) { try { - if (JavaCompiler.version().startsWith("1.6")) { + if (Javac.getJavaCompilerVersion() <= 6) { Class.forName("lombok.javac.java6.CommentCollectingScannerFactory").getMethod("preRegister", Context.class).invoke(null, context); } else { Class.forName("lombok.javac.java7.CommentCollectingScannerFactory").getMethod("preRegister", Context.class).invoke(null, context); @@ -76,7 +76,7 @@ public class CommentCatcher { private static void setInCompiler(JavaCompiler compiler, Context context, Map<JCCompilationUnit, List<CommentInfo>> commentsMap) { try { - if (JavaCompiler.version().startsWith("1.6")) { + if (Javac.getJavaCompilerVersion() <= 6) { Class<?> parserFactory = Class.forName("lombok.javac.java6.CommentCollectingParserFactory"); parserFactory.getMethod("setInCompiler",JavaCompiler.class, Context.class, Map.class).invoke(null, compiler, context, commentsMap); } else { diff --git a/src/utils/lombok/javac/Javac.java b/src/utils/lombok/javac/Javac.java index 75bb2dbf..b4e58b8f 100644 --- a/src/utils/lombok/javac/Javac.java +++ b/src/utils/lombok/javac/Javac.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009-2012 The Project Lombok Authors. + * Copyright (C) 2009-2013 The Project Lombok Authors. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -21,9 +21,11 @@ */ package lombok.javac; +import java.util.regex.Matcher; import java.util.regex.Pattern; import com.sun.tools.javac.code.TypeTags; +import com.sun.tools.javac.main.JavaCompiler; import com.sun.tools.javac.tree.JCTree; import com.sun.tools.javac.tree.JCTree.JCExpression; import com.sun.tools.javac.tree.JCTree.JCFieldAccess; @@ -42,6 +44,22 @@ public class Javac { private static final Pattern PRIMITIVE_TYPE_NAME_PATTERN = Pattern.compile( "^(boolean|byte|short|int|long|float|double|char)$"); + private static final Pattern VERSION_PARSER = Pattern.compile("^(\\d{1,6})\\.(\\d{1,6}).*$"); + + /** + * Returns the version of this java compiler, i.e. the JDK that it shipped in. For example, for javac v1.7, this returns {@code 7}. + */ + public static int getJavaCompilerVersion() { + Matcher m = VERSION_PARSER.matcher(JavaCompiler.version()); + if (m.matches()) { + int major = Integer.parseInt(m.group(1)); + int minor = Integer.parseInt(m.group(2)); + if (major == 1) return minor; + } + + return 6; + } + /** * Checks if the given expression (that really ought to refer to a type expression) represents a primitive type. */ |