com.intellij.psi.PsiReferenceList Java Examples

The following examples show how to use com.intellij.psi.PsiReferenceList. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PsiTypeVariablesExtractor.java    From litho with Apache License 2.0 6 votes vote down vote up
public static ImmutableList<TypeVariableName> getTypeVariables(PsiClass psiClass) {
  PsiTypeParameter[] psiTypeParameters = psiClass.getTypeParameters();

  final List<TypeVariableName> typeVariables = new ArrayList<>(psiTypeParameters.length);
  for (PsiTypeParameter psiTypeParameter : psiTypeParameters) {
    final PsiReferenceList extendsList = psiTypeParameter.getExtendsList();
    final PsiClassType[] psiClassTypes = extendsList.getReferencedTypes();

    final TypeName[] boundsTypeNames = new TypeName[psiClassTypes.length];
    for (int i = 0, size = psiClassTypes.length; i < size; i++) {
      boundsTypeNames[i] = PsiTypeUtils.getTypeName(psiClassTypes[i]);
    }

    final TypeVariableName typeVariable =
        TypeVariableName.get(psiTypeParameter.getName(), boundsTypeNames);
    typeVariables.add(typeVariable);
  }

  return ImmutableList.copyOf(typeVariables);
}
 
Example #2
Source File: ProducerUtils.java    From intellij with Apache License 2.0 6 votes vote down vote up
private static boolean extendsTestCase(PsiClass psiClass, Set<PsiClass> checkedClasses) {
  if (!checkedClasses.add(psiClass)) {
    return false;
  }
  PsiReferenceList extendsList = psiClass.getExtendsList();
  if (extendsList == null) {
    return false;
  }
  for (PsiJavaCodeReferenceElement ref : extendsList.getReferenceElements()) {
    if (JUnitUtil.TEST_CASE_CLASS.equals(ref.getQualifiedName())) {
      return true;
    }
    PsiElement clazz = ref.resolve();
    if (clazz instanceof PsiClass && extendsTestCase((PsiClass) clazz, checkedClasses)) {
      return true;
    }
  }
  return false;
}
 
Example #3
Source File: CodeGenerator.java    From ParcelablePlease with Apache License 2.0 6 votes vote down vote up
/**
 * Make the class implementing Parcelable
 */
private void makeClassImplementParcelable(PsiElementFactory elementFactory, JavaCodeStyleManager styleManager) {
  final PsiClassType[] implementsListTypes = psiClass.getImplementsListTypes();
  final String implementsType = "android.os.Parcelable";

  for (PsiClassType implementsListType : implementsListTypes) {
    PsiClass resolved = implementsListType.resolve();

    // Already implements Parcelable, no need to add it
    if (resolved != null && implementsType.equals(resolved.getQualifiedName())) {
      return;
    }
  }

  PsiJavaCodeReferenceElement implementsReference =
      elementFactory.createReferenceFromText(implementsType, psiClass);
  PsiReferenceList implementsList = psiClass.getImplementsList();

  if (implementsList != null) {
    styleManager.shortenClassReferences(implementsList.add(implementsReference));
  }
}