Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
issue1154: correcting resolved type hierarchy
- Loading branch information
1 parent
61db2ec
commit c7ee7cc
Showing
5 changed files
with
113 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
...er-core/src/main/java/com/github/javaparser/resolution/types/ResolvedTypeTransformer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,25 @@ | |||
/* | |||
* Copyright 2016 Federico Tomassetti | |||
* | |||
* Licensed under the Apache License, Version 2.0 (the "License"); | |||
* you may not use this file except in compliance with the License. | |||
* You may obtain a copy of the License at | |||
* | |||
* http://www.apache.org/licenses/LICENSE-2.0 | |||
* | |||
* Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, | |||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
* See the License for the specific language governing permissions and | |||
* limitations under the License. | |||
*/ | |||
|
|||
package com.github.javaparser.resolution.types; | |||
|
|||
/** | |||
* @author Federico Tomassetti | |||
*/ | |||
@FunctionalInterface | |||
public interface ResolvedTypeTransformer { | |||
ResolvedType transform(ResolvedType type); | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
...ithub/javaparser/resolution/types/parametrization/ResolvedTypeParameterValueProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,51 @@ | |||
package com.github.javaparser.resolution.types.parametrization; | |||
|
|||
import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; | |||
import com.github.javaparser.resolution.types.ResolvedType; | |||
import com.github.javaparser.resolution.types.ResolvedWildcard; | |||
|
|||
import java.util.Optional; | |||
|
|||
/** | |||
* @author Federico Tomassetti | |||
*/ | |||
public interface ResolvedTypeParameterValueProvider { | |||
|
|||
/** | |||
* Calculate the value for the given type parameter. | |||
* It could be inherited. | |||
*/ | |||
Optional<ResolvedType> typeParamValue(ResolvedTypeParameterDeclaration typeParameterDeclaration); | |||
|
|||
/** | |||
* Replace the type typeParametersValues present in the given type with the ones for which this type | |||
* has a value. | |||
*/ | |||
default ResolvedType useThisTypeParametersOnTheGivenType(ResolvedType type) { | |||
if (type.isTypeVariable()) { | |||
ResolvedTypeParameterDeclaration typeParameter = type.asTypeParameter(); | |||
if (typeParameter.declaredOnType()) { | |||
Optional<ResolvedType> typeParam = typeParamValue(typeParameter); | |||
if (typeParam.isPresent()) { | |||
type = typeParam.get(); | |||
} | |||
} | |||
} | |||
|
|||
if (type.isWildcard() && type.asWildcard().isBounded()) { | |||
if (type.asWildcard().isExtends()) { | |||
return ResolvedWildcard.extendsBound(useThisTypeParametersOnTheGivenType(type.asWildcard().getBoundedType())); | |||
} else { | |||
return ResolvedWildcard.superBound(useThisTypeParametersOnTheGivenType(type.asWildcard().getBoundedType())); | |||
} | |||
} | |||
|
|||
if (type.isReferenceType()) { | |||
type = type.asReferenceType().transformTypeParameters(this::useThisTypeParametersOnTheGivenType); | |||
} | |||
|
|||
return type; | |||
} | |||
|
|||
Optional<ResolvedType> getGenericParameterByName(String name); | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters