use of com.intellij.psi.PsiType in project intellij-community by JetBrains.
the class ComponentTypeOfMacro method calculateResult.
@Override
public Result calculateResult(@NotNull Expression[] params, final ExpressionContext context) {
if (params.length != 1)
return null;
final Result result = params[0].calculateResult(context);
if (result == null)
return null;
if (result instanceof PsiTypeResult) {
PsiType type = ((PsiTypeResult) result).getType();
if (type instanceof PsiArrayType) {
return new PsiTypeResult(((PsiArrayType) type).getComponentType(), context.getProject());
}
}
PsiExpression expr = MacroUtil.resultToPsiExpression(result, context);
PsiType type = expr == null ? MacroUtil.resultToPsiType(result, context) : expr.getType();
if (type instanceof PsiArrayType) {
return new PsiTypeResult(((PsiArrayType) type).getComponentType(), context.getProject());
}
LookupElement[] elements = params[0].calculateLookupItems(context);
if (elements != null) {
for (LookupElement element : elements) {
PsiTypeLookupItem typeLookupItem = element.as(PsiTypeLookupItem.CLASS_CONDITION_KEY);
if (typeLookupItem != null) {
PsiType psiType = typeLookupItem.getType();
if (psiType instanceof PsiArrayType) {
return new PsiTypeResult(((PsiArrayType) psiType).getComponentType(), context.getProject());
}
}
}
}
return new PsiElementResult(null);
}
use of com.intellij.psi.PsiType in project intellij-community by JetBrains.
the class SubtypesMacro method calculateLookupItems.
@Override
public LookupElement[] calculateLookupItems(@NotNull Expression[] params, ExpressionContext context) {
if (params.length == 0)
return LookupElement.EMPTY_ARRAY;
Result paramResult = params[0].calculateQuickResult(context);
if (paramResult instanceof PsiTypeResult) {
final PsiType type = ((PsiTypeResult) paramResult).getType();
final PsiFile file = PsiDocumentManager.getInstance(context.getProject()).getPsiFile(context.getEditor().getDocument());
final PsiElement element = file.findElementAt(context.getStartOffset());
final Set<LookupElement> set = new LinkedHashSet<>();
JavaTemplateUtil.addTypeLookupItem(set, type);
CodeInsightUtil.processSubTypes(type, element, false, PrefixMatcher.ALWAYS_TRUE, psiType -> JavaTemplateUtil.addTypeLookupItem(set, psiType));
return set.toArray(new LookupElement[set.size()]);
}
return LookupElement.EMPTY_ARRAY;
}
use of com.intellij.psi.PsiType in project intellij-community by JetBrains.
the class OptionalPostfixTemplate method getTemplateString.
@Nullable
@Override
public String getTemplateString(@NotNull PsiElement element) {
String className = "Optional";
String methodName = "ofNullable";
if (element instanceof PsiExpression) {
PsiType type = ((PsiExpression) element).getType();
if (type instanceof PsiPrimitiveType) {
if (PsiType.INT.equals(type)) {
className = "OptionalInt";
} else if (PsiType.DOUBLE.equals(type)) {
className = "OptionalDouble";
} else if (PsiType.LONG.equals(type)) {
className = "OptionalLong";
}
methodName = "of";
}
}
return "java.util." + className + "." + methodName + "($expr$)";
}
use of com.intellij.psi.PsiType in project intellij-community by JetBrains.
the class TypeSelector method setTypes.
public void setTypes(PsiType[] types) {
if (myComboBoxModel == null)
return;
PsiType oldType;
if (myComboBoxModel.getSize() > 0) {
oldType = getSelectedType();
} else {
oldType = null;
}
myComboBoxModel.setSuggestions(wrapToItems(types, myProject));
if (oldType != null) {
for (int i = 0; i < types.length; i++) {
PsiType type = types[i];
if (type.equals(oldType)) {
((JComboBox) myComponent).setSelectedIndex(i);
return;
}
}
}
if (types.length > 0) {
((JComboBox) myComponent).setSelectedIndex(0);
}
}
use of com.intellij.psi.PsiType in project intellij-community by JetBrains.
the class NullityInference method inferNullity.
public static Nullness inferNullity(PsiMethodImpl method) {
if (!InferenceFromSourceUtil.shouldInferFromSource(method)) {
return Nullness.UNKNOWN;
}
PsiType type = method.getReturnType();
if (type == null || type instanceof PsiPrimitiveType) {
return Nullness.UNKNOWN;
}
return CachedValuesManager.getCachedValue(method, () -> {
MethodData data = ContractInferenceIndexKt.getIndexedData(method);
NullityInferenceResult result = data == null ? null : data.getNullity();
Nullness nullness = result == null ? null : RecursionManager.doPreventingRecursion(method, true, () -> result.getNullness(method, data.methodBody(method)));
if (nullness == null)
nullness = Nullness.UNKNOWN;
return CachedValueProvider.Result.create(nullness, method, PsiModificationTracker.JAVA_STRUCTURE_MODIFICATION_COUNT);
});
}
Aggregations