use of com.intellij.psi.impl.source.PsiClassReferenceType in project android by JetBrains.
the class AndroidImplicitUsagesProvider method isImplicitConstructorUsage.
public boolean isImplicitConstructorUsage(PsiMethod method) {
if (!method.isConstructor()) {
return false;
}
if (!method.hasModifierProperty(PsiModifier.PUBLIC)) {
return false;
}
PsiParameterList parameterList = method.getParameterList();
int parameterCount = parameterList.getParametersCount();
if (parameterCount == 0) {
// Some Android classes need default constructors, and are invoked by inflaters
final PsiClass aClass = method.getContainingClass();
if (aClass != null) {
if (InheritanceUtil.isInheritor(aClass, CLASS_FRAGMENT) || InheritanceUtil.isInheritor(aClass, CLASS_V4_FRAGMENT) || InheritanceUtil.isInheritor(aClass, CLASS_BACKUP_AGENT)) {
// perhaps due to the XML DOM bindings?
return true;
}
}
return false;
}
// ActionProvider(android.content.Context context)
if (parameterCount < 1 || parameterCount > 3) {
return false;
}
PsiParameter[] parameters = parameterList.getParameters();
PsiType type = parameters[0].getType();
if (!(type instanceof PsiClassReferenceType)) {
return false;
}
PsiClassReferenceType classType = (PsiClassReferenceType) type;
PsiClass resolvedParameter = classType.resolve();
if (resolvedParameter == null || !CLASS_CONTEXT.equals(resolvedParameter.getQualifiedName())) {
return false;
}
if (parameterCount > 1) {
type = parameters[1].getType();
if (!(type instanceof PsiClassReferenceType)) {
return false;
}
classType = (PsiClassReferenceType) type;
resolvedParameter = classType.resolve();
if (resolvedParameter == null || !CLASS_ATTRIBUTE_SET.equals(resolvedParameter.getQualifiedName())) {
return false;
}
if (parameterCount > 2) {
type = parameters[2].getType();
if (!PsiType.INT.equals(type)) {
return false;
}
}
}
final PsiClass aClass = PsiTreeUtil.getParentOfType(method, PsiClass.class);
if (aClass == null) {
return false;
}
PsiClass viewBaseClass = JavaPsiFacade.getInstance(aClass.getProject()).findClass(CLASS_VIEW, method.getResolveScope());
if (viewBaseClass == null) {
return false;
}
return aClass.isInheritor(viewBaseClass, true) || parameterCount == 1 && InheritanceUtil.isInheritor(aClass, CLASS_ACTION_PROVIDER);
}
use of com.intellij.psi.impl.source.PsiClassReferenceType in project intellij-community by JetBrains.
the class PsiClassReferenceListStubImpl method getReferencedTypes.
@NotNull
@Override
public PsiClassType[] getReferencedTypes() {
if (myTypes != null)
return myTypes;
if (myNames.length == 0) {
myTypes = PsiClassType.EMPTY_ARRAY;
return myTypes;
}
PsiClassType[] types = new PsiClassType[myNames.length];
final boolean compiled = ((JavaClassReferenceListElementType) getStubType()).isCompiled(this);
if (compiled) {
for (int i = 0; i < types.length; i++) {
types[i] = new PsiClassReferenceType(new ClsJavaCodeReferenceElementImpl(getPsi(), myNames[i]), null);
}
} else {
final PsiElementFactory factory = JavaPsiFacade.getInstance(getProject()).getElementFactory();
int nullCount = 0;
final PsiReferenceList psi = getPsi();
for (int i = 0; i < types.length; i++) {
try {
final PsiJavaCodeReferenceElement ref = factory.createReferenceFromText(myNames[i], psi);
((PsiJavaCodeReferenceElementImpl) ref).setKindWhenDummy(PsiJavaCodeReferenceElementImpl.CLASS_NAME_KIND);
types[i] = factory.createType(ref);
} catch (IncorrectOperationException e) {
types[i] = null;
nullCount++;
}
}
if (nullCount > 0) {
PsiClassType[] newTypes = new PsiClassType[types.length - nullCount];
int cnt = 0;
for (PsiClassType type : types) {
if (type != null)
newTypes[cnt++] = type;
}
types = newTypes;
}
}
myTypes = types;
return types.clone();
}
use of com.intellij.psi.impl.source.PsiClassReferenceType in project intellij-community by JetBrains.
the class PsiImplUtil method getType.
@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);
}
use of com.intellij.psi.impl.source.PsiClassReferenceType in project intellij-community by JetBrains.
the class PsiImplUtil method buildTypeFromTypeString.
public static PsiType buildTypeFromTypeString(@NotNull final String typeName, @NotNull final PsiElement context, @NotNull final PsiFile psiFile) {
final PsiManager psiManager = psiFile.getManager();
if (typeName.indexOf('<') != -1 || typeName.indexOf('[') != -1 || typeName.indexOf('.') == -1) {
try {
return JavaPsiFacade.getInstance(psiManager.getProject()).getElementFactory().createTypeFromText(typeName, context);
}// invalid syntax will produce unresolved class type
catch (Exception ignored) {
}
}
PsiClass aClass = JavaPsiFacade.getInstance(psiManager.getProject()).findClass(typeName, context.getResolveScope());
PsiType resultType;
if (aClass == null) {
final LightClassReference ref = new LightClassReference(psiManager, PsiNameHelper.getShortClassName(typeName), typeName, PsiSubstitutor.EMPTY, psiFile);
resultType = new PsiClassReferenceType(ref, null);
} else {
PsiElementFactory factory = JavaPsiFacade.getInstance(psiManager.getProject()).getElementFactory();
PsiSubstitutor substitutor = factory.createRawSubstitutor(aClass);
resultType = factory.createType(aClass, substitutor);
}
return resultType;
}
use of com.intellij.psi.impl.source.PsiClassReferenceType in project intellij-community by JetBrains.
the class NamedDomainObjectCollectionTypeEnhancer method getReferenceType.
@Override
public PsiType getReferenceType(GrReferenceExpression ref, @Nullable PsiElement resolved) {
if (resolved != null)
return null;
GrExpression qualifierExpression = ref.getQualifierExpression();
if (qualifierExpression == null)
return null;
PsiType namedDomainCollectionType = GradleResolverUtil.getTypeOf(qualifierExpression);
if (!InheritanceUtil.isInheritor(namedDomainCollectionType, GradleCommonClassNames.GRADLE_API_NAMED_DOMAIN_OBJECT_COLLECTION)) {
return null;
}
PsiElement qResolved;
if (qualifierExpression instanceof GrReferenceExpression) {
qResolved = ((GrReferenceExpression) qualifierExpression).resolve();
} else if (qualifierExpression instanceof GrMethodCall) {
qResolved = ((GrMethodCall) qualifierExpression).resolveMethod();
} else {
return null;
}
String key = ref.getReferenceName();
if (key == null)
return null;
for (GroovyMapContentProvider provider : GroovyMapContentProvider.EP_NAME.getExtensions()) {
PsiType type = provider.getValueType(qualifierExpression, qResolved, key);
if (type != null) {
return type;
}
}
if (namedDomainCollectionType instanceof PsiClassReferenceType) {
final PsiClassReferenceType referenceType = (PsiClassReferenceType) namedDomainCollectionType;
final String fqName = TypesUtil.getQualifiedName(referenceType);
if (GradleCommonClassNames.GRADLE_API_SOURCE_SET_CONTAINER.equals(fqName)) {
final GroovyPsiManager psiManager = GroovyPsiManager.getInstance(ref.getProject());
return psiManager.createTypeByFQClassName(GradleCommonClassNames.GRADLE_API_SOURCE_SET, ref.getResolveScope());
} else if (GradleCommonClassNames.GRADLE_API_CONFIGURATION_CONTAINER.equals(fqName)) {
final GroovyPsiManager psiManager = GroovyPsiManager.getInstance(ref.getProject());
return psiManager.createTypeByFQClassName(GradleCommonClassNames.GRADLE_API_CONFIGURATION, ref.getResolveScope());
} else if (GradleCommonClassNames.GRADLE_API_TASK_CONTAINER.equals(fqName)) {
final GroovyPsiManager psiManager = GroovyPsiManager.getInstance(ref.getProject());
return psiManager.createTypeByFQClassName(GradleCommonClassNames.GRADLE_API_TASK, ref.getResolveScope());
} else if (GradleCommonClassNames.GRADLE_API_DISTRIBUTION_CONTAINER.equals(fqName)) {
final GroovyPsiManager psiManager = GroovyPsiManager.getInstance(ref.getProject());
return psiManager.createTypeByFQClassName(GradleCommonClassNames.GRADLE_API_DISTRIBUTION, ref.getResolveScope());
} else {
GradleExtensionsSettings.GradleExtensionsData extensionsData = GradleExtensionsContributor.Companion.getExtensionsFor(ref);
if (extensionsData != null) {
for (GradleExtensionsSettings.GradleExtension extension : extensionsData.extensions) {
if (StringUtil.isNotEmpty(extension.namedObjectTypeFqn) && extension.rootTypeFqn.equals(fqName)) {
final GroovyPsiManager psiManager = GroovyPsiManager.getInstance(ref.getProject());
return psiManager.createTypeByFQClassName(extension.namedObjectTypeFqn, ref.getResolveScope());
}
}
}
}
}
return null;
}
Aggregations