Skip to content

Commit

Permalink
resolve compilation issues for supporting JP 3.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ftomassetti committed Oct 23, 2017
1 parent a7337f0 commit 228526d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
Expand Up @@ -3,8 +3,11 @@
import com.github.javaparser.ast.CompilationUnit; import com.github.javaparser.ast.CompilationUnit;
import com.github.javaparser.ast.Node; import com.github.javaparser.ast.Node;
import com.github.javaparser.ast.body.MethodDeclaration; import com.github.javaparser.ast.body.MethodDeclaration;
import com.github.javaparser.ast.expr.Expression;
import com.github.javaparser.ast.type.ArrayType; import com.github.javaparser.ast.type.ArrayType;
import com.github.javaparser.ast.type.Type;
import com.github.javaparser.resolution.SymbolResolver; import com.github.javaparser.resolution.SymbolResolver;
import com.github.javaparser.resolution.types.ResolvedType;
import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade; import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade;
import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserMethodDeclaration; import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserMethodDeclaration;
import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; import com.github.javaparser.symbolsolver.model.resolution.TypeSolver;
Expand All @@ -26,22 +29,34 @@ public JavaSymbolSolver(TypeSolver typeSolver) {
this.typeSolver = typeSolver; this.typeSolver = typeSolver;
} }


/**
* Register this SymbolResolver into a CompilationUnit, so that symbol resolution becomes available to
* all nodes part of the CompilationUnit.
*/
public void inject(CompilationUnit destination) {
destination.setData(Node.SYMBOL_RESOLVER_KEY, this);
}

@Override @Override
public <T> T resolve(Node node, Class<T> resultClass) { public <T> T resolveDeclaration(Node node, Class<T> resultClass) {
if (node instanceof MethodDeclaration) { if (node instanceof MethodDeclaration) {
return resultClass.cast(new JavaParserMethodDeclaration((MethodDeclaration)node, typeSolver)); return resultClass.cast(new JavaParserMethodDeclaration((MethodDeclaration)node, typeSolver));
} }
if (node instanceof ArrayType) { throw new UnsupportedOperationException("Unable to find the declaration of type " + resultClass.getSimpleName()
return resultClass.cast(JavaParserFacade.get(typeSolver).convert((ArrayType)node, node)); + " from " + node.getClass().getSimpleName());
}

@Override
public <T> T toResolvedType(Type javaparserType, Class<T> resultClass) {
if (javaparserType instanceof ArrayType) {
return resultClass.cast(JavaParserFacade.get(typeSolver).convert((ArrayType)javaparserType, javaparserType));
} }
throw new UnsupportedOperationException("Unable to resolve to " + resultClass.getSimpleName() + " from " + node.getClass().getSimpleName()); throw new UnsupportedOperationException("Unable to get the resolved type of class "
+ resultClass.getSimpleName() + " from " + javaparserType);
} }


/** @Override
* Register this SymbolResolver into a CompilationUnit, so that symbol resolution becomes available to public ResolvedType calculateType(Expression expression) {
* all nodes part of the CompilationUnit. throw new UnsupportedOperationException("Unable to calculate type of " + expression);
*/
public void inject(CompilationUnit destination) {
destination.setData(Node.SYMBOL_RESOLVER_KEY, this);
} }
} }
Expand Up @@ -462,4 +462,9 @@ public ResolvedType visit(ModuleOpensStmt node, Boolean arg) {
public ResolvedType visit(UnparsableStmt node, Boolean arg) { public ResolvedType visit(UnparsableStmt node, Boolean arg) {
throw new UnsupportedOperationException(node.getClass().getCanonicalName()); throw new UnsupportedOperationException(node.getClass().getCanonicalName());
} }

@Override
public ResolvedType visit(ReceiverParameter node, Boolean arg) {
throw new UnsupportedOperationException(node.getClass().getCanonicalName());
}
} }

0 comments on commit 228526d

Please sign in to comment.