public abstract class FunctionHelper
extends java.lang.Object
Constructor and Description |
---|
FunctionHelper(PsiType resultType) |
Modifier and Type | Method and Description |
---|---|
static FunctionHelper |
create(PsiExpression expression,
int paramCount) |
static FunctionHelper |
create(PsiExpression expression,
int paramCount,
boolean allowReturns) |
abstract PsiExpression |
getExpression() |
java.lang.String |
getParameterName(int index) |
PsiType |
getResultType() |
java.lang.String |
getStatementText() |
java.lang.String |
getText() |
void |
preprocessVariable(ChainContext context,
ChainVariable var,
int index) |
void |
registerReusedElements(java.util.function.Consumer<? super PsiElement> consumer) |
void |
rename(java.lang.String oldName,
java.lang.String newName,
ChainContext context)
Rename the references of some variable if it's used inside this function
|
static <T extends PsiElement> |
replaceVarReference(T expressionOrCodeBlock,
java.lang.String name,
java.lang.String replacement,
ChainContext context)
Replaces all the references to the variable
name in given expression with replacement . |
static void |
suggestFromExpression(ChainVariable var,
Project project,
PsiExpression expression) |
void |
suggestOutputNames(ChainContext context,
ChainVariable var) |
abstract void |
transform(ChainContext context,
java.lang.String... argumentValues)
Adapts this function helper converting it to the valid expression and inlining SAM parameters with provided values.
|
java.lang.String |
tryLightTransform()
Try to perform "light" transformation.
|
public FunctionHelper(PsiType resultType)
public PsiType getResultType()
public final java.lang.String getText()
public java.lang.String getStatementText()
public abstract PsiExpression getExpression()
public java.lang.String tryLightTransform()
public abstract void transform(ChainContext context, java.lang.String... argumentValues)
context
- a context for which transformation should be performedargumentValues
- values (expressions) of the SAM parameters to be inlined into function body
(the length must be exactly the same as the number of SAM parameters).
Usually it's just the references to the existing variables, but other expressions
(e.g. constant literals) could be used as well if necessary.public void rename(java.lang.String oldName, java.lang.String newName, ChainContext context)
oldName
- old variable namenewName
- new variable namecontext
- a contextpublic void registerReusedElements(java.util.function.Consumer<? super PsiElement> consumer)
public java.lang.String getParameterName(int index)
public void preprocessVariable(ChainContext context, ChainVariable var, int index)
public void suggestOutputNames(ChainContext context, ChainVariable var)
public static void suggestFromExpression(ChainVariable var, Project project, PsiExpression expression)
public static FunctionHelper create(PsiExpression expression, int paramCount)
public static FunctionHelper create(PsiExpression expression, int paramCount, boolean allowReturns)
public static <T extends PsiElement> T replaceVarReference(T expressionOrCodeBlock, java.lang.String name, java.lang.String replacement, ChainContext context)
name
in given expression with replacement
.
If the replacement is a new name to the variable, the caller must take care that this new name was not used before.
expressionOrCodeBlock
- an expression or code block to search-and-replace references insidename
- a reference name to replacereplacement
- a replacement expression (new name or literal)context
- context