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

View File

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

View File

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

View File

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