Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add AbstractMethodLikeDeclarationContext
- Loading branch information
1 parent
27f0f20
commit 03055f9
Showing
5 changed files
with
44 additions
and
40 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
33 changes: 33 additions & 0 deletions
33
...avaparser/symbolsolver/javaparsermodel/contexts/AbstractMethodLikeDeclarationContext.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 | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.github.javaparser.symbolsolver.javaparsermodel.contexts; | ||
|
||
import com.github.javaparser.ast.Node; | ||
import com.github.javaparser.ast.body.Parameter; | ||
import com.github.javaparser.ast.nodeTypes.NodeWithParameters; | ||
import com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFactory; | ||
import com.github.javaparser.symbolsolver.model.declarations.ValueDeclaration; | ||
import com.github.javaparser.symbolsolver.model.resolution.SymbolReference; | ||
import com.github.javaparser.symbolsolver.model.resolution.TypeSolver; | ||
import com.github.javaparser.symbolsolver.resolution.SymbolDeclarator; | ||
|
||
/** | ||
* @author Federico Tomassetti | ||
*/ | ||
public abstract class AbstractMethodLikeDeclarationContext<T extends Node & NodeWithParameters<T>> extends AbstractJavaParserContext<T> { | ||
|
||
public AbstractMethodLikeDeclarationContext(T wrappedNode, TypeSolver typeSolver) { | ||
super(wrappedNode, typeSolver); | ||
} | ||
|
||
public final SymbolReference<? extends ValueDeclaration> solveSymbol(String name, TypeSolver typeSolver) { | ||
for (Parameter parameter : wrappedNode.getParameters()) { | ||
SymbolDeclarator sb = JavaParserFactory.getSymbolDeclarator(parameter, typeSolver); | ||
SymbolReference symbolReference = AbstractJavaParserContext.solveWith(sb, name); | ||
if (symbolReference.isSolved()) { | ||
return symbolReference; | ||
} | ||
} | ||
|
||
// if nothing is found we should ask the parent context | ||
return getParent().solveSymbol(name, typeSolver); | ||
} | ||
} |
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
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
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