Search in sources :

Example 41 with PsiType

use of com.intellij.psi.PsiType in project intellij-community by JetBrains.

the class CreateFieldFromParameterAction method isAvailable.

@Override
protected boolean isAvailable(PsiParameter psiParameter) {
    final PsiType type = getSubstitutedType(psiParameter);
    final PsiClass targetClass = PsiTreeUtil.getParentOfType(psiParameter, PsiClass.class);
    return FieldFromParameterUtils.isAvailable(psiParameter, type, targetClass) && psiParameter.getLanguage().isKindOf(JavaLanguage.INSTANCE);
}
Also used : PsiClass(com.intellij.psi.PsiClass) PsiType(com.intellij.psi.PsiType)

Example 42 with PsiType

use of com.intellij.psi.PsiType in project intellij-plugins by JetBrains.

the class CfmlExpressionTypeCalculator method checkAndReturnNumeric.

@Nullable
private static PsiType checkAndReturnNumeric(@NotNull CfmlExpression leftOperand, @NotNull CfmlExpression rightOperand) {
    PsiType rightType = rightOperand.getPsiType();
    if (rightType == null) {
        return null;
    }
    PsiType leftType = leftOperand.getPsiType();
    if (leftType == null) {
        return null;
    }
    if (isNumericType(leftType) && isNumericType(rightType)) {
        PsiClassType boxedType = ((PsiPrimitiveType) unboxAndBalanceTypes(leftType, rightType)).getBoxedType(leftOperand.getManager(), leftOperand.getResolveScope());
        return boxedType;
    }
    return null;
}
Also used : PsiClassType(com.intellij.psi.PsiClassType) PsiPrimitiveType(com.intellij.psi.PsiPrimitiveType) PsiType(com.intellij.psi.PsiType) Nullable(org.jetbrains.annotations.Nullable)

Example 43 with PsiType

use of com.intellij.psi.PsiType in project intellij-community by JetBrains.

the class GradleUnresolvedReferenceFilter method isReject.

@Override
public boolean isReject(@NotNull GrReferenceExpression expression) {
    final PsiType psiType = GradleResolverUtil.getTypeOf(expression);
    if (psiType == null) {
        PsiElement child = expression.getFirstChild();
        if (child == null)
            return false;
        PsiReference reference = child.getReference();
        if (reference instanceof GrReferenceExpression) {
            PsiType type = ((GrReferenceExpression) reference).getType();
            if (type != null) {
                PsiClassType extType = createGenericType(GRADLE_API_EXTRA_PROPERTIES_EXTENSION, expression, null);
                return TypeConversionUtil.areTypesConvertible(type, extType);
            }
        }
        return false;
    }
    Set<String> toIgnore = new HashSet<>(IGNORE_SET);
    GradleExtensionsSettings.GradleExtensionsData extensionsData = GradleExtensionsContributor.Companion.getExtensionsFor(expression);
    if (extensionsData != null) {
        for (GradleExtensionsSettings.GradleExtension extension : extensionsData.extensions) {
            if (StringUtil.isNotEmpty(extension.namedObjectTypeFqn)) {
                toIgnore.add(extension.namedObjectTypeFqn);
            }
        }
    }
    return toIgnore.contains(TypesUtil.getQualifiedName(psiType));
}
Also used : PsiClassType(com.intellij.psi.PsiClassType) PsiReference(com.intellij.psi.PsiReference) GradleExtensionsSettings(org.jetbrains.plugins.gradle.settings.GradleExtensionsSettings) PsiElement(com.intellij.psi.PsiElement) PsiType(com.intellij.psi.PsiType) GrReferenceExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression) HashSet(java.util.HashSet) ContainerUtil.newHashSet(com.intellij.util.containers.ContainerUtil.newHashSet)

Example 44 with PsiType

use of com.intellij.psi.PsiType in project intellij-community by JetBrains.

the class BaseScriptAnnotationChecker method checkApplicability.

@Override
public boolean checkApplicability(@NotNull AnnotationHolder holder, @NotNull GrAnnotation annotation) {
    if (GroovyCommonClassNames.GROOVY_TRANSFORM_BASE_SCRIPT.equals(annotation.getQualifiedName())) {
        PsiFile file = annotation.getContainingFile();
        if (file instanceof GroovyFile && !(((GroovyFile) file).isScript())) {
            holder.createErrorAnnotation(annotation, GroovyBundle.message("base.script.annotation.is.allowed.only.inside.scripts"));
            return true;
        }
        PsiElement pparent = annotation.getParent().getParent();
        if (pparent instanceof GrVariableDeclaration) {
            GrTypeElement typeElement = ((GrVariableDeclaration) pparent).getTypeElementGroovy();
            PsiType type = typeElement != null ? typeElement.getType() : null;
            if (!InheritanceUtil.isInheritor(type, GroovyCommonClassNames.GROOVY_LANG_SCRIPT)) {
                String typeText = type != null ? type.getCanonicalText() : CommonClassNames.JAVA_LANG_OBJECT;
                holder.createErrorAnnotation(annotation, GroovyBundle.message("declared.type.0.have.to.extend.script", typeText));
                return true;
            }
        }
    }
    return false;
}
Also used : GrVariableDeclaration(org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariableDeclaration) GrTypeElement(org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeElement) PsiFile(com.intellij.psi.PsiFile) GroovyFile(org.jetbrains.plugins.groovy.lang.psi.GroovyFile) PsiElement(com.intellij.psi.PsiElement) PsiType(com.intellij.psi.PsiType)

Example 45 with PsiType

use of com.intellij.psi.PsiType in project intellij-community by JetBrains.

the class GrReassignedInClosureLocalVarInspection method buildVisitor.

@NotNull
@Override
protected BaseInspectionVisitor buildVisitor() {
    return new BaseInspectionVisitor() {

        @Override
        public void visitReferenceExpression(@NotNull GrReferenceExpression referenceExpression) {
            super.visitReferenceExpression(referenceExpression);
            if (!PsiUtil.isLValue(referenceExpression))
                return;
            final PsiElement resolved = referenceExpression.resolve();
            if (!PsiUtil.isLocalVariable(resolved))
                return;
            final PsiType checked = GrReassignedLocalVarsChecker.getReassignedVarType(referenceExpression, false);
            if (checked == null)
                return;
            final GrControlFlowOwner varFlowOwner = ControlFlowUtils.findControlFlowOwner(resolved);
            final GrControlFlowOwner refFlorOwner = ControlFlowUtils.findControlFlowOwner(referenceExpression);
            if (isOtherScopeAndType(referenceExpression, checked, varFlowOwner, refFlorOwner)) {
                String flowDescription = getFlowDescription(refFlorOwner);
                final String message = GroovyInspectionBundle.message("local.var.0.is.reassigned", ((GrNamedElement) resolved).getName(), flowDescription);
                registerError(referenceExpression, message, LocalQuickFix.EMPTY_ARRAY, ProblemHighlightType.GENERIC_ERROR_OR_WARNING);
            }
        }
    };
}
Also used : GrControlFlowOwner(org.jetbrains.plugins.groovy.lang.psi.GrControlFlowOwner) BaseInspectionVisitor(org.jetbrains.plugins.groovy.codeInspection.BaseInspectionVisitor) NotNull(org.jetbrains.annotations.NotNull) PsiElement(com.intellij.psi.PsiElement) GrReferenceExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression) PsiType(com.intellij.psi.PsiType) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

PsiType (com.intellij.psi.PsiType)157 PsiElement (com.intellij.psi.PsiElement)34 Nullable (org.jetbrains.annotations.Nullable)24 GrExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression)24 NotNull (org.jetbrains.annotations.NotNull)21 PsiClassType (com.intellij.psi.PsiClassType)20 PsiClass (com.intellij.psi.PsiClass)14 GrReferenceExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression)13 PsiPrimitiveType (com.intellij.psi.PsiPrimitiveType)12 ArrayList (java.util.ArrayList)9 GrTypeElement (org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeElement)9 PsiArrayType (com.intellij.psi.PsiArrayType)7 PsiExpression (com.intellij.psi.PsiExpression)7 PsiField (com.intellij.psi.PsiField)7 NonNls (org.jetbrains.annotations.NonNls)7 GrVariable (org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable)7 PsiLiteralExpression (com.intellij.psi.PsiLiteralExpression)6 PsiMethod (com.intellij.psi.PsiMethod)6 GrStatement (org.jetbrains.plugins.groovy.lang.psi.api.statements.GrStatement)6 GrLiteral (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrLiteral)6