use of com.intellij.psi.PsiType in project android-parcelable-intellij-plugin by mcharmas.
the class MapSerializer method readValue.
@Override
public String readValue(SerializableValue field, String parcel) {
final List<PsiType> resolvedGenerics = PsiUtils.getResolvedGenerics(field.getType());
PsiType keyType = resolvedGenerics.get(1);
PsiType valueType = resolvedGenerics.get(0);
String sizeVariableName = field.getSimpleName() + "Size";
return new StringBuilder().append(String.format("int %s = %s.readInt();", sizeVariableName, parcel)).append(field.getName()).append(String.format(" = new java.util.HashMap<%s, %s>(%s);", keyType.getCanonicalText(), valueType.getCanonicalText(), sizeVariableName)).append(String.format("for(int i = 0; i < %s; i++) {", sizeVariableName)).append(typeSerializerFactory.getSerializer(keyType).readValue(SerializableValue.variable("key", keyType), parcel)).append(typeSerializerFactory.getSerializer(valueType).readValue(SerializableValue.variable("value", valueType), parcel)).append(field.getName()).append(".put(key, value);").append("}").toString();
}
use of com.intellij.psi.PsiType in project android-parcelable-intellij-plugin by mcharmas.
the class PsiUtils method isTypedClass.
/**
* Checks that the given type is an implementer of the given canonicalName with the given typed parameters
*
* @param type what we're checking against
* @param canonicalName the type must extend/implement this generic
* @param canonicalParamNames the type that the generic(s) must be (in this order)
* @return
*/
public static boolean isTypedClass(PsiType type, String canonicalName, String... canonicalParamNames) {
PsiClass parameterClass = PsiTypesUtil.getPsiClass(type);
if (parameterClass == null) {
return false;
}
// This is a safe cast, for if parameterClass != null, the type was checked in PsiTypesUtil#getPsiClass(...)
PsiClassType pct = (PsiClassType) type;
// Main class name doesn't match; exit early
if (!canonicalName.equals(parameterClass.getQualifiedName())) {
return false;
}
List<PsiType> psiTypes = new ArrayList<PsiType>(pct.resolveGenerics().getSubstitutor().getSubstitutionMap().values());
for (int i = 0; i < canonicalParamNames.length; i++) {
if (!isOfType(psiTypes.get(i), canonicalParamNames[i])) {
return false;
}
}
// Passed all screenings; must be a match!
return true;
}
use of com.intellij.psi.PsiType in project timber by JakeWharton.
the class WrongTimberUsageDetector method isSubclassOf.
private static boolean isSubclassOf(JavaContext context, PsiExpression expression, Class<?> cls) {
PsiType expressionType = expression.getType();
if (expressionType instanceof PsiClassType) {
PsiClassType classType = (PsiClassType) expressionType;
PsiClass resolvedClass = classType.resolve();
return context.getEvaluator().extendsClass(resolvedClass, cls.getName(), false);
}
return false;
}
use of com.intellij.psi.PsiType in project smali by JesusFreke.
the class SmaliMethodReference method resolve.
@Nullable
@Override
public PsiElement resolve() {
PsiClass containingClass = getContainingClass();
if (containingClass == null) {
return null;
}
SmaliMemberName memberName = getMemberName();
if (memberName == null) {
return null;
}
LightMethodBuilder pattern = new LightMethodBuilder(getManager(), SmaliLanguage.INSTANCE, memberName.getText());
for (PsiType type : getParameterTypes()) {
pattern.addParameter("", type);
}
SmaliTypeElement returnTypeElement = getReturnType();
if (returnTypeElement == null) {
return null;
}
pattern.setMethodReturnType(returnTypeElement.getType());
// TODO: what about static constructor?
pattern.setConstructor(memberName.getText().equals("<init>"));
return containingClass.findMethodBySignature(pattern, true);
}
use of com.intellij.psi.PsiType in project intellij-community by JetBrains.
the class ParametersMatcher method matchParameters.
private static MatchResult matchParameters(final PsiMethod method, final ChainCompletionContext context, final Set<String> additionalExcludedNames) {
int matched = 0;
int unMatched = 0;
boolean hasTarget = false;
for (final PsiParameter parameter : method.getParameterList().getParameters()) {
final PsiType type = parameter.getType();
final String canonicalText = type.getCanonicalText();
if (context.contains(canonicalText) || type instanceof PsiPrimitiveType) {
matched++;
} else {
unMatched++;
}
if (context.getTarget().getClassQName().equals(canonicalText) || additionalExcludedNames.contains(canonicalText)) {
hasTarget = true;
}
}
return new MatchResult(matched, unMatched, hasTarget);
}
Aggregations