本文整理汇总了Java中com.intellij.psi.PsiLocalVariable.getInitializer方法的典型用法代码示例。如果您正苦于以下问题:Java PsiLocalVariable.getInitializer方法的具体用法?Java PsiLocalVariable.getInitializer怎么用?Java PsiLocalVariable.getInitializer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.psi.PsiLocalVariable
的用法示例。
在下文中一共展示了PsiLocalVariable.getInitializer方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: IntroduceParameterSettingsUI
import com.intellij.psi.PsiLocalVariable; //导入方法依赖的package包/类
public IntroduceParameterSettingsUI(PsiLocalVariable onLocalVariable,
PsiExpression onExpression,
PsiMethod methodToReplaceIn,
TIntArrayList parametersToRemove) {
myHasInitializer = onLocalVariable != null && onLocalVariable.getInitializer() != null;
myIsInvokedOnDeclaration = onExpression == null;
final PsiParameter[] parameters = methodToReplaceIn.getParameterList().getParameters();
myParametersToRemove = new PsiParameter[parameters.length];
myParametersToRemoveChecked = new boolean[parameters.length];
parametersToRemove.forEach(new TIntProcedure() {
public boolean execute(final int paramNum) {
myParametersToRemove[paramNum] = parameters[paramNum];
return true;
}
});
myIsLocalVariable = onLocalVariable != null;
}
示例2: verifyVariable
import com.intellij.psi.PsiLocalVariable; //导入方法依赖的package包/类
public void verifyVariable(@NotNull final PsiLocalVariable psiLocalVariable, @NotNull final ProblemsHolder holder) {
boolean isVal = isSameName(psiLocalVariable.getTypeElement().getText());
boolean isVar = isVar(psiLocalVariable.getTypeElement().getText());
final String ann = isVal ? "val" : "var";
if (isVal || isVar) {
final PsiExpression initializer = psiLocalVariable.getInitializer();
if (initializer == null) {
holder.registerProblem(psiLocalVariable, "'" + ann + "' on a local variable requires an initializer expression", ProblemHighlightType.ERROR);
} else if (initializer instanceof PsiArrayInitializerExpression) {
holder.registerProblem(psiLocalVariable, "'" + ann + "' is not compatible with array initializer expressions. Use the full form (new int[] { ... } instead of just { ... })", ProblemHighlightType.ERROR);
} else if (initializer instanceof PsiLambdaExpression) {
holder.registerProblem(psiLocalVariable, "'" + ann + "' is not allowed with lambda expressions.", ProblemHighlightType.ERROR);
} else if (isVal) {
final PsiElement typeParentParent = psiLocalVariable.getParent();
if (typeParentParent instanceof PsiDeclarationStatement && typeParentParent.getParent() instanceof PsiForStatement) {
holder.registerProblem(psiLocalVariable, "'" + ann + "' is not allowed in old-style for loops", ProblemHighlightType.ERROR);
}
}
}
}
示例3: performForLocal
import com.intellij.psi.PsiLocalVariable; //导入方法依赖的package包/类
private static void performForLocal(boolean searchForSuper, boolean removeLocalVariable, boolean replaceAllOccurrences, boolean declareFinal, final boolean removeUnusedParameters)
{
final int offset = myEditor.getCaretModel().getOffset();
final PsiElement element = myFile.findElementAt(offset).getParent();
assertTrue(element instanceof PsiLocalVariable);
PsiMethod method = Util.getContainingMethod(element);
final PsiMethod methodToSearchFor;
if(searchForSuper)
{
final PsiMethod deepestSuperMethod = method.findDeepestSuperMethod();
methodToSearchFor = deepestSuperMethod != null ? deepestSuperMethod : method;
}
else
{
methodToSearchFor = method;
}
assertNotNull(method);
assertNotNull(methodToSearchFor);
final PsiLocalVariable localVariable = (PsiLocalVariable) element;
final PsiExpression parameterInitializer = localVariable.getInitializer();
TIntArrayList parametersToRemove = removeUnusedParameters ? Util.findParametersToRemove(method, parameterInitializer, null) : new TIntArrayList();
new IntroduceParameterProcessor(getProject(), method, methodToSearchFor, parameterInitializer, null, localVariable, removeLocalVariable, localVariable.getName(), replaceAllOccurrences,
IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_INACCESSIBLE, declareFinal, false, null, parametersToRemove).run();
}
示例4: debugVariable
import com.intellij.psi.PsiLocalVariable; //导入方法依赖的package包/类
public static void debugVariable(PsiLocalVariable variable) {
if (variable != null) {
PsiIdentifier id = variable.getNameIdentifier();
PsiTypeElement type = variable.getTypeElement();
PsiExpression init = variable.getInitializer();
System.out.println("variable -> " + variable.getText()
+ ", id=" + (id != null ? id.getText() : "null")
+ ", type=" + (type != null ? type.getText() : "null")
+ ", init=" + (init != null ? init.getText() : "null"));
}
}
示例5: performForLocal
import com.intellij.psi.PsiLocalVariable; //导入方法依赖的package包/类
private static void performForLocal(boolean searchForSuper, boolean removeLocalVariable, boolean replaceAllOccurrences, boolean declareFinal,
final boolean removeUnusedParameters) {
final int offset = myEditor.getCaretModel().getOffset();
final PsiElement element = myFile.findElementAt(offset).getParent();
assertTrue(element instanceof PsiLocalVariable);
PsiMethod method = Util.getContainingMethod(element);
final PsiMethod methodToSearchFor;
if (searchForSuper) {
final PsiMethod deepestSuperMethod = method.findDeepestSuperMethod();
methodToSearchFor = deepestSuperMethod != null ? deepestSuperMethod : method;
}
else {
methodToSearchFor = method;
}
assertNotNull(method);
assertNotNull(methodToSearchFor);
final PsiLocalVariable localVariable = (PsiLocalVariable)element;
final PsiExpression parameterInitializer = localVariable.getInitializer();
TIntArrayList parametersToRemove = removeUnusedParameters ? Util.findParametersToRemove(method, parameterInitializer, null) : new TIntArrayList();
new IntroduceParameterProcessor(
getProject(), method, methodToSearchFor,
parameterInitializer, null, localVariable, removeLocalVariable,
localVariable.getName(), replaceAllOccurrences,
IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_INACCESSIBLE,
declareFinal, false, null, parametersToRemove).run();
}
示例6: doFix
import com.intellij.psi.PsiLocalVariable; //导入方法依赖的package包/类
@Override
public void doFix(@NotNull final Project project, final ProblemDescriptor descriptor) {
final PsiElement nameElement = descriptor.getPsiElement();
final PsiLocalVariable variable =
(PsiLocalVariable)nameElement.getParent();
PsiExpression initializer = variable.getInitializer();
if (initializer == null) {
return;
}
if (initializer instanceof PsiArrayInitializerExpression) {
final PsiElementFactory factory =
JavaPsiFacade.getElementFactory(project);
final PsiType type = initializer.getType();
final String typeText;
if (type == null) {
typeText = "";
}
else {
typeText = type.getCanonicalText();
}
initializer = factory.createExpressionFromText("new " + typeText +
initializer.getText(), variable);
}
final PsiMember member =
PsiTreeUtil.getParentOfType(variable, PsiMember.class);
final Query<PsiReference> search =
ReferencesSearch.search(variable, new LocalSearchScope(member));
final Collection<PsiElement> replacedElements = new ArrayList<PsiElement>();
final Collection<PsiReference> references = search.findAll();
for (PsiReference reference : references) {
final PsiElement replacedElement =
reference.getElement().replace(initializer);
replacedElements.add(replacedElement);
}
HighlightUtils.highlightElements(replacedElements);
variable.delete();
}
示例7: isVar
import com.intellij.psi.PsiLocalVariable; //导入方法依赖的package包/类
public static boolean isVar( @NotNull PsiLocalVariable psiLocalVariable )
{
return psiLocalVariable.getInitializer() != null && isVar( psiLocalVariable.getTypeElement().getText() );
}
示例8: perform
import com.intellij.psi.PsiLocalVariable; //导入方法依赖的package包/类
private static boolean perform(boolean replaceAllOccurences,
int replaceFieldsWithGetters,
@NonNls String parameterName,
boolean searchForSuper,
boolean declareFinal,
final boolean removeUnusedParameters,
final boolean generateDelegate,
int enclosingLevel) {
final ElementToWorkOn[] elementToWorkOn = new ElementToWorkOn[1];
ElementToWorkOn
.processElementToWorkOn(myEditor, myFile, "INtr param", HelpID.INTRODUCE_PARAMETER, getProject(), new ElementToWorkOn.ElementsProcessor<ElementToWorkOn>() {
@Override
public boolean accept(ElementToWorkOn el) {
return true;
}
@Override
public void pass(final ElementToWorkOn e) {
if (e == null) return;
elementToWorkOn[0] = e;
}
});
final PsiExpression expr = elementToWorkOn[0].getExpression();
final PsiLocalVariable localVar = elementToWorkOn[0].getLocalVariable();
PsiElement context = expr == null ? localVar : expr;
PsiMethod method = Util.getContainingMethod(context);
if (method == null) return false;
final List<PsiMethod> methods = com.intellij.refactoring.introduceParameter.IntroduceParameterHandler.getEnclosingMethods(method);
assertTrue(methods.size() > enclosingLevel);
method = methods.get(enclosingLevel);
final PsiMethod methodToSearchFor;
if (searchForSuper) {
methodToSearchFor = method.findDeepestSuperMethod();
}
else {
methodToSearchFor = method;
}
PsiExpression[] occurences;
PsiExpression initializer;
if (expr == null) {
initializer = localVar.getInitializer();
occurences = CodeInsightUtil.findReferenceExpressions(method, localVar);
}
else {
initializer = expr;
occurences = new ExpressionOccurrenceManager(expr, method, null).findExpressionOccurrences();
}
TIntArrayList parametersToRemove = removeUnusedParameters ? Util.findParametersToRemove(method, initializer, occurences) : new TIntArrayList();
new IntroduceParameterProcessor(
getProject(), method, methodToSearchFor, initializer, expr, localVar, true, parameterName, replaceAllOccurences,
replaceFieldsWithGetters,
declareFinal, generateDelegate, null, parametersToRemove).run();
myEditor.getSelectionModel().removeSelection();
return true;
}
示例9: isVal
import com.intellij.psi.PsiLocalVariable; //导入方法依赖的package包/类
public static boolean isVal(@NotNull PsiLocalVariable psiLocalVariable) {
return psiLocalVariable.getInitializer() != null && isSameName(psiLocalVariable.getTypeElement().getText());
}
示例10: isValOrVar
import com.intellij.psi.PsiLocalVariable; //导入方法依赖的package包/类
public static boolean isValOrVar(@NotNull PsiLocalVariable psiLocalVariable) {
return psiLocalVariable.getInitializer() != null && isValOrVar(psiLocalVariable.getTypeElement().getText());
}
示例11: validateInitializerExist
import com.intellij.psi.PsiLocalVariable; //导入方法依赖的package包/类
private void validateInitializerExist(@NotNull ProblemNewBuilder problemNewBuilder, @NotNull PsiLocalVariable psiVariable) {
if (null == psiVariable.getInitializer()) {
problemNewBuilder.addError("'@Cleanup' variable declarations need to be initialized.");
}
}
示例12: perform
import com.intellij.psi.PsiLocalVariable; //导入方法依赖的package包/类
private static boolean perform(boolean replaceAllOccurences,
int replaceFieldsWithGetters,
@NonNls String parameterName,
boolean searchForSuper,
boolean declareFinal,
final boolean removeUnusedParameters,
final boolean generateDelegate,
int enclosingLevel)
{
final ElementToWorkOn[] elementToWorkOn = new ElementToWorkOn[1];
ElementToWorkOn.processElementToWorkOn(myEditor, myFile, "INtr param", HelpID.INTRODUCE_PARAMETER, getProject(), new ElementToWorkOn.ElementsProcessor<ElementToWorkOn>()
{
@Override
public boolean accept(ElementToWorkOn el)
{
return true;
}
@Override
public void pass(final ElementToWorkOn e)
{
if(e == null)
{
return;
}
elementToWorkOn[0] = e;
}
});
final PsiExpression expr = elementToWorkOn[0].getExpression();
final PsiLocalVariable localVar = elementToWorkOn[0].getLocalVariable();
PsiElement context = expr == null ? localVar : expr;
PsiMethod method = Util.getContainingMethod(context);
if(method == null)
{
return false;
}
final List<PsiMethod> methods = com.intellij.refactoring.introduceParameter.IntroduceParameterHandler.getEnclosingMethods(method);
assertTrue(methods.size() > enclosingLevel);
method = methods.get(enclosingLevel);
final PsiMethod methodToSearchFor;
if(searchForSuper)
{
methodToSearchFor = method.findDeepestSuperMethod();
}
else
{
methodToSearchFor = method;
}
PsiExpression[] occurences;
PsiExpression initializer;
if(expr == null)
{
initializer = localVar.getInitializer();
occurences = CodeInsightUtil.findReferenceExpressions(method, localVar);
}
else
{
initializer = expr;
occurences = new ExpressionOccurrenceManager(expr, method, null).findExpressionOccurrences();
}
TIntArrayList parametersToRemove = removeUnusedParameters ? Util.findParametersToRemove(method, initializer, occurences) : new TIntArrayList();
new IntroduceParameterProcessor(getProject(), method, methodToSearchFor, initializer, expr, localVar, true, parameterName, replaceAllOccurences, replaceFieldsWithGetters, declareFinal,
generateDelegate, null, parametersToRemove).run();
myEditor.getSelectionModel().removeSelection();
return true;
}