2 compile errors when I try to build MatJuice (cannot find symbol and incompatible types)

问题: I just found this tool, MatJuice, which could save me days or even weeks of development, but it doesn't compile. Although I don't know anything about Java, it doesn't loo...

问题:

I just found this tool, MatJuice, which could save me days or even weeks of development, but it doesn't compile.

Although I don't know anything about Java, it doesn't look so hairy: the two errors are both located in the same file, in the same function, and the functionality looks generic (findParent), so maybe a Java programmer will know what it is about on the instant.

A breaking issue has been posted here more than a year ago and it doesn't seem the authors are willing to correct it. That is why I am asking here.

Bellow are the two errors :

[javac] /home/geoffrey/mclab-core/languages/Natlab/src/natlab/utils/NodeFinder.java:62: error: cannot find symbol
[javac]         .filter(n -> clazz.isInstance(n) || n.getParent() == null)
[javac]                                              ^
[javac]   symbol:   method getParent()
[javac]   location: variable n of type Object

[javac] /home/geoffrey/mclab-core/languages/Natlab/src/natlab/utils/NodeFinder.java:66: error: incompatible types: Object cannot be converted to T
[javac]         .orElse(null);
[javac]                ^
[javac]   where T is a type-variable:
[javac]     T extends Object declared in method <T>findParent(Class<T>,ASTNode<?>)

Bellow is the related piece of code (the errors occur on line 3 and 7 in this extract)

public static <T> T findParent(Class<T> clazz, ASTNode<?> node) {
  return Stream.iterate(node, ASTNode::getParent)
      .filter(n -> clazz.isInstance(n) || n.getParent() == null)
      .findFirst()
      .filter(clazz::isInstance)
      .map(clazz::cast)
      .orElse(null);
}

The complete file is here (there are helpful comments in the file) along with the rest of the repo.

I tried to give it a go myself but with zero knowledge of Java, it is just too abstract for me to debug.


回答1:

These errors are come out because of compiler doesn't know what ast.ASTNode is. There is no such class in the project. But there is Natlab.gen target from ant build file:

mclab-core/languages/Natlab/build.xml

Try to run Natlab.gen target and the directory gen (that contains necessary package ast.ASTNode) will be generated inside Natlab directory. This should fix compilation errors.

  • 发表于 2019-03-05 13:41
  • 阅读 ( 72 )
  • 分类:sof

条评论

请先 登录 后评论
不写代码的码农
小编

篇文章

作家榜 »

  1. 小编 文章
返回顶部
部分文章转自于网络,若有侵权请联系我们删除