在 Eclipse 中找不到的继承方法
Inherited methods not found in Eclipse
我正在对 java 代码进行语义分析。部分class如下:
ClassOrInterfaceDeclaration -> TypeDeclaration -> BodyDeclaration -> Node
节点class是这样的:
public abstract class Node {
private final int beginLine;
private final int beginColumn;
private Scope enclosingScope;
@Deprecated
public Node(int line, int column) {
this.beginLine = line;
this.beginColumn = column;
this.endLine = line;
this.endColumn = column;
}
public Node(int beginLine, int beginColumn, int endLine, int endColumn) {
this.beginLine = beginLine;
this.beginColumn = beginColumn;
this.endLine = endLine;
this.endColumn = endColumn;
}
public void setMyScope(Scope enclosingScope) {
this.enclosingScope = enclosingScope;
}
public Scope getMyScope() {
return enclosingScope;
}
public final int getBeginLine() {
return beginLine;
}
public final int getBeginColumn() {
return beginColumn;
} ... ...
现在,当我从 ClassOrInterfaceDeclaration
的实例调用这些方法时,除了 setMyScope()
和 getMyScope()
之外的任何方法都可用。有点像新手。不知道为什么以及如何解决它。
ClassOrInterfaceDeclaration代码如下:
public final class ClassOrInterfaceDeclaration extends TypeDeclaration {
private final List<AnnotationExpr> annotations;
private final boolean isInterface;
private final List<TypeParameter> typeParameters;
private final List<ClassOrInterfaceType> extendsList;
private final List<ClassOrInterfaceType> implementsList;
public ClassOrInterfaceDeclaration(int line, int column, JavadocComment javaDoc, int modifiers, List<AnnotationExpr> annotations, boolean isInterface, String name, List<TypeParameter> typeParameters, List<ClassOrInterfaceType> extendsList, List<ClassOrInterfaceType> implementsList, List<BodyDeclaration> members) {
super(line, column, javaDoc, name, modifiers, members);
this.annotations = annotations;
this.isInterface = isInterface;
this.typeParameters = typeParameters;
this.extendsList = extendsList;
this.implementsList = implementsList;
}
public List<AnnotationExpr> getAnnotations() {
return annotations;
}
public boolean isInterface() {
return isInterface;
}
public List<TypeParameter> getTypeParameters() {
return typeParameters;
}
public List<ClassOrInterfaceType> getExtends() {
return extendsList;
}
public List<ClassOrInterfaceType> getImplements() {
return implementsList;
}
@Override
public <A> void accept(VoidVisitor<A> v, A arg) {
v.visit(this, arg);
}
@Override
public <R, A> R accept(GenericVisitor<R, A> v, A arg) {
return v.visit(this, arg);
}
}
TypeDeclaration 和 BodyDeclaration 类似。它们中没有关于行、列或范围的信息。然而,虽然 beginLine()
和 beginColumn()
工作良好,但 setMyScope(), getMyScope()
却不行。后两种方法是我加的。我怀疑我做了什么傻事但想不通。
这似乎是您无法引用最新 class 版本的问题。
可能的问题:
- 代码根本没有重新编译
- 同一src中的其他class可能存在编译错误。修复这些并再次编译。
- 您的 classpath 中可能有 jar 文件路径,其中 jar 没有被最新的替换。
请检查是否勾选了所有这些框。如果问题仍然存在,请告诉我们
我正在对 java 代码进行语义分析。部分class如下:
ClassOrInterfaceDeclaration -> TypeDeclaration -> BodyDeclaration -> Node
节点class是这样的:
public abstract class Node {
private final int beginLine;
private final int beginColumn;
private Scope enclosingScope;
@Deprecated
public Node(int line, int column) {
this.beginLine = line;
this.beginColumn = column;
this.endLine = line;
this.endColumn = column;
}
public Node(int beginLine, int beginColumn, int endLine, int endColumn) {
this.beginLine = beginLine;
this.beginColumn = beginColumn;
this.endLine = endLine;
this.endColumn = endColumn;
}
public void setMyScope(Scope enclosingScope) {
this.enclosingScope = enclosingScope;
}
public Scope getMyScope() {
return enclosingScope;
}
public final int getBeginLine() {
return beginLine;
}
public final int getBeginColumn() {
return beginColumn;
} ... ...
现在,当我从 ClassOrInterfaceDeclaration
的实例调用这些方法时,除了 setMyScope()
和 getMyScope()
之外的任何方法都可用。有点像新手。不知道为什么以及如何解决它。
ClassOrInterfaceDeclaration代码如下:
public final class ClassOrInterfaceDeclaration extends TypeDeclaration {
private final List<AnnotationExpr> annotations;
private final boolean isInterface;
private final List<TypeParameter> typeParameters;
private final List<ClassOrInterfaceType> extendsList;
private final List<ClassOrInterfaceType> implementsList;
public ClassOrInterfaceDeclaration(int line, int column, JavadocComment javaDoc, int modifiers, List<AnnotationExpr> annotations, boolean isInterface, String name, List<TypeParameter> typeParameters, List<ClassOrInterfaceType> extendsList, List<ClassOrInterfaceType> implementsList, List<BodyDeclaration> members) {
super(line, column, javaDoc, name, modifiers, members);
this.annotations = annotations;
this.isInterface = isInterface;
this.typeParameters = typeParameters;
this.extendsList = extendsList;
this.implementsList = implementsList;
}
public List<AnnotationExpr> getAnnotations() {
return annotations;
}
public boolean isInterface() {
return isInterface;
}
public List<TypeParameter> getTypeParameters() {
return typeParameters;
}
public List<ClassOrInterfaceType> getExtends() {
return extendsList;
}
public List<ClassOrInterfaceType> getImplements() {
return implementsList;
}
@Override
public <A> void accept(VoidVisitor<A> v, A arg) {
v.visit(this, arg);
}
@Override
public <R, A> R accept(GenericVisitor<R, A> v, A arg) {
return v.visit(this, arg);
}
}
TypeDeclaration 和 BodyDeclaration 类似。它们中没有关于行、列或范围的信息。然而,虽然 beginLine()
和 beginColumn()
工作良好,但 setMyScope(), getMyScope()
却不行。后两种方法是我加的。我怀疑我做了什么傻事但想不通。
这似乎是您无法引用最新 class 版本的问题。 可能的问题:
- 代码根本没有重新编译
- 同一src中的其他class可能存在编译错误。修复这些并再次编译。
- 您的 classpath 中可能有 jar 文件路径,其中 jar 没有被最新的替换。
请检查是否勾选了所有这些框。如果问题仍然存在,请告诉我们