本文整理汇总了Java中com.intellij.psi.PsiVariable.getInitializer方法的典型用法代码示例。如果您正苦于以下问题:Java PsiVariable.getInitializer方法的具体用法?Java PsiVariable.getInitializer怎么用?Java PsiVariable.getInitializer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.psi.PsiVariable
的用法示例。
在下文中一共展示了PsiVariable.getInitializer方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findMethodCall
import com.intellij.psi.PsiVariable; //导入方法依赖的package包/类
private PsiMethodCallExpression findMethodCall(PsiElement element) {
// This covers the case if there is a method being used to initialize a variable..
// i.e int a = random();
if (element instanceof PsiDeclarationStatement) {
PsiDeclarationStatement declarationStatement = (PsiDeclarationStatement) element;
for (PsiElement declarationElement : declarationStatement.getDeclaredElements()) {
if (declarationElement instanceof PsiVariable) {
PsiVariable variable = (PsiVariable) declarationElement;
PsiExpression initializer = variable.getInitializer();
if (initializer instanceof PsiMethodCallExpression) {
return (PsiMethodCallExpression) initializer;
}
}
}
}
if (element instanceof PsiExpressionStatement) {
PsiExpression expression = ((PsiExpressionStatement) element).getExpression();
if (expression instanceof PsiMethodCallExpression) {
return (PsiMethodCallExpression) expression;
}
}
return null;
}
示例2: create
import com.intellij.psi.PsiVariable; //导入方法依赖的package包/类
@Nullable
public DfaValue create(PsiVariable variable)
{
Object value = variable.computeConstantValue();
PsiType type = variable.getType();
if(value == null)
{
Boolean boo = computeJavaLangBooleanFieldReference(variable);
if(boo != null)
{
DfaConstValue unboxed = createFromValue(boo, PsiType.BOOLEAN, variable);
return myFactory.getBoxedFactory().createBoxed(unboxed);
}
PsiExpression initializer = variable.getInitializer();
if(initializer instanceof PsiLiteralExpression && initializer.textMatches(PsiKeyword.NULL))
{
return dfaNull;
}
return null;
}
return createFromValue(value, type, variable);
}
示例3: visitDeclarationStatement
import com.intellij.psi.PsiVariable; //导入方法依赖的package包/类
@Override
public void visitDeclarationStatement(
@NotNull PsiDeclarationStatement statement) {
if (assignedFrom) {
return;
}
super.visitDeclarationStatement(statement);
final PsiElement[] declaredElements = statement.getDeclaredElements();
for (PsiElement declaredElement : declaredElements) {
if (declaredElement instanceof PsiVariable) {
final PsiVariable declaredVariable =
(PsiVariable)declaredElement;
final PsiExpression initializer =
declaredVariable.getInitializer();
if (initializer != null &&
VariableAccessUtils.mayEvaluateToVariable(initializer,
variable)) {
assignedFrom = true;
return;
}
}
}
}
示例4: visitVariable
import com.intellij.psi.PsiVariable; //导入方法依赖的package包/类
@Override
public void visitVariable(@NotNull PsiVariable var) {
if (assignedFrom) {
return;
}
super.visitVariable(var);
final PsiExpression arg = var.getInitializer();
if (VariableAccessUtils.mayEvaluateToVariable(arg, variable)) {
assignedFrom = true;
}
}