Improving build diagnostics in IDEA. Fix minor problems in JSO

This commit is contained in:
Alexey Andreev 2016-04-21 22:29:40 +03:00
parent 7f379eaeb7
commit 0d3d6e883d
4 changed files with 52 additions and 31 deletions

View File

@ -329,11 +329,11 @@ class JSClassProcessor {
} }
if (method.getProgram() != null && method.getProgram().basicBlockCount() > 0) { if (method.getProgram() != null && method.getProgram().basicBlockCount() > 0) {
MethodReader overriden = getOverridenMethod(method); MethodReader overridden = getOverridenMethod(method);
if (overriden != null) { if (overridden != null) {
diagnostics.error(callLocation, "JS final method {{m0}} overrides {{m1}}. " diagnostics.error(callLocation, "JS final method {{m0}} overrides {{m1}}. "
+ "Overriding final method of overlay types is prohibited.", + "Overriding final method of overlay types is prohibited.",
method.getReference(), overriden.getReference()); method.getReference(), overridden.getReference());
} }
if (method.getProgram() != null && method.getProgram().basicBlockCount() > 0) { if (method.getProgram() != null && method.getProgram().basicBlockCount() > 0) {
invoke.setMethod(new MethodReference(method.getOwnerName(), method.getName() + "$static", invoke.setMethod(new MethodReference(method.getOwnerName(), method.getName() + "$static",
@ -545,7 +545,7 @@ class JSClassProcessor {
int jsParamCount = bodyAnnot.getValue("params").getList().size(); int jsParamCount = bodyAnnot.getValue("params").getList().size();
if (methodToProcess.parameterCount() != jsParamCount) { if (methodToProcess.parameterCount() != jsParamCount) {
diagnostics.error(location, "JSBody method {{m0}} declares " + methodToProcess.parameterCount() diagnostics.error(location, "JSBody method {{m0}} declares " + methodToProcess.parameterCount()
+ " parameters, but annotation specifies " + jsParamCount, methodToProcess); + " parameters, but annotation specifies " + jsParamCount, methodToProcess.getReference());
return; return;
} }
@ -554,11 +554,8 @@ class JSClassProcessor {
if (!isStatic) { if (!isStatic) {
++paramCount; ++paramCount;
} }
ValueType[] paramTypes = new ValueType[paramCount];
int offset = 0;
if (!isStatic) { if (!isStatic) {
ValueType paramType = ValueType.object(methodToProcess.getOwnerName()); ValueType paramType = ValueType.object(methodToProcess.getOwnerName());
paramTypes[offset++] = paramType;
if (!typeHelper.isSupportedType(paramType)) { if (!typeHelper.isSupportedType(paramType)) {
diagnostics.error(location, "Non-static JSBody method {{m0}} is owned by non-JS class {{c1}}", diagnostics.error(location, "Non-static JSBody method {{m0}} is owned by non-JS class {{c1}}",
methodToProcess.getReference(), methodToProcess.getOwnerName()); methodToProcess.getReference(), methodToProcess.getOwnerName());
@ -571,9 +568,6 @@ class JSClassProcessor {
} }
// generate parameter types for proxy method // generate parameter types for proxy method
for (int i = 0; i < methodToProcess.parameterCount(); ++i) {
paramTypes[offset++] = methodToProcess.parameterType(i);
}
ValueType[] proxyParamTypes = new ValueType[paramCount + 1]; ValueType[] proxyParamTypes = new ValueType[paramCount + 1];
for (int i = 0; i < paramCount; ++i) { for (int i = 0; i < paramCount; ++i) {
proxyParamTypes[i] = ValueType.parse(JSObject.class); proxyParamTypes[i] = ValueType.parse(JSObject.class);
@ -587,7 +581,7 @@ class JSClassProcessor {
methodToProcess.getName() + "$js_body$_" + methodIndexGenerator++, proxyParamTypes); methodToProcess.getName() + "$js_body$_" + methodIndexGenerator++, proxyParamTypes);
String script = bodyAnnot.getValue("script").getString(); String script = bodyAnnot.getValue("script").getString();
String[] parameterNames = bodyAnnot.getValue("params").getList().stream() String[] parameterNames = bodyAnnot.getValue("params").getList().stream()
.map(ann -> ann.getString()) .map(AnnotationValue::getString)
.toArray(String[]::new); .toArray(String[]::new);
// Parse JS script // Parse JS script
@ -598,15 +592,13 @@ class JSClassProcessor {
env.setLanguageVersion(Context.VERSION_1_8); env.setLanguageVersion(Context.VERSION_1_8);
env.setIdeMode(true); env.setIdeMode(true);
JSParser parser = new JSParser(env, errorReporter); JSParser parser = new JSParser(env, errorReporter);
//parser.enterFunction();
AstRoot rootNode; AstRoot rootNode;
try { try {
rootNode = parser.parse(new StringReader("function(){" + script + "}"), null, 0); rootNode = parser.parse(new StringReader("function(){" + script + "}"), null, 0);
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException("IO Error occured", e); throw new RuntimeException("IO Error occurred", e);
} }
AstNode body = ((FunctionNode) rootNode.getFirstChild()).getBody(); AstNode body = ((FunctionNode) rootNode.getFirstChild()).getBody();
//parser.exitFunction();
repository.methodMap.put(methodToProcess.getReference(), proxyMethod); repository.methodMap.put(methodToProcess.getReference(), proxyMethod);
if (errorReporter.hasErrors()) { if (errorReporter.hasErrors()) {

View File

@ -26,6 +26,7 @@ import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.net.URLClassLoader; import java.net.URLClassLoader;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
@ -160,6 +161,17 @@ public class TeaVMBuild {
line = location.getLine(); line = location.getLine();
startOffset = location.getStartOffset(); startOffset = location.getStartOffset();
endOffset = location.getEndOffset(); endOffset = location.getEndOffset();
file = new File(location.getPath());
if (line <= 0) {
int[] lines = getLineOffsets(file);
if (lines != null) {
line = Arrays.binarySearch(lines, (int) startOffset + 1);
if (line < 0) {
line = -line - 1;
}
}
}
} catch (Exception e) { } catch (Exception e) {
// just don't fill location fields // just don't fill location fields
} }
@ -169,9 +181,13 @@ public class TeaVMBuild {
DefaultProblemTextConsumer textConsumer = new DefaultProblemTextConsumer(); DefaultProblemTextConsumer textConsumer = new DefaultProblemTextConsumer();
problem.render(textConsumer); problem.render(textConsumer);
if (path != null) { if (file == null) {
file = lookupSource(path); if (path != null) {
path = file != null ? file.getPath() : null; file = lookupSource(path);
path = file != null ? file.getPath() : null;
}
} else {
path = file.getPath();
} }
if (startOffset < 0 && file != null && line > 0) { if (startOffset < 0 && file != null && line > 0) {

View File

@ -22,12 +22,14 @@ public class TeaVMElementLocation implements Serializable {
private int endOffset; private int endOffset;
private int line; private int line;
private int column; private int column;
private String path;
public TeaVMElementLocation(int startOffset, int endOffset, int line, int column) { public TeaVMElementLocation(int startOffset, int endOffset, int line, int column, String path) {
this.startOffset = startOffset; this.startOffset = startOffset;
this.endOffset = endOffset; this.endOffset = endOffset;
this.line = line; this.line = line;
this.column = column; this.column = column;
this.path = path;
} }
public int getStartOffset() { public int getStartOffset() {
@ -45,4 +47,8 @@ public class TeaVMElementLocation implements Serializable {
public int getColumn() { public int getColumn() {
return column; return column;
} }
public String getPath() {
return path;
}
} }

View File

@ -15,6 +15,7 @@
*/ */
package org.teavm.idea; package org.teavm.idea;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.components.ApplicationComponent; import com.intellij.openapi.components.ApplicationComponent;
import com.intellij.openapi.project.Project; import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectManager; import com.intellij.openapi.project.ProjectManager;
@ -87,26 +88,32 @@ public class TeaVMJPSRemoteService extends UnicastRemoteObject implements Applic
@Override @Override
public TeaVMElementLocation getMethodLocation(String className, String methodName, String methodDesc) public TeaVMElementLocation getMethodLocation(String className, String methodName, String methodDesc)
throws RemoteException { throws RemoteException {
for (Project project : projectManager.getOpenProjects()) { TeaVMElementLocation[] resultHolder = new TeaVMElementLocation[1];
JavaPsiFacade psi = JavaPsiFacade.getInstance(project);
PsiClass cls = psi.findClass(className, GlobalSearchScope.allScope(project));
if (cls == null) {
continue;
}
for (PsiMethod method : cls.getAllMethods()) { ApplicationManager.getApplication().runReadAction(() -> {
if (!method.getName().equals(methodName)) { for (Project project : projectManager.getOpenProjects()) {
JavaPsiFacade psi = JavaPsiFacade.getInstance(project);
PsiClass cls = psi.findClass(className, GlobalSearchScope.allScope(project));
if (cls == null) {
continue; continue;
} }
// TODO: check method raw signature
return getMethodLocation(method); for (PsiMethod method : cls.getAllMethods()) {
if (!method.getName().equals(methodName)) {
continue;
}
// TODO: check method raw signature
resultHolder[0] = getMethodLocation(method);
return;
}
} }
} });
return null;
return resultHolder[0];
} }
private TeaVMElementLocation getMethodLocation(PsiMethod method) { private TeaVMElementLocation getMethodLocation(PsiMethod method) {
return new TeaVMElementLocation(method.getTextOffset(), method.getTextOffset() + method.getTextLength(), return new TeaVMElementLocation(method.getTextOffset(), method.getTextOffset() + method.getTextLength(),
-1, -1); -1, -1, method.getContainingFile().getVirtualFile().getPath());
} }
} }