本文整理汇总了Java中com.intellij.psi.PsiVariable.getTypeElement方法的典型用法代码示例。如果您正苦于以下问题:Java PsiVariable.getTypeElement方法的具体用法?Java PsiVariable.getTypeElement怎么用?Java PsiVariable.getTypeElement使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.psi.PsiVariable
的用法示例。
在下文中一共展示了PsiVariable.getTypeElement方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: visitVariable
import com.intellij.psi.PsiVariable; //导入方法依赖的package包/类
@Override
public void visitVariable(@NotNull PsiVariable variable) {
super.visitVariable(variable);
final PsiType type = variable.getType();
final PsiType componentType = type.getDeepComponentType();
if (!(componentType instanceof PsiClassType)) {
return;
}
final String className = ((PsiClassType)componentType).getClassName();
@NonNls final String javaLangReflect = "java.lang.reflect.";
if (!className.startsWith(javaLangReflect)) {
return;
}
final PsiTypeElement typeElement = variable.getTypeElement();
if (typeElement == null) {
return;
}
registerError(typeElement);
}
示例2: satisfiedBy
import com.intellij.psi.PsiVariable; //导入方法依赖的package包/类
public boolean satisfiedBy(PsiElement element) {
if (!(element instanceof PsiVariable)) {
return false;
}
if (ErrorUtil.containsError(element)) {
return false;
}
final PsiVariable var = (PsiVariable)element;
final PsiTypeElement typeElement = var.getTypeElement();
if (typeElement == null) {
return false; // Could be true for enum constants.
}
final PsiType elementType = typeElement.getType();
final PsiType type = var.getType();
return elementType.getArrayDimensions() != type.getArrayDimensions();
}
示例3: visitVariable
import com.intellij.psi.PsiVariable; //导入方法依赖的package包/类
@Override
public void visitVariable(@NotNull PsiVariable var) {
super.visitVariable(var);
final PsiType declaredType = var.getType();
if (declaredType.getArrayDimensions() == 0) {
return;
}
final PsiTypeElement typeElement = var.getTypeElement();
if (typeElement == null) {
return; // Could be true for enum constants.
}
final PsiType elementType = typeElement.getType();
if (elementType.equals(declaredType)) {
return;
}
registerVariableError(var);
}
示例4: visitVariable
import com.intellij.psi.PsiVariable; //导入方法依赖的package包/类
@Override
public void visitVariable(@NotNull PsiVariable variable) {
super.visitVariable(variable);
final PsiType type = variable.getType();
final String typeString = type.getCanonicalText();
if (!"java.lang.ProcessBuilder".equals(typeString)) {
return;
}
final PsiTypeElement typeElement = variable.getTypeElement();
if (typeElement == null) {
return;
}
registerError(typeElement);
}
示例5: isAvailable
import com.intellij.psi.PsiVariable; //导入方法依赖的package包/类
@Override
public boolean isAvailable(@NotNull Project project, @NotNull PsiFile file, @NotNull PsiElement startElement, @NotNull PsiElement endElement)
{
final PsiVariable myVariable = (PsiVariable) startElement;
return myVariable.isValid() && myVariable.getTypeElement() != null && myVariable.getManager().isInProject(myVariable) && getReturnType() != null && getReturnType().isValid() &&
!TypeConversionUtil.isNullType(getReturnType()) && !TypeConversionUtil.isVoidType(getReturnType());
}
示例6: ensureBoundModelIsValid
import com.intellij.psi.PsiVariable; //导入方法依赖的package包/类
private static void ensureBoundModelIsValid(ProblemsHolder holder, PsiAnnotation annotation) {
final BoundMetaData boundMetaData = DataBindUtil.getBoundMetaData(annotation);
if (!boundMetaData.getBindingMetaData().isValidBindableModel()) {
final PsiClass boundClass = boundMetaData.getBindingMetaData().getBoundClass();
if (boundClass != null) {
final PsiVariable var = (PsiVariable) Util.getImmediateOwnerElement(annotation);
if (var == null) {
return;
}
final PsiTypeElement typeElement = var.getTypeElement();
if (typeElement == null) {
return;
}
holder.registerProblem(typeElement, "The model type (" + boundClass.getQualifiedName() + ") is not bindable.");
}
else {
final Collection<AnnotationSearchResult> autoBoundAnnotations
= boundMetaData.getBindingMetaData().getModelAnnotations();
if (autoBoundAnnotations.size() > 1) {
holder.registerProblem(annotation, "Multiple model binding annotations found");
}
}
}
else {
final PsiElement element = Util.getMethodOrField(annotation);
if (!Util.elementIsAnnotated(element, Types.JAVAX_INJECT)) {
holder.registerProblem(annotation, "Model specifier is not injected", new LocalQuickFix() {
@NotNull
@Override
public String getName() {
return "Add @Inject to class member";
}
@NotNull
@Override
public String getFamilyName() {
return GroupNames.BUGS_GROUP_NAME;
}
@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
final JavaPsiFacade instance = JavaPsiFacade.getInstance(project);
final PsiElementFactory elementFactory = instance.getElementFactory();
final PsiImportStatement importJavaxInject = instance.getElementFactory()
.createImportStatement(
instance.findClass(Types.JAVAX_INJECT,
ProjectScope.getAllScope(project))
);
final PsiImportList importList = ((PsiJavaFile) PsiUtil.getTopLevelClass(element).getParent()).getImportList();
importList.add(importJavaxInject);
((PsiModifierListOwner) element).getModifierList().addAnnotation("Inject");
}
});
}
}
}