本文整理汇总了Java中com.intellij.psi.util.PsiUtil.extractIterableTypeParameter方法的典型用法代码示例。如果您正苦于以下问题:Java PsiUtil.extractIterableTypeParameter方法的具体用法?Java PsiUtil.extractIterableTypeParameter怎么用?Java PsiUtil.extractIterableTypeParameter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.psi.util.PsiUtil
的用法示例。
在下文中一共展示了PsiUtil.extractIterableTypeParameter方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getArraysConversionMethod
import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
@Nullable
private static String getArraysConversionMethod(PsiType itemType, PsiType expectedType) {
String methodName = "asList";
PsiType componentType = PsiUtil.extractIterableTypeParameter(expectedType, true);
if (componentType == null) {
methodName = "stream";
componentType = getStreamComponentType(expectedType);
PsiPrimitiveType unboxedType = PsiPrimitiveType.getUnboxedType(componentType);
if (unboxedType != null) {
componentType = unboxedType;
}
}
if (componentType == null ||
!(itemType instanceof PsiArrayType) ||
!componentType.isAssignableFrom(((PsiArrayType)itemType).getComponentType())) {
return null;
}
return methodName;
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:22,代码来源:ReferenceExpressionCompletionContributor.java
示例2: isConvertible
import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
@Override
public Boolean isConvertible(@NotNull PsiType lType, @NotNull PsiType rType, @NotNull GroovyPsiElement context) {
if (context instanceof GrListOrMap &&
context.getReference() instanceof LiteralConstructorReference &&
((LiteralConstructorReference)context.getReference()).getConstructedClassType() != null) return null;
if (rType instanceof GrTupleType) {
final GrTupleType tupleType = (GrTupleType)rType;
final PsiType expectedComponent = PsiUtil.extractIterableTypeParameter(lType, false);
if (expectedComponent != null && isMethodCallConversion(context)) {
PsiType[] parameters = tupleType.getParameters();
if (parameters.length == 1) {
PsiType tupleComponent = parameters[0];
if (tupleComponent != null &&
TypesUtil.isAssignable(expectedComponent, tupleComponent, context) && hasDefaultConstructor(lType)) {
return true;
}
}
}
}
return null;
}
示例3: getIteratedType
import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
private static PsiType getIteratedType(PsiElement parent, PsiType collection) {
if (parent instanceof GrReferenceExpression) {
final GrExpression qualifier = ((GrReferenceExpression)parent).getQualifier();
if (qualifier != null) {
return ClosureParameterEnhancer.findTypeForIteration(qualifier, parent);
}
}
final PsiType iterable = PsiUtil.extractIterableTypeParameter(collection, true);
if (iterable != null && parent instanceof GrExpression) {
return PsiImplUtil.normalizeWildcardTypeByPosition(iterable, (GrExpression)parent);
}
else {
return iterable;
}
}
示例4: inferIteratorType
import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
private PsiType inferIteratorType(GroovyResolveResult iteratorMethodResult, GrExpression tupleInitializer) {
PsiElement method = iteratorMethodResult.getElement();
if (method instanceof PsiMethod) {
return iteratorMethodResult.getSubstitutor().substitute(((PsiMethod)method).getReturnType());
}
else {
PsiType initializerType = tupleInitializer.getType();
PsiType iterableParam = PsiUtil.extractIterableTypeParameter(initializerType, false);
JavaPsiFacade facade = JavaPsiFacade.getInstance(context.project);
PsiClass iterableClass = facade.findClass(CommonClassNames.JAVA_UTIL_ITERATOR, tupleInitializer.getResolveScope());
if (iterableClass != null && iterableParam != null) {
return facade.getElementFactory().createType(iterableClass, iterableParam);
}
else {
return facade.getElementFactory().createTypeFromText(CommonClassNames.JAVA_UTIL_ITERATOR, tupleInitializer);
}
}
}
示例5: addCollectConversion
import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
static void addCollectConversion(PsiReferenceExpression ref, Collection<ExpectedTypeInfo> expectedTypes, Consumer<LookupElement> consumer) {
final PsiExpression qualifier = ref.getQualifierExpression();
PsiType component = qualifier == null ? null : PsiUtil.substituteTypeParameter(qualifier.getType(), JAVA_UTIL_STREAM_STREAM, 0, true);
if (component == null) return;
JavaPsiFacade facade = JavaPsiFacade.getInstance(ref.getProject());
GlobalSearchScope scope = ref.getResolveScope();
PsiClass list = facade.findClass(JAVA_UTIL_LIST, scope);
PsiClass set = facade.findClass(JAVA_UTIL_SET, scope);
if (facade.findClass(JAVA_UTIL_STREAM_COLLECTORS, scope) == null || list == null || set == null) return;
boolean hasList = false;
boolean hasSet = false;
for (ExpectedTypeInfo info : expectedTypes) {
PsiType type = info.getDefaultType();
PsiClass expectedClass = PsiUtil.resolveClassInClassTypeOnly(type);
PsiType expectedComponent = PsiUtil.extractIterableTypeParameter(type, true);
if (expectedClass == null || expectedComponent == null || !TypeConversionUtil.isAssignable(expectedComponent, component)) continue;
if (!hasList && InheritanceUtil.isInheritorOrSelf(list, expectedClass, true)) {
hasList = true;
consumer.consume(new MyLookupElement("toList", type));
}
if (!hasSet && InheritanceUtil.isInheritorOrSelf(set, expectedClass, true)) {
hasSet = true;
consumer.consume(new MyLookupElement("toSet", type));
}
}
}
示例6: processDynamicElements
import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
@Override
public void processDynamicElements(@NotNull final PsiType qualifierType,
PsiClass aClass,
@NotNull final PsiScopeProcessor processor,
@NotNull final PsiElement place,
@NotNull final ResolveState state) {
final PsiType collectionType = PsiUtil.extractIterableTypeParameter(qualifierType, true);
if (collectionType == null) return;
PsiClass collectionClass = JavaPsiFacade.getInstance(place.getProject()).findClass(CommonClassNames.JAVA_UTIL_COLLECTION, place.getResolveScope());
final PsiScopeProcessor fieldSearcher = new FieldSearcher(processor, collectionClass);
ResolveUtil.processAllDeclarations(collectionType, fieldSearcher, state, place);
}
示例7: findTypeForIteration
import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
public static PsiType findTypeForIteration(@Nullable PsiType type, @NotNull PsiElement context) {
final PsiManager manager = context.getManager();
final GlobalSearchScope resolveScope = context.getResolveScope();
if (type instanceof PsiArrayType) {
return TypesUtil.boxPrimitiveType(((PsiArrayType)type).getComponentType(), manager, resolveScope);
}
if (type instanceof GrTupleType) {
PsiType[] types = ((GrTupleType)type).getParameters();
return types.length == 1 ? types[0] : null;
}
if (type instanceof GrRangeType) {
return ((GrRangeType)type).getIterationType();
}
PsiType fromIterator = findTypeFromIteratorMethod(type, context);
if (fromIterator != null) {
return fromIterator;
}
PsiType extracted = PsiUtil.extractIterableTypeParameter(type, true);
if (extracted != null) {
return extracted;
}
if (TypesUtil.isClassType(type, JAVA_LANG_STRING) || TypesUtil.isClassType(type, JAVA_IO_FILE)) {
return PsiType.getJavaLangString(manager, resolveScope);
}
if (InheritanceUtil.isInheritor(type, JAVA_UTIL_MAP)) {
return getEntryForMap(type, manager.getProject(), resolveScope);
}
return type;
}
示例8: isCastToRawCollectionFromArray
import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
/**
* It is assumed that collection class should have only one type param and this param defines collection's item type.
*/
@SuppressWarnings("ConstantConditions")
private static boolean isCastToRawCollectionFromArray(PsiType opType, PsiType castType) {
return castType instanceof PsiClassType &&
InheritanceUtil.isInheritor(castType, CommonClassNames.JAVA_UTIL_COLLECTION) &&
PsiUtil.extractIterableTypeParameter(castType, false) == null &&
((PsiClassType)castType).resolve().getTypeParameters().length == 1 &&
TypesUtil.getItemType(opType) != null;
}
示例9: getItemType
import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
@Nullable
public static PsiType getItemType(@Nullable PsiType containerType) {
if (containerType == null) return null;
if (containerType instanceof PsiArrayType) return ((PsiArrayType)containerType).getComponentType();
return PsiUtil.extractIterableTypeParameter(containerType, false);
}
示例10: getItemType
import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
@Nullable
private static PsiType getItemType(PsiType type) {
if (type instanceof PsiArrayType) {
return ((PsiArrayType)type).getComponentType();
}
else {
return PsiUtil.extractIterableTypeParameter(type, true);
}
}
示例11: addToArrayConversions
import com.intellij.psi.util.PsiUtil; //导入方法依赖的package包/类
private static void addToArrayConversions(final PsiElement element, final Object object, final String prefix, final PsiType itemType,
final Consumer<LookupElement> result, @Nullable final PsiElement qualifier,
final PsiType expectedType) {
final String callSpace = getSpace(CodeStyleSettingsManager.getSettings(element.getProject()).SPACE_WITHIN_METHOD_CALL_PARENTHESES);
final PsiType componentType = PsiUtil.extractIterableTypeParameter(itemType, true);
if (componentType == null || !(expectedType instanceof PsiArrayType)) return;
final PsiArrayType type = (PsiArrayType)expectedType;
if (!type.getComponentType().isAssignableFrom(componentType) ||
componentType instanceof PsiClassType && ((PsiClassType) componentType).hasParameters()) {
return;
}
final String bracketSpace = getSpace(CodeStyleSettingsManager.getSettings(element.getProject()).SPACE_WITHIN_BRACKETS);
if (object instanceof PsiVariable && !JavaCompletionUtil.mayHaveSideEffects(qualifier)) {
final PsiVariable variable = (PsiVariable)object;
addToArrayConversion(element, prefix,
"new " + componentType.getCanonicalText() +
"[" + bracketSpace + getQualifierText(qualifier) + variable.getName() + ".size(" + callSpace + ")" + bracketSpace + "]",
"new " + getQualifierText(qualifier) + componentType.getPresentableText() + "[" + variable.getName() + ".size()]", result, qualifier);
} else {
boolean hasEmptyArrayField = false;
final PsiClass psiClass = PsiUtil.resolveClassInType(type);
if (psiClass != null) {
for (final PsiField field : psiClass.getAllFields()) {
if (field.hasModifierProperty(PsiModifier.STATIC) && field.hasModifierProperty(PsiModifier.FINAL) &&
JavaPsiFacade.getInstance(field.getProject()).getResolveHelper().isAccessible(field, element, null) &&
type.isAssignableFrom(field.getType()) && isEmptyArrayInitializer(field.getInitializer())) {
boolean needQualify;
try {
needQualify = !field.isEquivalentTo(((PsiReferenceExpression)createExpression(field.getName(), element)).resolve());
}
catch (IncorrectOperationException e) {
continue;
}
addToArrayConversion(element, prefix,
(needQualify ? field.getContainingClass().getQualifiedName() + "." : "") + field.getName(),
(needQualify ? field.getContainingClass().getName() + "." : "") + field.getName(), result, qualifier);
hasEmptyArrayField = true;
}
}
}
if (!hasEmptyArrayField) {
addToArrayConversion(element, prefix,
"new " + componentType.getCanonicalText() + "[" + bracketSpace + "0" + bracketSpace + "]",
"new " + componentType.getPresentableText() + "[0]", result, qualifier);
}
}
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:51,代码来源:ReferenceExpressionCompletionContributor.java