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


Java PsiLocalVariable.getType方法代码示例

本文整理汇总了Java中com.intellij.psi.PsiLocalVariable.getType方法的典型用法代码示例。如果您正苦于以下问题:Java PsiLocalVariable.getType方法的具体用法?Java PsiLocalVariable.getType怎么用?Java PsiLocalVariable.getType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.intellij.psi.PsiLocalVariable的用法示例。


在下文中一共展示了PsiLocalVariable.getType方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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");
  }
}
 
开发者ID:mplushnikov,项目名称:lombok-intellij-plugin,代码行数:25,代码来源:CleanupProcessor.java

示例2: 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));
}
 
开发者ID:mplushnikov,项目名称:lombok-intellij-plugin,代码行数:17,代码来源:ValModifierTest.java

示例3: getTemplateString

import com.intellij.psi.PsiLocalVariable; //导入方法依赖的package包/类
@Nullable
@Override
public String getTemplateString(PsiElement psiElement) {
    String clazz;
    if (psiElement instanceof PsiReference) {
        // foo.mock
        PsiReference psiReference = (PsiReference) psiElement;
        PsiLocalVariable psiLocalVariable = (PsiLocalVariable) psiReference.resolve();
        if (psiLocalVariable == null) {
            return psiElement.getText();
        }
        PsiType psiType = psiLocalVariable.getType();
        clazz = psiType.getPresentableText() + ".class";
    } else if (psiElement instanceof PsiClassObjectAccessExpression) {
        // String.class.mock
        PsiClassObjectAccessExpression psiClassObjectAccessExpression = (PsiClassObjectAccessExpression) psiElement;
        String classText = psiClassObjectAccessExpression.getText();
        if (classText == null) {
            return psiElement.getText();
        }
        clazz = classText;
    } else {
        return psiElement.getText();
    }

    return "org.mockito.Mockito.mock(" + clazz + ")$END$";
}
 
开发者ID:krrrr38,项目名称:intellij-mockito-postfix-plugin,代码行数:28,代码来源:MockTemplate.java

示例4: showRefactoringDialog

import com.intellij.psi.PsiLocalVariable; //导入方法依赖的package包/类
@Override
protected BaseExpressionToFieldHandler.Settings showRefactoringDialog(PsiClass aClass, PsiLocalVariable local, PsiExpression[] occurences,
                                                                      boolean isStatic) {
  return new BaseExpressionToFieldHandler.Settings("xxx", null, occurences, true, isStatic, true, BaseExpressionToFieldHandler.InitializationPlace.IN_FIELD_DECLARATION,
                                                   PsiModifier.PRIVATE, local, local.getType(), false, aClass, true, myMakeEnumConstant);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:7,代码来源:MockLocalToFieldHandler.java


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