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);
}
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());
}
}
}
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);
}
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);
}
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());
}
Aggregations