Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
import javax.lang.model.element.*;
import static javax.lang.model.element.ElementKind.*;
import static javax.lang.model.element.Modifier.*;
import static javax.lang.model.SourceVersion.RELEASE_10;
import static javax.lang.model.SourceVersion.RELEASE_11;
import static javax.lang.model.SourceVersion.RELEASE_13;
import javax.lang.model.type.*;
import javax.lang.model.util.Elements;
import javax.lang.model.util.ElementFilter;
Expand Down Expand Up @@ -238,49 +241,6 @@ public static enum Options {
TRANSIENT_KEYWORD, VOID_KEYWORD, VOLATILE_KEYWORD
};

private static final SourceVersion SOURCE_VERSION_RELEASE_10;
private static final SourceVersion SOURCE_VERSION_RELEASE_11;
private static final SourceVersion SOURCE_VERSION_RELEASE_13;
private static final SourceVersion SOURCE_VERSION_RELEASE_14;
private static final SourceVersion SOURCE_VERSION_RELEASE_15;

static {
SourceVersion r10, r11, r13, r14, r15;

try {
r10 = SourceVersion.valueOf("RELEASE_10");
} catch (IllegalArgumentException ex) {
r10 = null;
}
try {
r11 = SourceVersion.valueOf("RELEASE_11");
} catch (IllegalArgumentException ex) {
r11 = null;
}
try {
r13 = SourceVersion.valueOf("RELEASE_13");
} catch (IllegalArgumentException ex) {
r13 = null;
}
try {
r14 = SourceVersion.valueOf("RELEASE_14");
} catch (IllegalArgumentException ex) {
r14 = null;
}

try {
r15 = SourceVersion.valueOf("RELEASE_15");
} catch (IllegalArgumentException ex) {
r15 = null;
}

SOURCE_VERSION_RELEASE_10 = r10;
SOURCE_VERSION_RELEASE_11 = r11;
SOURCE_VERSION_RELEASE_13 = r13;
SOURCE_VERSION_RELEASE_14 = r14;
SOURCE_VERSION_RELEASE_15 = r15;
}

private final ItemFactory<T> itemFactory;
private final Set<Options> options;

Expand Down Expand Up @@ -1585,8 +1545,7 @@ private void insideBlock(Env env) throws IOException {
addKeywordsForBlock(env);

String prefix = env.getPrefix();
if (SOURCE_VERSION_RELEASE_13 != null && env.getController().getSourceVersion().compareTo(SOURCE_VERSION_RELEASE_13) >= 0
&& Utilities.startsWith(YIELD_KEYWORD, prefix)) {
if (env.getController().getSourceVersion().compareTo(RELEASE_13) >= 0 && Utilities.startsWith(YIELD_KEYWORD, prefix)) {
TreePath parentPath = env.getPath().getParentPath();
if (parentPath.getLeaf().getKind() == Tree.Kind.CASE && parentPath.getParentPath().getLeaf().getKind() == Kind.SWITCH_EXPRESSION) {
addKeyword(env, YIELD_KEYWORD, null, false);
Expand Down Expand Up @@ -4748,9 +4707,7 @@ private void addKeywordsForBlock(Env env) {
}
tp = tp.getParentPath();
}
if (SOURCE_VERSION_RELEASE_10 != null &&
env.getController().getSourceVersion().compareTo(SOURCE_VERSION_RELEASE_10) >= 0 &&
Utilities.startsWith(VAR_KEYWORD, prefix)) {
if (env.getController().getSourceVersion().compareTo(RELEASE_10) >= 0 && Utilities.startsWith(VAR_KEYWORD, prefix)) {
results.add(itemFactory.createKeywordItem(VAR_KEYWORD, SPACE, anchorOffset, false));
}
}
Expand Down Expand Up @@ -4862,7 +4819,7 @@ private void addClassModifiers(Env env, Set<Modifier> modifiers) {
if (!modifiers.contains(ABSTRACT)) {
kws.add(ABSTRACT_KEYWORD);
}
if (!contains(modifiers, "SEALED") && !contains(modifiers, "NON_SEALED")) {
if (!modifiers.contains(SEALED) && !modifiers.contains(NON_SEALED)) {
if (!modifiers.contains(ABSTRACT)) {
kws.add(FINAL_KEYWORD);
}
Expand All @@ -4885,14 +4842,6 @@ private void addClassModifiers(Env env, Set<Modifier> modifiers) {
}
}

private static boolean contains(Set<Modifier> modifiers, String modifier) {
try {
return modifiers.contains(Modifier.valueOf(modifier));
} catch (IllegalArgumentException ex) {
return false;
}
}

private void addMemberModifiers(Env env, Set<Modifier> modifiers, boolean isLocal) {
String prefix = env.getPrefix();
List<String> kws = new ArrayList<>();
Expand Down Expand Up @@ -6322,7 +6271,7 @@ private boolean withinBounds(Env env, TypeMirror type, List<? extends TypeMirror
}

private void addVarTypeForLambdaParam(final Env env) throws IOException {
if (SOURCE_VERSION_RELEASE_11 == null || env.getController().getSourceVersion().compareTo(SOURCE_VERSION_RELEASE_11) < 0) {
if (env.getController().getSourceVersion().compareTo(RELEASE_11) < 0) {
return;
}
results.add(itemFactory.createKeywordItem(VAR_KEYWORD, SPACE, anchorOffset, false));
Expand Down
2 changes: 1 addition & 1 deletion java/java.source.base/manifest.mf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Manifest-Version: 1.0
OpenIDE-Module: org.netbeans.modules.java.source.base
OpenIDE-Module-Implementation-Version: 5
OpenIDE-Module-Implementation-Version: 6
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/java/source/base/Bundle.properties
OpenIDE-Module-Layer: org/netbeans/modules/java/source/base/layer.xml
OpenIDE-Module-Recommends: org.netbeans.libs.nbjavac
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,14 @@
import com.sun.source.util.SourcePositions;
import com.sun.source.util.TreePath;
import org.netbeans.api.java.source.support.ErrorAwareTreePathScanner;
import org.netbeans.api.java.source.support.ErrorAwareTreeScanner;
import com.sun.source.util.Trees;
import com.sun.tools.javac.api.JavacScope;
import com.sun.tools.javac.api.JavacTrees;
import com.sun.tools.javac.code.Flags;
import com.sun.tools.javac.code.Symbol;
import com.sun.tools.javac.code.Type;
import com.sun.tools.javac.comp.AttrContext;
import com.sun.tools.javac.comp.Enter;
import com.sun.tools.javac.comp.Env;
import com.sun.tools.javac.comp.Resolve;
import com.sun.tools.javac.tree.DCTree.DCReference;
import com.sun.tools.javac.tree.JCTree;
import com.sun.tools.javac.tree.JCTree.JCMethodDecl;
Expand All @@ -72,26 +69,16 @@

import com.sun.source.util.DocTrees;
import com.sun.tools.javac.api.JavacTaskImpl;
import com.sun.tools.javac.code.Kinds;
import com.sun.tools.javac.comp.ArgumentAttr;
import com.sun.tools.javac.comp.Attr;
import com.sun.tools.javac.comp.Check.CheckContext;
import com.sun.tools.javac.comp.DeferredAttr;
import com.sun.tools.javac.comp.InferenceContext;
import com.sun.tools.javac.main.JavaCompiler;
import com.sun.tools.javac.parser.JavacParser;
import com.sun.tools.javac.parser.Parser;
import com.sun.tools.javac.parser.ParserFactory;
import com.sun.tools.javac.parser.ScannerFactory;
import com.sun.tools.javac.tree.JCTree.JCBlock;
import com.sun.tools.javac.tree.JCTree.JCClassDecl;
import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
import com.sun.tools.javac.tree.JCTree.JCExpression;
import com.sun.tools.javac.tree.JCTree.JCVariableDecl;
import com.sun.tools.javac.util.JCDiagnostic;
import com.sun.tools.javac.util.Log;
import com.sun.tools.javac.util.Names;
import com.sun.tools.javac.util.Warner;
import java.lang.reflect.Method;
import org.netbeans.api.annotations.common.CheckForNull;
import org.netbeans.api.annotations.common.NonNull;
Expand All @@ -100,19 +87,15 @@
import org.netbeans.api.java.lexer.JavadocTokenId;
import org.netbeans.api.java.source.JavaSource.Phase;
import org.netbeans.api.lexer.TokenSequence;
import org.netbeans.lib.nbjavac.services.CancelService;
import org.netbeans.lib.nbjavac.services.NBAttr;
import org.netbeans.lib.nbjavac.services.NBParserFactory;
import org.netbeans.lib.nbjavac.services.NBResolve;
import org.netbeans.modules.java.source.TreeUtilitiesAccessor;
import org.netbeans.modules.java.source.builder.CommentHandlerService;
import org.netbeans.modules.java.source.builder.CommentSetImpl;
import org.netbeans.modules.java.source.matching.CopyFinder;
import org.netbeans.modules.java.source.matching.CopyFinder.HackScope;
import org.netbeans.modules.java.source.pretty.ImportAnalysis2;
import org.netbeans.modules.java.source.transform.ImmutableDocTreeTranslator;
import org.netbeans.modules.java.source.transform.ImmutableTreeTranslator;
import org.openide.util.Exceptions;

/**
*
Expand Down Expand Up @@ -906,9 +889,6 @@ public void report(JCDiagnostic diag) {
Env<AttrContext> env = getEnv(scope);
if (tree instanceof JCExpression)
return attr.attribExpr((JCTree) tree,env, Type.noType);
if (env.tree != null && env.tree.getKind() == Kind.VARIABLE && !VARIABLE_CAN_OWN_VARIABLES) {
env = env.next;
}
return attr.attribStat((JCTree) tree,env);
} finally {
unenter(jti.getContext(), (JCCompilationUnit) cut, (JCTree) tree);
Expand All @@ -929,18 +909,6 @@ private static void unenter(Context ctx, JCCompilationUnit cut, JCTree tree) {
}
}

private static boolean VARIABLE_CAN_OWN_VARIABLES;
static {
boolean result;
try {
SourceVersion.valueOf("RELEASE_12");
result = true;
} catch (IllegalArgumentException ex) {
result = false;
}
VARIABLE_CAN_OWN_VARIABLES = result;
}

private static Scope attributeTreeTo(JavacTaskImpl jti, CompilationUnitTree cut, Tree tree, Scope scope, Tree to, final List<Diagnostic<? extends JavaFileObject>> errors) {
Log log = Log.instance(jti.getContext());
JavaFileObject prev = log.useSource(new DummyJFO());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.security.ProtectionDomain;
import java.util.concurrent.atomic.AtomicReference;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.lang.model.SourceVersion;
Expand All @@ -35,33 +34,24 @@
*/
public class NoJavacHelper {

private static final AtomicReference<Boolean> hasWorkingJavac = new AtomicReference<>();
public static boolean hasWorkingJavac() {
Boolean res = hasWorkingJavac.get();
if (res != null) {
return res;
}
private static final boolean hasWorkingJavac;

static {
boolean res;
try {
SourceVersion.valueOf("RELEASE_17");
res = true;
} catch (IllegalArgumentException ex) {
//OK
res = false;
}
hasWorkingJavac.compareAndSet(null, res);
return hasWorkingJavac.get();
hasWorkingJavac = res;
}

public static boolean hasNbJavac() {
try {
Class.forName("com.sun.tools.javac.comp.Repair");
return true;
} catch (ClassNotFoundException ex) {
//OK
return false;
}
public static boolean hasWorkingJavac() {
return hasWorkingJavac;
}

// safety net if someone manages to start NB on JDK 8 with nb-javac uninstalled
@OnStart
public static class FixClasses implements Runnable {
Comment thread
mbien marked this conversation as resolved.

Expand Down Expand Up @@ -106,7 +96,7 @@ private void defineClass(String fqn, String injectToClass, byte[] classData) {
Class targetClass = Class.forName(injectToClass); //NOI18N

Method defineClass = unsafeClass.getDeclaredMethod("defineClass", String.class, byte[].class, int.class, int.class, ClassLoader.class, ProtectionDomain.class); //NOI18N
defineClass.invoke(unsafe, fqn, classData, 0, classData.length, targetClass.getClassLoader(), targetClass.getProtectionDomain()); //NOI18N
defineClass.invoke(unsafe, fqn, classData, 0, classData.length, targetClass.getClassLoader(), targetClass.getProtectionDomain()); //NOI18N
} catch (Throwable t) {
//ignore...
Logger.getLogger(NoJavacHelper.class.getName()).log(Level.WARNING, null, t);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
package org.netbeans.modules.java.source.indexing;

import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
Expand Down Expand Up @@ -59,6 +58,7 @@
import java.util.logging.Level;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import javax.lang.model.SourceVersion;

import javax.lang.model.element.ElementKind;
import javax.lang.model.element.ModuleElement;
Expand All @@ -82,7 +82,6 @@
import org.netbeans.api.java.source.ElementHandle;
import org.netbeans.api.project.FileOwnerQuery;
import org.netbeans.api.project.Project;
import org.netbeans.modules.classfile.ClassFile;
import org.netbeans.modules.java.source.ElementHandleAccessor;
import org.netbeans.modules.java.source.JavaSourceTaskFactoryManager;
import org.netbeans.modules.java.source.ModuleNames;
Expand Down Expand Up @@ -115,7 +114,6 @@
import org.openide.filesystems.FileObject;
import org.openide.filesystems.FileUtil;
import org.openide.filesystems.URLMapper;
import org.openide.modules.InstalledFileLocator;
import org.openide.util.Exceptions;
//import org.openide.util.NbBundle;
import org.openide.util.Pair;
Expand Down Expand Up @@ -1395,15 +1393,7 @@ private static File dumpHeap(@NonNull final String path) {
private static Pair<Object,Method> heapDumper;

private static String computeJavacVersion() {
if (NoJavacHelper.hasNbJavac()) {
File nbJavac = InstalledFileLocator.getDefault().locate("modules/ext/nb-javac-impl.jar", "org.netbeans.modules.nbjavac.impl", false);
if (nbJavac != null) {
return String.valueOf(nbJavac.lastModified());
}
return "-1";
} else {
return System.getProperty("java.vm.version", "unknown");
}
return SourceVersion.latest().toString();
Comment thread
mbien marked this conversation as resolved.
}

private static class FilterOutJDK7AndLaterWarnings implements Comparable<Diagnostic<? extends JavaFileObject>> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1039,23 +1039,14 @@ public void testRemoveResourceFromTWR4() throws Exception {
" }\n" +
"}\n"
);
String extraSemicolon;
//XXX: a difference between vanilla javac and nb-javac:
if (NoJavacHelper.hasNbJavac()) {
//with nb-javac wil preserve the semicolon:
extraSemicolon = ";";
} else {
//with vanilla javac, we don't:
extraSemicolon = "";
}
String golden =
"package hierbas.del.litoral;\n" +
"\n" +
"import java.io.*;\n" +
"\n" +
"public class Test {\n" +
" public void taragui() {\n" +
" try (InputStream in = new FileInputStream(\"\")" + extraSemicolon + ") {\n" +
" try (InputStream in = new FileInputStream(\"\")) {\n" +
" }\n" +
" }\n" +
"}\n";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@
import javax.lang.model.element.TypeElement;
import java.util.stream.Collectors;
import junit.framework.Test;

import static junit.framework.TestCase.assertFalse;
import static junit.framework.TestCase.assertTrue;

import org.netbeans.api.java.classpath.ClassPath;
import org.netbeans.api.java.source.ClassIndex;
import org.netbeans.api.java.source.ClassIndex.SearchKind;
Expand All @@ -48,7 +50,6 @@
import org.netbeans.api.java.source.JavaSource;
import org.netbeans.junit.NbTestSuite;
import org.netbeans.modules.classfile.ClassFile;
import org.netbeans.modules.java.source.NoJavacHelper;
import org.netbeans.modules.java.source.indexing.CompileWorker.ParsingOutput;
import org.netbeans.modules.java.source.indexing.JavaCustomIndexer.CompileTuple;
import org.netbeans.modules.parsing.spi.indexing.Context;
Expand Down Expand Up @@ -1958,13 +1959,7 @@ protected void tearDown() throws Exception {
}

public static Test suite() {
if (NoJavacHelper.hasNbJavac()) {
return new VanillaCompileWorkerTest("noop");
} else {
// return new VanillaCompileWorkerTest("testAnonymousClasses");
// return new VanillaCompileWorkerTest("testPreserveValidInitializers");
return new NbTestSuite(VanillaCompileWorkerTest.class);
}
return new NbTestSuite(VanillaCompileWorkerTest.class);
}

static {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,6 @@ public void run(CompilationController parameter) throws Exception {
}

public void testMultiSourceOutOfMemory() throws Exception {
if (NoJavacHelper.hasNbJavac()) {
return ;
}

FileObject f1 = createFile("test/Test1.java", "package test; class Test1 {}");
FileObject f2 = createFile("test/Test2.java", "package test; class Test2 {}");
Expand Down
Loading