use of com.intellij.psi.PsiType in project intellij-community by JetBrains.
the class GroovyNameSuggestionProvider method getSuggestedNames.
@Override
public SuggestedNameInfo getSuggestedNames(final PsiElement element, @Nullable PsiElement nameSuggestionContext, Set<String> result) {
if (nameSuggestionContext == null)
nameSuggestionContext = element;
if (element instanceof GrVariable && nameSuggestionContext instanceof GroovyPsiElement) {
final PsiType type = ((GrVariable) element).getTypeGroovy();
if (type != null) {
final String[] names = GroovyNameSuggestionUtil.suggestVariableNameByType(type, new DefaultGroovyVariableNameValidator((GroovyPsiElement) nameSuggestionContext));
result.addAll(Arrays.asList(names));
return new SuggestedNameInfo(names) {
@Override
public void nameChosen(String name) {
JavaStatisticsManager.incVariableNameUseCount(name, JavaCodeStyleManager.getInstance(element.getProject()).getVariableKind((GrVariable) element), ((GrVariable) element).getName(), type);
}
};
}
}
return null;
}
use of com.intellij.psi.PsiType in project intellij-community by JetBrains.
the class ClassGenerator method shouldBeGenerated.
private static boolean shouldBeGenerated(PsiMethod method) {
for (PsiMethod psiMethod : method.findSuperMethods()) {
if (!psiMethod.hasModifierProperty(PsiModifier.ABSTRACT)) {
final PsiType type = method.getReturnType();
final PsiType superType = psiMethod.getReturnType();
if (type != null && superType != null && !superType.isAssignableFrom(type)) {
return false;
}
}
}
return true;
}
use of com.intellij.psi.PsiType in project intellij-community by JetBrains.
the class MapKeysCompletionProvider method addCompletions.
@Override
protected void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet result) {
PsiElement element = parameters.getPosition();
GrReferenceExpression expression = (GrReferenceExpression) element.getParent();
GrExpression qualifierExpression = expression.getQualifierExpression();
if (qualifierExpression == null)
return;
PsiType mapType = qualifierExpression.getType();
if (!InheritanceUtil.isInheritor(mapType, CommonClassNames.JAVA_UTIL_MAP)) {
return;
}
PsiElement resolve = null;
if (qualifierExpression instanceof GrMethodCall) {
resolve = ((GrMethodCall) qualifierExpression).resolveMethod();
} else if (qualifierExpression instanceof GrReferenceExpression) {
resolve = ((GrReferenceExpression) qualifierExpression).resolve();
}
for (GroovyMapContentProvider provider : GroovyMapContentProvider.EP_NAME.getExtensions()) {
GroovyMapCompletionUtil.addKeyVariants(provider, qualifierExpression, resolve, result);
}
if (mapType instanceof GrMapType) {
for (String key : ((GrMapType) mapType).getStringKeys()) {
LookupElement lookup = LookupElementBuilder.create(key);
lookup = PrioritizedLookupElement.withPriority(lookup, 1);
result.addElement(lookup);
}
}
}
use of com.intellij.psi.PsiType in project timber by JakeWharton.
the class WrongTimberUsageDetector method getType.
private static Class<?> getType(PsiExpression expression) {
if (expression == null) {
return null;
}
if (expression instanceof PsiMethodCallExpression) {
PsiMethodCallExpression call = (PsiMethodCallExpression) expression;
PsiMethod method = call.resolveMethod();
if (method == null) {
return null;
}
String methodName = method.getName();
if (methodName.equals(GET_STRING_METHOD)) {
return String.class;
}
} else if (expression instanceof PsiLiteralExpression) {
PsiLiteralExpression literalExpression = (PsiLiteralExpression) expression;
PsiType expressionType = literalExpression.getType();
if (LintUtils.isString(expressionType)) {
return String.class;
} else if (expressionType == PsiType.INT) {
return Integer.TYPE;
} else if (expressionType == PsiType.FLOAT) {
return Float.TYPE;
} else if (expressionType == PsiType.CHAR) {
return Character.TYPE;
} else if (expressionType == PsiType.BOOLEAN) {
return Boolean.TYPE;
} else if (expressionType == PsiType.NULL) {
return Object.class;
}
}
PsiType type = expression.getType();
if (type != null) {
Class<?> typeClass = getTypeClass(type);
return typeClass != null ? typeClass : Object.class;
}
return null;
}
use of com.intellij.psi.PsiType in project intellij-community by JetBrains.
the class TargetType method create.
@Nullable
public static TargetType create(final PsiArrayType arrayType) {
PsiType currentComponentType = arrayType.getComponentType();
while (currentComponentType instanceof PsiArrayType) {
currentComponentType = ((PsiArrayType) currentComponentType).getComponentType();
}
if (!(currentComponentType instanceof PsiClassType)) {
return null;
}
final String targetQName = arrayType.getCanonicalText();
return new TargetType(targetQName, true, arrayType);
}
Aggregations