use of com.intellij.psi.impl.source.PsiClassReferenceType in project GsonFormat by zzz40500.
the class ConvertBridge method evalFieldEntity.
private FieldEntity evalFieldEntity(FieldEntity fieldEntity, PsiType type) {
if (type instanceof PsiPrimitiveType) {
if (fieldEntity == null) {
fieldEntity = new FieldEntity();
}
fieldEntity.setType(type.getPresentableText());
return fieldEntity;
} else if (type instanceof PsiArrayType) {
if (fieldEntity == null) {
fieldEntity = new IterableFieldEntity();
}
IterableFieldEntity iterableFieldEntity = (IterableFieldEntity) fieldEntity;
iterableFieldEntity.setDeep(iterableFieldEntity.getDeep() + 1);
return evalFieldEntity(fieldEntity, ((PsiArrayType) type).getComponentType());
} else if (type instanceof PsiClassReferenceType) {
PsiClass psi = ((PsiClassReferenceType) type).resolveGenerics().getElement();
if (isCollection(psi)) {
if (fieldEntity == null) {
fieldEntity = new IterableFieldEntity();
}
IterableFieldEntity iterableFieldEntity = (IterableFieldEntity) fieldEntity;
iterableFieldEntity.setDeep(iterableFieldEntity.getDeep() + 1);
PsiType[] parameters = ((PsiClassReferenceType) type).getParameters();
if (parameters.length > 0) {
PsiType parameter = parameters[0];
if (parameter instanceof PsiWildcardType) {
if (((PsiWildcardType) parameter).isExtends()) {
final PsiType extendsBound = ((PsiWildcardType) parameter).getExtendsBound();
evalFieldEntity(fieldEntity, extendsBound);
}
if (((PsiWildcardType) parameter).isSuper()) {
final PsiType superBound = ((PsiWildcardType) parameter).getSuperBound();
evalFieldEntity(fieldEntity, superBound);
}
} else if (parameter instanceof PsiClassReferenceType) {
PsiClass element = ((PsiClassReferenceType) parameter).resolveGenerics().getElement();
handleClassReferenceType(fieldEntity, element);
}
}
return fieldEntity;
} else {
if (fieldEntity == null) {
fieldEntity = new FieldEntity();
}
handleClassReferenceType(fieldEntity, psi);
return fieldEntity;
}
}
if (fieldEntity == null) {
fieldEntity = new IterableFieldEntity();
}
return fieldEntity;
}
use of com.intellij.psi.impl.source.PsiClassReferenceType in project intellij-community by JetBrains.
the class AnnotationsHighlightUtil method checkApplicability.
@Nullable
public static HighlightInfo checkApplicability(@NotNull PsiAnnotation annotation, @NotNull LanguageLevel level, @NotNull PsiFile file) {
if (ANY_ANNOTATION_ALLOWED.accepts(annotation)) {
return null;
}
PsiJavaCodeReferenceElement nameRef = annotation.getNameReferenceElement();
if (nameRef == null)
return null;
PsiAnnotationOwner owner = annotation.getOwner();
PsiAnnotation.TargetType[] targets = AnnotationTargetUtil.getTargetsForLocation(owner);
if (owner == null || targets.length == 0) {
String message = JavaErrorMessages.message("annotation.not.allowed.here");
return annotationError(annotation, message);
}
if (!(owner instanceof PsiModifierList)) {
HighlightInfo info = HighlightUtil.checkFeature(annotation, HighlightUtil.Feature.TYPE_ANNOTATIONS, level, file);
if (info != null)
return info;
}
PsiAnnotation.TargetType applicable = AnnotationTargetUtil.findAnnotationTarget(annotation, targets);
if (applicable == PsiAnnotation.TargetType.UNKNOWN)
return null;
if (applicable == null) {
String target = JavaErrorMessages.message("annotation.target." + targets[0]);
String message = JavaErrorMessages.message("annotation.not.applicable", nameRef.getText(), target);
return annotationError(annotation, message);
}
if (applicable == PsiAnnotation.TargetType.TYPE_USE) {
if (owner instanceof PsiClassReferenceType) {
PsiJavaCodeReferenceElement ref = ((PsiClassReferenceType) owner).getReference();
HighlightInfo info = checkReferenceTarget(annotation, ref);
if (info != null)
return info;
} else if (owner instanceof PsiModifierList) {
PsiElement nextElement = PsiTreeUtil.skipSiblingsForward((PsiModifierList) owner, PsiComment.class, PsiWhiteSpace.class, PsiTypeParameterList.class);
if (nextElement instanceof PsiTypeElement) {
PsiTypeElement typeElement = (PsiTypeElement) nextElement;
PsiType type = typeElement.getType();
if (PsiType.VOID.equals(type)) {
String message = JavaErrorMessages.message("annotation.not.allowed.void");
return annotationError(annotation, message);
}
if (!(type instanceof PsiPrimitiveType)) {
PsiJavaCodeReferenceElement ref = getOutermostReferenceElement(typeElement.getInnermostComponentReferenceElement());
HighlightInfo info = checkReferenceTarget(annotation, ref);
if (info != null)
return info;
}
}
} else if (owner instanceof PsiTypeElement) {
PsiElement context = PsiTreeUtil.skipParentsOfType((PsiTypeElement) owner, PsiTypeElement.class);
if (context instanceof PsiClassObjectAccessExpression) {
String message = JavaErrorMessages.message("annotation.not.allowed.class");
return annotationError(annotation, message);
}
}
}
return null;
}
use of com.intellij.psi.impl.source.PsiClassReferenceType in project intellij-community by JetBrains.
the class PsiNewExpressionImpl method doGetType.
@Nullable
private PsiType doGetType(@Nullable PsiAnnotation stopAt) {
PsiType type = null;
SmartList<PsiAnnotation> annotations = new SmartList<>();
boolean stop = false;
for (ASTNode child = getFirstChildNode(); child != null; child = child.getTreeNext()) {
IElementType elementType = child.getElementType();
if (elementType == JavaElementType.ANNOTATION) {
PsiAnnotation annotation = (PsiAnnotation) child.getPsi();
annotations.add(annotation);
if (annotation == stopAt)
stop = true;
} else if (elementType == JavaElementType.JAVA_CODE_REFERENCE) {
assert type == null : this;
type = new PsiClassReferenceType((PsiJavaCodeReferenceElement) child.getPsi(), null);
if (stop)
return type;
} else if (ElementType.PRIMITIVE_TYPE_BIT_SET.contains(elementType)) {
assert type == null : this;
PsiElementFactory factory = JavaPsiFacade.getInstance(getProject()).getElementFactory();
PsiAnnotation[] copy = ContainerUtil.copyAndClear(annotations, PsiAnnotation.ARRAY_FACTORY, true);
type = factory.createPrimitiveTypeFromText(child.getText()).annotate(TypeAnnotationProvider.Static.create(copy));
if (stop)
return type;
} else if (elementType == JavaTokenType.LBRACKET) {
assert type != null : this;
PsiAnnotation[] copy = ContainerUtil.copyAndClear(annotations, PsiAnnotation.ARRAY_FACTORY, true);
type = type.createArrayType().annotate(TypeAnnotationProvider.Static.create(copy));
if (stop)
return type;
} else if (elementType == JavaElementType.ANONYMOUS_CLASS) {
PsiElementFactory factory = JavaPsiFacade.getInstance(getProject()).getElementFactory();
PsiClass aClass = (PsiClass) child.getPsi();
PsiSubstitutor substitutor = aClass instanceof PsiTypeParameter ? PsiSubstitutor.EMPTY : factory.createRawSubstitutor(aClass);
PsiAnnotation[] copy = ContainerUtil.copyAndClear(annotations, PsiAnnotation.ARRAY_FACTORY, true);
type = factory.createType(aClass, substitutor, PsiUtil.getLanguageLevel(aClass)).annotate(TypeAnnotationProvider.Static.create(copy));
if (stop)
return type;
}
}
// stop == true means annotation is misplaced
return stop ? null : type;
}
use of com.intellij.psi.impl.source.PsiClassReferenceType in project intellij-community by JetBrains.
the class PsiAnnotationImpl method getOwner.
@Nullable
@Override
public PsiAnnotationOwner getOwner() {
PsiElement parent = getParent();
if (parent instanceof PsiAnnotationOwner) {
return (PsiAnnotationOwner) parent;
}
if (parent instanceof PsiNewExpression) {
return ((PsiNewExpression) parent).getOwner(this);
}
if (parent instanceof PsiReferenceExpression) {
PsiElement ctx = parent.getParent();
if (ctx instanceof PsiMethodReferenceExpression) {
return new PsiClassReferenceType((PsiJavaCodeReferenceElement) parent, null);
}
} else if (parent instanceof PsiJavaCodeReferenceElement) {
PsiElement ctx = PsiTreeUtil.skipParentsOfType(parent, PsiJavaCodeReferenceElement.class);
if (ctx instanceof PsiReferenceList || ctx instanceof PsiNewExpression || ctx instanceof PsiTypeElement || ctx instanceof PsiAnonymousClass) {
return new PsiClassReferenceType((PsiJavaCodeReferenceElement) parent, null);
}
}
PsiTypeElement typeElement = null;
PsiElement anchor = null;
if (parent instanceof PsiMethod) {
typeElement = ((PsiMethod) parent).getReturnTypeElement();
anchor = ((PsiMethod) parent).getParameterList();
} else if (parent instanceof PsiField || parent instanceof PsiParameter || parent instanceof PsiLocalVariable) {
typeElement = ((PsiVariable) parent).getTypeElement();
anchor = ((PsiVariable) parent).getNameIdentifier();
}
if (typeElement != null && anchor != null) {
return JavaSharedImplUtil.getType(typeElement, anchor, this);
}
return null;
}
use of com.intellij.psi.impl.source.PsiClassReferenceType in project intellij-community by JetBrains.
the class ClsTypeElementImpl method calculateBaseType.
@NotNull
private PsiType calculateBaseType() {
PsiType result = PsiJavaParserFacadeImpl.getPrimitiveType(myTypeText);
if (result != null)
return result;
ClsElementImpl childElement = myChild.getValue();
if (childElement instanceof ClsTypeElementImpl) {
if (isArray()) {
switch(myVariance) {
case VARIANCE_NONE:
return ((PsiTypeElement) childElement).getType().createArrayType();
case VARIANCE_EXTENDS:
return PsiWildcardType.createExtends(getManager(), ((PsiTypeElement) childElement).getType());
case VARIANCE_SUPER:
return PsiWildcardType.createSuper(getManager(), ((PsiTypeElement) childElement).getType());
default:
assert false : myVariance;
return null;
}
} else {
assert isVarArgs() : this;
return new PsiEllipsisType(((PsiTypeElement) childElement).getType());
}
}
if (childElement instanceof ClsJavaCodeReferenceElementImpl) {
PsiClassReferenceType psiClassReferenceType = new PsiClassReferenceType((PsiJavaCodeReferenceElement) childElement, null);
switch(myVariance) {
case VARIANCE_NONE:
return psiClassReferenceType;
case VARIANCE_EXTENDS:
return PsiWildcardType.createExtends(getManager(), psiClassReferenceType);
case VARIANCE_SUPER:
return PsiWildcardType.createSuper(getManager(), psiClassReferenceType);
case VARIANCE_INVARIANT:
return PsiWildcardType.createUnbounded(getManager());
default:
assert false : myVariance;
return null;
}
}
assert childElement == null : this;
return PsiWildcardType.createUnbounded(getManager());
}
Aggregations