diff --git a/javaparser-symbol-solver-core/pom.xml b/javaparser-symbol-solver-core/pom.xml
deleted file mode 100644
index c07194d..0000000
--- a/javaparser-symbol-solver-core/pom.xml
+++ /dev/null
@@ -1,69 +0,0 @@
-
-
-
- sdg
- es.upv.mist.slicing
- 1.3.0
-
- 4.0.0
-
- javaparser-symbol-solver-core
- com.github.javaparser
- 3.23.2
- jar
- A Symbol Solver for Java, built on top of JavaParser (core)
-
-
-
- GNU Lesser General Public License
- http://www.gnu.org/licenses/lgpl-3.0.html
- repo
-
-
- Apache License, Version 2.0
- http://www.apache.org/licenses/LICENSE-2.0.txt
- repo
- A business-friendly OSS license
-
-
-
-
- 1.8
- ${maven.build.timestamp}
-
-
-
-
- com.github.javaparser
- javaparser-core
- 3.23.1
-
-
- org.javassist
- javassist
- 3.28.0-GA
-
-
- com.google.guava
- guava
- 31.0.1-jre
-
-
-
-
-
-
-
- org.apache.maven.plugins
- maven-jar-plugin
-
-
-
- com.github.javaparser.symbolsolver.core
-
-
-
-
-
-
-
diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/core/package-info.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/core/package-info.java
deleted file mode 100644
index 2755f8f..0000000
--- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/core/package-info.java
+++ /dev/null
@@ -1 +0,0 @@
-package com.github.javaparser.symbolsolver.core;
\ No newline at end of file
diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/core/resolution/Context.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/core/resolution/Context.java
deleted file mode 100644
index 821ec7d..0000000
--- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/core/resolution/Context.java
+++ /dev/null
@@ -1,381 +0,0 @@
-/*
- * Copyright (C) 2015-2016 Federico Tomassetti
- * Copyright (C) 2017-2020 The JavaParser Team.
- *
- * This file is part of JavaParser.
- *
- * JavaParser can be used either under the terms of
- * a) the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- * b) the terms of the Apache License
- *
- * You should have received a copy of both licenses in LICENCE.LGPL and
- * LICENCE.APACHE. Please refer to those files for details.
- *
- * JavaParser is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- */
-
-package com.github.javaparser.symbolsolver.core.resolution;
-
-import com.github.javaparser.ast.Node;
-import com.github.javaparser.ast.body.Parameter;
-import com.github.javaparser.ast.body.VariableDeclarator;
-import com.github.javaparser.ast.expr.PatternExpr;
-import com.github.javaparser.resolution.MethodUsage;
-import com.github.javaparser.resolution.declarations.*;
-import com.github.javaparser.resolution.types.ResolvedType;
-import com.github.javaparser.symbolsolver.javaparsermodel.contexts.AbstractJavaParserContext;
-import com.github.javaparser.symbolsolver.model.resolution.SymbolReference;
-import com.github.javaparser.symbolsolver.model.resolution.Value;
-
-import java.util.Collections;
-import java.util.List;
-import java.util.Optional;
-
-/**
- * Context is very similar to scope.
- * In the context we look for solving symbols.
- *
- * @author Federico Tomassetti
- */
-public interface Context {
-
- /**
- * @return The parent context, if there is one. For example, a method exists within a compilation unit.
- */
- Optional getParent();
-
-
- /* Type resolution */
-
- /**
- * Default to no generics available in this context, delegating solving to the parent context.
- * Contexts which have generics available to it will override this method.
- * For example class and method declarations, and method calls.
- *
- * @param name For example, solving {@code T} within {@code class Foo {}} or
- * @return The resolved generic type, if found.
- */
- default Optional solveGenericType(String name) {
- // Default to solving within the parent context.
- return solveGenericTypeInParentContext(name);
- }
-
- default Optional solveGenericTypeInParentContext(String name) {
- Optional optionalParentContext = getParent();
- if (!optionalParentContext.isPresent()) {
- return Optional.empty();
- }
-
- // Delegate solving to the parent context.
- return optionalParentContext.get().solveGenericType(name);
- }
-
- /**
- * Default to being unable to solve any reference in this context, delegating solving to the parent context.
- * Contexts which exist as the "parent" of a resolvable type will override this method.
- * For example, a compilation unit can contain classes. A class declaration can also contain types (e.g. a subclass).
- *
- * @param name For example, solving {@code List} or {@code java.util.List}.
- * @return The declaration associated with the given type name.
- */
- default SymbolReference solveType(String name) {
- // Default to solving within the parent context.
- return solveTypeInParentContext(name);
- }
-
- default SymbolReference solveTypeInParentContext(String name) {
- Optional optionalParentContext = getParent();
- if (!optionalParentContext.isPresent()) {
- return SymbolReference.unsolved(ResolvedReferenceTypeDeclaration.class);
- }
-
- // Delegate solving to the parent context.
- return optionalParentContext.get().solveType(name);
- }
-
- /* Symbol resolution */
-
- /**
- * Used where a symbol is being used (e.g. solving {@code x} when used as an argument {@code doubleThis(x)}, or calculation {@code return x * 2;}).
- * @param name the variable / reference / identifier used.
- * @return // FIXME: Better documentation on how this is different to solveSymbolAsValue()
- */
- default SymbolReference extends ResolvedValueDeclaration> solveSymbol(String name) {
- // Default to solving within the parent context.
- return solveSymbolInParentContext(name);
- }
-
- default SymbolReference extends ResolvedValueDeclaration> solveSymbolInParentContext(String name) {
- Optional optionalParentContext = getParent();
- if (!optionalParentContext.isPresent()) {
- return SymbolReference.unsolved(ResolvedValueDeclaration.class);
- }
-
- // Delegate solving to the parent context.
- return optionalParentContext.get().solveSymbol(name);
- }
-
- /**
- * Used where a symbol is being used (e.g. solving {@code x} when used as an argument {@code doubleThis(x)}, or calculation {@code return x * 2;}).
- * @param name the variable / reference / identifier used.
- * @return // FIXME: Better documentation on how this is different to solveSymbol()
- */
- default Optional solveSymbolAsValue(String name) {
- SymbolReference extends ResolvedValueDeclaration> ref = solveSymbol(name);
- if (!ref.isSolved()) {
- return Optional.empty();
- }
-
- return Optional.of(Value.from(ref.getCorrespondingDeclaration()));
- }
-
- default Optional solveSymbolAsValueInParentContext(String name) {
- SymbolReference extends ResolvedValueDeclaration> ref = solveSymbolInParentContext(name);
- if (!ref.isSolved()) {
- return Optional.empty();
- }
-
- return Optional.of(Value.from(ref.getCorrespondingDeclaration()));
- }
-
-
- /**
- * The fields that are declared and in this immediate context made visible to a given child.
- * This list could include values which are shadowed.
- */
- default List fieldsExposedToChild(Node child) {
- return Collections.emptyList();
- }
-
- /**
- * The local variables that are declared in this immediate context and made visible to a given child.
- * This list could include values which are shadowed.
- */
- default List localVariablesExposedToChild(Node child) {
- return Collections.emptyList();
- }
-
- /**
- * The parameters that are declared in this immediate context and made visible to a given child.
- * This list could include values which are shadowed.
- */
- default List parametersExposedToChild(Node child) {
- return Collections.emptyList();
- }
-
- /**
- * The pattern expressions that are declared in this immediate context and made visible to a given child.
- * This list could include values which are shadowed.
- */
- default List patternExprsExposedToChild(Node child) {
- return Collections.emptyList();
- }
-
- /**
- */
- default List patternExprsExposedFromChildren() {
- return Collections.emptyList();
- }
-
- /**
- */
- default List negatedPatternExprsExposedFromChildren() {
- return Collections.emptyList();
- }
-
- /**
- * Aim to resolve the given name by looking for a variable matching it.
- *
- * To do it consider local variables that are visible in a certain scope as defined in JLS 6.3. Scope of a
- * Declaration.
- *
- * 1. The scope of a local variable declaration in a block (§14.4) is the rest of the block in which the
- * declaration
- * appears, starting with its own initializer and including any further declarators to the right in the local
- * variable declaration statement.
- *
- * 2. The scope of a local variable declared in the ForInit part of a basic for statement (§14.14.1) includes all
- * of the following:
- * 2.1 Its own initializer
- * 2.2 Any further declarators to the right in the ForInit part of the for statement
- * 2.3 The Expression and ForUpdate parts of the for statement
- * 2.4 The contained Statement
- *
- * 3. The scope of a local variable declared in the FormalParameter part of an enhanced for statement (§14.14.2) is
- * the contained Statement.
- * 4. The scope of a parameter of an exception handler that is declared in a catch clause of a try statement
- * (§14.20) is the entire block associated with the catch.
- *
- * 5. The scope of a variable declared in the ResourceSpecification of a try-with-resources statement (§14.20.3) is
- * from the declaration rightward over the remainder of the ResourceSpecification and the entire try block
- * associated with the try-with-resources statement.
- */
- default Optional localVariableDeclarationInScope(String name) {
- if (!getParent().isPresent()) {
- return Optional.empty();
- }
-
- // First check if the variable is directly declared within this context.
- Node wrappedNode = ((AbstractJavaParserContext) this).getWrappedNode();
- Context parentContext = getParent().get();
- Optional localResolutionResults = parentContext
- .localVariablesExposedToChild(wrappedNode)
- .stream()
- .filter(vd -> vd.getNameAsString().equals(name))
- .findFirst();
-
- if (localResolutionResults.isPresent()) {
- return localResolutionResults;
- }
-
-
- // If we don't find the variable locally, escalate up the scope hierarchy to see if it is declared there.
- return parentContext.localVariableDeclarationInScope(name);
- }
-
- default Optional parameterDeclarationInScope(String name) {
- if (!getParent().isPresent()) {
- return Optional.empty();
- }
-
- // First check if the parameter is directly declared within this context.
- Node wrappedNode = ((AbstractJavaParserContext) this).getWrappedNode();
- Context parentContext = getParent().get();
- Optional localResolutionResults = parentContext
- .parametersExposedToChild(wrappedNode)
- .stream()
- .filter(vd -> vd.getNameAsString().equals(name))
- .findFirst();
-
- if (localResolutionResults.isPresent()) {
- return localResolutionResults;
- }
-
- // If we don't find the parameter locally, escalate up the scope hierarchy to see if it is declared there.
- return parentContext.parameterDeclarationInScope(name);
- }
-
-
- /**
- * With respect to solving, the AST "parent" of a block statement is not necessarily the same as the scope parent.
- * Example:
- *
- *
{@code
- * public String x() {
- * if(x) {
- * // Parent node: the block attached to the method declaration
- * // Scope-parent: the block attached to the method declaration
- * } else if {
- * // Parent node: the if
- * // Scope-parent: the block attached to the method declaration
- * } else {
- * // Parent node: the elseif
- * // Scope-parent: the block attached to the method declaration
- * }
- * }
- * }
- */
- default Optional patternExprInScope(String name) {
- if (!getParent().isPresent()) {
- return Optional.empty();
- }
- Context parentContext = getParent().get();
-
- // FIXME: "scroll backwards" from the wrapped node
- // FIXME: If there are multiple patterns, throw an error?
-
- // First check if the pattern is directly declared within this context.
- Node wrappedNode = ((AbstractJavaParserContext) this).getWrappedNode();
- Optional localResolutionResults = parentContext
- .patternExprsExposedToChild(wrappedNode)
- .stream()
- .filter(vd -> vd.getNameAsString().equals(name))
- .findFirst();
-
- if (localResolutionResults.isPresent()) {
- return localResolutionResults;
- }
-
- // If we don't find the parameter locally, escalate up the scope hierarchy to see if it is declared there.
- return parentContext.patternExprInScope(name);
- }
-
- default Optional fieldDeclarationInScope(String name) {
- if (!getParent().isPresent()) {
- return Optional.empty();
- }
- Context parentContext = getParent().get();
- // First check if the parameter is directly declared within this context.
- Node wrappedNode = ((AbstractJavaParserContext) this).getWrappedNode();
- Optional localResolutionResults = parentContext
- .fieldsExposedToChild(wrappedNode)
- .stream()
- .filter(vd -> vd.getName().equals(name))
- .findFirst();
-
- if (localResolutionResults.isPresent()) {
- return localResolutionResults;
- }
-
- // If we don't find the field locally, escalate up the scope hierarchy to see if it is declared there.
- return parentContext.fieldDeclarationInScope(name);
- }
-
-
- /* Constructor resolution */
-
- /**
- * We find the method declaration which is the best match for the given name and list of typeParametersValues.
- */
- default SymbolReference solveConstructor(List argumentsTypes) {
- throw new IllegalArgumentException("Constructor resolution is available only on Class Context");
- }
-
- /* Methods resolution */
-
- /**
- * We find the method declaration which is the best match for the given name and list of typeParametersValues.
- */
- default SymbolReference solveMethod(String name, List argumentsTypes, boolean staticOnly) {
- // Default to solving within the parent context.
- return solveMethodInParentContext(name, argumentsTypes, staticOnly);
- }
-
- default SymbolReference solveMethodInParentContext(String name, List argumentsTypes, boolean staticOnly) {
- Optional optionalParentContext = getParent();
- if (!optionalParentContext.isPresent()) {
- return SymbolReference.unsolved(ResolvedMethodDeclaration.class);
- }
-
- // Delegate solving to the parent context.
- return optionalParentContext.get().solveMethod(name, argumentsTypes, staticOnly);
- }
-
- /**
- * Similar to solveMethod but we return a MethodUsage.
- * A MethodUsage corresponds to a MethodDeclaration plus the resolved type variables.
- */
- default Optional solveMethodAsUsage(String name, List argumentsTypes) {
- SymbolReference methodSolved = solveMethod(name, argumentsTypes, false);
- if (methodSolved.isSolved()) {
- ResolvedMethodDeclaration methodDeclaration = methodSolved.getCorrespondingDeclaration();
- if (!(methodDeclaration instanceof TypeVariableResolutionCapability)) {
- throw new UnsupportedOperationException(String.format(
- "Resolved method declarations must implement %s.",
- TypeVariableResolutionCapability.class.getName()
- ));
- }
-
- MethodUsage methodUsage = ((TypeVariableResolutionCapability) methodDeclaration).resolveTypeVariables(this, argumentsTypes);
- return Optional.of(methodUsage);
- } else {
- return Optional.empty();
- }
- }
-
-}
diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparser/Navigator.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparser/Navigator.java
deleted file mode 100644
index b0a46db..0000000
--- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparser/Navigator.java
+++ /dev/null
@@ -1,269 +0,0 @@
-/*
- * Copyright (C) 2015-2016 Federico Tomassetti
- * Copyright (C) 2017-2020 The JavaParser Team.
- *
- * This file is part of JavaParser.
- *
- * JavaParser can be used either under the terms of
- * a) the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- * b) the terms of the Apache License
- *
- * You should have received a copy of both licenses in LICENCE.LGPL and
- * LICENCE.APACHE. Please refer to those files for details.
- *
- * JavaParser is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- */
-
-package com.github.javaparser.symbolsolver.javaparser;
-
-import com.github.javaparser.ast.CompilationUnit;
-import com.github.javaparser.ast.Node;
-import com.github.javaparser.ast.body.*;
-import com.github.javaparser.ast.expr.MethodCallExpr;
-import com.github.javaparser.ast.expr.NameExpr;
-import com.github.javaparser.ast.expr.SimpleName;
-import com.github.javaparser.ast.stmt.ReturnStmt;
-import com.github.javaparser.ast.stmt.SwitchStmt;
-
-import java.util.Optional;
-
-/**
- * This class can be used to easily retrieve nodes from a JavaParser AST.
- *
- * Note that methods with the prefix `demand` indicate that if the search value is not found, an exception will be thrown.
- *
- * @author Federico Tomassetti
- */
-public final class Navigator {
-
- private Navigator() {
- // prevent instantiation
- }
-
- public static ClassOrInterfaceDeclaration demandClass(CompilationUnit cu, String qualifiedName) {
- ClassOrInterfaceDeclaration cd = demandClassOrInterface(cu, qualifiedName);
- if (cd.isInterface()) {
- throw new IllegalStateException("Type is not a class");
- }
- return cd;
- }
-
- public static ClassOrInterfaceDeclaration demandClassOrInterface(CompilationUnit compilationUnit, String qualifiedName) {
- return findType(compilationUnit, qualifiedName)
- .map(res -> res.toClassOrInterfaceDeclaration().orElseThrow(() -> new IllegalStateException("Type is not a class or an interface, it is " + res.getClass().getCanonicalName())))
- .orElseThrow(() -> new IllegalStateException("No type named '" + qualifiedName + "'found"));
- }
-
- /**
- * Returns the {@code (i+1)}'th constructor of the given type declaration, in textual order. The constructor that
- * appears first has the index 0, the second one the index 1, and so on.
- *
- * @param td The type declaration to search in. Note that only classes and enums have constructors.
- * @param index The index of the desired constructor.
- * @return The desired ConstructorDeclaration if it was found, else an exception is thrown.
- */
- public static ConstructorDeclaration demandConstructor(TypeDeclaration> td, int index) {
- // TODO: Refactor to use `td.findAll(ConstructorDeclaration.class);` - potential difference re: searching only immediate children?
- ConstructorDeclaration found = null;
- int i = 0;
- for (BodyDeclaration> bd : td.getMembers()) {
- if (bd instanceof ConstructorDeclaration) {
- ConstructorDeclaration cd = (ConstructorDeclaration) bd;
- if (i == index) {
- found = cd;
- break;
- }
- i++;
- }
- }
- if (found == null) {
- throw new IllegalStateException("No constructor with index " + index);
- }
- return found;
- }
-
- public static EnumDeclaration demandEnum(CompilationUnit cu, String qualifiedName) {
- Optional> res = findType(cu, qualifiedName);
- if (!res.isPresent()) {
- throw new IllegalStateException("No type found");
- }
- if (!(res.get() instanceof EnumDeclaration)) {
- throw new IllegalStateException("Type is not an enum");
- }
- return (EnumDeclaration) res.get();
- }
-
- public static VariableDeclarator demandField(ClassOrInterfaceDeclaration cd, String name) {
- for (BodyDeclaration> bd : cd.getMembers()) {
- if (bd instanceof FieldDeclaration) {
- FieldDeclaration fd = (FieldDeclaration) bd;
- for (VariableDeclarator vd : fd.getVariables()) {
- if (vd.getName().getId().equals(name)) {
- return vd;
- }
- }
- }
- }
- throw new IllegalStateException("No field with given name");
- }
-
- public static ClassOrInterfaceDeclaration demandInterface(CompilationUnit cu, String qualifiedName) {
- ClassOrInterfaceDeclaration cd = demandClassOrInterface(cu, qualifiedName);
- if (!cd.isInterface()) {
- throw new IllegalStateException("Type is not an interface");
- }
- return cd;
- }
-
- public static MethodDeclaration demandMethod(TypeDeclaration> cd, String name) {
- MethodDeclaration found = null;
- for (BodyDeclaration> bd : cd.getMembers()) {
- if (bd instanceof MethodDeclaration) {
- MethodDeclaration md = (MethodDeclaration) bd;
- if (md.getNameAsString().equals(name)) {
- if (found != null) {
- throw new IllegalStateException("Ambiguous getName");
- }
- found = md;
- }
- }
- }
- if (found == null) {
- throw new IllegalStateException("No method called " + name);
- }
- return found;
- }
-
- public static N demandNodeOfGivenClass(Node node, Class clazz) {
- return node.findFirst(clazz).orElseThrow(IllegalArgumentException::new);
- }
-
- public static Node demandParentNode(Node node) {
- return node.getParentNode().orElseThrow(() -> new IllegalStateException("Parent not found, the node does not appear to be inserted in a correct AST"));
- }
-
- public static ReturnStmt demandReturnStmt(MethodDeclaration method) {
- return demandNodeOfGivenClass(method, ReturnStmt.class);
- }
-
- public static SwitchStmt demandSwitch(Node node) {
- return findSwitchHelper(node).orElseThrow(IllegalArgumentException::new);
- }
-
- public static Optional demandVariableDeclaration(Node node, String name) {
- return node.findFirst(VariableDeclarator.class, n -> n.getNameAsString().equals(name));
- }
-
- public static Optional findMethodCall(Node node, String methodName) {
- return node.findFirst(MethodCallExpr.class, n -> n.getNameAsString().equals(methodName));
- }
-
- public static Optional findNameExpression(Node node, String name) {
- return node.findFirst(NameExpr.class, n -> n.getNameAsString().equals(name));
- }
-
- /**
- * @deprecated Use {@link #demandNodeOfGivenClass(Node, Class)}
- */
- @Deprecated
- public static N findNodeOfGivenClass(Node node, Class clazz) {
- return demandNodeOfGivenClass(node, clazz);
- }
-
- /**
- * @deprecated Use {@link #demandReturnStmt(MethodDeclaration)}
- */
- @Deprecated
- public static ReturnStmt findReturnStmt(MethodDeclaration method) {
- return demandReturnStmt(method);
- }
-
- public static Optional findSimpleName(Node node, String name) {
- return node.findFirst(SimpleName.class, n -> n.asString().equals(name));
- }
-
- /**
- * @deprecated Use {@link #demandSwitch(Node)}
- */
- @Deprecated
- public static SwitchStmt findSwitch(Node node) {
- return demandSwitch(node);
- }
-
- private static Optional findSwitchHelper(Node node) {
- if (node instanceof SwitchStmt) {
- return Optional.of((SwitchStmt) node);
- }
-
- return node.findFirst(SwitchStmt.class);
- }
-
- /**
- * Looks among the type declared in the Compilation Unit for one having the specified name.
- * The name can be qualified with respect to the compilation unit. For example, if the compilation
- * unit is in package a.b; and it contains two top level classes named C and D, with class E being defined inside D
- * then the qualifiedName that can be resolved are "C", "D", and "D.E".
- */
- public static Optional> findType(CompilationUnit cu, String qualifiedName) {
- if (cu.getTypes().isEmpty()) {
- return Optional.empty();
- }
-
- final String typeName = getOuterTypeName(qualifiedName);
- Optional> type = cu.getTypes().stream().filter((t) -> t.getName().getId().equals(typeName)).findFirst();
-
- final String innerTypeName = getInnerTypeName(qualifiedName);
- if (type.isPresent() && !innerTypeName.isEmpty()) {
- return findType(type.get(), innerTypeName);
- }
- return type;
- }
-
- /**
- * Looks among the type declared in the TypeDeclaration for one having the specified name.
- * The name can be qualified with respect to the TypeDeclaration. For example, if the class declaration defines
- * class D and class D contains an internal class named E then the qualifiedName that can be resolved are "D", and
- * "D.E".
- */
- public static Optional> findType(TypeDeclaration> td, String qualifiedName) {
- final String typeName = getOuterTypeName(qualifiedName);
-
- Optional> type = Optional.empty();
- for (Node n : td.getMembers()) {
- if (n instanceof TypeDeclaration && ((TypeDeclaration>) n).getName().getId().equals(typeName)) {
- type = Optional.of((TypeDeclaration>) n);
- break;
- }
- }
- final String innerTypeName = getInnerTypeName(qualifiedName);
- if (type.isPresent() && !innerTypeName.isEmpty()) {
- return findType(type.get(), innerTypeName);
- }
- return type;
- }
-
- private static String getInnerTypeName(String qualifiedName) {
- if (qualifiedName.contains(".")) {
- return qualifiedName.split("\\.", 2)[1];
- }
- return "";
- }
-
- private static String getOuterTypeName(String qualifiedName) {
- return qualifiedName.split("\\.", 2)[0];
- }
-
- /**
- * @deprecated Use {@link #demandParentNode(Node)}
- */
- @Deprecated
- public static Node requireParentNode(Node node) {
- return demandParentNode(node);
- }
-
-}
diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/LambdaArgumentTypePlaceholder.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/LambdaArgumentTypePlaceholder.java
deleted file mode 100644
index ed8eebe..0000000
--- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/javaparsermodel/LambdaArgumentTypePlaceholder.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * Copyright (C) 2015-2016 Federico Tomassetti
- * Copyright (C) 2017-2020 The JavaParser Team.
- *
- * This file is part of JavaParser.
- *
- * JavaParser can be used either under the terms of
- * a) the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- * b) the terms of the Apache License
- *
- * You should have received a copy of both licenses in LICENCE.LGPL and
- * LICENCE.APACHE. Please refer to those files for details.
- *
- * JavaParser is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- */
-
-package com.github.javaparser.symbolsolver.javaparsermodel;
-
-import com.github.javaparser.resolution.declarations.ResolvedMethodLikeDeclaration;
-import com.github.javaparser.resolution.types.ResolvedType;
-import com.github.javaparser.symbolsolver.model.resolution.SymbolReference;
-
-/**
- * Placeholder used to represent a lambda argument type while it is being
- * calculated.
- *
- * @author Federico Tomassetti
- */
-public class LambdaArgumentTypePlaceholder implements ResolvedType {
-
- private int pos;
- private SymbolReference extends ResolvedMethodLikeDeclaration> method;
-
- public LambdaArgumentTypePlaceholder(int pos) {
- this.pos = pos;
- }
-
- @Override
- public boolean isArray() {
- return false;
- }
-
- @Override
- public boolean isPrimitive() {
- return false;
- }
-
- @Override
- public boolean isReferenceType() {
- return false;
- }
-
- @Override
- public String describe() {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public boolean isTypeVariable() {
- return false;
- }
-
- public void setMethod(SymbolReference extends ResolvedMethodLikeDeclaration> method) {
- this.method = method;
- }
-
- @Override
- public boolean isAssignableBy(ResolvedType other) {
- throw new UnsupportedOperationException();
- }
-
-}
diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/logic/FunctionalInterfaceLogic.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/logic/FunctionalInterfaceLogic.java
deleted file mode 100644
index 2431a3d..0000000
--- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/logic/FunctionalInterfaceLogic.java
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
- * Copyright (C) 2015-2016 Federico Tomassetti
- * Copyright (C) 2017-2020 The JavaParser Team.
- *
- * This file is part of JavaParser.
- *
- * JavaParser can be used either under the terms of
- * a) the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- * b) the terms of the Apache License
- *
- * You should have received a copy of both licenses in LICENCE.LGPL and
- * LICENCE.APACHE. Please refer to those files for details.
- *
- * JavaParser is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- */
-
-package com.github.javaparser.symbolsolver.logic;
-
-import com.github.javaparser.resolution.MethodUsage;
-import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration;
-import com.github.javaparser.resolution.types.ResolvedType;
-
-import java.lang.reflect.Method;
-import java.lang.reflect.Parameter;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Optional;
-import java.util.Set;
-import java.util.stream.Collectors;
-
-/**
- * @author Federico Tomassetti
- */
-public final class FunctionalInterfaceLogic {
-
- private static String JAVA_LANG_FUNCTIONAL_INTERFACE = FunctionalInterface.class.getCanonicalName();
-
- private FunctionalInterfaceLogic() {
- // prevent instantiation
- }
-
- /**
- * Get the functional method defined by the type, if any.
- */
- public static Optional getFunctionalMethod(ResolvedType type) {
- Optional optionalTypeDeclaration = type.asReferenceType().getTypeDeclaration();
- if(!optionalTypeDeclaration.isPresent()) {
- return Optional.empty();
- }
-
- ResolvedReferenceTypeDeclaration typeDeclaration = optionalTypeDeclaration.get();
- if (type.isReferenceType() && typeDeclaration.isInterface()) {
- return getFunctionalMethod(typeDeclaration);
- } else {
- return Optional.empty();
- }
- }
-
- /**
- * Get the functional method defined by the type, if any.
- */
- public static Optional getFunctionalMethod(ResolvedReferenceTypeDeclaration typeDeclaration) {
- //We need to find all abstract methods
- Set methods = typeDeclaration.getAllMethods().stream()
- .filter(m -> m.getDeclaration().isAbstract())
- // Remove methods inherited by Object:
- // Consider the case of Comparator which define equals. It would be considered a functional method.
- .filter(m -> !declaredOnObject(m))
- .collect(Collectors.toSet());
-
- if (methods.size() == 1) {
- return Optional.of(methods.iterator().next());
- } else {
- return Optional.empty();
- }
- }
-
- public static boolean isFunctionalInterfaceType(ResolvedType type) {
- if (type.isReferenceType()) {
- Optional optionalTypeDeclaration = type.asReferenceType().getTypeDeclaration();
- if (optionalTypeDeclaration.isPresent() && optionalTypeDeclaration.get().hasAnnotation(JAVA_LANG_FUNCTIONAL_INTERFACE)) {
- return true;
- }
- }
- return getFunctionalMethod(type).isPresent();
- }
-
- private static String getSignature(Method m) {
- return String.format("%s(%s)", m.getName(), String.join(", ", Arrays.stream(m.getParameters()).map(p -> toSignature(p)).collect(Collectors.toList())));
- }
-
- private static String toSignature(Parameter p) {
- return p.getType().getCanonicalName();
- }
-
- private static List OBJECT_METHODS_SIGNATURES = Arrays.stream(Object.class.getDeclaredMethods())
- .map(method -> getSignature(method))
- .collect(Collectors.toList());
-
- private static boolean declaredOnObject(MethodUsage m) {
- return OBJECT_METHODS_SIGNATURES.contains(m.getDeclaration().getSignature());
- }
-}
diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/logic/InferenceContext.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/logic/InferenceContext.java
deleted file mode 100644
index 931730a..0000000
--- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/logic/InferenceContext.java
+++ /dev/null
@@ -1,222 +0,0 @@
-/*
- * Copyright (C) 2015-2016 Federico Tomassetti
- * Copyright (C) 2017-2020 The JavaParser Team.
- *
- * This file is part of JavaParser.
- *
- * JavaParser can be used either under the terms of
- * a) the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- * b) the terms of the Apache License
- *
- * You should have received a copy of both licenses in LICENCE.LGPL and
- * LICENCE.APACHE. Please refer to those files for details.
- *
- * JavaParser is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- */
-
-package com.github.javaparser.symbolsolver.logic;
-
-import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration;
-import com.github.javaparser.resolution.types.*;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.stream.Collectors;
-
-/**
- * @author Federico Tomassetti
- */
-public class InferenceContext {
-
- private int nextInferenceVariableId = 0;
- private ObjectProvider objectProvider;
- private List inferenceVariableTypes = new ArrayList<>();
- private Map inferenceVariableTypeMap = new HashMap<>();
-
- public InferenceContext(ObjectProvider objectProvider) {
- this.objectProvider = objectProvider;
- }
-
- private InferenceVariableType inferenceVariableTypeForTp(ResolvedTypeParameterDeclaration tp) {
- if (!inferenceVariableTypeMap.containsKey(tp.getName())) {
- InferenceVariableType inferenceVariableType = new InferenceVariableType(nextInferenceVariableId++, objectProvider);
- inferenceVariableTypes.add(inferenceVariableType);
- inferenceVariableType.setCorrespondingTp(tp);
- inferenceVariableTypeMap.put(tp.getName(), inferenceVariableType);
- }
- return inferenceVariableTypeMap.get(tp.getName());
- }
-
- /**
- * @return the actual with the inference variable inserted
- */
- public ResolvedType addPair(ResolvedType target, ResolvedType actual) {
- target = placeInferenceVariables(target);
- actual = placeInferenceVariables(actual);
- registerCorrespondance(target, actual);
- return target;
- }
-
- public ResolvedType addSingle(ResolvedType actual) {
- return placeInferenceVariables(actual);
- }
-
- private void registerCorrespondance(ResolvedType formalType, ResolvedType actualType) {
- if (formalType.isReferenceType() && actualType.isReferenceType()) {
- ResolvedReferenceType formalTypeAsReference = formalType.asReferenceType();
- ResolvedReferenceType actualTypeAsReference = actualType.asReferenceType();
-
- if (!formalTypeAsReference.getQualifiedName().equals(actualTypeAsReference.getQualifiedName())) {
- List ancestors = actualTypeAsReference.getAllAncestors();
- final String formalParamTypeQName = formalTypeAsReference.getQualifiedName();
- List correspondingFormalType = ancestors.stream().filter((a) -> a.getQualifiedName().equals(formalParamTypeQName)).collect(Collectors.toList());
- if (correspondingFormalType.isEmpty()) {
- ancestors = formalTypeAsReference.getAllAncestors();
- final String actualParamTypeQname = actualTypeAsReference.getQualifiedName();
- List correspondingActualType = ancestors.stream().filter(a -> a.getQualifiedName().equals(actualParamTypeQname)).collect(Collectors.toList());
- if (correspondingActualType.isEmpty()) {
- throw new ConfilictingGenericTypesException(formalType, actualType);
- }
- correspondingFormalType = correspondingActualType;
-
- }
- actualTypeAsReference = correspondingFormalType.get(0).asReferenceType();
- }
-
- if (formalTypeAsReference.getQualifiedName().equals(actualTypeAsReference.getQualifiedName())) {
- if (!formalTypeAsReference.typeParametersValues().isEmpty()) {
- if (actualTypeAsReference.isRawType()) {
- // nothing to do
- } else {
- int i = 0;
- for (ResolvedType formalTypeParameter : formalTypeAsReference.typeParametersValues()) {
- registerCorrespondance(formalTypeParameter, actualTypeAsReference.typeParametersValues().get(i));
- i++;
- }
- }
- }
- }
- } else if (formalType instanceof InferenceVariableType && !actualType.isPrimitive()) {
- ((InferenceVariableType) formalType).registerEquivalentType(actualType);
- if (actualType instanceof InferenceVariableType) {
- ((InferenceVariableType) actualType).registerEquivalentType(formalType);
- }
- } else if (actualType.isNull()) {
- // nothing to do
- } else if (actualType.equals(formalType)) {
- // nothing to do
- } else if (actualType.isArray() && formalType.isArray()) {
- registerCorrespondance(formalType.asArrayType().getComponentType(), actualType.asArrayType().getComponentType());
- } else if (formalType.isWildcard()) {
- // nothing to do
- if ((actualType instanceof InferenceVariableType) && formalType.asWildcard().isBounded()) {
- ((InferenceVariableType) actualType).registerEquivalentType(formalType.asWildcard().getBoundedType());
- if (formalType.asWildcard().getBoundedType() instanceof InferenceVariableType) {
- ((InferenceVariableType) formalType.asWildcard().getBoundedType()).registerEquivalentType(actualType);
- }
- }
- if (actualType.isWildcard()) {
- ResolvedWildcard formalWildcard = formalType.asWildcard();
- ResolvedWildcard actualWildcard = actualType.asWildcard();
- if (formalWildcard.isBounded() && formalWildcard.getBoundedType() instanceof InferenceVariableType) {
- if (formalWildcard.isSuper() && actualWildcard.isSuper()) {
- ((InferenceVariableType) formalType.asWildcard().getBoundedType()).registerEquivalentType(actualWildcard.getBoundedType());
- } else if (formalWildcard.isExtends() && actualWildcard.isExtends()) {
- ((InferenceVariableType) formalType.asWildcard().getBoundedType()).registerEquivalentType(actualWildcard.getBoundedType());
- }
- }
- }
-
- if (actualType.isReferenceType()) {
- if (formalType.asWildcard().isBounded()) {
- registerCorrespondance(formalType.asWildcard().getBoundedType(), actualType);
- }
- }
- } else if (actualType instanceof InferenceVariableType) {
- if (formalType instanceof ResolvedReferenceType) {
- ((InferenceVariableType) actualType).registerEquivalentType(formalType);
- } else if (formalType instanceof InferenceVariableType) {
- ((InferenceVariableType) actualType).registerEquivalentType(formalType);
- }
- } else if (actualType.isConstraint()) {
- ResolvedLambdaConstraintType constraintType = actualType.asConstraintType();
- if (constraintType.getBound() instanceof InferenceVariableType) {
- ((InferenceVariableType) constraintType.getBound()).registerEquivalentType(formalType);
- }
- } else if (actualType.isPrimitive()) {
- if (formalType.isPrimitive()) {
- // nothing to do
- } else {
- registerCorrespondance(formalType, objectProvider.byName(actualType.asPrimitive().getBoxTypeQName()));
- }
- } else if (actualType.isReferenceType()) {
- if (formalType.isPrimitive()) {
- if (formalType.asPrimitive().getBoxTypeQName().equals(actualType.describe())) {
- registerCorrespondance(objectProvider.byName(formalType.asPrimitive().getBoxTypeQName()), actualType);
- } else {
- // nothing to do
- }
- } else {
- // nothing to do
- }
- } else {
- throw new UnsupportedOperationException(formalType.describe() + " " + actualType.describe());
- }
- }
-
- private ResolvedType placeInferenceVariables(ResolvedType type) {
- if (type.isWildcard()) {
- if (type.asWildcard().isExtends()) {
- return ResolvedWildcard.extendsBound(placeInferenceVariables(type.asWildcard().getBoundedType()));
- } else if (type.asWildcard().isSuper()) {
- return ResolvedWildcard.superBound(placeInferenceVariables(type.asWildcard().getBoundedType()));
- } else {
- return type;
- }
- } else if (type.isTypeVariable()) {
- return inferenceVariableTypeForTp(type.asTypeParameter());
- } else if (type.isReferenceType()) {
- return type.asReferenceType().transformTypeParameters(tp -> placeInferenceVariables(tp));
- } else if (type.isArray()) {
- return new ResolvedArrayType(placeInferenceVariables(type.asArrayType().getComponentType()));
- } else if (type.isNull() || type.isPrimitive() || type.isVoid()) {
- return type;
- } else if (type.isConstraint()) {
- return ResolvedLambdaConstraintType.bound(placeInferenceVariables(type.asConstraintType().getBound()));
- } else if (type instanceof InferenceVariableType) {
- return type;
- } else {
- throw new UnsupportedOperationException(type.describe());
- }
- }
-
- public ResolvedType resolve(ResolvedType type) {
- if (type instanceof InferenceVariableType) {
- InferenceVariableType inferenceVariableType = (InferenceVariableType) type;
- return inferenceVariableType.equivalentType();
- } else if (type.isReferenceType()) {
- return type.asReferenceType().transformTypeParameters(tp -> resolve(tp));
- } else if (type.isNull() || type.isPrimitive() || type.isVoid()) {
- return type;
- } else if (type.isArray()) {
- return new ResolvedArrayType(resolve(type.asArrayType().getComponentType()));
- } else if (type.isWildcard()) {
- if (type.asWildcard().isExtends()) {
- return ResolvedWildcard.extendsBound(resolve(type.asWildcard().getBoundedType()));
- } else if (type.asWildcard().isSuper()) {
- return ResolvedWildcard.superBound(resolve(type.asWildcard().getBoundedType()));
- } else {
- return type;
- }
- } else {
- throw new UnsupportedOperationException(type.describe());
- }
- }
-}
diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/logic/InferenceVariableType.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/logic/InferenceVariableType.java
deleted file mode 100644
index e85fa22..0000000
--- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/logic/InferenceVariableType.java
+++ /dev/null
@@ -1,169 +0,0 @@
-/*
- * Copyright (C) 2015-2016 Federico Tomassetti
- * Copyright (C) 2017-2020 The JavaParser Team.
- *
- * This file is part of JavaParser.
- *
- * JavaParser can be used either under the terms of
- * a) the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- * b) the terms of the Apache License
- *
- * You should have received a copy of both licenses in LICENCE.LGPL and
- * LICENCE.APACHE. Please refer to those files for details.
- *
- * JavaParser is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- */
-
-package com.github.javaparser.symbolsolver.logic;
-
-import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration;
-import com.github.javaparser.resolution.types.ResolvedReferenceType;
-import com.github.javaparser.resolution.types.ResolvedType;
-import com.github.javaparser.resolution.types.ResolvedTypeVariable;
-import com.github.javaparser.resolution.types.ResolvedWildcard;
-
-import java.util.HashSet;
-import java.util.Set;
-import java.util.stream.Collectors;
-
-/**
- * An element using during type inference.
- *
- * @author Federico Tomassetti
- */
-public class InferenceVariableType implements ResolvedType {
- @Override
- public String toString() {
- return "InferenceVariableType{" +
- "id=" + id +
- '}';
- }
-
- private int id;
- private ResolvedTypeParameterDeclaration correspondingTp;
-
- public void setCorrespondingTp(ResolvedTypeParameterDeclaration correspondingTp) {
- this.correspondingTp = correspondingTp;
- }
-
- private Set equivalentTypes = new HashSet<>();
- private ObjectProvider objectProvider;
-
- public void registerEquivalentType(ResolvedType type) {
- this.equivalentTypes.add(type);
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) return true;
- if (!(o instanceof InferenceVariableType)) return false;
-
- InferenceVariableType that = (InferenceVariableType) o;
-
- return id == that.id;
-
- }
-
- @Override
- public int hashCode() {
- return id;
- }
-
- private Set superTypes = new HashSet<>();
-
- public InferenceVariableType(int id, ObjectProvider objectProvider) {
- this.id = id;
- this.objectProvider = objectProvider;
- }
-
- public static InferenceVariableType fromWildcard(ResolvedWildcard wildcard, int id, ObjectProvider objectProvider) {
- InferenceVariableType inferenceVariableType = new InferenceVariableType(id, objectProvider);
- if (wildcard.isExtends()) {
- inferenceVariableType.superTypes.add(wildcard.getBoundedType());
- }
- if (wildcard.isSuper()) {
- // I am not sure about this one...
- inferenceVariableType.superTypes.add(wildcard.getBoundedType());
- }
- return inferenceVariableType;
- }
-
- @Override
- public String describe() {
- return "InferenceVariable_" + id;
- }
-
- @Override
- public boolean isAssignableBy(ResolvedType other) {
- throw new UnsupportedOperationException();
- }
-
- private Set concreteEquivalentTypesAlsoIndirectly(Set considered, InferenceVariableType inferenceVariableType) {
- considered.add(inferenceVariableType);
- Set result = new HashSet<>();
- result.addAll(inferenceVariableType.equivalentTypes.stream().filter(t -> !t.isTypeVariable() && !(t instanceof InferenceVariableType)).collect(Collectors.toSet()));
- inferenceVariableType.equivalentTypes.stream().filter(t -> t instanceof InferenceVariableType).forEach(t -> {
- InferenceVariableType ivt = (InferenceVariableType)t;
- if (!considered.contains(ivt)) {
- result.addAll(concreteEquivalentTypesAlsoIndirectly(considered, ivt));
- }
- });
- return result;
- }
-
- public ResolvedType equivalentType() {
- Set concreteEquivalent = concreteEquivalentTypesAlsoIndirectly(new HashSet<>(), this);
- if (concreteEquivalent.isEmpty()) {
- if (correspondingTp == null) {
- return objectProvider.object();
- } else {
- return new ResolvedTypeVariable(correspondingTp);
- }
- }
- if (concreteEquivalent.size() == 1) {
- return concreteEquivalent.iterator().next();
- }
- Set notTypeVariables = equivalentTypes.stream()
- .filter(t -> !t.isTypeVariable() && !hasInferenceVariables(t))
- .collect(Collectors.toSet());
- if (notTypeVariables.size() == 1) {
- return notTypeVariables.iterator().next();
- } else if (notTypeVariables.size() == 0 && !superTypes.isEmpty()) {
- if (superTypes.size() == 1) {
- return superTypes.iterator().next();
- } else {
- throw new IllegalStateException("Super types are: " + superTypes);
- }
- } else {
- throw new IllegalStateException("Equivalent types are: " + equivalentTypes);
- }
- }
-
- private boolean hasInferenceVariables(ResolvedType type){
- if (type instanceof InferenceVariableType){
- return true;
- }
-
- if (type.isReferenceType()){
- ResolvedReferenceType refType = type.asReferenceType();
- for (ResolvedType t : refType.typeParametersValues()){
- if (hasInferenceVariables(t)){
- return true;
- }
- }
- return false;
- }
-
- if (type.isWildcard()){
- ResolvedWildcard wildcardType = type.asWildcard();
- return hasInferenceVariables(wildcardType.getBoundedType());
- }
-
- return false;
- }
-}
diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/logic/MethodResolutionCapability.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/logic/MethodResolutionCapability.java
deleted file mode 100644
index 20783e1..0000000
--- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/logic/MethodResolutionCapability.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Copyright (C) 2015-2016 Federico Tomassetti
- * Copyright (C) 2017-2020 The JavaParser Team.
- *
- * This file is part of JavaParser.
- *
- * JavaParser can be used either under the terms of
- * a) the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- * b) the terms of the Apache License
- *
- * You should have received a copy of both licenses in LICENCE.LGPL and
- * LICENCE.APACHE. Please refer to those files for details.
- *
- * JavaParser is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- */
-
-package com.github.javaparser.symbolsolver.logic;
-
-import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration;
-import com.github.javaparser.resolution.types.ResolvedType;
-import com.github.javaparser.symbolsolver.model.resolution.SymbolReference;
-
-import java.util.List;
-
-public interface MethodResolutionCapability {
- SymbolReference solveMethod(String name, List argumentsTypes,
- boolean staticOnly);
-}
diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/model/resolution/SymbolReference.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/model/resolution/SymbolReference.java
deleted file mode 100644
index c5f70ff..0000000
--- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/model/resolution/SymbolReference.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * Copyright (C) 2015-2016 Federico Tomassetti
- * Copyright (C) 2017-2020 The JavaParser Team.
- *
- * This file is part of JavaParser.
- *
- * JavaParser can be used either under the terms of
- * a) the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- * b) the terms of the Apache License
- *
- * You should have received a copy of both licenses in LICENCE.LGPL and
- * LICENCE.APACHE. Please refer to those files for details.
- *
- * JavaParser is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- */
-
-package com.github.javaparser.symbolsolver.model.resolution;
-
-import com.github.javaparser.resolution.declarations.ResolvedDeclaration;
-
-import java.util.Optional;
-
-/**
- * A reference to a symbol. It can solved or not solved. If solved the corresponding
- * declaration will be provided.
- *
- * @author Federico Tomassetti
- */
-public class SymbolReference {
-
- private Optional extends S> correspondingDeclaration;
-
- private SymbolReference(Optional extends S> correspondingDeclaration) {
- this.correspondingDeclaration = correspondingDeclaration;
- }
-
- /**
- * Create a solve reference to the given symbol.
- */
- public static SymbolReference solved(S2 symbolDeclaration) {
- return new SymbolReference(Optional.of(symbolDeclaration));
- }
-
- /**
- * Create an unsolved reference specifying the type of the value expected.
- */
- public static SymbolReference unsolved(Class clazz) {
- return new SymbolReference<>(Optional.empty());
- }
-
- @Override
- public String toString() {
- return "SymbolReference{" + correspondingDeclaration + "}";
- }
-
- /**
- * The corresponding declaration. If not solve this throws UnsupportedOperationException.
- * // TODO: Convert this to returning Optional.
- */
- public S getCorrespondingDeclaration() {
- if (!isSolved()) {
- throw new UnsupportedOperationException("CorrespondingDeclaration not available for unsolved symbol.");
- }
- return correspondingDeclaration.get();
- }
-
- /**
- * Is the reference solved?
- */
- public boolean isSolved() {
- return correspondingDeclaration.isPresent();
- }
-
- public static SymbolReference adapt(SymbolReference extends O> ref, Class clazz) {
- if (ref.isSolved()) {
- return SymbolReference.solved(ref.getCorrespondingDeclaration());
- } else {
- return SymbolReference.unsolved(clazz);
- }
- }
-}
diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/model/resolution/TypeSolver.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/model/resolution/TypeSolver.java
deleted file mode 100644
index 1fc4242..0000000
--- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/model/resolution/TypeSolver.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * Copyright (C) 2015-2016 Federico Tomassetti
- * Copyright (C) 2017-2020 The JavaParser Team.
- *
- * This file is part of JavaParser.
- *
- * JavaParser can be used either under the terms of
- * a) the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- * b) the terms of the Apache License
- *
- * You should have received a copy of both licenses in LICENCE.LGPL and
- * LICENCE.APACHE. Please refer to those files for details.
- *
- * JavaParser is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- */
-
-package com.github.javaparser.symbolsolver.model.resolution;
-
-import com.github.javaparser.resolution.UnsolvedSymbolException;
-import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration;
-
-/**
- * An element able to find TypeDeclaration from their name.
- * TypeSolvers are organized in hierarchies.
- *
- * @author Federico Tomassetti
- */
-public interface TypeSolver {
-
- String JAVA_LANG_OBJECT = Object.class.getCanonicalName();
-
- /**
- * Get the root of the hierarchy of type solver.
- */
- default TypeSolver getRoot() {
- if (getParent() == null) {
- return this;
- } else {
- return getParent().getRoot();
- }
- }
-
- /**
- * Parent of the this TypeSolver. This can return null.
- */
- TypeSolver getParent();
-
- /**
- * Set the parent of this TypeSolver.
- */
- void setParent(TypeSolver parent);
-
- /**
- * Try to solve the type with the given name. It always return a SymbolReference which can be solved
- * or unsolved.
- */
- SymbolReference tryToSolveType(String name);
-
- /**
- * Solve the given type. Either the type is found and returned or an UnsolvedSymbolException is thrown.
- */
- default ResolvedReferenceTypeDeclaration solveType(String name) throws UnsolvedSymbolException {
- SymbolReference ref = tryToSolveType(name);
- if (ref.isSolved()) {
- return ref.getCorrespondingDeclaration();
- } else {
- throw new UnsolvedSymbolException(name, this.toString());
- }
- }
-
- /**
- * @return A resolved reference to {@code java.lang.Object}
- */
- default ResolvedReferenceTypeDeclaration getSolvedJavaLangObject() throws UnsolvedSymbolException {
- return solveType(JAVA_LANG_OBJECT);
- }
-
- default boolean hasType(String name) {
- return tryToSolveType(name).isSolved();
- }
-}
diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/model/resolution/Value.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/model/resolution/Value.java
deleted file mode 100644
index be1ab2d..0000000
--- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/model/resolution/Value.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Copyright (C) 2015-2016 Federico Tomassetti
- * Copyright (C) 2017-2020 The JavaParser Team.
- *
- * This file is part of JavaParser.
- *
- * JavaParser can be used either under the terms of
- * a) the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- * b) the terms of the Apache License
- *
- * You should have received a copy of both licenses in LICENCE.LGPL and
- * LICENCE.APACHE. Please refer to those files for details.
- *
- * JavaParser is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- */
-
-package com.github.javaparser.symbolsolver.model.resolution;
-
-import com.github.javaparser.resolution.declarations.ResolvedValueDeclaration;
-import com.github.javaparser.resolution.types.ResolvedType;
-
-/**
- * Any type of value.
- *
- * @author Federico Tomassetti
- */
-public class Value {
- private ResolvedType type;
- private String name;
-
- public Value(ResolvedType type, String name) {
- this.type = type;
- this.name = name;
- }
-
- /**
- * Create a Value from a ValueDeclaration.
- */
- public static Value from(ResolvedValueDeclaration decl) {
- ResolvedType type = decl.getType();
- return new Value(type, decl.getName());
- }
-
- @Override
- public String toString() {
- return "Value{" +
- "type=" + type +
- ", name='" + name + '\'' +
- '}';
- }
-
- public String getName() {
- return name;
- }
-
- public ResolvedType getType() {
- return type;
- }
-
-}
diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/model/typesystem/LazyType.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/model/typesystem/LazyType.java
deleted file mode 100644
index d32182e..0000000
--- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/model/typesystem/LazyType.java
+++ /dev/null
@@ -1,140 +0,0 @@
-/*
- * Copyright (C) 2015-2016 Federico Tomassetti
- * Copyright (C) 2017-2020 The JavaParser Team.
- *
- * This file is part of JavaParser.
- *
- * JavaParser can be used either under the terms of
- * a) the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- * b) the terms of the Apache License
- *
- * You should have received a copy of both licenses in LICENCE.LGPL and
- * LICENCE.APACHE. Please refer to those files for details.
- *
- * JavaParser is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- */
-
-package com.github.javaparser.symbolsolver.model.typesystem;
-
-import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration;
-import com.github.javaparser.resolution.types.*;
-
-import java.util.Map;
-import java.util.function.Function;
-
-public class LazyType implements ResolvedType {
- private ResolvedType concrete;
- private Function provider;
-
- public LazyType(Function provider) {
- this.provider = provider;
- }
-
- private ResolvedType getType() {
- if (concrete == null) {
- concrete = provider.apply(null);
- }
- return concrete;
- }
-
- @Override
- public boolean isArray() {
- return getType().isArray();
- }
-
- @Override
- public int arrayLevel() {
- return getType().arrayLevel();
- }
-
- @Override
- public boolean isPrimitive() {
- return getType().isPrimitive();
- }
-
- @Override
- public boolean isNull() {
- return getType().isNull();
- }
-
- @Override
- public boolean isReference() {
- return getType().isReference();
- }
-
- @Override
- public boolean isReferenceType() {
- return getType().isReferenceType();
- }
-
- @Override
- public boolean isVoid() {
- return getType().isVoid();
- }
-
- @Override
- public boolean isTypeVariable() {
- return getType().isTypeVariable();
- }
-
- @Override
- public boolean isWildcard() {
- return getType().isWildcard();
- }
-
- @Override
- public ResolvedArrayType asArrayType() {
- return getType().asArrayType();
- }
-
- @Override
- public ResolvedReferenceType asReferenceType() {
- return getType().asReferenceType();
- }
-
- @Override
- public ResolvedTypeParameterDeclaration asTypeParameter() {
- return getType().asTypeParameter();
- }
-
- @Override
- public ResolvedTypeVariable asTypeVariable() {
- return getType().asTypeVariable();
- }
-
- @Override
- public ResolvedPrimitiveType asPrimitive() {
- return getType().asPrimitive();
- }
-
- @Override
- public ResolvedWildcard asWildcard() {
- return getType().asWildcard();
- }
-
- @Override
- public String describe() {
- return getType().describe();
- }
-
- @Override
- public ResolvedType replaceTypeVariables(ResolvedTypeParameterDeclaration tp, ResolvedType replaced,
- Map inferredTypes) {
- return getType().replaceTypeVariables(tp, replaced, inferredTypes);
- }
-
- @Override
- public ResolvedType replaceTypeVariables(ResolvedTypeParameterDeclaration tp, ResolvedType replaced) {
- return getType().replaceTypeVariables(tp, replaced);
- }
-
- @Override
- public boolean isAssignableBy(ResolvedType other) {
- return getType().isAssignableBy(other);
- }
-}
diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/model/typesystem/NullType.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/model/typesystem/NullType.java
deleted file mode 100644
index dac282e..0000000
--- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/model/typesystem/NullType.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * Copyright (C) 2015-2016 Federico Tomassetti
- * Copyright (C) 2017-2020 The JavaParser Team.
- *
- * This file is part of JavaParser.
- *
- * JavaParser can be used either under the terms of
- * a) the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- * b) the terms of the Apache License
- *
- * You should have received a copy of both licenses in LICENCE.LGPL and
- * LICENCE.APACHE. Please refer to those files for details.
- *
- * JavaParser is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- */
-
-package com.github.javaparser.symbolsolver.model.typesystem;
-
-import com.github.javaparser.resolution.types.ResolvedType;
-
-/**
- * This is a virtual type used to represent null values.
- *
- * @author Federico Tomassetti
- */
-public class NullType implements ResolvedType {
-
- public static final NullType INSTANCE = new NullType();
-
- private NullType() {
- // prevent instantiation
- }
-
- @Override
- public boolean isArray() {
- return false;
- }
-
- @Override
- public boolean isPrimitive() {
- return false;
- }
-
- public boolean isNull() {
- return true;
- }
-
- @Override
- public boolean isReferenceType() {
- return false;
- }
-
- @Override
- public String describe() {
- return "null";
- }
-
- @Override
- public boolean isTypeVariable() {
- return false;
- }
-
- @Override
- public boolean isAssignableBy(ResolvedType other) {
- throw new UnsupportedOperationException("It does not make sense to assign a value to null, it can only be assigned");
- }
-
-}
diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/model/typesystem/ReferenceTypeImpl.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/model/typesystem/ReferenceTypeImpl.java
deleted file mode 100644
index bbb6bc5..0000000
--- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/model/typesystem/ReferenceTypeImpl.java
+++ /dev/null
@@ -1,266 +0,0 @@
-/*
- * Copyright (C) 2015-2016 Federico Tomassetti
- * Copyright (C) 2017-2020 The JavaParser Team.
- *
- * This file is part of JavaParser.
- *
- * JavaParser can be used either under the terms of
- * a) the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- * b) the terms of the Apache License
- *
- * You should have received a copy of both licenses in LICENCE.LGPL and
- * LICENCE.APACHE. Please refer to those files for details.
- *
- * JavaParser is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- */
-
-package com.github.javaparser.symbolsolver.model.typesystem;
-
-import com.github.javaparser.resolution.MethodUsage;
-import com.github.javaparser.resolution.declarations.ResolvedFieldDeclaration;
-import com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration;
-import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration;
-import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration;
-import com.github.javaparser.resolution.types.ResolvedReferenceType;
-import com.github.javaparser.resolution.types.ResolvedType;
-import com.github.javaparser.resolution.types.ResolvedTypeTransformer;
-import com.github.javaparser.resolution.types.ResolvedTypeVariable;
-import com.github.javaparser.resolution.types.parametrization.ResolvedTypeParametersMap;
-import com.github.javaparser.symbolsolver.javaparsermodel.LambdaArgumentTypePlaceholder;
-import com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserTypeVariableDeclaration;
-import com.github.javaparser.symbolsolver.logic.FunctionalInterfaceLogic;
-import com.github.javaparser.symbolsolver.model.resolution.SymbolReference;
-import com.github.javaparser.symbolsolver.model.resolution.TypeSolver;
-
-import java.util.*;
-import java.util.stream.Collectors;
-
-/**
- * @author Federico Tomassetti
- */
-// TODO Remove references to typeSolver: it is needed to instantiate other instances of ReferenceTypeUsage
-// and to get the Object type declaration
-public class ReferenceTypeImpl extends ResolvedReferenceType {
-
- private TypeSolver typeSolver;
-
- public static ResolvedReferenceType undeterminedParameters(ResolvedReferenceTypeDeclaration typeDeclaration, TypeSolver typeSolver) {
- return new ReferenceTypeImpl(typeDeclaration, typeDeclaration.getTypeParameters().stream().map(
- ResolvedTypeVariable::new
- ).collect(Collectors.toList()), typeSolver);
- }
-
- @Override
- protected ResolvedReferenceType create(ResolvedReferenceTypeDeclaration typeDeclaration, List typeParametersCorrected) {
- return new ReferenceTypeImpl(typeDeclaration, typeParametersCorrected, typeSolver);
- }
-
- @Override
- protected ResolvedReferenceType create(ResolvedReferenceTypeDeclaration typeDeclaration) {
- return new ReferenceTypeImpl(typeDeclaration, typeSolver);
- }
-
- public ReferenceTypeImpl(ResolvedReferenceTypeDeclaration typeDeclaration, TypeSolver typeSolver) {
- super(typeDeclaration);
- this.typeSolver = typeSolver;
- }
-
- public ReferenceTypeImpl(ResolvedReferenceTypeDeclaration typeDeclaration, List typeArguments, TypeSolver typeSolver) {
- super(typeDeclaration, typeArguments);
- this.typeSolver = typeSolver;
- }
-
- @Override
- public ResolvedTypeParameterDeclaration asTypeParameter() {
- if (this.typeDeclaration instanceof JavaParserTypeVariableDeclaration) {
- JavaParserTypeVariableDeclaration javaParserTypeVariableDeclaration = (JavaParserTypeVariableDeclaration) this.typeDeclaration;
- return javaParserTypeVariableDeclaration.asTypeParameter();
- }
- throw new UnsupportedOperationException(this.typeDeclaration.getClass().getCanonicalName());
- }
-
- /**
- * This method checks if ThisType t = new OtherType() would compile.
- */
- @Override
- public boolean isAssignableBy(ResolvedType other) {
- if (other instanceof NullType) {
- return !this.isPrimitive();
- }
- // everything is assignable to Object except void
- if (!other.isVoid() && this.isJavaLangObject()) {
- return true;
- }
- // consider boxing
- if (other.isPrimitive()) {
- if (this.isJavaLangObject()) {
- return true;
- } else {
- // Check if 'other' can be boxed to match this type
- if (isCorrespondingBoxingType(other.describe())) return true;
-
- // Resolve the boxed type and check if it can be assigned via widening reference conversion
- SymbolReference type = typeSolver.tryToSolveType(other.asPrimitive().getBoxTypeQName());
- return type.getCorrespondingDeclaration().canBeAssignedTo(super.typeDeclaration);
- }
- }
- if (other instanceof LambdaArgumentTypePlaceholder) {
- return FunctionalInterfaceLogic.isFunctionalInterfaceType(this);
- } else if (other instanceof ReferenceTypeImpl) {
- ReferenceTypeImpl otherRef = (ReferenceTypeImpl) other;
- if (compareConsideringTypeParameters(otherRef)) {
- return true;
- }
- for (ResolvedReferenceType otherAncestor : otherRef.getAllAncestors()) {
- if (compareConsideringTypeParameters(otherAncestor)) {
- return true;
- }
- }
- return false;
- } else if (other.isTypeVariable()) {
- for (ResolvedTypeParameterDeclaration.Bound bound : other.asTypeVariable().asTypeParameter().getBounds()) {
- if (bound.isExtends()) {
- if (this.isAssignableBy(bound.getType())) {
- return true;
- }
- }
- }
- return false;
- } else if (other.isConstraint()){
- return isAssignableBy(other.asConstraintType().getBound());
- } else if (other.isWildcard()) {
- if (this.isJavaLangObject()) {
- return true;
- } else if (other.asWildcard().isExtends()) {
- return isAssignableBy(other.asWildcard().getBoundedType());
- } else {
- return false;
- }
- } else if (other.isUnionType()) {
- return other.asUnionType().getCommonAncestor()
- .map(ancestor -> isAssignableBy(ancestor)).orElse(false);
- } else {
- return false;
- }
- }
-
- @Override
- public Set getDeclaredMethods() {
- // TODO replace variables
- Set methods = new HashSet<>();
-
- getTypeDeclaration().ifPresent(referenceTypeDeclaration -> {
- for (ResolvedMethodDeclaration methodDeclaration : referenceTypeDeclaration.getDeclaredMethods()) {
- MethodUsage methodUsage = new MethodUsage(methodDeclaration);
- methods.add(methodUsage);
- }
- });
-
- return methods;
- }
-
- @Override
- public ResolvedType toRawType() {
- if (this.isRawType()) {
- return this;
- } else {
- return new ReferenceTypeImpl(typeDeclaration, typeSolver);
- }
- }
-
- @Override
- public boolean mention(List typeParameters) {
- return typeParametersValues().stream().anyMatch(tp -> tp.mention(typeParameters));
- }
-
- /**
- * Execute a transformation on all the type parameters of this element.
- */
- @Override
- public ResolvedType transformTypeParameters(ResolvedTypeTransformer transformer) {
- ResolvedType result = this;
- int i = 0;
- for (ResolvedType tp : this.typeParametersValues()) {
- ResolvedType transformedTp = transformer.transform(tp);
- // Identity comparison on purpose
- if (transformedTp != tp) {
- List typeParametersCorrected = result.asReferenceType().typeParametersValues();
- typeParametersCorrected.set(i, transformedTp);
- result = create(typeDeclaration, typeParametersCorrected);
- }
- i++;
- }
- return result;
- }
-
- public List getAllAncestors() {
- // We need to go through the inheritance line and propagate the type parametes
-
- List ancestors = typeDeclaration.getAllAncestors();
-
- ancestors = ancestors.stream()
- .map(a -> typeParametersMap().replaceAll(a).asReferenceType())
- .collect(Collectors.toList());
-
- // Avoid repetitions of Object
- ancestors.removeIf(ResolvedReferenceType::isJavaLangObject);
- ResolvedReferenceTypeDeclaration objectType = typeSolver.getSolvedJavaLangObject();
- ancestors.add(create(objectType));
-
- return ancestors;
- }
-
- public List getDirectAncestors() {
- // We need to go through the inheritance line and propagate the type parameters
-
- List ancestors = typeDeclaration.getAncestors();
-
- ancestors = ancestors.stream()
- .map(a -> typeParametersMap().replaceAll(a).asReferenceType())
- .collect(Collectors.toList());
-
-
- // Avoid repetitions of Object -- remove them all and, if appropriate, add it back precisely once.
- ancestors.removeIf(ResolvedReferenceType::isJavaLangObject);
-
- // Conditionally re-insert java.lang.Object as an ancestor.
- if(this.getTypeDeclaration().isPresent()) {
- ResolvedReferenceTypeDeclaration thisTypeDeclaration = this.getTypeDeclaration().get();
- if (thisTypeDeclaration.isClass()) {
- Optional optionalSuperClass = thisTypeDeclaration.asClass().getSuperClass();
- boolean superClassIsJavaLangObject = optionalSuperClass.isPresent() && optionalSuperClass.get().isJavaLangObject();
- boolean thisIsJavaLangObject = thisTypeDeclaration.asClass().isJavaLangObject();
- if (superClassIsJavaLangObject && !thisIsJavaLangObject) {
- ancestors.add(create(typeSolver.getSolvedJavaLangObject()));
- }
- } else {
- // If this isn't a class (i.e. is enum or interface (or record?)), add java.lang.Object as a supertype
- // TODO: Should we also add the implicit java.lang.Enum ancestor in the case of enums?
- // TODO: getDirectAncestors() shouldn't be inserting implicit ancesters...? See also issue #2696
- ancestors.add(create(typeSolver.getSolvedJavaLangObject()));
- }
- }
-
- return ancestors;
- }
-
- public ResolvedReferenceType deriveTypeParameters(ResolvedTypeParametersMap typeParametersMap) {
- return create(typeDeclaration, typeParametersMap);
- }
-
- @Override
- public Set getDeclaredFields() {
- Set allFields = new LinkedHashSet<>();
-
- if (getTypeDeclaration().isPresent()) {
- allFields.addAll(getTypeDeclaration().get().getDeclaredFields());
- }
-
- return allFields;
- }
-}
diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/MyObjectProvider.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/MyObjectProvider.java
deleted file mode 100644
index f79fdf7..0000000
--- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/reflectionmodel/MyObjectProvider.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Copyright (C) 2015-2016 Federico Tomassetti
- * Copyright (C) 2017-2020 The JavaParser Team.
- *
- * This file is part of JavaParser.
- *
- * JavaParser can be used either under the terms of
- * a) the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- * b) the terms of the Apache License
- *
- * You should have received a copy of both licenses in LICENCE.LGPL and
- * LICENCE.APACHE. Please refer to those files for details.
- *
- * JavaParser is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- */
-
-package com.github.javaparser.symbolsolver.reflectionmodel;
-
-import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration;
-import com.github.javaparser.resolution.types.ResolvedReferenceType;
-import com.github.javaparser.symbolsolver.logic.ObjectProvider;
-import com.github.javaparser.symbolsolver.model.resolution.TypeSolver;
-import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl;
-import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver;
-
-/**
- * @author Federico Tomassetti
- */
-public class MyObjectProvider implements ObjectProvider {
-
- public static final MyObjectProvider INSTANCE = new MyObjectProvider();
-
- private MyObjectProvider() {
- // prevent instantiation
- }
-
- @Override
- public ResolvedReferenceType object() {
- return new ReferenceTypeImpl(new ReflectionClassDeclaration(Object.class, new ReflectionTypeSolver()), new ReflectionTypeSolver());
- }
-
- @Override
- public ResolvedReferenceType byName(String qualifiedName) {
- TypeSolver typeSolver = new ReflectionTypeSolver();
- ResolvedReferenceTypeDeclaration typeDeclaration = typeSolver.solveType(qualifiedName);
- if (!typeDeclaration.getTypeParameters().isEmpty()) {
- throw new UnsupportedOperationException();
- }
- return new ReferenceTypeImpl(typeDeclaration, typeSolver);
- }
-
-}
diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/ConstructorResolutionLogic.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/ConstructorResolutionLogic.java
deleted file mode 100644
index 84848a6..0000000
--- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/ConstructorResolutionLogic.java
+++ /dev/null
@@ -1,238 +0,0 @@
-/*
- * Copyright (C) 2015-2016 Federico Tomassetti
- * Copyright (C) 2017-2020 The JavaParser Team.
- *
- * This file is part of JavaParser.
- *
- * JavaParser can be used either under the terms of
- * a) the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- * b) the terms of the Apache License
- *
- * You should have received a copy of both licenses in LICENCE.LGPL and
- * LICENCE.APACHE. Please refer to those files for details.
- *
- * JavaParser is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- */
-
-package com.github.javaparser.symbolsolver.resolution;
-
-import com.github.javaparser.resolution.MethodAmbiguityException;
-import com.github.javaparser.resolution.declarations.ResolvedConstructorDeclaration;
-import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration;
-import com.github.javaparser.resolution.types.ResolvedArrayType;
-import com.github.javaparser.resolution.types.ResolvedType;
-import com.github.javaparser.symbolsolver.model.resolution.SymbolReference;
-import com.github.javaparser.symbolsolver.model.resolution.TypeSolver;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.stream.Collectors;
-
-/**
- * @author Fred Lefévère-Laoide
- */
-public class ConstructorResolutionLogic {
-
- private static List groupVariadicParamValues(List argumentsTypes, int startVariadic,
- ResolvedType variadicType) {
- List res = new ArrayList<>(argumentsTypes.subList(0, startVariadic));
- List variadicValues = argumentsTypes.subList(startVariadic, argumentsTypes.size());
- if (variadicValues.isEmpty()) {
- // TODO if there are no variadic values we should default to the bound of the formal type
- res.add(variadicType);
- } else {
- ResolvedType componentType = findCommonType(variadicValues);
- res.add(new ResolvedArrayType(componentType));
- }
- return res;
- }
-
- private static ResolvedType findCommonType(List variadicValues) {
- if (variadicValues.isEmpty()) {
- throw new IllegalArgumentException();
- }
- // TODO implement this decently
- return variadicValues.get(0);
- }
-
- public static boolean isApplicable(ResolvedConstructorDeclaration constructor, List argumentsTypes,
- TypeSolver typeSolver) {
- return isApplicable(constructor, argumentsTypes, typeSolver, false);
- }
-
- private static boolean isApplicable(ResolvedConstructorDeclaration constructor, List argumentsTypes,
- TypeSolver typeSolver, boolean withWildcardTolerance) {
- if (constructor.hasVariadicParameter()) {
- int pos = constructor.getNumberOfParams() - 1;
- if (constructor.getNumberOfParams() == argumentsTypes.size()) {
- // check if the last value is directly assignable as an array
- ResolvedType expectedType = constructor.getLastParam().getType();
- ResolvedType actualType = argumentsTypes.get(pos);
- if (!expectedType.isAssignableBy(actualType)) {
- for (ResolvedTypeParameterDeclaration tp : constructor.getTypeParameters()) {
- expectedType = MethodResolutionLogic.replaceTypeParam(expectedType, tp, typeSolver);
- }
- if (!expectedType.isAssignableBy(actualType)) {
- if (actualType.isArray()
- && expectedType.isAssignableBy(actualType.asArrayType().getComponentType())) {
- argumentsTypes.set(pos, actualType.asArrayType().getComponentType());
- } else {
- argumentsTypes = groupVariadicParamValues(argumentsTypes, pos,
- constructor.getLastParam().getType());
- }
- }
- } // else it is already assignable, nothing to do
- } else {
- if (pos > argumentsTypes.size()) {
- return false;
- }
- argumentsTypes =
- groupVariadicParamValues(argumentsTypes, pos, constructor.getLastParam().getType());
- }
- }
-
- if (constructor.getNumberOfParams() != argumentsTypes.size()) {
- return false;
- }
- Map matchedParameters = new HashMap<>();
- boolean needForWildCardTolerance = false;
- for (int i = 0; i < constructor.getNumberOfParams(); i++) {
- ResolvedType expectedType = constructor.getParam(i).getType();
- ResolvedType actualType = argumentsTypes.get(i);
- if ((expectedType.isTypeVariable() && !(expectedType.isWildcard()))
- && expectedType.asTypeParameter().declaredOnMethod()) {
- matchedParameters.put(expectedType.asTypeParameter().getName(), actualType);
- continue;
- }
- boolean isAssignableWithoutSubstitution =
- expectedType.isAssignableBy(actualType) || (constructor.getParam(i).isVariadic()
- && new ResolvedArrayType(expectedType).isAssignableBy(actualType));
- if (!isAssignableWithoutSubstitution && expectedType.isReferenceType()
- && actualType.isReferenceType()) {
- isAssignableWithoutSubstitution = MethodResolutionLogic.isAssignableMatchTypeParameters(
- expectedType.asReferenceType(), actualType.asReferenceType(), matchedParameters);
- }
- if (!isAssignableWithoutSubstitution) {
- for (ResolvedTypeParameterDeclaration tp : constructor.getTypeParameters()) {
- expectedType = MethodResolutionLogic.replaceTypeParam(expectedType, tp, typeSolver);
- }
- for (ResolvedTypeParameterDeclaration tp : constructor.declaringType().getTypeParameters()) {
- expectedType = MethodResolutionLogic.replaceTypeParam(expectedType, tp, typeSolver);
- }
-
- if (!expectedType.isAssignableBy(actualType)) {
- if (actualType.isWildcard() && withWildcardTolerance && !expectedType.isPrimitive()) {
- needForWildCardTolerance = true;
- continue;
- }
- if (constructor.hasVariadicParameter() && i == constructor.getNumberOfParams() - 1) {
- if (new ResolvedArrayType(expectedType).isAssignableBy(actualType)) {
- continue;
- }
- }
- return false;
- }
- }
- }
- return !withWildcardTolerance || needForWildCardTolerance;
- }
-
- /**
- * @param constructors we expect the methods to be ordered such that inherited methods are later in the list
- * @param argumentsTypes
- * @param typeSolver
- * @return
- */
- public static SymbolReference findMostApplicable(
- List constructors, List argumentsTypes, TypeSolver typeSolver) {
- SymbolReference res =
- findMostApplicable(constructors, argumentsTypes, typeSolver, false);
- if (res.isSolved()) {
- return res;
- }
- return findMostApplicable(constructors, argumentsTypes, typeSolver, true);
- }
-
- public static SymbolReference findMostApplicable(
- List constructors, List argumentsTypes, TypeSolver typeSolver, boolean wildcardTolerance) {
- List applicableConstructors = constructors.stream().filter((m) -> isApplicable(m, argumentsTypes, typeSolver, wildcardTolerance)).collect(Collectors.toList());
- if (applicableConstructors.isEmpty()) {
- return SymbolReference.unsolved(ResolvedConstructorDeclaration.class);
- }
- if (applicableConstructors.size() == 1) {
- return SymbolReference.solved(applicableConstructors.get(0));
- } else {
- ResolvedConstructorDeclaration winningCandidate = applicableConstructors.get(0);
- ResolvedConstructorDeclaration other = null;
- boolean possibleAmbiguity = false;
- for (int i = 1; i < applicableConstructors.size(); i++) {
- other = applicableConstructors.get(i);
- if (isMoreSpecific(winningCandidate, other, typeSolver)) {
- possibleAmbiguity = false;
- } else if (isMoreSpecific(other, winningCandidate, typeSolver)) {
- possibleAmbiguity = false;
- winningCandidate = other;
- } else {
- if (winningCandidate.declaringType().getQualifiedName()
- .equals(other.declaringType().getQualifiedName())) {
- possibleAmbiguity = true;
- } else {
- // we expect the methods to be ordered such that inherited methods are later in the list
- }
- }
- if (possibleAmbiguity) {
- // pick the first exact match if it exists
- if (!MethodResolutionLogic.isExactMatch(winningCandidate, argumentsTypes)) {
- if (MethodResolutionLogic.isExactMatch(other, argumentsTypes)) {
- winningCandidate = other;
- } else {
- throw new MethodAmbiguityException("Ambiguous constructor call: cannot find a most applicable constructor: " + winningCandidate + ", " + other);
- }
- }
- }
- }
-
- return SymbolReference.solved(winningCandidate);
- }
- }
-
- private static boolean isMoreSpecific(ResolvedConstructorDeclaration constructorA,
- ResolvedConstructorDeclaration constructorB, TypeSolver typeSolver) {
- boolean oneMoreSpecificFound = false;
- if (constructorA.getNumberOfParams() < constructorB.getNumberOfParams()) {
- return true;
- }
- if (constructorA.getNumberOfParams() > constructorB.getNumberOfParams()) {
- return false;
- }
- for (int i = 0; i < constructorA.getNumberOfParams(); i++) {
- ResolvedType tdA = constructorA.getParam(i).getType();
- ResolvedType tdB = constructorB.getParam(i).getType();
- // B is more specific
- if (tdB.isAssignableBy(tdA) && !tdA.isAssignableBy(tdB)) {
- oneMoreSpecificFound = true;
- }
- // A is more specific
- if (tdA.isAssignableBy(tdB) && !tdB.isAssignableBy(tdA)) {
- return false;
- }
- // if it matches a variadic and a not variadic I pick the not variadic
- if (!tdA.isArray() && tdB.isArray()) {
- return true;
- }
- // FIXME
- if (i == (constructorA.getNumberOfParams() - 1) && tdA.arrayLevel() > tdB.arrayLevel()) {
- return true;
- }
- }
- return oneMoreSpecificFound;
- }
-
-}
diff --git a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/MethodResolutionLogic.java b/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/MethodResolutionLogic.java
deleted file mode 100644
index a238948..0000000
--- a/javaparser-symbol-solver-core/src/main/java/com/github/javaparser/symbolsolver/resolution/MethodResolutionLogic.java
+++ /dev/null
@@ -1,868 +0,0 @@
-/*
- * Copyright (C) 2015-2016 Federico Tomassetti
- * Copyright (C) 2017-2020 The JavaParser Team.
- *
- * This file is part of JavaParser.
- *
- * JavaParser can be used either under the terms of
- * a) the GNU Lesser General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- * b) the terms of the Apache License
- *
- * You should have received a copy of both licenses in LICENCE.LGPL and
- * LICENCE.APACHE. Please refer to those files for details.
- *
- * JavaParser is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- */
-
-package com.github.javaparser.symbolsolver.resolution;
-
-import com.github.javaparser.resolution.MethodAmbiguityException;
-import com.github.javaparser.resolution.MethodUsage;
-import com.github.javaparser.resolution.declarations.*;
-import com.github.javaparser.resolution.types.*;
-import com.github.javaparser.symbolsolver.logic.MethodResolutionCapability;
-import com.github.javaparser.symbolsolver.model.resolution.SymbolReference;
-import com.github.javaparser.symbolsolver.model.resolution.TypeSolver;
-import com.github.javaparser.symbolsolver.model.typesystem.ReferenceTypeImpl;
-
-import java.util.*;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.function.Function;
-import java.util.function.Predicate;
-import java.util.stream.Collectors;
-
-/**
- * @author Federico Tomassetti
- */
-public class MethodResolutionLogic {
-
- private static String JAVA_LANG_OBJECT = Object.class.getCanonicalName();
-
- private static List groupVariadicParamValues(List argumentsTypes, int startVariadic, ResolvedType variadicType) {
- List res = new ArrayList<>(argumentsTypes.subList(0, startVariadic));
- List variadicValues = argumentsTypes.subList(startVariadic, argumentsTypes.size());
- if (variadicValues.isEmpty()) {
- // TODO if there are no variadic values we should default to the bound of the formal type
- res.add(variadicType);
- } else {
- ResolvedType componentType = findCommonType(variadicValues);
- res.add(new ResolvedArrayType(componentType));
- }
- return res;
- }
-
- private static ResolvedType findCommonType(List variadicValues) {
- if (variadicValues.isEmpty()) {
- throw new IllegalArgumentException();
- }
- // TODO implement this decently
- return variadicValues.get(0);
- }
-
- public static boolean isApplicable(ResolvedMethodDeclaration method, String name, List argumentsTypes, TypeSolver typeSolver) {
- return isApplicable(method, name, argumentsTypes, typeSolver, false);
- }
-
- /**
- * Note the specific naming here -- parameters are part of the method declaration,
- * while arguments are the values passed when calling a method.
- * Note that "needle" refers to that value being used as a search/query term to match against.
- *
- * @return true, if the given ResolvedMethodDeclaration matches the given name/types (normally obtained from a MethodUsage)
- *
- * @see {@link MethodResolutionLogic#isApplicable(MethodUsage, String, List, TypeSolver)}
- */
- private static boolean isApplicable(ResolvedMethodDeclaration methodDeclaration, String needleName, List needleArgumentTypes, TypeSolver typeSolver, boolean withWildcardTolerance) {
- if (!methodDeclaration.getName().equals(needleName)) {
- return false;
- }
-
- // The index of the final method parameter (on the method declaration).
- int countOfMethodParametersDeclared = methodDeclaration.getNumberOfParams();
- int lastMethodParameterIndex = Math.max(0, countOfMethodParametersDeclared - 1);
-
- // The index of the final argument passed (on the method usage).
- int countOfNeedleArgumentsPassed = needleArgumentTypes.size();
- int lastNeedleArgumentIndex = Math.max(0, countOfNeedleArgumentsPassed - 1);
-
- boolean methodIsDeclaredWithVariadicParameter = methodDeclaration.hasVariadicParameter();
-
- if (!methodIsDeclaredWithVariadicParameter && (countOfNeedleArgumentsPassed != countOfMethodParametersDeclared)) {
- // If it is not variadic, and the number of parameters/arguments are unequal -- this is not a match.
- return false;
- }
-
- if (methodIsDeclaredWithVariadicParameter) {
- // If the method declaration we're considering has a variadic parameter,
- // attempt to convert the given list of arguments to fit this pattern
- // e.g. foo(String s, String... s2) {} --- consider the first argument, then group the remainder as an array
-
- ResolvedType expectedVariadicParameterType = methodDeclaration.getLastParam().getType();
- for (ResolvedTypeParameterDeclaration tp : methodDeclaration.getTypeParameters()) {
- expectedVariadicParameterType = replaceTypeParam(expectedVariadicParameterType, tp, typeSolver);
- }
-
- if(countOfNeedleArgumentsPassed <= (countOfMethodParametersDeclared - 2)) {
- // If it is variadic, and the number of arguments are short by **two or more** -- this is not a match.
- // Note that omitting the variadic parameter is treated as an empty array
- // (thus being short of only 1 argument is fine, but being short of 2 or more is not).
- return false;
- } else if (countOfNeedleArgumentsPassed == (countOfMethodParametersDeclared - 1)) {
- // If it is variadic and we are short of **exactly one** parameter, this is a match.
- // Note that omitting the variadic parameter is treated as an empty array
- // (thus being short of only 1 argument is fine, but being short of 2 or more is not).
-
- // thus group the "empty" value into an empty array...
- needleArgumentTypes = groupVariadicParamValues(needleArgumentTypes, lastMethodParameterIndex, methodDeclaration.getLastParam().getType());
- } else if (countOfNeedleArgumentsPassed > countOfMethodParametersDeclared) {
- // If it is variadic, and we have an "excess" of arguments, group the "trailing" arguments into an array.
- // Confirm all of these grouped "trailing" arguments have the required type -- if not, this is not a valid type. (Maybe this is also done later..?)
- for(int variadicArgumentIndex = countOfMethodParametersDeclared; variadicArgumentIndex < countOfNeedleArgumentsPassed; variadicArgumentIndex++) {
- ResolvedType currentArgumentType = needleArgumentTypes.get(variadicArgumentIndex);
- boolean argumentIsAssignableToVariadicComponentType = expectedVariadicParameterType.asArrayType().getComponentType().isAssignableBy(currentArgumentType);
- if(!argumentIsAssignableToVariadicComponentType) {
- // If any of the arguments are not assignable to the expected variadic type, this is not a match.
- return false;
- }
- }
- needleArgumentTypes = groupVariadicParamValues(needleArgumentTypes, lastMethodParameterIndex, methodDeclaration.getLastParam().getType());
- } else if (countOfNeedleArgumentsPassed == countOfMethodParametersDeclared) {
- ResolvedType actualArgumentType = needleArgumentTypes.get(lastNeedleArgumentIndex);
- boolean finalArgumentIsArray = actualArgumentType.isArray() && expectedVariadicParameterType.isAssignableBy(actualArgumentType.asArrayType().getComponentType());
- if(finalArgumentIsArray) {
- // Treat as an array of values -- in which case the expected parameter type is the common type of this array.
- // no need to do anything
-// expectedVariadicParameterType = actualArgumentType.asArrayType().getComponentType();
- } else {
- // Treat as a single value -- in which case, the expected parameter type is the same as the single value.
- needleArgumentTypes = groupVariadicParamValues(needleArgumentTypes, lastMethodParameterIndex, methodDeclaration.getLastParam().getType());
- }
- } else {
- // Should be unreachable.
- }
- }
-
-
- // The index of the final argument passed (on the method usage).
- int countOfNeedleArgumentsPassedAfterGrouping = needleArgumentTypes.size();
- int lastNeedleArgumentIndexAfterGrouping = Math.max(0, countOfNeedleArgumentsPassed - 1);
-
- // If variadic parameters are possible then they will have been "grouped" into a single argument.
- // At this point, therefore, the number of arguments must be equal -- if they're not, then there is no match.
- if (countOfNeedleArgumentsPassedAfterGrouping != countOfMethodParametersDeclared) {
- return false;
- }
-
-
- Map matchedParameters = new HashMap<>();
- boolean needForWildCardTolerance = false;
- for (int i = 0; i < countOfMethodParametersDeclared; i++) {
- ResolvedType expectedDeclaredType = methodDeclaration.getParam(i).getType();
- ResolvedType actualArgumentType = needleArgumentTypes.get(i);
- if ((expectedDeclaredType.isTypeVariable() && !(expectedDeclaredType.isWildcard())) && expectedDeclaredType.asTypeParameter().declaredOnMethod()) {
- matchedParameters.put(expectedDeclaredType.asTypeParameter().getName(), actualArgumentType);
- continue;
- }
-
- boolean isAssignableWithoutSubstitution = expectedDeclaredType.isAssignableBy(actualArgumentType) ||
- (methodDeclaration.getParam(i).isVariadic() && new ResolvedArrayType(expectedDeclaredType).isAssignableBy(actualArgumentType));
-
- if (!isAssignableWithoutSubstitution && expectedDeclaredType.isReferenceType() && actualArgumentType.isReferenceType()) {
- isAssignableWithoutSubstitution = isAssignableMatchTypeParameters(
- expectedDeclaredType.asReferenceType(),
- actualArgumentType.asReferenceType(),
- matchedParameters);
- }
- if (!isAssignableWithoutSubstitution) {
- List typeParameters = methodDeclaration.getTypeParameters();
- typeParameters.addAll(methodDeclaration.declaringType().getTypeParameters());
- for (ResolvedTypeParameterDeclaration tp : typeParameters) {
- expectedDeclaredType = replaceTypeParam(expectedDeclaredType, tp, typeSolver);
- }
-
- if (!expectedDeclaredType.isAssignableBy(actualArgumentType)) {
- if (actualArgumentType.isWildcard() && withWildcardTolerance && !expectedDeclaredType.isPrimitive()) {
- needForWildCardTolerance = true;
- continue;
- }
- // if the expected is java.lang.Math.max(double,double) and the type parameters are defined with constrain
- // for example LambdaConstraintType{bound=TypeVariable {ReflectionTypeParameter{typeVariable=T}}}, LambdaConstraintType{bound=TypeVariable {ReflectionTypeParameter{typeVariable=U}}}
- // we want to keep this method for future resolution
- if (actualArgumentType.isConstraint() && withWildcardTolerance && expectedDeclaredType.isPrimitive()) {
- needForWildCardTolerance = true;
- continue;
- }
- if (methodIsDeclaredWithVariadicParameter && i == countOfMethodParametersDeclared - 1) {
- if (new ResolvedArrayType(expectedDeclaredType).isAssignableBy(actualArgumentType)) {
- continue;
- }
- }
- return false;
- }
- }
- }
- return !withWildcardTolerance || needForWildCardTolerance;
- }
-
- public static boolean isAssignableMatchTypeParameters(ResolvedType expected, ResolvedType actual,
- Map matchedParameters) {
- if (expected.isReferenceType() && actual.isReferenceType()) {
- return isAssignableMatchTypeParameters(expected.asReferenceType(), actual.asReferenceType(), matchedParameters);
- } else if (expected.isTypeVariable()) {
- matchedParameters.put(expected.asTypeParameter().getName(), actual);
- return true;
- } else if (expected.isArray()) {
- matchedParameters.put(expected.asArrayType().getComponentType().toString(), actual);
- return true;
- } else {
- throw new UnsupportedOperationException(expected.getClass().getCanonicalName() + " " + actual.getClass().getCanonicalName());
- }
- }
-
- public static boolean isAssignableMatchTypeParameters(ResolvedReferenceType expected, ResolvedReferenceType actual,
- Map matchedParameters) {
- if (actual.getQualifiedName().equals(expected.getQualifiedName())) {
- return isAssignableMatchTypeParametersMatchingQName(expected, actual, matchedParameters);
- } else {
- List ancestors = actual.getAllAncestors();
- for (ResolvedReferenceType ancestor : ancestors) {
- if (isAssignableMatchTypeParametersMatchingQName(expected, ancestor, matchedParameters)) {
- return true;
- }
- }
- }
- return false;
- }
-
- private static boolean isAssignableMatchTypeParametersMatchingQName(ResolvedReferenceType expected, ResolvedReferenceType actual,
- Map matchedParameters) {
-
- if (!expected.getQualifiedName().equals(actual.getQualifiedName())) {
- return false;
- }
- if (expected.typeParametersValues().size() != actual.typeParametersValues().size()) {
- throw new UnsupportedOperationException();
- //return true;
- }
- for (int i = 0; i < expected.typeParametersValues().size(); i++) {
- ResolvedType expectedParam = expected.typeParametersValues().get(i);
- ResolvedType actualParam = actual.typeParametersValues().get(i);
-
- // In the case of nested parameterizations eg. List <-> List
- // we should peel off one layer and ensure R <-> Integer
- if (expectedParam.isReferenceType() && actualParam.isReferenceType()) {
- ResolvedReferenceType r1 = expectedParam.asReferenceType();
- ResolvedReferenceType r2 = actualParam.asReferenceType();
- // we can have r1=A and r2=A.B (with B extends A and B is an inner class of A)
- // in this case we want to verify expected parameter from the actual parameter ancestors
- return isAssignableMatchTypeParameters(r1, r2, matchedParameters);
- }
-
- if (expectedParam.isTypeVariable()) {
- String expectedParamName = expectedParam.asTypeParameter().getName();
- if (!actualParam.isTypeVariable() || !actualParam.asTypeParameter().getName().equals(expectedParamName)) {
- return matchTypeVariable(expectedParam.asTypeVariable(), actualParam, matchedParameters);
- }
- } else if (expectedParam.isReferenceType()) {
- if (actualParam.isTypeVariable()) {
- return matchTypeVariable(actualParam.asTypeVariable(), expectedParam, matchedParameters);
- } else if (!expectedParam.equals(actualParam)) {
- return false;
- }
- } else if (expectedParam.isWildcard()) {
- if (expectedParam.asWildcard().isExtends()) {
- return isAssignableMatchTypeParameters(expectedParam.asWildcard().getBoundedType(), actual, matchedParameters);
- }
- // TODO verify super bound
- return true;
- } else {
- throw new UnsupportedOperationException(expectedParam.describe());
- }
- }
- return true;
- }
-
- private static boolean matchTypeVariable(ResolvedTypeVariable typeVariable, ResolvedType type, Map matchedParameters) {
- String typeParameterName = typeVariable.asTypeParameter().getName();
- if (matchedParameters.containsKey(typeParameterName)) {
- ResolvedType matchedParameter = matchedParameters.get(typeParameterName);
- if (matchedParameter.isAssignableBy(type)) {
- return true;
- } else if (type.isAssignableBy(matchedParameter)) {
- // update matchedParameters to contain the more general type
- matchedParameters.put(typeParameterName, type);
- return true;
- }
- return false;
- } else {
- matchedParameters.put(typeParameterName, type);
- }
- return true;
- }
-
- public static ResolvedType replaceTypeParam(ResolvedType type, ResolvedTypeParameterDeclaration tp, TypeSolver typeSolver) {
- if (type.isTypeVariable() || type.isWildcard()) {
- if (type.describe().equals(tp.getName())) {
- List bounds = tp.getBounds();
- if (bounds.size() > 1) {
- throw new UnsupportedOperationException();
- } else if (bounds.size() == 1) {
- return bounds.get(0).getType();
- } else {
- return new ReferenceTypeImpl(typeSolver.solveType(JAVA_LANG_OBJECT), typeSolver);
- }
- }
- return type;
- } else if (type.isPrimitive()) {
- return type;
- } else if (type.isArray()) {
- return new ResolvedArrayType(replaceTypeParam(type.asArrayType().getComponentType(), tp, typeSolver));
- } else if (type.isReferenceType()) {
- ResolvedReferenceType result = type.asReferenceType();
- result = result.transformTypeParameters(typeParam -> replaceTypeParam(typeParam, tp, typeSolver)).asReferenceType();
- return result;
- } else {
- throw new UnsupportedOperationException("Replacing " + type + ", param " + tp + " with " + type.getClass().getCanonicalName());
- }
- }
-
- /**
- * Note the specific naming here -- parameters are part of the method declaration,
- * while arguments are the values passed when calling a method.
- * Note that "needle" refers to that value being used as a search/query term to match against.
- *
- * @return true, if the given MethodUsage matches the given name/types (normally obtained from a ResolvedMethodDeclaration)
- *
- * @see {@link MethodResolutionLogic#isApplicable(ResolvedMethodDeclaration, String, List, TypeSolver)} }
- * @see {@link MethodResolutionLogic#isApplicable(ResolvedMethodDeclaration, String, List, TypeSolver, boolean)}
- */
- public static boolean isApplicable(MethodUsage methodUsage, String needleName, List needleParameterTypes, TypeSolver typeSolver) {
- if (!methodUsage.getName().equals(needleName)) {
- return false;
- }
-
- // The index of the final method parameter (on the method declaration).
- int countOfMethodUsageArgumentsPassed = methodUsage.getNoParams();
- int lastMethodUsageArgumentIndex = Math.max(0, countOfMethodUsageArgumentsPassed - 1);
-
- // The index of the final argument passed (on the method usage).
- int needleParameterCount = needleParameterTypes.size();
- int lastNeedleParameterIndex = Math.max(0, needleParameterCount - 1);
-
- // TODO: Does the method usage have a declaration at this point..?
- boolean methodIsDeclaredWithVariadicParameter = methodUsage.getDeclaration().hasVariadicParameter();
-
- // If the counts do not match and the method is not variadic, this is not a match.
- if (!methodIsDeclaredWithVariadicParameter && !(needleParameterCount == countOfMethodUsageArgumentsPassed)) {
- return false;
- }
-
- // If the counts do not match and we have provided too few arguments, this is not a match. Note that variadic parameters
- // allow you to omit the vararg, which would allow a difference of one, but a difference in count of 2 or more is not a match.
- if (!(needleParameterCount == countOfMethodUsageArgumentsPassed) && needleParameterCount < lastMethodUsageArgumentIndex) {
- return false;
- }
-
- // Iterate over the arguments given to the method, and compare their types against the given method's declared parameter types
- for (int i = 0; i < needleParameterCount; i++) {
- ResolvedType actualArgumentType = needleParameterTypes.get(i);
-
- ResolvedType expectedArgumentType;
- boolean reachedVariadicParam = methodIsDeclaredWithVariadicParameter && i >= lastMethodUsageArgumentIndex;
- if (!reachedVariadicParam) {
- // Not yet reached the variadic parameters -- the expected type is just whatever is at that position.
- expectedArgumentType = methodUsage.getParamType(i);
- } else {
- // We have reached the variadic parameters -- the expected type is the type of the last declared parameter.
- expectedArgumentType = methodUsage.getParamType(lastMethodUsageArgumentIndex);
- // Note that the given variadic value might be an array - if so, use the array's component type rather.
- // This is only valid if ONE argument has been given to the vararg parameter.
- // Example: {@code void test(String... s) {}} and {@code test(stringArray)} -- {@code String... is assignable by stringArray}
- // Example: {@code void test(String[]... s) {}} and {@code test(stringArrayArray)} -- {@code String[]... is assignable by stringArrayArray}
- boolean argumentIsArray = (needleParameterCount == countOfMethodUsageArgumentsPassed) && expectedArgumentType.isAssignableBy(actualArgumentType);
- if (!argumentIsArray) {
- // Get the component type of the declared parameter type.
- expectedArgumentType = expectedArgumentType.asArrayType().getComponentType();
- }
- }
-
- // Consider type parameters directly on the method declaration, and ALSO on the enclosing type (e.g. a class)
- List typeParameters = methodUsage.getDeclaration().getTypeParameters();
- typeParameters.addAll(methodUsage.declaringType().getTypeParameters());
-
- ResolvedType expectedTypeWithoutSubstitutions = expectedArgumentType;
- ResolvedType expectedTypeWithInference = expectedArgumentType;
- Map derivedValues = new HashMap<>();
-
- // For each declared parameter, infer the types that will replace generics (type parameters)
- for (int j = 0; j < countOfMethodUsageArgumentsPassed; j++) {
- ResolvedParameterDeclaration parameter = methodUsage.getDeclaration().getParam(j);
- ResolvedType parameterType = parameter.getType();
- if (parameter.isVariadic()) {
- // Don't continue if a vararg parameter is reached and there are no arguments left
- if (needleParameterCount == j) {
- break;
- }
- parameterType = parameterType.asArrayType().getComponentType();
- }
- inferTypes(needleParameterTypes.get(j), parameterType, derivedValues);
- }
-
- for (Map.Entry entry : derivedValues.entrySet()) {
- ResolvedTypeParameterDeclaration tp = entry.getKey();
- expectedTypeWithInference = expectedTypeWithInference.replaceTypeVariables(tp, entry.getValue());
- }
-
- // Consider cases where type variables can be replaced (e.g. add(E element) vs add(String element))
- for (ResolvedTypeParameterDeclaration tp : typeParameters) {
- if (tp.getBounds().isEmpty()) {
- //expectedArgumentType = expectedArgumentType.replaceTypeVariables(tp.getName(), new ReferenceTypeUsageImpl(typeSolver.solveType(JAVA_LANG_OBJECT), typeSolver));
- expectedArgumentType = expectedArgumentType.replaceTypeVariables(tp, ResolvedWildcard.extendsBound(new ReferenceTypeImpl(typeSolver.solveType(JAVA_LANG_OBJECT), typeSolver)));
- } else if (tp.getBounds().size() == 1) {
- ResolvedTypeParameterDeclaration.Bound bound = tp.getBounds().get(0);
- if (bound.isExtends()) {
- //expectedArgumentType = expectedArgumentType.replaceTypeVariables(tp.getName(), bound.getType());
- expectedArgumentType = expectedArgumentType.replaceTypeVariables(tp, ResolvedWildcard.extendsBound(bound.getType()));
- } else {
- //expectedArgumentType = expectedArgumentType.replaceTypeVariables(tp.getName(), new ReferenceTypeUsageImpl(typeSolver.solveType(JAVA_LANG_OBJECT), typeSolver));
- expectedArgumentType = expectedArgumentType.replaceTypeVariables(tp, ResolvedWildcard.superBound(bound.getType()));
- }
- } else {
- throw new UnsupportedOperationException();
- }
- }
-
- // Consider cases where type variables involve bounds e.g. super/extends
- ResolvedType expectedTypeWithSubstitutions = expectedTypeWithoutSubstitutions;
- for (ResolvedTypeParameterDeclaration tp : typeParameters) {
- if (tp.getBounds().isEmpty()) {
- expectedTypeWithSubstitutions = expectedTypeWithSubstitutions.replaceTypeVariables(tp, new ReferenceTypeImpl(typeSolver.solveType(JAVA_LANG_OBJECT), typeSolver));
- } else if (tp.getBounds().size() == 1) {
- ResolvedTypeParameterDeclaration.Bound bound = tp.getBounds().get(0);
- if (bound.isExtends()) {
- expectedTypeWithSubstitutions = expectedTypeWithSubstitutions.replaceTypeVariables(tp, bound.getType());
- } else {
- expectedTypeWithSubstitutions = expectedTypeWithSubstitutions.replaceTypeVariables(tp, new ReferenceTypeImpl(typeSolver.solveType(JAVA_LANG_OBJECT), typeSolver));
- }
- } else {
- throw new UnsupportedOperationException();
- }
- }
-
- // If the given argument still isn't applicable even after considering type arguments/generics, this is not a match.
- if (!expectedArgumentType.isAssignableBy(actualArgumentType)
- && !expectedTypeWithSubstitutions.isAssignableBy(actualArgumentType)
- && !expectedTypeWithInference.isAssignableBy(actualArgumentType)
- && !expectedTypeWithoutSubstitutions.isAssignableBy(actualArgumentType)) {
- return false;
- }
- }
-
- // If the checks above haven't failed, then we've found a match.
- return true;
- }
-
- /**
- * Filters by given function {@param keyExtractor} using a stateful filter mechanism.
- *
- *
- * The example above would return a distinct list of persons containing only one person per name.
- */
- private static Predicate distinctByKey(Function super T, ?> keyExtractor) {
- Set