本文整理汇总了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");
}
}
示例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));
}
示例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$";
}
示例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);
}