当前位置: 首页>>代码示例>>Java>>正文


Java PsiVariable.getInitializer方法代码示例

本文整理汇总了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;
}
 
开发者ID:mParticle,项目名称:mparticle-android-sdk,代码行数:24,代码来源:MpApiDetector.java

示例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);
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:23,代码来源:DfaConstValue.java

示例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;
      }
    }
  }
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:24,代码来源:VariableAssignedFromVisitor.java

示例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;
  }
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:12,代码来源:VariableAssignedFromVisitor.java


注:本文中的com.intellij.psi.PsiVariable.getInitializer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。