use of com.intellij.psi.PsiType in project intellij-community by JetBrains.
the class GrChangeVariableType method doFix.
@Override
protected void doFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) throws IncorrectOperationException {
final PsiElement element = descriptor.getPsiElement();
final PsiElement parent = element.getParent();
try {
final PsiType type = JavaPsiFacade.getElementFactory(project).createTypeFromText(myType, element);
if (parent instanceof GrVariable) {
((GrVariable) parent).setType(type);
} else if (element instanceof GrReferenceExpression && parent instanceof GrAssignmentExpression && ((GrAssignmentExpression) parent).getLValue() == element) {
final PsiElement resolved = ((GrReferenceExpression) element).resolve();
if (resolved instanceof GrVariable && !(resolved instanceof GrParameter)) {
((GrVariable) resolved).setType(type);
}
}
} catch (IncorrectOperationException e) {
LOG.error(e);
}
}
use of com.intellij.psi.PsiType in project intellij-community by JetBrains.
the class AsTypeTransformation method couldApply.
@Override
protected boolean couldApply(@NotNull GrSafeCastExpression expression) {
GrTypeElement typeElement = expression.getCastTypeElement();
if (typeElement == null)
return false;
PsiType type = typeElement.getType();
return type instanceof PsiClassType && ((PsiClassType) type).getParameterCount() == 0;
}
use of com.intellij.psi.PsiType in project intellij-community by JetBrains.
the class GroovyConditionalCanBeElvisInspection method checkForStringIsEmpty.
/**
* checks for the case string.isEmpty() ? something_else : string
*/
private static boolean checkForStringIsEmpty(GrExpression condition, GrExpression elseBranch) {
if (condition instanceof GrMethodCall)
condition = ((GrMethodCall) condition).getInvokedExpression();
if (!(condition instanceof GrReferenceExpression))
return false;
final GrExpression qualifier = ((GrReferenceExpression) condition).getQualifier();
if (qualifier == null)
return false;
if (!PsiEquivalenceUtil.areElementsEquivalent(qualifier, elseBranch))
return false;
final PsiType type = qualifier.getType();
if (type == null)
return false;
if (!type.equalsToText(CommonClassNames.JAVA_LANG_STRING))
return false;
final PsiElement resolved = ((GrReferenceExpression) condition).resolve();
return resolved instanceof PsiMethod && "isEmpty".equals(((PsiMethod) resolved).getName()) && ((PsiMethod) resolved).getParameterList().getParametersCount() == 0;
}
use of com.intellij.psi.PsiType in project intellij-community by JetBrains.
the class GroovyUntypedAccessInspection method buildVisitor.
@Override
@NotNull
protected BaseInspectionVisitor buildVisitor() {
return new BaseInspectionVisitor() {
@Override
public void visitReferenceExpression(@NotNull GrReferenceExpression refExpr) {
super.visitReferenceExpression(refExpr);
if (PsiUtil.isThisOrSuperRef(refExpr))
return;
GroovyResolveResult resolveResult = refExpr.advancedResolve();
PsiElement resolved = resolveResult.getElement();
if (resolved != null) {
if (GrHighlightUtil.isDeclarationAssignment(refExpr) || resolved instanceof PsiPackage)
return;
} else {
GrExpression qualifier = refExpr.getQualifierExpression();
if (qualifier == null && GrHighlightUtil.isDeclarationAssignment(refExpr))
return;
}
final PsiType refExprType = refExpr.getType();
if (refExprType == null) {
if (resolved != null) {
registerError(refExpr);
}
} else if (refExprType instanceof PsiClassType && ((PsiClassType) refExprType).resolve() == null) {
registerError(refExpr);
}
}
};
}
use of com.intellij.psi.PsiType in project intellij-community by JetBrains.
the class GrExpressionCategory method getClassType.
@Nullable
public static PsiClass getClassType(GrExpression expr) {
final PsiType type = expr.getType();
if (type instanceof PsiClassType) {
PsiClassType classType = (PsiClassType) type;
return classType.resolve();
} else {
final String text = type.getPresentableText();
final Project project = expr.getProject();
final JavaPsiFacade facade = JavaPsiFacade.getInstance(project);
return facade.findClass(text, GlobalSearchScope.allScope(project));
}
}
Aggregations