com.intellij.psi.PsiLocalVariable Java Examples
The following examples show how to use
com.intellij.psi.PsiLocalVariable.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractInflateViewAction.java From idea-android-studio-plugin with GNU General Public License v2.0 | 6 votes |
@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); }
Example #2
Source File: DeclarationStatementTranslator.java From java2typescript with Apache License 2.0 | 6 votes |
public static void translate(PsiDeclarationStatement stmt, TranslationContext ctx) { for (int i = 0; i < stmt.getDeclaredElements().length; i++) { if(i > 0) { ctx.append(", "); } PsiElement element1 = stmt.getDeclaredElements()[i]; if (element1 instanceof PsiStatement) { StatementTranslator.translate((PsiStatement) element1, ctx); } else if (element1 instanceof PsiLocalVariable) { LocalVariableTranslator.translate((PsiLocalVariable) element1, ctx); } else { System.err.println("Not managed " + element1); } } }
Example #3
Source File: CleanupProcessor.java From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License | 6 votes |
@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(); }
Example #4
Source File: CleanupProcessor.java From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License | 6 votes |
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"); } }
Example #5
Source File: ValModifierTest.java From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License | 6 votes |
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)); }
Example #6
Source File: ThinrDetector.java From thinr with Apache License 2.0 | 5 votes |
private void markLeakSuspects(PsiElement element, PsiElement lambdaBody, @NonNull final JavaContext context) { if (element instanceof PsiReferenceExpression) { PsiReferenceExpression ref = (PsiReferenceExpression) element; if (ref.getQualifierExpression() == null) { PsiElement res = ref.resolve(); if (!(res instanceof PsiParameter)) { if (!(res instanceof PsiClass)) { boolean error = false; if (res instanceof PsiLocalVariable) { PsiLocalVariable lVar = (PsiLocalVariable) res; if (!isParent(lambdaBody, lVar.getParent())) { error = true; } } if (res instanceof PsiField) { PsiField field = (PsiField) res; final PsiModifierList modifierList = field.getModifierList(); if (modifierList == null) { error = true; } else if (!modifierList.hasExplicitModifier(PsiModifier.STATIC)) { error = true; } } if (error) { context.report(ISSUE, element, context.getNameLocation(element), "Possible leak"); } } } } } for (PsiElement psiElement : element.getChildren()) { markLeakSuspects(psiElement, lambdaBody, context); } }
Example #7
Source File: AbstractInflateViewAction.java From idea-android-studio-plugin with GNU General Public License v2.0 | 5 votes |
@Override protected boolean isValidForFile(@NotNull Project project, @NotNull Editor editor, @NotNull PsiFile file) { int offset = editor.getCaretModel().getOffset(); PsiElement psiElement = file.findElementAt(offset); if(!PlatformPatterns.psiElement().inside(PsiLocalVariable.class).accepts(psiElement)) { return false; } PsiLocalVariable psiLocalVariable = PsiTreeUtil.getParentOfType(psiElement, PsiLocalVariable.class); return InflateViewAnnotator.matchInflate(psiLocalVariable) != null; }
Example #8
Source File: ValModifierTest.java From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License | 5 votes |
public void testValModifiers() { PsiFile file = myFixture.configureByFile(getTestName(false) + ".java"); PsiLocalVariable var = PsiTreeUtil.getParentOfType(file.findElementAt(myFixture.getCaretOffset()), PsiLocalVariable.class); assertNotNull(var); assertNotNull(var.getModifierList()); assertTrue("val should make variable final", var.getModifierList().hasModifierProperty(PsiModifier.FINAL)); }
Example #9
Source File: VarModifierTest.java From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License | 5 votes |
public void testVarModifiers() { PsiFile file = myFixture.configureByFile(getTestName(false) + ".java"); PsiLocalVariable var = PsiTreeUtil.getParentOfType(file.findElementAt(myFixture.getCaretOffset()), PsiLocalVariable.class); assertNotNull(var); assertNotNull(var.getModifierList()); boolean isFinal = var.getModifierList().hasModifierProperty(PsiModifier.FINAL); assertFalse("var doesn't make variable final", isFinal); }
Example #10
Source File: VarModifierTest.java From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License | 5 votes |
public void testVarModifiersEditing() { PsiFile file = myFixture.configureByFile(getTestName(false) + ".java"); PsiLocalVariable var = PsiTreeUtil.getParentOfType(file.findElementAt(myFixture.getCaretOffset()), PsiLocalVariable.class); assertNotNull(var); assertNotNull(var.getType()); myFixture.type('1'); PsiDocumentManager.getInstance(getProject()).commitAllDocuments(); assertTrue(var.isValid()); assertEquals(PsiPrimitiveType.INT, var.getType()); assertNotNull(var.getModifierList()); boolean isFinal = var.getModifierList().hasModifierProperty(PsiModifier.FINAL); assertFalse("var doesn't make variable final", isFinal); }
Example #11
Source File: ValTest.java From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License | 5 votes |
private void verifyLocalVariableType(final String expectedType) { final PsiElement elementAtCaret = myFixture.getFile().findElementAt(myFixture.getCaretOffset()); assertTrue(elementAtCaret instanceof PsiIdentifier); final PsiElement localVariable = elementAtCaret.getParent(); assertTrue(localVariable.toString(), localVariable instanceof PsiLocalVariable); final PsiType type = ((PsiLocalVariable) localVariable).getType(); assertNotNull(localVariable.toString(), type); assertTrue(type.getCanonicalText(), type.equalsToText(expectedType)); }
Example #12
Source File: VarTest.java From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License | 5 votes |
private void verifyLocalVariableType(final String expectedType) { final PsiElement elementAtCaret = myFixture.getFile().findElementAt(myFixture.getCaretOffset()); assertTrue(elementAtCaret instanceof PsiIdentifier); final PsiElement localVariable = elementAtCaret.getParent(); assertTrue(localVariable.toString(), localVariable instanceof PsiLocalVariable); final PsiType type = ((PsiLocalVariable) localVariable).getType(); assertNotNull(localVariable.toString(), type); assertTrue(type.getCanonicalText(), type.equalsToText(expectedType)); }
Example #13
Source File: ValModifierProcessor.java From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public boolean isSupported(@NotNull PsiModifierList modifierList) { final PsiElement parent = modifierList.getParent(); return (parent instanceof PsiLocalVariable && ValProcessor.isVal((PsiLocalVariable) parent)); }
Example #14
Source File: CleanupProcessor.java From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License | 4 votes |
private void validateInitializerExist(@NotNull ProblemNewBuilder problemNewBuilder, @NotNull PsiLocalVariable psiVariable) { if (null == psiVariable.getInitializer()) { problemNewBuilder.addError("'@Cleanup' variable declarations need to be initialized."); } }