You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@netbeans.apache.org by jl...@apache.org on 2017/12/12 04:19:28 UTC
[incubator-netbeans] 03/03: Adjusting to recent changes to Source
in JDK 10.
This is an automated email from the ASF dual-hosted git repository.
jlahoda pushed a commit to branch jdk-javac
in repository https://gitbox.apache.org/repos/asf/incubator-netbeans.git
commit 00d491b77e3b7803ed865719fe6da0e5c1a941b2
Author: Jan Lahoda <jl...@netbeans.org>
AuthorDate: Sun Dec 10 22:34:03 2017 +0100
Adjusting to recent changes to Source in JDK 10.
---
.../netbeans/api/java/source/ElementUtilities.java | 3 +-
.../modules/java/source/base/SourceLevelUtils.java | 37 ++++++++++++++++++++++
.../java/source/builder/ElementsService.java | 3 +-
.../java/source/parsing/CachingFileManager.java | 9 +++---
.../modules/java/source/parsing/JavacParser.java | 15 +++++----
.../java/source/parsing/ModuleFileManager.java | 9 +++---
6 files changed, 59 insertions(+), 17 deletions(-)
diff --git a/java.source.base/src/org/netbeans/api/java/source/ElementUtilities.java b/java.source.base/src/org/netbeans/api/java/source/ElementUtilities.java
index c61429e..665c0e7 100644
--- a/java.source.base/src/org/netbeans/api/java/source/ElementUtilities.java
+++ b/java.source.base/src/org/netbeans/api/java/source/ElementUtilities.java
@@ -89,6 +89,7 @@ import org.netbeans.api.annotations.common.NonNull;
import org.netbeans.api.annotations.common.NullAllowed;
import org.netbeans.modules.java.source.builder.ElementsService;
import org.netbeans.modules.java.source.JavadocEnv;
+import org.netbeans.modules.java.source.base.SourceLevelUtils;
import org.openide.util.Parameters;
/**
@@ -273,7 +274,7 @@ public final class ElementUtilities {
members.add(member);
}
}
- if (te.getKind().isClass() || te.getKind().isInterface() && Source.instance(ctx).allowDefaultMethods()) {
+ if (te.getKind().isClass() || te.getKind().isInterface() && SourceLevelUtils.allowDefaultMethods(Source.instance(ctx))) {
VarSymbol thisPseudoMember = new VarSymbol(Flags.FINAL | Flags.HASINIT, Names.instance(ctx)._this, (ClassType)te.asType(), (ClassSymbol)te);
if (acceptor == null || acceptor.accept(thisPseudoMember, type))
members.add(thisPseudoMember);
diff --git a/java.source.base/src/org/netbeans/modules/java/source/base/SourceLevelUtils.java b/java.source.base/src/org/netbeans/modules/java/source/base/SourceLevelUtils.java
new file mode 100644
index 0000000..5fb9037
--- /dev/null
+++ b/java.source.base/src/org/netbeans/modules/java/source/base/SourceLevelUtils.java
@@ -0,0 +1,37 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */package org.netbeans.modules.java.source.base;
+
+import com.sun.tools.javac.code.Source;
+
+/**
+ *
+ * @author lahvac
+ */
+public class SourceLevelUtils {
+
+ public static final Source JDK1_5 = Source.lookup("5");
+ public static final Source JDK1_6 = Source.lookup("6");
+ public static final Source JDK1_7 = Source.lookup("7");
+ public static final Source JDK1_8 = Source.lookup("8");
+ public static final Source JDK1_9 = Source.lookup("9");
+
+ public static boolean allowDefaultMethods(Source in) {
+ return in.compareTo(JDK1_8) >= 0;
+ }
+}
diff --git a/java.source.base/src/org/netbeans/modules/java/source/builder/ElementsService.java b/java.source.base/src/org/netbeans/modules/java/source/builder/ElementsService.java
index 40c0cad..7a48421 100644
--- a/java.source.base/src/org/netbeans/modules/java/source/builder/ElementsService.java
+++ b/java.source.base/src/org/netbeans/modules/java/source/builder/ElementsService.java
@@ -38,6 +38,7 @@ import javax.lang.model.element.*;
import static javax.lang.model.element.ElementKind.*;
import javax.lang.model.type.*;
import javax.lang.model.util.Types;
+import org.netbeans.modules.java.source.base.SourceLevelUtils;
/**
* Utility methods for working with Element instances.
@@ -63,7 +64,7 @@ public class ElementsService {
jctypes = com.sun.tools.javac.code.Types.instance(context);
names = Names.instance(context);
types = JavacTypes.instance(context);
- allowDefaultMethods = Source.instance(context).allowDefaultMethods();
+ allowDefaultMethods = SourceLevelUtils.allowDefaultMethods(Source.instance(context));
}
/**
diff --git a/java.source.base/src/org/netbeans/modules/java/source/parsing/CachingFileManager.java b/java.source.base/src/org/netbeans/modules/java/source/parsing/CachingFileManager.java
index 24108e8..294be61 100644
--- a/java.source.base/src/org/netbeans/modules/java/source/parsing/CachingFileManager.java
+++ b/java.source.base/src/org/netbeans/modules/java/source/parsing/CachingFileManager.java
@@ -42,6 +42,7 @@ import org.netbeans.api.annotations.common.NonNull;
import org.netbeans.api.annotations.common.NullAllowed;
import org.netbeans.api.java.classpath.ClassPath;
import org.netbeans.modules.java.preprocessorbridge.spi.JavaFileFilterImplementation;
+import org.netbeans.modules.java.source.base.SourceLevelUtils;
import org.netbeans.modules.java.source.classpath.CacheClassPath;
import org.netbeans.modules.java.source.util.Iterators;
import org.openide.util.Exceptions;
@@ -240,7 +241,7 @@ public class CachingFileManager implements JavaFileManager, PropertyChangeListen
String folderName = FileObjects.convertPackage2Folder( packageName );
List<Iterable<JavaFileObject>> idxs = new LinkedList<>();
List<? extends String> prefixes = null;
- final boolean supportsMultiRelease = sourceLevel != null && sourceLevel.compareTo(Source.JDK1_9)>= 0;
+ final boolean supportsMultiRelease = sourceLevel != null && sourceLevel.compareTo(SourceLevelUtils.JDK1_9) >= 0;
for(ClassPath.Entry entry : roots) {
try {
Archive archive = provider.getArchive( entry.getURL(), cacheFile );
@@ -297,7 +298,7 @@ public class CachingFileManager implements JavaFileManager, PropertyChangeListen
final String className,
final JavaFileObject.Kind kind) {
final String[] namePair = FileObjects.getParentRelativePathAndName(className);
- final boolean supportsMultiRelease = sourceLevel != null && sourceLevel.compareTo(Source.JDK1_9)>= 0;
+ final boolean supportsMultiRelease = sourceLevel != null && sourceLevel.compareTo(SourceLevelUtils.JDK1_9)>= 0;
List<? extends String> reloc = null;
for( ClassPath.Entry root : roots) {
try {
@@ -345,7 +346,7 @@ public class CachingFileManager implements JavaFileManager, PropertyChangeListen
assert pkgName != null;
assert relativeName != null;
final String resourceName = FileObjects.resolveRelativePath(pkgName,relativeName);
- final boolean supportsMultiRelease = sourceLevel != null && sourceLevel.compareTo(Source.JDK1_9)>= 0;
+ final boolean supportsMultiRelease = sourceLevel != null && sourceLevel.compareTo(SourceLevelUtils.JDK1_9) >= 0;
List<? extends String> reloc = null;
for( ClassPath.Entry root : roots) {
try {
@@ -383,7 +384,7 @@ public class CachingFileManager implements JavaFileManager, PropertyChangeListen
prefixes.add(""); //NOI18N
final Source[] sources = Source.values();
for (int i=0; i< sources.length; i++) {
- if (sources[i].compareTo(Source.JDK1_9) >=0 && sources[i].compareTo(sourceLevel) <=0) {
+ if (sources[i].compareTo(SourceLevelUtils.JDK1_9) >=0 && sources[i].compareTo(sourceLevel) <=0) {
prefixes.add(String.format(
"META-INF/versions/%s", //NOI18N
normalizeSourceLevel(sources[i].name)));
diff --git a/java.source.base/src/org/netbeans/modules/java/source/parsing/JavacParser.java b/java.source.base/src/org/netbeans/modules/java/source/parsing/JavacParser.java
index 83dce2a..c878ef1 100644
--- a/java.source.base/src/org/netbeans/modules/java/source/parsing/JavacParser.java
+++ b/java.source.base/src/org/netbeans/modules/java/source/parsing/JavacParser.java
@@ -100,6 +100,7 @@ import org.netbeans.lib.nbjavac.services.NBJavacTrees;
import org.netbeans.lib.nbjavac.services.NBMessager;
import org.netbeans.lib.nbjavac.services.NBResolve;
import org.netbeans.lib.nbjavac.services.NBTreeMaker;
+import org.netbeans.modules.java.source.base.SourceLevelUtils;
import org.netbeans.modules.java.source.indexing.JavaIndex;
import org.netbeans.modules.java.source.tasklist.CompilerSettings;
import org.netbeans.modules.java.source.usages.ClassIndexImpl;
@@ -938,7 +939,7 @@ public class JavacParser extends Parser {
} else {
if (isModuleInfo) {
//Module info requires at least 9 otherwise module.compete fails with ISE.
- final com.sun.tools.javac.code.Source java9 = com.sun.tools.javac.code.Source.JDK1_9;
+ final com.sun.tools.javac.code.Source java9 = SourceLevelUtils.JDK1_9;
final com.sun.tools.javac.code.Source required = com.sun.tools.javac.code.Source.lookup(sourceLevel);
if (required == null || required.compareTo(java9) < 0) {
sourceLevel = java9.name;
@@ -963,7 +964,7 @@ public class JavacParser extends Parser {
}
}
}
- if (source.compareTo(com.sun.tools.javac.code.Source.JDK1_5) >= 0 &&
+ if (source.compareTo(SourceLevelUtils.JDK1_5) >= 0 &&
!hasResource("java/lang/StringBuilder", new ClassPath[] {bootClassPath}, new ClassPath[] {classPath}, new ClassPath[] {srcClassPath})) { //NOI18N
LOGGER.log(warnLevel,
"Even though the source level of {0} is set to: {1}, java.lang.StringBuilder cannot be found on the bootclasspath: {2}\n" +
@@ -971,28 +972,28 @@ public class JavacParser extends Parser {
new Object[]{srcClassPath, sourceLevel, bootClassPath}); //NOI18N
return com.sun.tools.javac.code.Source.JDK1_4;
}
- if (source.compareTo(com.sun.tools.javac.code.Source.JDK1_7) >= 0 &&
+ if (source.compareTo(SourceLevelUtils.JDK1_7) >= 0 &&
!hasResource("java/lang/AutoCloseable", new ClassPath[] {bootClassPath}, new ClassPath[] {classPath}, new ClassPath[] {srcClassPath})) { //NOI18N
LOGGER.log(warnLevel,
"Even though the source level of {0} is set to: {1}, java.lang.AutoCloseable cannot be found on the bootclasspath: {2}\n" + //NOI18N
"Try with resources is unsupported.", //NOI18N
new Object[]{srcClassPath, sourceLevel, bootClassPath}); //NOI18N
}
- if (source.compareTo(com.sun.tools.javac.code.Source.JDK1_8) >= 0 &&
+ if (source.compareTo(SourceLevelUtils.JDK1_8) >= 0 &&
!hasResource("java/util/stream/Streams", new ClassPath[] {bootClassPath}, new ClassPath[] {classPath}, new ClassPath[] {srcClassPath})) { //NOI18N
LOGGER.log(warnLevel,
"Even though the source level of {0} is set to: {1}, java.util.stream.Streams cannot be found on the bootclasspath: {2}\n" + //NOI18N
"Changing source level to 1.7", //NOI18N
new Object[]{srcClassPath, sourceLevel, bootClassPath}); //NOI18N
- return com.sun.tools.javac.code.Source.JDK1_7;
+ return SourceLevelUtils.JDK1_7;
}
- if (source.compareTo(com.sun.tools.javac.code.Source.JDK1_9) >= 0 &&
+ if (source.compareTo(SourceLevelUtils.JDK1_9) >= 0 &&
!hasResource("java/util/zip/CRC32C", new ClassPath[] {moduleBoot}, new ClassPath[] {moduleCompile, moduleAllUnnamed}, new ClassPath[] {srcClassPath})) { //NOI18N
LOGGER.log(warnLevel,
"Even though the source level of {0} is set to: {1}, java.util.zip.CRC32C cannot be found on the system module path: {2}\n" + //NOI18N
"Changing source level to 1.8", //NOI18N
new Object[]{srcClassPath, sourceLevel, bootClassPath}); //NOI18N
- return com.sun.tools.javac.code.Source.JDK1_8;
+ return SourceLevelUtils.JDK1_8;
}
return source;
}
diff --git a/java.source.base/src/org/netbeans/modules/java/source/parsing/ModuleFileManager.java b/java.source.base/src/org/netbeans/modules/java/source/parsing/ModuleFileManager.java
index 4f0770f..914face 100644
--- a/java.source.base/src/org/netbeans/modules/java/source/parsing/ModuleFileManager.java
+++ b/java.source.base/src/org/netbeans/modules/java/source/parsing/ModuleFileManager.java
@@ -42,6 +42,7 @@ import org.netbeans.api.annotations.common.NullAllowed;
import org.netbeans.api.annotations.common.NullUnknown;
import org.netbeans.api.java.classpath.ClassPath;
import org.netbeans.api.java.source.SourceUtils;
+import org.netbeans.modules.java.source.base.SourceLevelUtils;
import org.netbeans.modules.java.source.util.Iterators;
import org.openide.util.Exceptions;
@@ -94,7 +95,7 @@ final class ModuleFileManager implements JavaFileManager {
try {
final List<Iterable<JavaFileObject>> res = new ArrayList<>();
List<? extends String> prefixes = null;
- final boolean supportsMultiRelease = sourceLevel != null && sourceLevel.compareTo(Source.JDK1_9) >= 0;
+ final boolean supportsMultiRelease = sourceLevel != null && sourceLevel.compareTo(SourceLevelUtils.JDK1_9) >= 0;
for (URL root : ml.getModuleRoots()) {
final Archive archive = cap.getArchive(root, cacheFile);
if (archive != null) {
@@ -164,7 +165,7 @@ final class ModuleFileManager implements JavaFileManager {
@NonNull final JavaFileObject.Kind kind) {
final ModuleLocation ml = ModuleLocation.cast(l);
final String[] namePair = FileObjects.getParentRelativePathAndName(className);
- final boolean supportsMultiRelease = sourceLevel != null && sourceLevel.compareTo(Source.JDK1_9)>= 0;
+ final boolean supportsMultiRelease = sourceLevel != null && sourceLevel.compareTo(SourceLevelUtils.JDK1_9) >= 0;
List<? extends String> reloc = null;
for (URL root : ml.getModuleRoots()) {
try {
@@ -329,7 +330,7 @@ final class ModuleFileManager implements JavaFileManager {
assert pkgName != null;
assert relativeName != null;
final String resourceName = FileObjects.resolveRelativePath(pkgName,relativeName);
- final boolean supportsMultiRelease = sourceLevel != null && sourceLevel.compareTo(Source.JDK1_9) >= 0;
+ final boolean supportsMultiRelease = sourceLevel != null && sourceLevel.compareTo(SourceLevelUtils.JDK1_9) >= 0;
List<? extends String> reloc = null;
for (URL root : ml.getModuleRoots()) {
try {
@@ -388,7 +389,7 @@ final class ModuleFileManager implements JavaFileManager {
prefixes.add(""); //NOI18N
final Source[] sources = Source.values();
for (int i=0; i< sources.length; i++) {
- if (sources[i].compareTo(Source.JDK1_9) >=0 && sources[i].compareTo(sourceLevel) <=0) {
+ if (sources[i].compareTo(SourceLevelUtils.JDK1_9) >=0 && sources[i].compareTo(sourceLevel) <=0) {
prefixes.add(String.format(
"META-INF/versions/%s", //NOI18N
normalizeSourceLevel(sources[i].name)));
--
To stop receiving notification emails like this one, please contact
"commits@netbeans.apache.org" <co...@netbeans.apache.org>.