本文整理汇总了Java中com.intellij.psi.PsiClassType.resolveGenerics方法的典型用法代码示例。如果您正苦于以下问题:Java PsiClassType.resolveGenerics方法的具体用法?Java PsiClassType.resolveGenerics怎么用?Java PsiClassType.resolveGenerics使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.psi.PsiClassType
的用法示例。
在下文中一共展示了PsiClassType.resolveGenerics方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: create
import com.intellij.psi.PsiClassType; //导入方法依赖的package包/类
@Nullable
public static TargetType create(final PsiClassType classType) {
final PsiClassType.ClassResolveResult resolvedGenerics = classType.resolveGenerics();
final PsiClass resolvedClass = resolvedGenerics.getElement();
if (resolvedClass == null) {
return null;
}
final String classQName = resolvedClass.getQualifiedName();
if (classQName == null) {
return null;
}
if (resolvedClass.hasTypeParameters()) {
return null;
}
return new TargetType(classQName, false, classType);
}
示例2: getReferenceElements
import com.intellij.psi.PsiClassType; //导入方法依赖的package包/类
@Override
@NotNull
public PsiJavaCodeReferenceElement[] getReferenceElements() {
PsiClassType[] types = getReferencedTypes();
if (types.length == 0) return PsiJavaCodeReferenceElement.EMPTY_ARRAY;
PsiManagerEx manager = getManager();
List<PsiJavaCodeReferenceElement> result = ContainerUtil.newArrayList();
for (PsiClassType type : types) {
PsiClassType.ClassResolveResult resolveResult = type.resolveGenerics();
PsiClass resolved = resolveResult.getElement();
if (resolved != null) {
result.add(new LightClassReference(manager, type.getCanonicalText(), resolved, resolveResult.getSubstitutor()));
}
}
return result.toArray(new PsiJavaCodeReferenceElement[result.size()]);
}
示例3: extractTypeParameters
import com.intellij.psi.PsiClassType; //导入方法依赖的package包/类
@NotNull
public static PsiType[] extractTypeParameters(@NotNull PsiType psiType, @NotNull PsiManager psiManager) {
if (!(psiType instanceof PsiClassType)) {
return PsiType.EMPTY_ARRAY;
}
final PsiClassType classType = (PsiClassType) psiType;
final PsiClassType.ClassResolveResult classResolveResult = classType.resolveGenerics();
final PsiClass psiClass = classResolveResult.getElement();
if (psiClass == null) {
return PsiType.EMPTY_ARRAY;
}
final PsiSubstitutor psiSubstitutor = classResolveResult.getSubstitutor();
final PsiTypeParameter[] typeParameters = psiClass.getTypeParameters();
final PsiType[] psiTypes = PsiType.createArray(typeParameters.length);
for (int i = 0; i < typeParameters.length; i++) {
PsiType psiSubstituteKeyType = psiSubstitutor.substitute(typeParameters[i]);
if (null == psiSubstituteKeyType) {
psiSubstituteKeyType = PsiType.getJavaLangObject(psiManager, GlobalSearchScope.allScope(psiManager.getProject()));
}
psiTypes[i] = psiSubstituteKeyType;
}
return psiTypes;
}
示例4: visitType
import com.intellij.psi.PsiClassType; //导入方法依赖的package包/类
private void visitType(@NotNull PsiClassType type, Map<PsiClass, PsiClassType.ClassResolveResult> map)
{
PsiClassType.ClassResolveResult resolveResult = type.resolveGenerics();
PsiClass psiClass = resolveResult.getElement();
if(psiClass == null || InheritanceImplUtil.hasObjectQualifiedName(psiClass) || map.containsKey(psiClass))
{
return;
}
map.put(psiClass, resolveResult);
for(PsiType superType : getSuperTypes(psiClass))
{
superType = type.isRaw() && superType instanceof PsiClassType ? ((PsiClassType) superType).rawType() : resolveResult.getSubstitutor().substitute(superType);
superType = PsiClassImplUtil.correctType(superType, myResolveScope);
if(superType instanceof PsiClassType)
{
visitType((PsiClassType) superType, map);
}
}
}
示例5: visitClassType
import com.intellij.psi.PsiClassType; //导入方法依赖的package包/类
public X visitClassType(final PsiClassType classType) {
super.visitClassType(classType);
final PsiClassType.ClassResolveResult result = classType.resolveGenerics();
if (result.getElement() != null) {
for (final PsiType type : result.getSubstitutor().getSubstitutionMap().values()) {
if (type != null) {
type.accept(this);
}
}
}
return null;
}
示例6: suggestVariantsForCollectionMembers
import com.intellij.psi.PsiClassType; //导入方法依赖的package包/类
private List<FieldExpression> suggestVariantsForCollectionMembers(PsiType nextExtensionBaseType, int depth, String nexpr) {
List<FieldExpression> result = new LinkedList<FieldExpression>();
PsiClass nextExtensionBase = PsiUtil.resolveClassInType(nextExtensionBaseType);
if (nextExtensionBase != null) {
result.addAll(suggestVariants(nextExtensionBase, nexpr, depth - 1));
final String nexprComp = nexpr + "[0]";
if (nextExtensionBaseType instanceof PsiArrayType) {
result.add(new FieldExpression(fieldDefinition, nexprComp));
PsiType compType = ((PsiArrayType) nextExtensionBaseType).getComponentType();
PsiClass compClass = PsiUtil.resolveClassInType(compType);
if (compClass != null) {
result.addAll(suggestVariants(compClass, nexprComp, depth - 1));
}
}
else if (isOfTypeList(nextExtensionBase)) {
PsiClassType listClassType = (PsiClassType) nextExtensionBaseType;
if (listClassType.hasParameters()) {
PsiClassType.ClassResolveResult resolveResult = listClassType.resolveGenerics();
PsiType paramType = resolveResult.getSubstitutor().substitute(listClassType.getParameters()[0]);
if (paramType instanceof PsiClassType) {
PsiClass paramClass = PsiUtil.resolveClassInType(paramType);
result.addAll(suggestVariants(paramClass, nexprComp, depth - 1));
}
}
result.add(new FieldExpression(fieldDefinition, nexprComp));
}
}
return result;
}
示例7: getPsiClass
import com.intellij.psi.PsiClassType; //导入方法依赖的package包/类
private static PsiClass getPsiClass(PsiClass wrapperClass, PsiType psiFieldType) {
PsiClassType psiClassType = (PsiClassType) psiFieldType;
PsiClassType.ClassResolveResult classResolveResult = psiClassType.resolveGenerics();
PsiClass outerClass = classResolveResult.getElement();
// If Lazy<Foo> or Provider<Foo>, extract Foo as the interesting type.
if (PsiConsultantImpl.isLazyOrProvider(outerClass)) {
PsiType genericType = extractFirstTypeParameter(psiClassType);
// Convert genericType to its PsiClass and store in psiClass
wrapperClass = getClass(genericType);
}
return wrapperClass;
}
示例8: getCollectionClassType
import com.intellij.psi.PsiClassType; //导入方法依赖的package包/类
@NotNull
public static PsiClassType getCollectionClassType(@NotNull PsiClassType psiType, @NotNull Project project, @NotNull String qualifiedName) {
final PsiElementFactory elementFactory = JavaPsiFacade.getElementFactory(project);
final JavaPsiFacade facade = JavaPsiFacade.getInstance(project);
final GlobalSearchScope globalsearchscope = GlobalSearchScope.allScope(project);
PsiClass genericClass = facade.findClass(qualifiedName, globalsearchscope);
if (null != genericClass) {
final PsiClassType.ClassResolveResult classResolveResult = psiType.resolveGenerics();
final PsiSubstitutor derivedSubstitutor = classResolveResult.getSubstitutor();
final List<PsiType> typeList = new ArrayList<PsiType>(2);
final Map<String, PsiType> nameTypeMap = new HashMap<String, PsiType>();
for (Map.Entry<PsiTypeParameter, PsiType> entry : derivedSubstitutor.getSubstitutionMap().entrySet()) {
final PsiType entryValue = entry.getValue();
if (null != entryValue) {
nameTypeMap.put(entry.getKey().getName(), entryValue);
typeList.add(entryValue);
}
}
PsiSubstitutor genericSubstitutor = PsiSubstitutor.EMPTY;
final PsiTypeParameter[] typeParameters = genericClass.getTypeParameters();
for (int i = 0; i < typeParameters.length; i++) {
final PsiTypeParameter psiTypeParameter = typeParameters[i];
PsiType mappedType = nameTypeMap.get(psiTypeParameter.getName());
if (null == mappedType && typeList.size() > i) {
mappedType = typeList.get(i);
}
if (null == mappedType) {
mappedType = PsiType.getJavaLangObject(PsiManager.getInstance(project), globalsearchscope);
}
if (mappedType instanceof PsiWildcardType) {
mappedType = ((PsiWildcardType) mappedType).getBound();
}
genericSubstitutor = genericSubstitutor.put(psiTypeParameter, mappedType);
}
return elementFactory.createType(genericClass, genericSubstitutor);
}
return elementFactory.createTypeByFQClassName(qualifiedName, globalsearchscope);
}
示例9: processTypeParameter
import com.intellij.psi.PsiClassType; //导入方法依赖的package包/类
/**
* Some type parameters (e.g. {@link com.intellij.psi.impl.source.resolve.graphInference.InferenceVariable} change their supers at will,
* so caching the hierarchy is impossible.
*/
@Nullable
private static PsiSubstitutor processTypeParameter(PsiTypeParameter parameter, GlobalSearchScope scope, PsiClass superClass, Set<PsiTypeParameter> visited, PsiSubstitutor derivedSubstitutor)
{
if(parameter.getManager().areElementsEquivalent(parameter, superClass))
{
return PsiSubstitutor.EMPTY;
}
if(!visited.add(parameter))
{
return null;
}
for(PsiClassType type : parameter.getExtendsListTypes())
{
PsiClassType.ClassResolveResult result = type.resolveGenerics();
PsiClass psiClass = result.getElement();
if(psiClass == null)
{
continue;
}
PsiSubstitutor answer;
if(psiClass instanceof PsiTypeParameter)
{
answer = processTypeParameter((PsiTypeParameter) psiClass, scope, superClass, visited, derivedSubstitutor);
if(answer != null)
{
return answer;
}
}
else
{
answer = getSuperSubstitutorWithCaching(superClass, psiClass, scope, result.getSubstitutor());
if(answer != null)
{
return composeSubstitutors(derivedSubstitutor, answer, superClass);
}
}
}
return null;
}