com.intellij.psi.PsiPrimitiveType Java Examples

The following examples show how to use com.intellij.psi.PsiPrimitiveType. 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: PsiTypeUtils.java    From litho with Apache License 2.0 6 votes vote down vote up
static TypeName getTypeName(PsiType type) {
  if (type instanceof PsiPrimitiveType) {
    // float
    return getPrimitiveTypeName((PsiPrimitiveType) type);
  } else if (type instanceof PsiClassType && ((PsiClassType) type).getParameterCount() > 0) {
    // Set<Integer>
    PsiClassType classType = (PsiClassType) type;
    return ParameterizedTypeName.get(
        guessClassName(classType.rawType().getCanonicalText()),
        getTypeNameArray(classType.getParameters()));
  } else if (type instanceof PsiArrayType) {
    // int[]
    PsiType componentType = ((PsiArrayType) type).getComponentType();
    return ArrayTypeName.of(getTypeName(componentType));
  } else if (type.getCanonicalText().contains("?")) {
    // ? extends Type
    return getWildcardTypeName(type.getCanonicalText());
  } else {
    return guessClassName(type.getCanonicalText());
  }
}
 
Example #2
Source File: PsiTypeUtils.java    From litho with Apache License 2.0 6 votes vote down vote up
private static TypeName getPrimitiveTypeName(PsiPrimitiveType type) {
  switch (type.getCanonicalText()) {
    case "void":
      return TypeName.VOID;
    case "boolean":
      return TypeName.BOOLEAN;
    case "byte":
      return TypeName.BYTE;
    case "short":
      return TypeName.SHORT;
    case "int":
      return TypeName.INT;
    case "long":
      return TypeName.LONG;
    case "char":
      return TypeName.CHAR;
    case "float":
      return TypeName.FLOAT;
    case "double":
      return TypeName.DOUBLE;
    default:
      throw new UnsupportedOperationException(
          "Unknown primitive type: " + type.getCanonicalText());
  }
}
 
Example #3
Source File: ClassSuggestionNodeFactory.java    From intellij-spring-assistant with MIT License 6 votes vote down vote up
@NotNull
public static MetadataProxy newMetadataProxy(Module module, @NotNull PsiType type) {
  if (type instanceof PsiArrayType) {
    return new ArrayMetadataProxy(module, (PsiArrayType) type);
  } else if (type instanceof PsiPrimitiveType) {
    PsiPrimitiveType primitiveType = (PsiPrimitiveType) type;
    type = getBoxedTypeFromPrimitiveType(module, primitiveType);
  }

  if (type instanceof PsiClassType) {
    SuggestionNodeType suggestionNodeType = getSuggestionNodeType(type);
    if (suggestionNodeType == SuggestionNodeType.MAP) {
      return new MapClassMetadataProxy((PsiClassType) type);
    } else {
      return new ClassMetadataProxy((PsiClassType) type);
    }
  }

  throw new IllegalAccessError(
      "Supports only PsiArrayType, PsiPrimitiveType & PsiClassType types");
}
 
Example #4
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 #5
Source File: PsiCustomUtil.java    From intellij-spring-assistant with MIT License 5 votes vote down vote up
@Nullable
private static SuggestionNodeType getSuggestionNodeTypeForPrimitive(PsiType type) {
  if (PsiType.BOOLEAN.equals(type) || PsiType.BOOLEAN
      .equals(PsiPrimitiveType.getUnboxedType(type))) {
    return BOOLEAN;
  } else if (PsiType.BYTE.equals(type) || PsiType.BYTE
      .equals(PsiPrimitiveType.getUnboxedType(type))) {
    return BYTE;
  } else if (PsiType.SHORT.equals(type) || PsiType.SHORT
      .equals(PsiPrimitiveType.getUnboxedType(type))) {
    return SHORT;
  } else if (PsiType.INT.equals(type) || PsiType.INT
      .equals(PsiPrimitiveType.getUnboxedType(type))) {
    return INT;
  } else if (PsiType.LONG.equals(type) || PsiType.LONG
      .equals(PsiPrimitiveType.getUnboxedType(type))) {
    return LONG;
  } else if (PsiType.FLOAT.equals(type) || PsiType.FLOAT
      .equals(PsiPrimitiveType.getUnboxedType(type))) {
    return FLOAT;
  } else if (PsiType.DOUBLE.equals(type) || PsiType.DOUBLE
      .equals(PsiPrimitiveType.getUnboxedType(type))) {
    return DOUBLE;
  } else if (PsiType.CHAR.equals(type) || PsiType.CHAR
      .equals(PsiPrimitiveType.getUnboxedType(type))) {
    return CHAR;
  }
  return null;
}
 
Example #6
Source File: PsiCustomUtil.java    From intellij-spring-assistant with MIT License 5 votes vote down vote up
@Nullable
public static String toClassFqn(@NotNull PsiType type) {
  if (type instanceof PsiArrayType) {
    String componentLongName = toClassFqn(PsiArrayType.class.cast(type).getComponentType());
    if (componentLongName != null) {
      return componentLongName + "[]";
    }
  } else if (type instanceof PsiPrimitiveType) {
    return type.getPresentableText();
  } else if (type instanceof PsiClassType) {
    return type.getCanonicalText();
  }
  return null;
}
 
Example #7
Source File: PsiCustomUtil.java    From intellij-spring-assistant with MIT License 5 votes vote down vote up
@Nullable
public static String toClassNonQualifiedName(@NotNull PsiType type) {
  if (type instanceof PsiArrayType) {
    String componentLongName =
        toClassNonQualifiedName(PsiArrayType.class.cast(type).getComponentType());
    if (componentLongName != null) {
      return componentLongName + "[]";
    }
  } else if (type instanceof PsiPrimitiveType) {
    return type.getPresentableText();
  } else if (type instanceof PsiClassType) {
    return ((PsiClassType) type).getClassName();
  }
  return null;
}
 
Example #8
Source File: PsiCustomUtil.java    From intellij-spring-assistant with MIT License 5 votes vote down vote up
@NotNull
public static PsiType getBoxedTypeFromPrimitiveType(Module module,
    PsiPrimitiveType primitiveType) {
  PsiType boxedPrimitiveType = safeGetValidType(module, primitiveType.getBoxedTypeName());
  assert boxedPrimitiveType instanceof PsiClassType;
  return boxedPrimitiveType;
}
 
Example #9
Source File: PsiCustomUtil.java    From intellij-spring-assistant with MIT License 5 votes vote down vote up
@Nullable
public static String typeToFqn(Module module, @NotNull PsiType type) {
  if (isValidType(type)) {
    if (type instanceof PsiArrayType) {
      type = PsiArrayType.class.cast(type).getComponentType();
      return type.getCanonicalText();
    } else if (type instanceof PsiPrimitiveType) {
      return getBoxedTypeFromPrimitiveType(module, (PsiPrimitiveType) type).getCanonicalText();
    } else if (type instanceof PsiClassType) {
      return type.getCanonicalText();
    }
  }
  return null;
}
 
Example #10
Source File: VarModifierTest.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void testVarModifiersEditing() {
  PsiFile file = myFixture.configureByFile(getTestName(false) + ".java");
  PsiLocalVariable var = PsiTreeUtil.getParentOfType(file.findElementAt(myFixture.getCaretOffset()), PsiLocalVariable.class);
  assertNotNull(var);
  assertNotNull(var.getType());

  myFixture.type('1');
  PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
  assertTrue(var.isValid());
  assertEquals(PsiPrimitiveType.INT, var.getType());

  assertNotNull(var.getModifierList());
  boolean isFinal = var.getModifierList().hasModifierProperty(PsiModifier.FINAL);
  assertFalse("var doesn't make variable final", isFinal);
}
 
Example #11
Source File: InnerBuilderUtils.java    From innerbuilder with Apache License 2.0 4 votes vote down vote up
public static boolean isPrimitive(PsiField psiField) {
    return (psiField.getType() instanceof PsiPrimitiveType);
}