本文整理汇总了Java中com.intellij.psi.PsiLocalVariable类的典型用法代码示例。如果您正苦于以下问题:Java PsiLocalVariable类的具体用法?Java PsiLocalVariable怎么用?Java PsiLocalVariable使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PsiLocalVariable类属于com.intellij.psi包,在下文中一共展示了PsiLocalVariable类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: inferType
import com.intellij.psi.PsiLocalVariable; //导入依赖的package包/类
@Nullable
public PsiType inferType( PsiTypeElement typeElement )
{
PsiType psiType = null;
final PsiElement parent = typeElement.getParent();
if( (parent instanceof PsiLocalVariable && isVar( (PsiLocalVariable)parent )) ||
(parent instanceof PsiParameter && isVarForEach( (PsiParameter)parent )) )
{
if( parent instanceof PsiLocalVariable )
{
psiType = processLocalVariableInitializer( ((PsiLocalVariable)parent).getInitializer() );
}
else
{
psiType = processForeach( ((PsiParameter)parent).getDeclarationScope() );
}
if( null == psiType )
{
psiType = PsiType.getJavaLangObject( typeElement.getManager(), GlobalSearchScope.allScope( typeElement.getProject() ) );
}
}
return psiType;
}
示例2: seekChildren
import com.intellij.psi.PsiLocalVariable; //导入依赖的package包/类
private static void seekChildren(PsiElement element, PsiIdentifier target, Find find) {
for (PsiElement child : element.getChildren()) {
if (child instanceof PsiLocalVariable) {
PsiLocalVariable localVariable = (PsiLocalVariable) child;
if (isSameName(target, localVariable.getNameIdentifier())) {
find.findLocalVariable = localVariable;
return;
}
}
if (child instanceof PsiParameter) {
PsiParameter parameter = (PsiParameter) child;
if (isSameName(target, parameter.getNameIdentifier())) {
find.findParameter = parameter;
return;
}
}
seekChildren(child, target, find);
if (!find.isEmpty()) return;
}
}
示例3: buildVisitor
import com.intellij.psi.PsiLocalVariable; //导入依赖的package包/类
@NotNull
@Override
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, final boolean isOnTheFly) {
return new JavaElementVisitor() {
@Override
public void visitReferenceExpression(PsiReferenceExpression psiReferenceExpression) {
}
@Override
public void visitLocalVariable(PsiLocalVariable variable) {
super.visitLocalVariable(variable);
if (VariantPool.isJump()) {
if (isFindYYY(variable.toString())) {
holder.registerProblem(variable, DESCRIPTION_TEMPLATE, myQuickFix);
log.info("isFindYYY" + variable );
}
}
}
};
}
示例4: 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;
}
示例5: actionPerformedImpl
import com.intellij.psi.PsiLocalVariable; //导入依赖的package包/类
@Override
public void actionPerformedImpl(@NotNull final Project project, final Editor editor) {
PsiFile file = PsiUtilBase.getPsiFileInEditor(editor, project);
if(file == null) {
return;
}
int offset = editor.getCaretModel().getOffset();
PsiElement psiElement = file.findElementAt(offset);
if(psiElement == null) {
return;
}
PsiLocalVariable psiLocalVariable = PsiTreeUtil.getParentOfType(psiElement, PsiLocalVariable.class);
InflateViewAnnotator.InflateContainer inflateContainer = InflateViewAnnotator.matchInflate(psiLocalVariable);
if(inflateContainer == null) {
return;
}
generate(inflateContainer, editor, file);
}
示例6: wrapContext
import com.intellij.psi.PsiLocalVariable; //导入依赖的package包/类
private PsiElement wrapContext(Project project, final PsiElement originalContext) {
if (project.isDefault()) return originalContext;
PsiElement context = originalContext;
final DebugProcessImpl process = DebuggerManagerEx.getInstanceEx(project).getContext().getDebugProcess();
if (process != null) {
final Map<ObjectReference, ValueMarkup> markupMap = ValueDescriptorImpl.getMarkupMap(process);
if (markupMap != null && markupMap.size() > 0) {
final Pair<String, Map<String, ObjectReference>> markupVariables = createMarkupVariablesText(markupMap);
int offset = markupVariables.getFirst().length() - 1;
final TextWithImportsImpl textWithImports = new TextWithImportsImpl(CodeFragmentKind.CODE_BLOCK, markupVariables.getFirst(), "", myDelegate.getFileType());
final JavaCodeFragment codeFragment = myDelegate.createCodeFragment(textWithImports, context, project);
codeFragment.accept(new JavaRecursiveElementVisitor() {
public void visitLocalVariable(PsiLocalVariable variable) {
final String name = variable.getName();
variable.putUserData(LABEL_VARIABLE_VALUE_KEY, markupVariables.getSecond().get(name));
}
});
final PsiElement newContext = codeFragment.findElementAt(offset);
if (newContext != null) {
context = newContext;
}
}
}
return context;
}
示例7: 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);
}
}
}
}
示例8: inferType
import com.intellij.psi.PsiLocalVariable; //导入依赖的package包/类
@Nullable
public PsiType inferType(PsiTypeElement typeElement) {
PsiType psiType = null;
final PsiElement parent = typeElement.getParent();
if ((parent instanceof PsiLocalVariable && isValOrVar((PsiLocalVariable) parent)) ||
(parent instanceof PsiParameter && isValOrVarForEach((PsiParameter) parent))) {
if (parent instanceof PsiLocalVariable) {
psiType = processLocalVariableInitializer(((PsiLocalVariable) parent).getInitializer());
} else {
psiType = processParameterDeclaration(((PsiParameter) parent).getDeclarationScope());
}
if (null == psiType) {
psiType = PsiType.getJavaLangObject(typeElement.getManager(), GlobalSearchScope.allScope(typeElement.getProject()));
}
}
return psiType;
}
示例9: verifyAnnotation
import com.intellij.psi.PsiLocalVariable; //导入依赖的package包/类
@NotNull
@Override
public Collection<LombokProblem> verifyAnnotation(@NotNull PsiAnnotation psiAnnotation) {
// TODO warning: "You're assigning an auto-cleanup variable to something else. This is a bad idea."
final ProblemNewBuilder problemNewBuilder = new ProblemNewBuilder(2);
PsiLocalVariable psiVariable = PsiTreeUtil.getParentOfType(psiAnnotation, PsiLocalVariable.class);
if (null != psiVariable) {
final String cleanupName = PsiAnnotationUtil.getStringAnnotationValue(psiAnnotation, "value");
if (StringUtil.isEmptyOrSpaces(cleanupName)) {
problemNewBuilder.addError("'@Cleanup': value cannot be the empty string");
} else {
validateCleanUpMethodExists(psiVariable, cleanupName, problemNewBuilder);
}
validateInitializerExist(problemNewBuilder, psiVariable);
} else {
problemNewBuilder.addError("'@Cleanup' is legal only on local variable declarations");
}
return problemNewBuilder.getProblems();
}
示例10: validateCleanUpMethodExists
import com.intellij.psi.PsiLocalVariable; //导入依赖的package包/类
private void validateCleanUpMethodExists(@NotNull PsiLocalVariable psiVariable, @NotNull String cleanupName, @NotNull ProblemNewBuilder problemNewBuilder) {
final PsiType psiType = psiVariable.getType();
if (psiType instanceof PsiClassType) {
final PsiClassType psiClassType = (PsiClassType) psiType;
final PsiClass psiClassOfField = psiClassType.resolve();
final PsiMethod[] methods;
if (psiClassOfField != null) {
methods = psiClassOfField.findMethodsByName(cleanupName, true);
boolean hasCleanupMethod = false;
for (PsiMethod method : methods) {
if (0 == method.getParameterList().getParametersCount()) {
hasCleanupMethod = true;
}
}
if (!hasCleanupMethod) {
problemNewBuilder.addError("'@Cleanup': method '%s()' not found on target class", cleanupName);
}
}
} else {
problemNewBuilder.addError("'@Cleanup': is legal only on a local variable declaration inside a block");
}
}
示例11: testValModifiersEditing
import com.intellij.psi.PsiLocalVariable; //导入依赖的package包/类
public void testValModifiersEditing() {
PsiFile file = myFixture.configureByText("a.java", "import lombok.val;\nclass Foo { {val o = <caret>;} }");
PsiLocalVariable var = PsiTreeUtil.getParentOfType(file.findElementAt(myFixture.getCaretOffset()), PsiLocalVariable.class);
assertNotNull(var);
PsiType type1 = var.getType();
assertNotNull(type1);
assertEquals("lombok.val", type1.getCanonicalText(false));
myFixture.type('1');
PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
assertTrue(var.isValid());
assertNotNull(var.getModifierList());
assertTrue("val should make variable final", var.getModifierList().hasModifierProperty(PsiModifier.FINAL));
}
示例12: getAnnotationOwner
import com.intellij.psi.PsiLocalVariable; //导入依赖的package包/类
@Nullable
static PsiModifierListOwner getAnnotationOwner(@Nullable PsiElement element)
{
if(element == null)
{
return null;
}
PsiElement owner = element.getParent();
if(!(owner instanceof PsiModifierListOwner) || !(owner instanceof PsiNameIdentifierOwner))
{
return null;
}
if(owner instanceof PsiParameter || owner instanceof PsiLocalVariable)
{
return null;
}
// support non-Java languages where getNameIdentifier may return non-physical psi with the same range
PsiElement nameIdentifier = ((PsiNameIdentifierOwner) owner).getNameIdentifier();
if(nameIdentifier == null || !nameIdentifier.getTextRange().equals(element.getTextRange()))
{
return null;
}
return (PsiModifierListOwner) owner;
}
示例13: 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();
}
示例14: visitNewExpression
import com.intellij.psi.PsiLocalVariable; //导入依赖的package包/类
@Override
public void visitNewExpression(PsiNewExpression expression) {
super.visitNewExpression(expression);
PsiMethod constructor = expression.resolveConstructor();
if (constructor == null) return;
JavaEvaluator evaluator = mContext.getEvaluator();
PsiClass cls = constructor.getContainingClass();
boolean isView = evaluator.extendsClass(cls, CLASS_VIEW, true);
if (!isView) return;
Location location = this.mContext.getLocation(expression);
PsiElement psiElement = expression.getParent();
//创建的变量没有赋值给本地变量,无法指定注解
if (!(psiElement instanceof PsiLocalVariable)) {
this.mContext.report(DynamicNewViewDetector.ISSUE, expression, location, "检测到动态创建view操作,new 操作的结果需要赋值给本地变量");
return;
}
PsiLocalVariable localVariable = (PsiLocalVariable) psiElement;
PsiModifierList modifierList = localVariable.getModifierList();
if (modifierList == null) {
this.mContext.report(DynamicNewViewDetector.ISSUE, expression, location, "检测到动态创建view操作,确认是否为view指定了唯一标识");
return;
}
PsiAnnotation[] annotations = modifierList.getAnnotations();
for (PsiAnnotation annotation : annotations) {
String fullName = annotation.getQualifiedName();
if (IDENTIFIER_ANNOTATION.equals(fullName)) {
return;
}
}
this.mContext.report(DynamicNewViewDetector.ISSUE, expression, location, "检测到动态创建view操作,确认是否为view指定了唯一标识");
}
示例15: getVariable
import com.intellij.psi.PsiLocalVariable; //导入依赖的package包/类
/**
* ローカル変数取得 (宣言文で定義された変数)
* @param declaration ルートノード
* @return ローカル変数 (空要素の場合もあります)
*/
public static @Nullable PsiLocalVariable getVariable(PsiDeclarationStatement declaration) {
PsiElement[] elements = declaration.getDeclaredElements();
for (PsiElement element : elements) {
if (element instanceof PsiLocalVariable) {
PsiLocalVariable valiable = (PsiLocalVariable) element;
return valiable;
}
}
return null;
}