use of com.intellij.psi.PsiModifierListOwner in project intellij-community by JetBrains.
the class ToggleSourceInferredAnnotations method isAvailable.
@Override
public boolean isAvailable(@NotNull final Project project, Editor editor, PsiFile file) {
final PsiElement leaf = file.findElementAt(editor.getCaretModel().getOffset());
final PsiModifierListOwner owner = getAnnotationOwner(leaf);
if (owner != null && isSourceCode(owner)) {
boolean hasSrcInferredAnnotation = ContainerUtil.or(findSignatureNonCodeAnnotations(owner, true), annotation -> AnnotationUtil.isInferredAnnotation(annotation));
if (hasSrcInferredAnnotation) {
setText((CodeInsightSettings.getInstance().SHOW_SOURCE_INFERRED_ANNOTATIONS ? "Hide" : "Show") + " annotations inferred from source code");
return true;
}
}
return false;
}
use of com.intellij.psi.PsiModifierListOwner in project intellij-community by JetBrains.
the class SameReturnValueInspection method checkElement.
@Override
@Nullable
public CommonProblemDescriptor[] checkElement(@NotNull RefEntity refEntity, @NotNull AnalysisScope scope, @NotNull InspectionManager manager, @NotNull GlobalInspectionContext globalContext, @NotNull ProblemDescriptionsProcessor processor) {
if (refEntity instanceof RefMethod) {
final RefMethod refMethod = (RefMethod) refEntity;
if (refMethod.isConstructor())
return null;
if (refMethod.hasSuperMethods())
return null;
String returnValue = refMethod.getReturnValueIfSame();
if (returnValue != null) {
final String message;
if (refMethod.getDerivedMethods().isEmpty()) {
message = InspectionsBundle.message("inspection.same.return.value.problem.descriptor", "<code>" + returnValue + "</code>");
} else if (refMethod.hasBody()) {
message = InspectionsBundle.message("inspection.same.return.value.problem.descriptor1", "<code>" + returnValue + "</code>");
} else {
message = InspectionsBundle.message("inspection.same.return.value.problem.descriptor2", "<code>" + returnValue + "</code>");
}
final PsiModifierListOwner element = refMethod.getElement();
if (element != null) {
return new ProblemDescriptor[] { manager.createProblemDescriptor(element.getNavigationElement(), message, false, null, ProblemHighlightType.GENERIC_ERROR_OR_WARNING) };
}
}
}
return null;
}
use of com.intellij.psi.PsiModifierListOwner in project intellij-community by JetBrains.
the class AddAnnotationIntention method isAvailable.
// include not in project files
@Override
public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
final PsiModifierListOwner owner = AddAnnotationPsiFix.getContainer(file, editor.getCaretModel().getOffset());
if (owner == null || !ExternalAnnotationsManagerImpl.areExternalAnnotationsApplicable(owner)) {
return false;
}
Pair<String, String[]> annotations = getAnnotations(project);
String toAdd = annotations.first;
String[] toRemove = annotations.second;
if (toRemove.length > 0 && isAnnotatedSkipInferred(owner, toRemove)) {
return false;
}
setText(AddAnnotationPsiFix.calcText(owner, toAdd));
if (isAnnotatedSkipInferred(owner, toAdd))
return false;
return canAnnotate(owner);
}
use of com.intellij.psi.PsiModifierListOwner in project intellij-community by JetBrains.
the class AddAnnotationIntention method invoke.
@Override
public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
PsiModifierListOwner owner = AddAnnotationPsiFix.getContainer(file, editor.getCaretModel().getOffset());
if (owner == null || !owner.isValid())
return;
Pair<String, String[]> annotations = getAnnotations(project);
String toAdd = annotations.first;
String[] toRemove = annotations.second;
AddAnnotationFix fix = new AddAnnotationFix(toAdd, owner, toRemove);
fix.invoke(project, editor, file);
}
use of com.intellij.psi.PsiModifierListOwner in project intellij-community by JetBrains.
the class GrDeprecatedAPIUsageInspection method buildVisitor.
@NotNull
@Override
protected BaseInspectionVisitor buildVisitor() {
return new BaseInspectionVisitor() {
@Override
public void visitReferenceExpression(@NotNull GrReferenceExpression ref) {
super.visitReferenceExpression(ref);
checkRef(ref);
}
@Override
public void visitCodeReferenceElement(@NotNull GrCodeReferenceElement ref) {
super.visitCodeReferenceElement(ref);
checkRef(ref);
}
private void checkRef(GrReferenceElement ref) {
PsiElement resolved = ref.resolve();
if (isDeprecated(resolved)) {
PsiElement toHighlight = getElementToHighlight(ref);
registerError(toHighlight, GroovyBundle.message("0.is.deprecated", ref.getReferenceName()), LocalQuickFix.EMPTY_ARRAY, ProblemHighlightType.LIKE_DEPRECATED);
}
}
@NotNull
public PsiElement getElementToHighlight(@NotNull GrReferenceElement refElement) {
final PsiElement refNameElement = refElement.getReferenceNameElement();
return refNameElement != null ? refNameElement : refElement;
}
private boolean isDeprecated(PsiElement resolved) {
if (resolved instanceof PsiDocCommentOwner) {
return ((PsiDocCommentOwner) resolved).isDeprecated();
}
if (resolved instanceof PsiModifierListOwner && PsiImplUtil.isDeprecatedByAnnotation((PsiModifierListOwner) resolved)) {
return true;
}
return false;
}
};
}
Aggregations