com.intellij.psi.PsiTypeParameter Java Examples

The following examples show how to use com.intellij.psi.PsiTypeParameter. 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: TypeParametersTranslator.java    From java2typescript with Apache License 2.0 6 votes vote down vote up
public static String print(PsiTypeParameter[] parameters, TranslationContext ctx) {
    StringBuilder builder = new StringBuilder();
    for (int i = 0; i < parameters.length; i++) {
        PsiTypeParameter p = parameters[i];
        builder.append(p.getName());
        PsiClassType[] extensions = p.getExtendsList().getReferencedTypes();
        if (extensions.length > 0) {
            builder.append(" extends ");
            for (PsiClassType ext : extensions) {
                builder.append(TypeHelper.printType(ext, ctx));
            }
        }
        if (i != parameters.length - 1) {
            builder.append(", ");
        }
    }
    return builder.toString();
}
 
Example #3
Source File: VariableGeneratorService.java    From easy_javadoc with Apache License 2.0 5 votes vote down vote up
/**
 * 获取方法内部的变量
 *
 * @param psiMethod psi方法
 * @return {@link java.util.Map<java.lang.String,java.lang.Object>}
 */
private Map<String, Object> getMethodInnerVariable(PsiMethod psiMethod) {
    Map<String, Object> map = Maps.newHashMap();
    map.put("author", config.getAuthor());
    map.put("methodName", psiMethod.getName());
    map.put("methodReturnType", psiMethod.getReturnType() == null ? "" : psiMethod.getReturnType().getPresentableText());
    map.put("methodParamTypes",
        Arrays.stream(psiMethod.getTypeParameters()).map(PsiTypeParameter::getQualifiedName).toArray(String[]::new));
    map.put("methodParamNames",
        Arrays.stream(psiMethod.getParameterList().getParameters()).map(PsiParameter::getName).toArray(String[]::new));
    return map;
}
 
Example #4
Source File: PsiMethodExtractorUtils.java    From litho with Apache License 2.0 5 votes vote down vote up
private static TypeVariableName toTypeVariableName(PsiTypeParameter psiTypeParameter) {
  String typeName = psiTypeParameter.getName();
  TypeName[] typeBounds =
      Arrays.stream(psiTypeParameter.getBounds())
          .filter(PsiType.class::isInstance)
          .map(bound -> PsiTypeUtils.getTypeName((PsiType) bound))
          .toArray(TypeName[]::new);
  return TypeVariableName.get(typeName, typeBounds);
}
 
Example #5
Source File: PsiCustomUtil.java    From intellij-spring-assistant with MIT License 5 votes vote down vote up
@Nullable
public static Map<PsiTypeParameter, PsiType> getTypeParameters(PsiType type) {
  if (type instanceof PsiArrayType) {
    return getTypeParameters(((PsiArrayType) type).getComponentType());
  } else if (type instanceof PsiPrimitiveType) {
    return null;
  } else if (type instanceof PsiClassType) {
    PsiClassType.ClassResolveResult resolveResult =
        PsiClassType.class.cast(type).resolveGenerics();
    if (resolveResult.isValidResult()) {
      return resolveResult.getSubstitutor().getSubstitutionMap();
    }
  }
  return null;
}
 
Example #6
Source File: HaxeTypeParamPsiMixinImpl.java    From intellij-haxe with Apache License 2.0 5 votes vote down vote up
@Override
public int getTypeParameterIndex(PsiTypeParameter typeParameter) {
  PsiTypeParameter[] params = getTypeParameters();
  int i = 0;
  for (; i < params.length; ++i) {
    if (typeParameter == params[i]) {
      break;
    }
  }
  return i < params.length ? i : -1;
}
 
Example #7
Source File: PsiCustomUtil.java    From intellij-spring-assistant with MIT License 4 votes vote down vote up
@Nullable
public static Map<PsiTypeParameter, PsiType> getTypeParameters(@NotNull PsiElement psiElement) {
  PsiType psiType = getReferredPsiType(psiElement);
  return getTypeParameters(psiType);
}
 
Example #8
Source File: HaxeTypeParamPsiMixinImpl.java    From intellij-haxe with Apache License 2.0 4 votes vote down vote up
@Override
public PsiTypeParameter[] getTypeParameters() {
  HaxeTypeList list = (HaxeTypeList) UsefulPsiTreeUtil.getChildOfType(this, HaxeTokenTypes.TYPE_LIST);
  HaxeTypeListPart[] parts = UsefulPsiTreeUtil.getChildrenOfType(list, HaxeTypeListPart.class, null);
  return null != parts ? parts : new PsiTypeParameter[0];
}
 
Example #9
Source File: LombokLightClassBuilder.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public LombokLightClassBuilder withParameterType(@NotNull PsiTypeParameter psiTypeParameter) {
  getTypeParameterList().addParameter(psiTypeParameter);
  return this;
}