Java 类com.intellij.psi.impl.source.PsiClassReferenceType 实例源码

项目:intellij-plugin    文件:ClassCompletionResolver.java   
@Override
public Stream<LookupElementBuilder> resolveCompletions(String propertyName, PsiType psiType) {
    PsiType[] parameters = ((PsiClassReferenceType) psiType).getParameters();
    Stream<PsiClass> psiClassStream = null;
    if (parameters.length == 1 && parameters[0] instanceof PsiWildcardType) {
        PsiWildcardType psiWildcardType = ((PsiWildcardType) parameters[0]);
        if (psiWildcardType.isBounded()) {
            if (psiWildcardType.isExtends()) {
                psiClassStream = subClasses((PsiClassType) psiWildcardType.getExtendsBound()).stream();
            } else if (psiWildcardType.isSuper()) {
                psiClassStream = superClasses((PsiClassType) psiWildcardType.getSuperBound()).stream();
            }
        }
    }
    if (psiClassStream != null) {
        return psiClassStream.map(this::buildClassLookup).filter(Optional::isPresent).map(Optional::get);
    } else {
        return Stream.empty();
    }
}
项目:camel-idea-plugin    文件:CamelDocumentationProvider.java   
private boolean isPsiMethodCamelLanguage(PsiMethod method) {
    PsiType type = method.getReturnType();
    if (type != null && type instanceof PsiClassReferenceType) {
        PsiClassReferenceType clazz = (PsiClassReferenceType) type;
        PsiClass resolved = clazz.resolve();
        if (resolved != null) {
            boolean language = getCamelIdeaUtils().isCamelExpressionOrLanguage(resolved);
            // try parent using some weird/nasty stub stuff which is how complex IDEA AST
            // is when its parsing the Camel route builder
            if (!language) {
                PsiElement elem = resolved.getParent();
                if (elem instanceof PsiTypeParameterList) {
                    elem = elem.getParent();
                }
                if (elem instanceof PsiClass) {
                    language = getCamelIdeaUtils().isCamelExpressionOrLanguage((PsiClass) elem);
                }
            }
            return language;
        }
    }

    return false;
}
项目:intellij-ce-playground    文件:SmartTypePointerManagerImpl.java   
@Override
public SmartTypePointer visitClassType(PsiClassType classType) {
  final PsiClassType.ClassResolveResult resolveResult = classType.resolveGenerics();
  final PsiClass aClass = resolveResult.getElement();
  if (aClass == null) {
    return createClassReferenceTypePointer(classType);
  }
  if (classType instanceof PsiClassReferenceType) {
    classType = ((PsiClassReferenceType)classType).createImmediateCopy();
  }
  final PsiSubstitutor substitutor = resolveResult.getSubstitutor();
  final HashMap<SmartPsiElementPointer, SmartTypePointer> map = new HashMap<SmartPsiElementPointer, SmartTypePointer>();
  for (PsiTypeParameter typeParameter : PsiUtil.typeParametersIterable(aClass)) {
    final PsiType substitutionResult = substitutor.substitute(typeParameter);
    if (substitutionResult != null) {
      final SmartPsiElementPointer pointer = myPsiPointerManager.createSmartPsiElementPointer(typeParameter);
      map.put(pointer, substitutionResult.accept(this));
    }
  }
  return new ClassTypePointer(classType, myPsiPointerManager.createSmartPsiElementPointer(aClass), map);
}
项目:intellij-ce-playground    文件:PsiThisExpressionImpl.java   
@Override
public PsiType getType() {
  PsiJavaCodeReferenceElement qualifier = getQualifier();
  if (qualifier != null){
    PsiElement qualifierResolve = qualifier.resolve();
    if (qualifierResolve instanceof PsiClass) return new PsiImmediateClassType((PsiClass)qualifierResolve, PsiSubstitutor.EMPTY);
    return new PsiClassReferenceType(qualifier, null);
  }
  for(PsiElement scope = getContext(); scope != null; scope = scope.getContext()){
    if (scope instanceof PsiClass){
      PsiClass aClass = (PsiClass)scope;
      return new PsiImmediateClassType(aClass, PsiSubstitutor.EMPTY);
    }
    else if (scope instanceof PsiExpressionList && scope.getParent() instanceof PsiAnonymousClass){
      scope = scope.getParent();
    }
    else if (scope instanceof JavaCodeFragment){
      PsiType fragmentThisType = ((JavaCodeFragment)scope).getThisType();
      if (fragmentThisType != null) return fragmentThisType;
    }
  }
  return null;
}
项目:intellij-ce-playground    文件:ReferenceParameterListTest.java   
public void testParameterListInExtends() throws Exception {
  final PsiManager manager = PsiManager.getInstance(myProject);
  final PsiElementFactory factory = JavaPsiFacade.getInstance(manager.getProject()).getElementFactory();
  final PsiClass classFromText = factory.createClassFromText("class X extends Y<Z, W> {}", null);
  final PsiClass classX = classFromText.getInnerClasses()[0];
  final PsiJavaCodeReferenceElement[] extendsOfX = classX.getExtendsList().getReferenceElements();
  assertEquals(1, extendsOfX.length);
  final PsiJavaCodeReferenceElement ref = extendsOfX[0];
  assertEquals("Y<Z,W>", ref.getCanonicalText());
  assertEquals("Y", ref.getReferenceName());
  final PsiTypeElement[] refParams = ref.getParameterList().getTypeParameterElements();
  assertEquals(2, refParams.length);
  assertEquals("Z", refParams[0].getType().getCanonicalText());
  assertEquals("W", refParams[1].getType().getCanonicalText());
  final PsiType refType = factory.createType(ref);
  assertEquals("Y<Z,W>", refType.getCanonicalText());
  final PsiJavaCodeReferenceElement reference = ((PsiClassReferenceType) refType).getReference();
  assertEquals("Y<Z,W>", reference.getCanonicalText());
}
项目:AndroidParcelablePlugin    文件:ParcelableListGenerator.java   
@Override
    public void readMethod(PsiCodeBlock methodBody, PsiElementFactory factory, PsiField field) {
        if (null == methodBody) {
            return;
        }

        String fieldName = field.getName();
        String parameterType = ((PsiClassReferenceType) field.getType()).getParameters()[0].getPresentableText();

//        // phones = new ArrayList<>();
//        // in.readTypedList(phones, Phone.CREATOR);
//        methodBody.add(factory.createStatementFromText(fieldName + " = new ArrayList<" + parameterType + ">();", null));
//        methodBody.add(factory.createStatementFromText("in.readTypedList(" + fieldName + ", " + parameterType + ".CREATOR);", null));

        // phones = in.createTypedArrayList(Phone.CREATOR);
        methodBody.add(factory.createStatementFromText(fieldName + " = in.createTypedArrayList(" + parameterType + ".CREATOR);", null));


    }
项目:eddy    文件:Converter.java   
UnresolvedClassItem(@NotNull final Converter env, @NotNull final PsiClassReferenceType cls, @Nullable final Parent parent) {
  this.env = env;
  this.cls = cls;
  PsiPackage pkg = Place.getElementPackage(cls.getReference(), env.project);
  _parent = parent == null ? pkg == null ? LocalPkg$.MODULE$ : (Package)env.addContainer(pkg) : parent;

  if (cls instanceof PsiModifierListOwner) {
    _isFinal = ((PsiModifierListOwner)cls).hasModifierProperty(PsiModifier.FINAL);
    _isAbstract = ((PsiModifierListOwner)cls).hasModifierProperty(PsiModifier.ABSTRACT);
    _isStatic = Place.isStatic((PsiModifierListOwner) cls);
  }

  List<TypeArg> jargs = new SmartList<TypeArg>();
  for (PsiType arg : cls.getParameters())
    jargs.add(env.convertTypeArg(arg,parent));
  _targs = scala.collection.JavaConversions.asScalaBuffer(jargs).toList();
}
项目:smogen    文件:PsiTypeConverter.java   
@Nullable
@Override
public TypeBuilder visitClassType(PsiClassType classType) {
    String name = (classType instanceof PsiClassReferenceType) ?
            ((PsiClassReferenceType) classType).getReference().getQualifiedName() :
            classType.getClassName();

    String mappedName = typeParameterMap.containsKey(name) ? typeParameterMap.get(name) : name;

    typeBuilder.withName(mappedName);

    for (PsiType param : classType.getParameters()) {
        PsiTypeParameterConverter converter = new PsiTypeParameterConverter(typeParameterMap);
        param.accept(converter);
        typeBuilder.withTypeBinding(converter.getTypeParameterBuilder());
    }

    return super.visitClassType(classType);
}
项目:idea-android-studio-plugin    文件:InflateViewAnnotator.java   
@Nullable
public static InflateContainer matchInflate(PsiLocalVariable psiLocalVariable) {
    PsiType psiType = psiLocalVariable.getType();
    if(psiType instanceof PsiClassReferenceType) {
        PsiMethodCallExpression psiMethodCallExpression = PsiTreeUtil.findChildOfType(psiLocalVariable, PsiMethodCallExpression.class);
        if(psiMethodCallExpression != null) {
            PsiMethod psiMethod = psiMethodCallExpression.resolveMethod();

            // @TODO: replace "inflate"; resolve method and check nethod calls
            if(psiMethod != null && psiMethod.getName().equals("inflate")) {
                PsiExpression[] expressions = psiMethodCallExpression.getArgumentList().getExpressions();
                if(expressions.length > 0 && expressions[0] instanceof PsiReferenceExpression) {
                    PsiFile xmlFile = AndroidUtils.findXmlResource((PsiReferenceExpression) expressions[0]);
                    if(xmlFile != null) {
                        return new InflateContainer(xmlFile, ((PsiLocalVariable) psiLocalVariable));
                    }
                }
            }
        }
    }

    return null;
}
项目:tools-idea    文件:SmartTypePointerManagerImpl.java   
@Override
public SmartTypePointer visitClassType(PsiClassType classType) {
  final PsiClassType.ClassResolveResult resolveResult = classType.resolveGenerics();
  final PsiClass aClass = resolveResult.getElement();
  if (aClass == null) {
    if (classType instanceof PsiClassReferenceType) {
      return new ClassReferenceTypePointer((PsiClassReferenceType)classType);
    }
    return new SimpleTypePointer(classType);
  }
  if (classType instanceof PsiClassReferenceType) {
    classType = ((PsiClassReferenceType)classType).createImmediateCopy();
  }
  final PsiSubstitutor substitutor = resolveResult.getSubstitutor();
  final HashMap<SmartPsiElementPointer, SmartTypePointer> map = new HashMap<SmartPsiElementPointer, SmartTypePointer>();
  for (PsiTypeParameter typeParameter : PsiUtil.typeParametersIterable(aClass)) {
    final PsiType substitutionResult = substitutor.substitute(typeParameter);
    if (substitutionResult != null) {
      final SmartPsiElementPointer pointer = myPsiPointerManager.createSmartPsiElementPointer(typeParameter);
      map.put(pointer, substitutionResult.accept(this));
    }
  }
  return new ClassTypePointer(classType, myPsiPointerManager.createSmartPsiElementPointer(aClass), map);
}
项目:tools-idea    文件:PsiThisExpressionImpl.java   
@Override
public PsiType getType() {
  PsiJavaCodeReferenceElement qualifier = getQualifier();
  if (qualifier != null){
    PsiElement qualifierResolve = qualifier.resolve();
    if (qualifierResolve instanceof PsiClass) return new PsiImmediateClassType((PsiClass)qualifierResolve, PsiSubstitutor.EMPTY);
    return new PsiClassReferenceType(qualifier, null);
  }
  for(PsiElement scope = getContext(); scope != null; scope = scope.getContext()){
    if (scope instanceof PsiClass){
      PsiClass aClass = (PsiClass)scope;
      return new PsiImmediateClassType(aClass, PsiSubstitutor.EMPTY);
    }
    else if (scope instanceof PsiExpressionList && scope.getParent() instanceof PsiAnonymousClass){
      scope = scope.getParent();
    }
    else if (scope instanceof JavaCodeFragment){
      PsiType fragmentThisType = ((JavaCodeFragment)scope).getThisType();
      if (fragmentThisType != null) return fragmentThisType;
    }
  }
  return null;
}
项目:tools-idea    文件:ReferenceParameterListTest.java   
public void testParameterListInExtends() throws Exception {
  final PsiManager manager = PsiManager.getInstance(myProject);
  final PsiElementFactory factory = JavaPsiFacade.getInstance(manager.getProject()).getElementFactory();
  final PsiClass classFromText = factory.createClassFromText("class X extends Y<Z, W> {}", null);
  final PsiClass classX = classFromText.getInnerClasses()[0];
  final PsiJavaCodeReferenceElement[] extendsOfX = classX.getExtendsList().getReferenceElements();
  assertEquals(1, extendsOfX.length);
  final PsiJavaCodeReferenceElement ref = extendsOfX[0];
  assertEquals("Y<Z,W>", ref.getCanonicalText());
  assertEquals("Y", ref.getReferenceName());
  final PsiTypeElement[] refParams = ref.getParameterList().getTypeParameterElements();
  assertEquals(2, refParams.length);
  assertEquals("Z", refParams[0].getType().getCanonicalText());
  assertEquals("W", refParams[1].getType().getCanonicalText());
  final PsiType refType = factory.createType(ref);
  assertEquals("Y<Z,W>", refType.getCanonicalText());
  final PsiJavaCodeReferenceElement reference = ((PsiClassReferenceType) refType).getReference();
  assertEquals("Y<Z,W>", reference.getCanonicalText());
}
项目:consulo-java    文件:PsiThisExpressionImpl.java   
@Override
public PsiType getType() {
  PsiJavaCodeReferenceElement qualifier = getQualifier();
  if (qualifier != null){
    PsiClass qualifierResolve = (PsiClass)qualifier.resolve();
    if (qualifierResolve != null) return new PsiImmediateClassType(qualifierResolve, PsiSubstitutor.EMPTY);

    return new PsiClassReferenceType(qualifier, null);
  }
  for(PsiElement scope = getContext(); scope != null; scope = scope.getContext()){
    if (scope instanceof PsiClass){
      PsiClass aClass = (PsiClass)scope;
      return new PsiImmediateClassType(aClass, PsiSubstitutor.EMPTY);
    }
    else if (scope instanceof PsiExpressionList && scope.getParent() instanceof PsiAnonymousClass){
      scope = scope.getParent();
    }
    else if (scope instanceof JavaCodeFragment){
      PsiType fragmentThisType = ((JavaCodeFragment)scope).getThisType();
      if (fragmentThisType != null) return fragmentThisType;
    }
  }
  return null;
}
项目:consulo-java    文件:JavaBreadcrumbsInfoProvider.java   
@NotNull
private static String getTypeText(@Nullable PsiType type, boolean isDumb)
{
    // todo PsiTypeVisitor ?
    String result;
    if(type == null)
    {
        result = "";
    }
    else if(!isDumb || type instanceof PsiPrimitiveType)
    {
        result = type.getCanonicalText(false);
    }
    else if(type instanceof PsiClassReferenceType)
    {
        result = ((PsiClassReferenceType) type).getReference().getReferenceName();
    }
    else
    {
        result = "";
    }
    return getShortClassName(notNullize(result));
}
项目:consulo-java    文件:ReferenceParameterListTest.java   
public void testParameterListInExtends() throws Exception {
  final PsiManager manager = PsiManager.getInstance(myProject);
  final PsiElementFactory factory = JavaPsiFacade.getInstance(manager.getProject()).getElementFactory();
  final PsiClass classFromText = factory.createClassFromText("class X extends Y<Z, W> {}", null);
  final PsiClass classX = classFromText.getInnerClasses()[0];
  final PsiJavaCodeReferenceElement[] extendsOfX = classX.getExtendsList().getReferenceElements();
  assertEquals(1, extendsOfX.length);
  final PsiJavaCodeReferenceElement ref = extendsOfX[0];
  assertEquals("Y<Z,W>", ref.getCanonicalText());
  assertEquals("Y", ref.getReferenceName());
  final PsiTypeElement[] refParams = ref.getParameterList().getTypeParameterElements();
  assertEquals(2, refParams.length);
  assertEquals("Z", refParams[0].getType().getCanonicalText());
  assertEquals("W", refParams[1].getType().getCanonicalText());
  final PsiType refType = factory.createType(ref);
  assertEquals("Y<Z,W>", refType.getCanonicalText());
  final PsiJavaCodeReferenceElement reference = ((PsiClassReferenceType) refType).getReference();
  assertEquals("Y<Z,W>", reference.getCanonicalText());
}
项目:intellij-plugin    文件:EnumCompletionResolver.java   
@Override
public boolean canHandle(PsiType psiType) {
    if (psiType instanceof PsiClassReferenceType) {
        PsiClass resolved = ((PsiClassReferenceType) psiType).resolve();
        return resolved != null && resolved.isEnum();
    }
    return false;
}
项目:intellij-plugin    文件:EnumCompletionResolver.java   
@Override
public Stream<LookupElementBuilder> resolveCompletions(String propertyName, PsiType psiType) {
    PsiClass resolved = ((PsiClassReferenceType) psiType).resolve();
    if (resolved != null) {
        return Arrays.stream(resolved.getChildren())
                .filter(child -> child instanceof PsiEnumConstant)
                .map(child -> buildEnumLookup((PsiEnumConstant) child))
                .filter(Optional::isPresent)
                .map(Optional::get);
    }
    return Stream.empty();
}
项目:intellij-plugin    文件:ClassCompletionResolver.java   
@Override
public boolean canHandle(PsiType psiType) {
    if (psiType instanceof PsiClassReferenceType) {
        PsiClass resolved = ((PsiClassReferenceType) psiType).resolve();
        if (resolved != null && JAVA_LANG_CLASS.equals(resolved.getQualifiedName())) {
            return true;
        }
    }
    return false;
}
项目:intellij-ce-playground    文件:PsiClassReferenceTypePointerFactory.java   
@Nullable
@Override
public SmartTypePointer createClassTypePointer(@NotNull PsiClassType classType, @NotNull Project project) {
  if (classType instanceof PsiClassReferenceType) {
    return new ClassReferenceTypePointer((PsiClassReferenceType)classType, project);
  }

  return null;
}
项目:intellij-ce-playground    文件:PsiClassReferenceTypePointerFactory.java   
ClassReferenceTypePointer(@NotNull PsiClassReferenceType type, Project project) {
  super(type);
  myProject = project;

  final PsiJavaCodeReferenceElement reference = type.getReference();
  mySmartPsiElementPointer = SmartPointerManager.getInstance(myProject).createSmartPsiElementPointer(reference);
  myReferenceText = reference.getText();
}
项目:intellij-ce-playground    文件:JavaResolveCache.java   
@Nullable
public <T extends PsiExpression> PsiType getType(@NotNull T expr, @NotNull Function<T, PsiType> f) {
  final boolean isOverloadCheck = MethodCandidateInfo.isOverloadCheck();
  PsiType type = isOverloadCheck ? null : myCalculatedTypes.get(expr);
  if (type == null) {
    final RecursionGuard.StackStamp dStackStamp = PsiDiamondType.ourDiamondGuard.markStack();
    type = f.fun(expr);
    if (!dStackStamp.mayCacheNow() || isOverloadCheck) {
      return type;
    }
    if (type == null) type = TypeConversionUtil.NULL_TYPE;
    myCalculatedTypes.put(expr, type);

    if (type instanceof PsiClassReferenceType) {
      // convert reference-based class type to the PsiImmediateClassType, since the reference may become invalid
      PsiClassType.ClassResolveResult result = ((PsiClassReferenceType)type).resolveGenerics();
      PsiClass psiClass = result.getElement();
      type = psiClass == null
             ? type // for type with unresolved reference, leave it in the cache
                    // for clients still might be able to retrieve its getCanonicalText() from the reference text
             : new PsiImmediateClassType(psiClass, result.getSubstitutor(), ((PsiClassReferenceType)type).getLanguageLevel(), type.getAnnotations());
    }
  }

  if (!type.isValid()) {
    if (expr.isValid()) {
      PsiJavaCodeReferenceElement refInside = type instanceof PsiClassReferenceType ? ((PsiClassReferenceType)type).getReference() : null;
      @NonNls String typeinfo = type + " (" + type.getClass() + ")" + (refInside == null ? "" : "; ref inside: "+refInside + " ("+refInside.getClass()+") valid:"+refInside.isValid());
      LOG.error("Type is invalid: " + typeinfo + "; expr: '" + expr + "' (" + expr.getClass() + ") is valid");
    }
    else {
      LOG.error("Expression: '"+expr+"' is invalid, must not be used for getType()");
    }
  }

  return type == TypeConversionUtil.NULL_TYPE ? null : type;
}
项目:intellij-ce-playground    文件:PsiImplUtil.java   
@NotNull
public static PsiType getType(@NotNull PsiClassObjectAccessExpression classAccessExpression) {
  GlobalSearchScope resolveScope = classAccessExpression.getResolveScope();
  PsiManager manager = classAccessExpression.getManager();
  final PsiClass classClass = JavaPsiFacade.getInstance(manager.getProject()).findClass("java.lang.Class", resolveScope);
  if (classClass == null) {
    return new PsiClassReferenceType(new LightClassReference(manager, "Class", "java.lang.Class", resolveScope), null);
  }
  if (!PsiUtil.isLanguageLevel5OrHigher(classAccessExpression)) {
    //Raw java.lang.Class
    return JavaPsiFacade.getInstance(manager.getProject()).getElementFactory().createType(classClass);
  }

  PsiSubstitutor substitutor = PsiSubstitutor.EMPTY;
  PsiType operandType = classAccessExpression.getOperand().getType();
  if (operandType instanceof PsiPrimitiveType && !PsiType.NULL.equals(operandType)) {
    if (PsiType.VOID.equals(operandType)) {
      operandType = JavaPsiFacade.getInstance(manager.getProject()).getElementFactory()
          .createTypeByFQClassName("java.lang.Void", classAccessExpression.getResolveScope());
    }
    else {
      operandType = ((PsiPrimitiveType)operandType).getBoxedType(classAccessExpression);
    }
  }
  final PsiTypeParameter[] typeParameters = classClass.getTypeParameters();
  if (typeParameters.length == 1) {
    substitutor = substitutor.put(typeParameters[0], operandType);
  }

  return new PsiImmediateClassType(classClass, substitutor);
}
项目:intellij-ce-playground    文件:PsiTypeLookupItem.java   
public static boolean isDiamond(PsiType type) {
  boolean diamond = false;
  if (type instanceof PsiClassReferenceType) {
    final PsiReferenceParameterList parameterList = ((PsiClassReferenceType)type).getReference().getParameterList();
    if (parameterList != null) {
      final PsiTypeElement[] typeParameterElements = parameterList.getTypeParameterElements();
      diamond = typeParameterElements.length == 1 && typeParameterElements[0].getType() instanceof PsiDiamondType;
    }
  }
  return diamond;
}
项目:intellij-ce-playground    文件:ReferenceParameterListTest.java   
public void testResolvableParameterListInExtends() throws Exception {
  final PsiManager manager = PsiManager.getInstance(myProject);
  final PsiElementFactory factory = JavaPsiFacade.getInstance(manager.getProject()).getElementFactory();
  final PsiClass classFromText = factory.createClassFromText(
          "class Z {} class W{}" +
          "class Y<A, B> {} " +
          "class X extends Y<Z, W> {}",
          null);


  WriteCommandAction.runWriteCommandAction(null, new Runnable() {
    @Override
    public void run() {
      try {
        classFromText.setName("Q");
      }
      catch (IncorrectOperationException e) {
        LOG.error(e);
      }
    }
  });
  final PsiClass classX = classFromText.getInnerClasses()[3];
  final PsiJavaCodeReferenceElement[] extendsOfX = classX.getExtendsList().getReferenceElements();
  assertEquals(1, extendsOfX.length);
  final PsiJavaCodeReferenceElement ref = extendsOfX[0];
  assertEquals("Q.Y<Q.Z,Q.W>", ref.getCanonicalText());
  assertEquals("Y", ref.getReferenceName());
  final PsiTypeElement[] refParams = ref.getParameterList().getTypeParameterElements();
  assertEquals(2, refParams.length);
  assertEquals("Q.Z", refParams[0].getType().getCanonicalText());
  assertEquals("Q.W", refParams[1].getType().getCanonicalText());
  final PsiType refType = factory.createType(ref);
  assertEquals("Q.Y<Q.Z,Q.W>", refType.getCanonicalText());
  final PsiJavaCodeReferenceElement reference = ((PsiClassReferenceType) refType).getReference();
  assertEquals("Q.Y<Q.Z,Q.W>", reference.getCanonicalText());
}
项目:intellij-ce-playground    文件:ParcelableQuickFix.java   
@Nullable
private static PsiType getListElementType(@NotNull PsiType type) {
  if (type instanceof PsiClassReferenceType) {
    PsiClassReferenceType refType = (PsiClassReferenceType)type;
    PsiType[] elemTypes = refType.getParameters();
    if (elemTypes.length == 1 &&
            (type.getCanonicalText().startsWith(JAVA_UTIL_LIST) || type.getCanonicalText().startsWith(JAVA_UTIL_ARRAY_LIST))) {
      return elemTypes[0];
    }
  }
  return null;
}
项目:intellij-ce-playground    文件:Analyser.java   
@Nullable
private static String getQualifiedName(PsiElement element) {
  if (element instanceof PsiTypeElement) {
    PsiTypeElement psiTypeElement = (PsiTypeElement)element;
    PsiType type1 = psiTypeElement.getType();
    if (type1 instanceof PsiClassReferenceType) {
      PsiClassReferenceType type = (PsiClassReferenceType)type1;
      return getQualifiedName(type.resolve());
    }
  }
  return null;
}
项目:SerializableParcelableGenerator    文件:EnumerationSerializerFactory.java   
@Override
public TypeSerializer getSerializer(PsiType psiType) {
    if (psiType instanceof PsiClassReferenceType && ((PsiClassReferenceType) psiType).resolve().isEnum()) {
        return mSerializer;
    }

    return null;
}
项目:tools-idea    文件:JavaResolveCache.java   
@Nullable
public <T extends PsiExpression> PsiType getType(@NotNull T expr, @NotNull Function<T, PsiType> f) {
  PsiType type = getCachedType(expr);
  if (type == null) {
    final RecursionGuard.StackStamp dStackStamp = PsiDiamondType.ourDiamondGuard.markStack();
    final RecursionGuard.StackStamp gStackStamp = PsiResolveHelper.ourGraphGuard.markStack();
    type = f.fun(expr);
    if (!dStackStamp.mayCacheNow() || !gStackStamp.mayCacheNow()) {
      return type;
    }
    if (type == null) type = TypeConversionUtil.NULL_TYPE;
    Reference<PsiType> ref = new SoftReference<PsiType>(type);
    myCalculatedTypes.put(expr, ref);

    if (type instanceof PsiClassReferenceType) {
      // convert reference-based class type to the PsiImmediateClassType, since the reference may become invalid
      PsiClassType.ClassResolveResult result = ((PsiClassReferenceType)type).resolveGenerics();
      PsiClass psiClass = result.getElement();
      type = psiClass == null
             ? type // for type with unresolved reference, leave it in the cache
                    // for clients still might be able to retrieve its getCanonicalText() from the reference text
             : new PsiImmediateClassType(psiClass, result.getSubstitutor(), ((PsiClassReferenceType)type).getLanguageLevel(), type.getAnnotations());
    }
  }

  if (!type.isValid()) {
    if (expr.isValid()) {
      PsiJavaCodeReferenceElement refInside = type instanceof PsiClassReferenceType ? ((PsiClassReferenceType)type).getReference() : null;
      @NonNls String typeinfo = type + " (" + type.getClass() + ")" + (refInside == null ? "" : "; ref inside: "+refInside + " ("+refInside.getClass()+") valid:"+refInside.isValid());
      LOG.error("Type is invalid: " + typeinfo + "; expr: '" + expr + "' (" + expr.getClass() + ") is valid");
    }
    else {
      LOG.error("Expression: '"+expr+"' is invalid, must not be used for getType()");
    }
  }

  return type == TypeConversionUtil.NULL_TYPE ? null : type;
}
项目:tools-idea    文件:PsiImplUtil.java   
public static PsiType getType(@NotNull PsiClassObjectAccessExpression classAccessExpression) {
  GlobalSearchScope resolveScope = classAccessExpression.getResolveScope();
  PsiManager manager = classAccessExpression.getManager();
  final PsiClass classClass = JavaPsiFacade.getInstance(manager.getProject()).findClass("java.lang.Class", resolveScope);
  if (classClass == null) {
    return new PsiClassReferenceType(new LightClassReference(manager, "Class", "java.lang.Class", resolveScope), null);
  }
  if (!PsiUtil.isLanguageLevel5OrHigher(classAccessExpression)) {
    //Raw java.lang.Class
    return JavaPsiFacade.getInstance(manager.getProject()).getElementFactory().createType(classClass);
  }

  PsiSubstitutor substitutor = PsiSubstitutor.EMPTY;
  PsiType operandType = classAccessExpression.getOperand().getType();
  if (operandType instanceof PsiPrimitiveType && !PsiType.NULL.equals(operandType)) {
    if (PsiType.VOID.equals(operandType)) {
      operandType = JavaPsiFacade.getInstance(manager.getProject()).getElementFactory()
          .createTypeByFQClassName("java.lang.Void", classAccessExpression.getResolveScope());
    }
    else {
      operandType = ((PsiPrimitiveType)operandType).getBoxedType(classAccessExpression);
    }
  }
  final PsiTypeParameter[] typeParameters = classClass.getTypeParameters();
  if (typeParameters.length == 1) {
    substitutor = substitutor.put(typeParameters[0], operandType);
  }

  return new PsiImmediateClassType(classClass, substitutor);
}
项目:tools-idea    文件:PsiTypeLookupItem.java   
public static boolean isDiamond(PsiType type) {
  boolean diamond = false;
  if (type instanceof PsiClassReferenceType) {
    final PsiReferenceParameterList parameterList = ((PsiClassReferenceType)type).getReference().getParameterList();
    if (parameterList != null) {
      final PsiTypeElement[] typeParameterElements = parameterList.getTypeParameterElements();
      diamond = typeParameterElements.length == 1 && typeParameterElements[0].getType() instanceof PsiDiamondType;
    }
  }
  return diamond;
}
项目:tools-idea    文件:ReferenceParameterListTest.java   
public void testResolvableParameterListInExtends() throws Exception {
  final PsiManager manager = PsiManager.getInstance(myProject);
  final PsiElementFactory factory = JavaPsiFacade.getInstance(manager.getProject()).getElementFactory();
  final PsiClass classFromText = factory.createClassFromText(
          "class Z {} class W{}" +
          "class Y<A, B> {} " +
          "class X extends Y<Z, W> {}",
          null);


  ApplicationManager.getApplication().runWriteAction(new Runnable() {
    @Override
    public void run() {
      try {
        classFromText.setName("Q");
      } catch (IncorrectOperationException e) {
        LOG.error(e);
      }
    }
  });
  final PsiClass classX = classFromText.getInnerClasses()[3];
  final PsiJavaCodeReferenceElement[] extendsOfX = classX.getExtendsList().getReferenceElements();
  assertEquals(1, extendsOfX.length);
  final PsiJavaCodeReferenceElement ref = extendsOfX[0];
  assertEquals("Q.Y<Q.Z,Q.W>", ref.getCanonicalText());
  assertEquals("Y", ref.getReferenceName());
  final PsiTypeElement[] refParams = ref.getParameterList().getTypeParameterElements();
  assertEquals(2, refParams.length);
  assertEquals("Q.Z", refParams[0].getType().getCanonicalText());
  assertEquals("Q.W", refParams[1].getType().getCanonicalText());
  final PsiType refType = factory.createType(ref);
  assertEquals("Q.Y<Q.Z,Q.W>", refType.getCanonicalText());
  final PsiJavaCodeReferenceElement reference = ((PsiClassReferenceType) refType).getReference();
  assertEquals("Q.Y<Q.Z,Q.W>", reference.getCanonicalText());
}
项目:lombok-intellij-plugin    文件:BuilderHandler.java   
private PsiType calculateResultType(@NotNull PsiMethod psiMethod, PsiClass builderPsiClass, PsiClass psiClass) {
  final Collection<PsiParameter> builderParameters = getBuilderParameters(psiMethod, Collections.<PsiField>emptySet());

  final Collection<PsiType> types = new ArrayList<>();
  for (PsiVariable psiVariable : builderParameters) {

    final PsiAnnotation obtainViaAnnotation = PsiAnnotationSearchUtil.findAnnotation(psiVariable, BUILDER_OBTAIN_VIA_ANNOTATION);
    if (null != obtainViaAnnotation) {
      final String viaFieldName = PsiAnnotationUtil.getStringAnnotationValue(obtainViaAnnotation, BUILDER_OBTAIN_VIA_FIELD);

      final PsiField fieldByName = psiClass.findFieldByName(viaFieldName, false);
      if (fieldByName != null) {
        psiVariable = fieldByName;
      }
    }


    final PsiType psiVariableType = psiVariable.getType();

    if (psiVariableType instanceof PsiClassReferenceType) {
      final PsiClass resolvedPsiVariableClass = ((PsiClassReferenceType) psiVariableType).resolve();
      if (resolvedPsiVariableClass instanceof PsiTypeParameter) {
        types.add(psiVariableType);
      }
    }
  }
  final PsiElementFactory factory = JavaPsiFacade.getElementFactory(psiClass.getProject());
  return factory.createType(builderPsiClass, types.toArray(new PsiType[types.size()]));
}
项目:android-parcelable-intellij-plugin    文件:EnumerationSerializerFactory.java   
@Override
public TypeSerializer getSerializer(PsiType psiType) {
    if (psiType instanceof PsiClassReferenceType && ((PsiClassReferenceType) psiType).resolve().isEnum()) {
        return mSerializer;
    }

    return null;
}
项目:android-parcelable-intellij-plugin    文件:GenericListSerializer.java   
@NotNull
private String getGenericType(SerializableValue field) {
    String genericType = "";
    try {
        PsiType[] parameters = ((PsiClassReferenceType) field.getType()).getParameters();
        if (parameters.length > 0) {
            genericType = parameters[0].getCanonicalText();
        }
    } catch (Exception ignored) {
    }
    return genericType;
}
项目:consulo-java    文件:SmartTypePointerManagerImpl.java   
@Override
public SmartTypePointer visitClassType(PsiClassType classType)
{
    final PsiClassType.ClassResolveResult resolveResult = classType.resolveGenerics();
    final PsiClass aClass = resolveResult.getElement();
    if(aClass == null)
    {
        return createClassReferenceTypePointer(classType);
    }
    if(classType instanceof PsiClassReferenceType)
    {
        classType = ((PsiClassReferenceType) classType).createImmediateCopy();
    }
    final PsiSubstitutor substitutor = resolveResult.getSubstitutor();
    final HashMap<SmartPsiElementPointer, SmartTypePointer> map = new HashMap<SmartPsiElementPointer,
            SmartTypePointer>();
    for(PsiTypeParameter typeParameter : PsiUtil.typeParametersIterable(aClass))
    {
        final PsiType substitutionResult = substitutor.substitute(typeParameter);
        if(substitutionResult != null)
        {
            final SmartPsiElementPointer pointer = myPsiPointerManager.createSmartPsiElementPointer
                    (typeParameter);
            map.put(pointer, substitutionResult.accept(this));
        }
    }
    return new ClassTypePointer(classType, myPsiPointerManager.createSmartPsiElementPointer(aClass), map);
}
项目:consulo-java    文件:PsiClassReferenceTypePointerFactory.java   
@Nullable
@Override
public SmartTypePointer createClassTypePointer(@NotNull PsiClassType classType, @NotNull Project project)
{
    if(classType instanceof PsiClassReferenceType)
    {
        return new ClassReferenceTypePointer((PsiClassReferenceType) classType, project);
    }

    return null;
}
项目:consulo-java    文件:PsiClassReferenceTypePointerFactory.java   
ClassReferenceTypePointer(@NotNull PsiClassReferenceType type, Project project)
{
    super(type);
    myProject = project;

    final PsiJavaCodeReferenceElement reference = type.getReference();
    mySmartPsiElementPointer = SmartPointerManager.getInstance(myProject).createSmartPsiElementPointer
            (reference);
    myReferenceText = reference.getText();
}
项目:consulo-java    文件:PsiImplUtil.java   
@NotNull
public static PsiType getType(@NotNull PsiClassObjectAccessExpression classAccessExpression)
{
    GlobalSearchScope resolveScope = classAccessExpression.getResolveScope();
    PsiManager manager = classAccessExpression.getManager();
    final PsiClass classClass = JavaPsiFacade.getInstance(manager.getProject()).findClass("java.lang.Class", resolveScope);
    if(classClass == null)
    {
        return new PsiClassReferenceType(new LightClassReference(manager, "Class", "java.lang.Class", resolveScope), null);
    }
    if(!PsiUtil.isLanguageLevel5OrHigher(classAccessExpression))
    {
        //Raw java.lang.Class
        return JavaPsiFacade.getInstance(manager.getProject()).getElementFactory().createType(classClass);
    }

    PsiSubstitutor substitutor = PsiSubstitutor.EMPTY;
    PsiType operandType = classAccessExpression.getOperand().getType();
    if(operandType instanceof PsiPrimitiveType && !PsiType.NULL.equals(operandType))
    {
        if(PsiType.VOID.equals(operandType))
        {
            operandType = JavaPsiFacade.getInstance(manager.getProject()).getElementFactory().createTypeByFQClassName("java.lang.Void", classAccessExpression.getResolveScope());
        }
        else
        {
            operandType = ((PsiPrimitiveType) operandType).getBoxedType(classAccessExpression);
        }
    }
    final PsiTypeParameter[] typeParameters = classClass.getTypeParameters();
    if(typeParameters.length == 1)
    {
        substitutor = substitutor.put(typeParameters[0], operandType);
    }

    return new PsiImmediateClassType(classClass, substitutor);
}
项目:consulo-java    文件:PsiTypeLookupItem.java   
public static boolean isDiamond(PsiType type)
{
    boolean diamond = false;
    if(type instanceof PsiClassReferenceType)
    {
        final PsiReferenceParameterList parameterList = ((PsiClassReferenceType) type).getReference().getParameterList();
        if(parameterList != null)
        {
            final PsiTypeElement[] typeParameterElements = parameterList.getTypeParameterElements();
            diamond = typeParameterElements.length == 1 && typeParameterElements[0].getType() instanceof PsiDiamondType;
        }
    }
    return diamond;
}
项目:consulo-java    文件:ReferenceParameterListTest.java   
public void testResolvableParameterListInExtends() throws Exception {
  final PsiManager manager = PsiManager.getInstance(myProject);
  final PsiElementFactory factory = JavaPsiFacade.getInstance(manager.getProject()).getElementFactory();
  final PsiClass classFromText = factory.createClassFromText(
          "class Z {} class W{}" +
          "class Y<A, B> {} " +
          "class X extends Y<Z, W> {}",
          null);


  ApplicationManager.getApplication().runWriteAction(new Runnable() {
    @Override
    public void run() {
      try {
        classFromText.setName("Q");
      } catch (IncorrectOperationException e) {
        LOG.error(e);
      }
    }
  });
  final PsiClass classX = classFromText.getInnerClasses()[3];
  final PsiJavaCodeReferenceElement[] extendsOfX = classX.getExtendsList().getReferenceElements();
  assertEquals(1, extendsOfX.length);
  final PsiJavaCodeReferenceElement ref = extendsOfX[0];
  assertEquals("Q.Y<Q.Z,Q.W>", ref.getCanonicalText());
  assertEquals("Y", ref.getReferenceName());
  final PsiTypeElement[] refParams = ref.getParameterList().getTypeParameterElements();
  assertEquals(2, refParams.length);
  assertEquals("Q.Z", refParams[0].getType().getCanonicalText());
  assertEquals("Q.W", refParams[1].getType().getCanonicalText());
  final PsiType refType = factory.createType(ref);
  assertEquals("Q.Y<Q.Z,Q.W>", refType.getCanonicalText());
  final PsiJavaCodeReferenceElement reference = ((PsiClassReferenceType) refType).getReference();
  assertEquals("Q.Y<Q.Z,Q.W>", reference.getCanonicalText());
}