Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No warnings and lints #13

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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 @@ -68,7 +68,7 @@ public synchronized void run() {
boolean notify = true;
try (var ctx = Fn.activate(p)) {
if (inst == null) {
inst = m.getDeclaringClass().newInstance();
inst = m.getDeclaringClass().getConstructor().newInstance();
}
result = m.invoke(inst);
if (result == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ public void start(Stage primaryStage) throws Exception {
start(primaryStage, this.getParameters().getRaw().get(0));
}

@SuppressWarnings("unchecked")
final void start(Stage primaryStage, String callee) {
BorderPane r = new BorderPane();
Object[] arr = findInitialSize(callee);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,7 @@ private static void assertGC(Reference<Object> ref) {
}

try {
System.gc();
System.runFinalization();
forceGC();
} catch (Error err) {
LOG.log(Level.INFO, "Problems during GCing attempt of " + ref.get(), err);
}
Expand All @@ -111,4 +110,10 @@ private static void assertGC(Reference<Object> ref) {
LOG.log(Level.FINE, "Good: No GC of {1} for {0} ms.", new Object[]{took, ref.get()});
}

@SuppressWarnings("deprecation")
private static void forceGC() {
System.gc();
System.runFinalization();
}

}
2 changes: 1 addition & 1 deletion boot-fx/src/test/java/org/netbeans/html/boot/fx/KOFx.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public synchronized void run() {
try (var ctx = Fn.activate(p)) {
assert ctx != null;
if (inst == null) {
inst = m.getDeclaringClass().newInstance();
inst = m.getDeclaringClass().getConstructor().newInstance();
}
result = m.invoke(inst);
if (result == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public synchronized void run() {
try (Closeable a = Fn.activate(p)) {
assert a != null;
if (inst == null) {
inst = m.getDeclaringClass().newInstance();
inst = m.getDeclaringClass().getConstructor().newInstance();
}
result = m.invoke(inst);
if (result == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ public static void initialized() throws Exception {

@Override
public BrwsrCtx createContext() {
KO4J fx = new KO4J(browserContext);
KO4J fx = new KO4J();
TyrusContext tc = new TyrusContext();
Contexts.Builder cb = Contexts.newBuilder().
register(Technology.class, fx.knockout(), 10).
Expand All @@ -225,19 +225,19 @@ public Object createJSON(Map<String, Object> values) {
private static native void setProperty(Object json, String key, Object value);

@Override
@JavaScriptBody(args = { "s", "args" }, body = """
var f = new Function(s);
@JavaScriptBody(args = { "script", "args" }, body = """
var f = new Function(script);
return f.apply(null, args);
"""
)
public native Object executeScript(String script, Object[] arguments);
public native Object executeScript(String script, Object[] args);

private static String findBaseURL() {
return baseUri.toString();
}

@Override
public URI prepareURL(String content, String mimeType, String[] parameters) {
public String prepareWebResource(String content, String mimeType, String[] parameters) {
try {
final URL baseURL = new URL(findBaseURL());
StringBuilder sb = new StringBuilder();
Expand All @@ -253,7 +253,7 @@ public URI prepareURL(String content, String mimeType, String[] parameters) {
URLConnection c = query.openConnection();
BufferedReader br = new BufferedReader(new InputStreamReader(c.getInputStream()));
URI connectTo = new URI(br.readLine());
return connectTo;
return connectTo.toString();
} catch (IOException ex) {
throw new IllegalStateException(ex);
} catch (URISyntaxException ex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import java.lang.reflect.Method;
import net.java.html.js.JavaScriptBody;
import org.netbeans.html.boot.spi.Fn;
import org.netbeans.html.boot.impl.FnContext;
import org.testng.IHookCallBack;
import org.testng.IHookable;
import org.testng.ITest;
Expand Down Expand Up @@ -55,7 +54,7 @@ public String getTestName() {
public synchronized void executeTest() throws Throwable {
skipAsyncJavaTestWhenNoPromise();
// BEGIN: net.java.html.boot.script.ScriptEngineCase#run
Object instance = method.getDeclaringClass().newInstance();;
Object instance = method.getDeclaringClass().getConstructor().newInstance();
for (int round = 0;; round++) {
try (var ctx = Fn.activate(p)) {
assert ctx != null;
Expand Down
22 changes: 12 additions & 10 deletions boot/src/main/java/org/netbeans/html/boot/impl/FnUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ private boolean generateBody(boolean hasCode) {
super.visitMethodInsn(
Opcodes.INVOKESTATIC,
"org/netbeans/html/boot/spi/Fn", "isValid",
"(Lorg/netbeans/html/boot/spi/Fn;)Z"
"(Lorg/netbeans/html/boot/spi/Fn;)Z", false
);
Label ifNotNull = new Label();
super.visitJumpInsn(Opcodes.IFNE, ifNotNull);
Expand All @@ -269,7 +269,8 @@ private boolean generateBody(boolean hasCode) {
}
super.visitMethodInsn(Opcodes.INVOKESTATIC,
"org/netbeans/html/boot/spi/Fn", "define",
"(Ljava/lang/Class;ZLjava/lang/String;[Ljava/lang/String;)Lorg/netbeans/html/boot/spi/Fn;"
"(Ljava/lang/Class;ZLjava/lang/String;[Ljava/lang/String;)Lorg/netbeans/html/boot/spi/Fn;",
false
);
Label noPresenter = new Label();
super.visitInsn(Opcodes.DUP);
Expand All @@ -284,7 +285,8 @@ private boolean generateBody(boolean hasCode) {
super.visitLdcInsn(resource);
super.visitMethodInsn(Opcodes.INVOKESTATIC,
"org/netbeans/html/boot/spi/Fn", "preload",
"(Lorg/netbeans/html/boot/spi/Fn;Ljava/lang/Class;Ljava/lang/String;)Lorg/netbeans/html/boot/spi/Fn;"
"(Lorg/netbeans/html/boot/spi/Fn;Ljava/lang/Class;Ljava/lang/String;)Lorg/netbeans/html/boot/spi/Fn;",
false
);
}
super.visitInsn(Opcodes.DUP);
Expand Down Expand Up @@ -362,7 +364,7 @@ public void visitBaseType(char descriptor) {
throw new IllegalStateException(t.toString());
}
FindInMethod.super.visitMethodInsn(Opcodes.INVOKESTATIC,
factory, "valueOf", "(" + descriptor + ")L" + factory + ";"
factory, "valueOf", "(" + descriptor + ")L" + factory + ";", false
);
FindInMethod.super.visitInsn(Opcodes.AASTORE);
}
Expand Down Expand Up @@ -419,13 +421,13 @@ private void loadObject() {
int lastSlash = FindInClass.this.name.lastIndexOf('/');
String jsCallbacks = FindInClass.this.name.substring(0, lastSlash + 1) + "$JsCallbacks$";
FindInMethod.super.visitFieldInsn(Opcodes.GETSTATIC, jsCallbacks, "VM", "L" + jsCallbacks + ";");
FindInMethod.super.visitMethodInsn(Opcodes.INVOKEVIRTUAL, jsCallbacks, "current", "()L" + jsCallbacks + ";");
FindInMethod.super.visitMethodInsn(Opcodes.INVOKEVIRTUAL, jsCallbacks, "current", "()L" + jsCallbacks + ";", false);
FindInMethod.super.visitInsn(Opcodes.AASTORE);
}

if (!fia.asyncJavaScript()) {
super.visitMethodInsn(Opcodes.INVOKEVIRTUAL,
"org/netbeans/html/boot/spi/Fn", "invoke", "(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;"
"org/netbeans/html/boot/spi/Fn", "invoke", "(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;", false
);
switch (sv.returnType.getSort()) {
case Type.VOID:
Expand All @@ -442,7 +444,7 @@ private void loadObject() {
super.visitJumpInsn(Opcodes.IFNULL, handleNullValue);
super.visitTypeInsn(Opcodes.CHECKCAST, "java/lang/Boolean");
super.visitMethodInsn(Opcodes.INVOKEVIRTUAL,
"java/lang/Boolean", "booleanValue", "()Z"
"java/lang/Boolean", "booleanValue", "()Z", false
);
super.visitInsn(Opcodes.IRETURN);
super.visitLabel(handleNullValue);
Expand All @@ -453,13 +455,13 @@ private void loadObject() {
default:
super.visitTypeInsn(Opcodes.CHECKCAST, "java/lang/Number");
super.visitMethodInsn(Opcodes.INVOKEVIRTUAL,
"java/lang/Number", sv.returnType.getClassName() + "Value", "()" + sv.returnType.getDescriptor()
"java/lang/Number", sv.returnType.getClassName() + "Value", "()" + sv.returnType.getDescriptor(), false
);
super.visitInsn(sv.returnType.getOpcode(Opcodes.IRETURN));
}
} else {
super.visitMethodInsn(Opcodes.INVOKEVIRTUAL,
"org/netbeans/html/boot/spi/Fn", "invokeLater", "(Ljava/lang/Object;[Ljava/lang/Object;)V"
"org/netbeans/html/boot/spi/Fn", "invokeLater", "(Ljava/lang/Object;[Ljava/lang/Object;)V", false
);
super.visitInsn(Opcodes.RETURN);
}
Expand All @@ -471,7 +473,7 @@ private void loadObject() {
super.visitInsn(Opcodes.DUP);
super.visitLdcInsn("No presenter active. Use BrwsrCtx.execute!");
super.visitMethodInsn(Opcodes.INVOKESPECIAL,
"java/lang/IllegalStateException", "<init>", "(Ljava/lang/String;)V"
"java/lang/IllegalStateException", "<init>", "(Ljava/lang/String;)V", false
);
this.visitInsn(Opcodes.ATHROW);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public final class JavaScriptProcesor extends AbstractProcessor {
public JavaScriptProcesor() {
}

@SuppressWarnings("deprecation")
@Override
public Set<String> getSupportedAnnotationTypes() {
Set<String> set = new HashSet<>();
Expand Down Expand Up @@ -152,6 +153,19 @@ public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment
checkJavaScriptBody(r, e, msg);
}

processGroup(roundEnv, msg);

generateCallbackClass(javacalls);
javacalls.clear();
if (roundEnv.processingOver()) {
generateJavaScriptBodyList(bodies);
bodies.clear();
}
return true;
}

@SuppressWarnings("deprecation")
private void processGroup(RoundEnvironment roundEnv, final Messager msg) {
for (Element e : roundEnv.getElementsAnnotatedWith(JavaScriptResource.Group.class)) {
JavaScriptResource.Group g = e.getAnnotation(JavaScriptResource.Group.class);
if (g == null) {
Expand All @@ -161,13 +175,6 @@ public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment
checkJavaScriptBody(r, e, msg);
}
}

if (roundEnv.processingOver()) {
generateCallbackClass(javacalls);
generateJavaScriptBodyList(bodies);
javacalls.clear();
}
return true;
}

private void checkJavaScriptBody(JavaScriptResource r, Element e, final Messager msg) {
Expand Down Expand Up @@ -528,7 +535,7 @@ private void generateCallbackClass(Map<String,Map<String, ExecutableElement>> pr
Map<String, ExecutableElement> map = pkgEn.getValue();
StringBuilder source = new StringBuilder();
source.append("package ").append(pkgName).append(";\n");
source.append("@java.lang.SuppressWarnings(\"all\")\n");
source.append("@java.lang.SuppressWarnings({\"unchecked\", \"all\"})\n");
source.append("public final class $JsCallbacks$ {\n");
source.append(" static final $JsCallbacks$ VM = new $JsCallbacks$(null);\n");
source.append(" private final org.netbeans.html.boot.spi.Fn.Ref<?> ref;\n");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public void assertClassDefined() {

@Test public void instanceMethod() throws Throwable {
Method plus = methodClass.getMethod("plusInst", int.class);
java.lang.Object inst = methodClass.newInstance();
java.lang.Object inst = methodClass.getConstructor().newInstance();
try {
assertEquals(plus.invoke(inst, 10), 10);
} catch (InvocationTargetException ex) {
Expand All @@ -94,7 +94,7 @@ public void assertClassDefined() {
}

@Test public void getThis() throws Throwable {
java.lang.Object th = methodClass.newInstance();
java.lang.Object th = methodClass.getConstructor().newInstance();
Method st = methodClass.getMethod("getThis");
try {
assertEquals(st.invoke(th), th);
Expand Down Expand Up @@ -154,7 +154,7 @@ public void run() {

@Test public void callJavaScriptMethodOnOwnClass() throws Throwable {
try {
java.lang.Object thiz = methodClass.newInstance();
java.lang.Object thiz = methodClass.getConstructor().newInstance();
Method st = methodClass.getMethod("returnYourSelf", methodClass);
assertEquals(st.invoke(null, thiz), thiz, "Returns this");
} catch (InvocationTargetException ex) {
Expand All @@ -172,6 +172,7 @@ public void run() {
assertEquals(st.invoke(null, "42"), 42, "Meaning of JavaScript?");
}

@SuppressWarnings("unchecked")
@Test public void passEnum() throws Throwable {
Class<?> enmClazz = methodClass.getDeclaredClasses()[0];
assertTrue(Enum.class.isAssignableFrom(enmClazz), "It is an enum: " + enmClazz);
Expand Down Expand Up @@ -199,7 +200,7 @@ public void run() {

@Test public void recordError() throws Throwable {
Method st = methodClass.getMethod("recordError", java.lang.Object.class);
assertEquals(st.invoke(methodClass.newInstance(), "Hello"), "Hello", "The same parameter returned");
assertEquals(st.invoke(methodClass.getConstructor().newInstance(), "Hello"), "Hello", "The same parameter returned");
}

@Test public void plusOrMul() throws Throwable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ public final void displayPage(URL page, Runnable onPageLoad) {
}
}

@SuppressWarnings("unchecked")
static <T extends Exception> T raise(Class<T> aClass, Exception ex) throws T {
throw (T)ex;
}
Expand Down Expand Up @@ -357,7 +358,7 @@ public <Request, Response> void service(HttpServer<Request, Response, ?, ?> serv
String prefix = "http://" + server.getServerName(rqst) + ":" + server.getServerPort(rqst) + "/";
Writer w = server.getWriter(rspns);
server.setContentType(rspns, "text/html");
final Command cmd = new Command(server, Browser.this, prefix);
final Command<Request, Response, ?> cmd = new Command<>(server, Browser.this, prefix);
try {
is = new InputStreamReader(page.openStream());
} catch (IOException ex) {
Expand Down Expand Up @@ -403,7 +404,7 @@ public <Request, Response> void service(HttpServer<Request, Response, ?, ?> serv
w.close();
} else if (path.equals("/command.js")) {
String id = server.getParameter(rqst, "id");
Command c = SESSIONS.get(id);
Command<Request, Response, ?> c = findCommand(id);
if (c == null) {
server.getWriter(rspns).write("No command for " + id);
server.setStatus(rspns, 404);
Expand Down Expand Up @@ -461,6 +462,11 @@ public <Request, Response> void service(HttpServer<Request, Response, ?, ?> serv
}
}

@SuppressWarnings("unchecked")
private <Request, Response> Command<Request, Response, ?> findCommand(String id) {
return SESSIONS.get(id);
}

private void emitScript(Writer w, String prefix, String id) throws IOException {
w.write(" <script id='exec' type='text/javascript'>");
w.write("\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ final class DynamicHTTP extends Handler {
server = s;
}

@SuppressWarnings("unchecked")
@Override
public <Request, Response> void service(HttpServer<Request, Response, ?, ?> s, Request request, Response response) throws IOException {
if ("/dynamic".equals(s.getRequestURI(request))) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public void run() {
updateName.invoke(null, getTestName(), cnt);
}
if (inst == null) {
inst = m.getDeclaringClass().newInstance();
inst = m.getDeclaringClass().getConstructor().newInstance();
}
result = m.invoke(inst);
if (result == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public Object executeScript(String script, Object[] arguments) {
}

@Override
public URI prepareURL(String content, String mimeType, String[] parameters) {
public String prepareWebResource(String content, String mimeType, String[] parameters) {
try {
final URL baseURL = new URL(JavaScriptUtilities.findBaseURL());
StringBuilder sb = new StringBuilder();
Expand All @@ -132,7 +132,7 @@ public URI prepareURL(String content, String mimeType, String[] parameters) {
URLConnection c = query.openConnection();
BufferedReader br = new BufferedReader(new InputStreamReader(c.getInputStream()));
URI connectTo = new URI(br.readLine());
return connectTo;
return connectTo.toString();
} catch (IOException | URISyntaxException ex) {
throw new IllegalStateException(ex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public static Object[][] serverFactories() {
return arr.toArray(new Object[0][]);
}

@SuppressWarnings("unchecked")
static Fn.Presenter[] collect(
String browserName, Collection<? super ITest> res,
Class<? extends Annotation> test, Supplier<Class[]> tests
Expand Down
1 change: 1 addition & 0 deletions generic/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
</compilerArguments>
<testSource>15</testSource>
<testTarget>1.8</testTarget>
<failOnWarning>false</failOnWarning>
</configuration>
</plugin>
<plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1132,7 +1132,7 @@ private static Object createReferenceFor(Object obj) {
}

private static final class WeakHolder extends PhantomReference<Object> {
private static final ReferenceQueue QUEUE = new ReferenceQueue();
private static final ReferenceQueue<Object> QUEUE = new ReferenceQueue<>();
private static final Set<WeakHolder> active = new HashSet<WeakHolder>();
private final Object knockout;

Expand Down
Loading