Search in sources :

Example 76 with PsiType

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

the class ReturnDocTagInfo method isValidInContext.

@Override
public boolean isValidInContext(PsiElement element) {
    if (!(element instanceof PsiMethod))
        return false;
    PsiMethod method = (PsiMethod) element;
    final PsiType type = method.getReturnType();
    if (type == null)
        return false;
    return !PsiType.VOID.equals(type);
}
Also used : PsiMethod(com.intellij.psi.PsiMethod) PsiType(com.intellij.psi.PsiType)

Example 77 with PsiType

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

the class PsiTypeTokenizer method tokenize.

@Override
public void tokenize(@NotNull PsiTypeElement element, TokenConsumer consumer) {
    final PsiType type = element.getType();
    if (type instanceof PsiDisjunctionType) {
        tokenizeComplexType(element, consumer);
        return;
    }
    final PsiClass psiClass = PsiUtil.resolveClassInType(type);
    if (psiClass == null || psiClass.getContainingFile() == null || psiClass.getContainingFile().getVirtualFile() == null) {
        return;
    }
    final String name = psiClass.getName();
    if (name == null) {
        return;
    }
    final VirtualFile virtualFile = psiClass.getContainingFile().getVirtualFile();
    final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(element.getProject()).getFileIndex();
    final boolean isInSource = (virtualFile != null) && fileIndex.isInContent(virtualFile);
    if (isInSource) {
        final String elementText = element.getText();
        if (elementText.contains(name)) {
            consumer.consumeToken(element, elementText, true, 0, getRangeToCheck(elementText, name), IdentifierSplitter.getInstance());
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiDisjunctionType(com.intellij.psi.PsiDisjunctionType) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) PsiClass(com.intellij.psi.PsiClass) PsiType(com.intellij.psi.PsiType)

Example 78 with PsiType

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

the class ClassMappingNameConverter method getVariants.

@NotNull
@Override
public Collection<String> getVariants(ConvertContext context) {
    DomElement parent = context.getInvocationElement().getParent();
    assert parent != null;
    List<DomElement> children = DomUtil.getDefinedChildren(parent, true, true);
    DomElement classElement = ContainerUtil.find(children, domElement -> domElement.getAnnotation(MappingClass.class) != null);
    if (classElement == null)
        return Collections.emptyList();
    Object value = ((GenericDomValue) classElement).getValue();
    if (value == null)
        return Collections.emptyList();
    PsiType type;
    if (value instanceof PsiType) {
        type = (PsiType) value;
    } else if (value instanceof PsiClass) {
        type = PsiTypesUtil.getClassType((PsiClass) value);
    } else {
        LOG.error("wrong type: " + value.getClass());
        return Collections.emptyList();
    }
    JavaCodeStyleManager codeStyleManager = JavaCodeStyleManager.getInstance(context.getProject());
    SuggestedNameInfo info = codeStyleManager.suggestVariableName(VariableKind.LOCAL_VARIABLE, null, null, type);
    return Arrays.asList(info.names);
}
Also used : JavaCodeStyleManager(com.intellij.psi.codeStyle.JavaCodeStyleManager) PsiClass(com.intellij.psi.PsiClass) SuggestedNameInfo(com.intellij.psi.codeStyle.SuggestedNameInfo) PsiType(com.intellij.psi.PsiType) NotNull(org.jetbrains.annotations.NotNull)

Example 79 with PsiType

use of com.intellij.psi.PsiType in project kotlin by JetBrains.

the class ViewTagDetector method visitMethod.

@Override
public void visitMethod(@NonNull JavaContext context, @Nullable UastVisitor visitor, @NonNull UCallExpression call, @NonNull UMethod method) {
    // http://code.google.com/p/android/issues/detail?id=18273
    if (context.getMainProject().getMinSdk() >= 14) {
        return;
    }
    JavaEvaluator evaluator = context.getEvaluator();
    if (!evaluator.isMemberInSubClassOf(method, CLASS_VIEW, false)) {
        return;
    }
    List<UExpression> arguments = call.getValueArguments();
    if (arguments.size() != 2) {
        return;
    }
    UExpression tagArgument = arguments.get(1);
    if (tagArgument == null) {
        return;
    }
    PsiType type = TypeEvaluator.evaluate(context, tagArgument);
    if ((!(type instanceof PsiClassType))) {
        return;
    }
    PsiClass typeClass = ((PsiClassType) type).resolve();
    if (typeClass == null) {
        return;
    }
    String objectType;
    if (InheritanceUtil.isInheritor(typeClass, false, CLASS_VIEW)) {
        objectType = "views";
    } else if (InheritanceUtil.isInheritor(typeClass, false, CURSOR_CLS)) {
        objectType = "cursors";
    } else if (typeClass.getName() != null && typeClass.getName().endsWith("ViewHolder")) {
        objectType = "view holders";
    } else {
        return;
    }
    String message = String.format("Avoid setting %1$s as values for `setTag`: " + "Can lead to memory leaks in versions older than Android 4.0", objectType);
    context.report(ISSUE, call, context.getUastLocation(tagArgument), message);
}
Also used : UExpression(org.jetbrains.uast.UExpression) PsiClassType(com.intellij.psi.PsiClassType) PsiClass(com.intellij.psi.PsiClass) JavaEvaluator(com.android.tools.klint.client.api.JavaEvaluator) PsiType(com.intellij.psi.PsiType)

Example 80 with PsiType

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

the class LiteralExpressionPsiTest method runBigIntegerLiteral.

private void runBigIntegerLiteral(@Language(value = OgnlLanguage.ID, prefix = OgnlLanguage.EXPRESSION_PREFIX, suffix = OgnlLanguage.EXPRESSION_SUFFIX) final String bigIntegerExpression) {
    final OgnlLiteralExpression expression = parse(bigIntegerExpression);
    final PsiType type = expression.getType();
    assertNotNull(type);
    assertEquals("java.math.BigInteger", type.getCanonicalText());
    assertEquals(new BigInteger(bigIntegerExpression.substring(0, bigIntegerExpression.length() - 1)), expression.getConstantValue());
}
Also used : BigInteger(java.math.BigInteger) PsiType(com.intellij.psi.PsiType)

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