use of com.intellij.psi.PsiJavaCodeReferenceElement in project qi4j-sdk by Qi4j.
the class ConcernsAnnotationDeclaredCorrectlyInspection method checkClass.
@Override
public final ProblemDescriptor[] checkClass(@NotNull PsiClass psiClass, @NotNull InspectionManager manager, boolean isOnTheFly) {
// If class does not have @Concerns, ignore
PsiAnnotation concernsAnnotation = getConcernsAnnotation(psiClass);
if (concernsAnnotation == null) {
return null;
}
// If @Concerns declared in class, suggest remove @Concerns annotation
if (!psiClass.isInterface()) {
String message = message("concerns.annotation.declared.correctly.error.annotation.declared.in.class");
RemoveConcernsAnnotationFix fix = new RemoveConcernsAnnotationFix(concernsAnnotation);
ProblemDescriptor problemDescriptor = manager.createProblemDescriptor(concernsAnnotation, message, fix, GENERIC_ERROR_OR_WARNING);
return new ProblemDescriptor[] { problemDescriptor };
}
// If @Concerns annotation is empty, ignore
List<PsiAnnotationMemberValue> concernsAnnotationValue = getConcernsAnnotationValue(concernsAnnotation);
if (concernsAnnotationValue.isEmpty()) {
return null;
}
// If ConcernOfClass is not resolved, ignore
Project project = psiClass.getProject();
GlobalSearchScope searchScope = determineSearchScope(psiClass);
PsiClass concernOfClass = getConcernOfClass(project, searchScope);
if (concernOfClass == null) {
return null;
}
List<ProblemDescriptor> problems = new LinkedList<ProblemDescriptor>();
for (PsiAnnotationMemberValue concernClassAnnotationValue : concernsAnnotationValue) {
PsiJavaCodeReferenceElement concernClassReference = getConcernClassReference(concernClassAnnotationValue);
// If it's not a class reference, ignore
if (concernClassReference == null) {
continue;
}
// If class reference can't be resolved, ignore
PsiClass concernClass = (PsiClass) concernClassReference.resolve();
if (concernClass == null) {
continue;
}
// If concern class does not inherit concern class, suggest remove that reference.
if (!concernClass.isInheritor(concernOfClass, true)) {
String message = Qi4jResourceBundle.message("concerns.annotation.declared.correctly.error.concern.class.does.not.extend.ConcernOf", concernClass.getQualifiedName());
RemoveInvalidConcernClassReferenceFix fix = new RemoveInvalidConcernClassReferenceFix(concernClassAnnotationValue, concernClassReference);
ProblemDescriptor problemDescriptor = manager.createProblemDescriptor(concernClassAnnotationValue, message, fix, GENERIC_ERROR_OR_WARNING);
problems.add(problemDescriptor);
} else {
// TODO: Test whether it is a generic concern
// TODO: Test whether it is a specific concern
}
}
return problems.toArray(new ProblemDescriptor[problems.size()]);
}
use of com.intellij.psi.PsiJavaCodeReferenceElement in project qi4j-sdk by Qi4j.
the class SideEffectsAnnotationDeclaredCorrectlyInspection method checkClass.
@Override
public final ProblemDescriptor[] checkClass(@NotNull PsiClass psiClass, @NotNull InspectionManager manager, boolean isOnTheFly) {
// If class does not have @SideEffects, ignore
PsiAnnotation sideEffectsAnnotation = getSideEffectsAnnotation(psiClass);
if (sideEffectsAnnotation == null) {
return null;
}
// If @SideEffects declared in class, suggest remove @SideEffects annotation
if (!psiClass.isInterface()) {
String message = message("side.effects.annotation.declared.correctly.error.annotation.declared.in.class");
RemoveSideEffectsAnnotationFix fix = new RemoveSideEffectsAnnotationFix(sideEffectsAnnotation);
ProblemDescriptor problemDescriptor = manager.createProblemDescriptor(sideEffectsAnnotation, message, fix, GENERIC_ERROR_OR_WARNING);
return new ProblemDescriptor[] { problemDescriptor };
}
// If @SideEffects annotation is empty, ignore
List<PsiAnnotationMemberValue> sideEffectsAnnotationValue = getSideEffectsAnnotationValue(sideEffectsAnnotation);
if (sideEffectsAnnotationValue.isEmpty()) {
return null;
}
// If SideEffectOf is not resolved, ignore
Project project = psiClass.getProject();
GlobalSearchScope searchScope = determineSearchScope(psiClass);
PsiClass sideEffectOfClass = Qi4jSideEffectUtil.getGenericSideEffectClass(project, searchScope);
if (sideEffectOfClass == null) {
return null;
}
List<ProblemDescriptor> problems = new LinkedList<ProblemDescriptor>();
for (PsiAnnotationMemberValue sideEffectClassReferenceWrapper : sideEffectsAnnotationValue) {
PsiJavaCodeReferenceElement sideEffectClassReference = getSideEffectClassReference(sideEffectClassReferenceWrapper);
// If it's not a class reference, ignore
if (sideEffectClassReference == null) {
continue;
}
// If class reference can't be resolved, ignore
PsiClass sideEffectClass = (PsiClass) sideEffectClassReference.resolve();
if (sideEffectClass == null) {
continue;
}
// If side effect class does not inherit SideEffectOf class, suggest remove that reference.
if (!sideEffectClass.isInheritor(sideEffectOfClass, true)) {
String message = Qi4jResourceBundle.message("side.effects.annotation.declared.correctly.error.side.effect.does.not.extend.side.effect.of", sideEffectClass.getQualifiedName());
RemoveAnnotationValueFix fix = new RemoveAnnotationValueFix(sideEffectClassReferenceWrapper, sideEffectClassReference);
ProblemDescriptor problemDescriptor = manager.createProblemDescriptor(sideEffectClassReferenceWrapper, message, fix, GENERIC_ERROR_OR_WARNING);
problems.add(problemDescriptor);
} else {
// TODO: Test whether it is a generic side effect
// TODO: Test whether it is a specific side effect
}
}
return problems.toArray(new ProblemDescriptor[problems.size()]);
}
use of com.intellij.psi.PsiJavaCodeReferenceElement in project intellij-community by JetBrains.
the class PsiJavaCodeReferenceCodeFragmentImpl method getReferenceElement.
@Override
public PsiJavaCodeReferenceElement getReferenceElement() {
final CompositeElement treeElement = calcTreeElement();
LOG.assertTrue(treeElement.getFirstChildNode().getElementType() == JavaElementType.JAVA_CODE_REFERENCE);
return (PsiJavaCodeReferenceElement) SourceTreeToPsiMap.treeElementToPsi(treeElement.getFirstChildNode());
}
use of com.intellij.psi.PsiJavaCodeReferenceElement in project intellij-community by JetBrains.
the class GrThrowsClauseImpl method add.
@Override
public PsiElement add(@NotNull PsiElement element) throws IncorrectOperationException {
if (element instanceof GrCodeReferenceElement || element instanceof PsiJavaCodeReferenceElement) {
if (findChildByClass(GrCodeReferenceElement.class) == null) {
getNode().addLeaf(GroovyTokenTypes.kTHROWS, "throws", null);
} else {
PsiElement lastChild = getLastChild();
lastChild = PsiUtil.skipWhitespacesAndComments(lastChild, false);
if (!lastChild.getNode().getElementType().equals(GroovyTokenTypes.mCOMMA)) {
getNode().addLeaf(GroovyTokenTypes.mCOMMA, ",", null);
}
}
if (element instanceof PsiJavaCodeReferenceElement) {
element = GroovyPsiElementFactory.getInstance(getProject()).createCodeReferenceElementFromText(element.getText());
}
}
return super.add(element);
}
use of com.intellij.psi.PsiJavaCodeReferenceElement in project intellij-community by JetBrains.
the class GrThrowsClauseImpl method getReferenceElements.
@Override
@NotNull
public PsiJavaCodeReferenceElement[] getReferenceElements() {
PsiClassType[] types = getReferencedTypes();
if (types.length == 0)
return PsiJavaCodeReferenceElement.EMPTY_ARRAY;
PsiManagerEx manager = getManager();
List<PsiJavaCodeReferenceElement> result = ContainerUtil.newArrayList();
for (PsiClassType type : types) {
PsiClassType.ClassResolveResult resolveResult = type.resolveGenerics();
PsiClass resolved = resolveResult.getElement();
if (resolved != null) {
result.add(new LightClassReference(manager, type.getCanonicalText(), resolved, resolveResult.getSubstitutor()));
}
}
return result.toArray(new PsiJavaCodeReferenceElement[result.size()]);
}
Aggregations