Skip to content

Commit

Permalink
MethodBinding fix related to JLS compliance, QualifiedName fix
Browse files Browse the repository at this point in the history
Signed-off-by: David Thompson <davthomp@redhat.com>
  • Loading branch information
datho7561 authored and mickaelistria committed May 26, 2024
1 parent a8a6518 commit 13b1a06
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1046,6 +1046,22 @@ private Expression convertExpressionImpl(JCExpression javac) {
res.setName((SimpleName)convertName(fieldAccess.getIdentifier()));
return res;
}
if (fieldAccess.getExpression() instanceof JCIdent parentFieldAccess && Objects.equals(Names.instance(this.context)._this, parentFieldAccess.getName())) {
FieldAccess res = this.ast.newFieldAccess();
commonSettings(res, javac);
res.setExpression(convertExpression(parentFieldAccess));
if (convertName(fieldAccess.getIdentifier()) instanceof SimpleName name) {
res.setName(name);
}
return res;
}
if (fieldAccess.getExpression() instanceof JCIdent qualifier) {
Name qualifierName = convertName(qualifier.getName());
SimpleName qualifiedName = (SimpleName)convertName(fieldAccess.getIdentifier());
QualifiedName res = this.ast.newQualifiedName(qualifierName, qualifiedName);
commonSettings(res, javac);
return res;
}
FieldAccess res = this.ast.newFieldAccess();
commonSettings(res, javac);
res.setExpression(convertExpression(fieldAccess.getExpression()));
Expand Down Expand Up @@ -1386,7 +1402,7 @@ private Expression convertExpressionImpl(JCExpression javac) {
switchExpr = jcp.getExpression();
}
res.setExpression(convertExpression(switchExpr));

List<JCCase> cases = jcSwitch.getCases();
Iterator<JCCase> it = cases.iterator();
ArrayList<JCTree> bodyList = new ArrayList<>();
Expand All @@ -1401,7 +1417,7 @@ private Expression convertExpressionImpl(JCExpression javac) {
bodyList.add(switchCase.getBody());
}
}

Iterator<JCTree> stmtIterator = bodyList.iterator();
while(stmtIterator.hasNext()) {
JCTree next = stmtIterator.next();
Expand All @@ -1425,16 +1441,16 @@ private Expression convertExpressionImpl(JCExpression javac) {
}
return null;
}

private Expression convertExpressionOrNull(JCExpression javac) {
return convertExpressionImpl(javac);
}

private Expression convertExpression(JCExpression javac) {
Expression ret = convertExpressionImpl(javac);
if( ret != null )
return ret;

// Handle errors or default situation
if (javac instanceof JCErroneous error) {
if (error.getErrorTrees().size() == 1) {
Expand Down Expand Up @@ -2346,7 +2362,7 @@ private void sortModifierNodesByPosition(List<IExtendedModifier> l) {
return a1.getStartPosition() - a2.getStartPosition();
});
}

private void convertModifiers(JCModifiers modifiers, ASTNode parent, List<IExtendedModifier> res) {
Iterator<javax.lang.model.element.Modifier> mods = modifiers.getFlags().iterator();
while(mods.hasNext()) {
Expand All @@ -2361,7 +2377,7 @@ private List<IExtendedModifier> convertModifierAnnotations(JCModifiers modifier
sortModifierNodesByPosition(res);
return res;
}

private void convertModifierAnnotations(JCModifiers modifiers, ASTNode parent, List<IExtendedModifier> res) {
modifiers.getAnnotations().stream().map(this::convert).forEach(res::add);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.Signature;
import org.eclipse.jdt.core.dom.AST;
import org.eclipse.jdt.core.dom.ASTNode;
import org.eclipse.jdt.core.dom.IAnnotationBinding;
import org.eclipse.jdt.core.dom.IBinding;
Expand Down Expand Up @@ -287,7 +288,7 @@ public ITypeBinding getReturnType() {
@Override
public ITypeBinding[] getExceptionTypes() {
ASTNode node = this.resolver.findNode(this.methodSymbol);
if (node instanceof MethodDeclaration method) {
if (node.getAST().apiLevel() >= AST.JLS8 && node instanceof MethodDeclaration method) {
return ((List<Type>)method.thrownExceptionTypes()).stream()
.map(Type::resolveBinding)
.toArray(ITypeBinding[]::new);
Expand Down

0 comments on commit 13b1a06

Please sign in to comment.