mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
an ability to turn off gutter icons for annotations inferred from source (IDEA-135399)
This commit is contained in:
+20
-10
@@ -23,6 +23,7 @@ import com.intellij.codeInsight.intention.IntentionAction;
|
||||
import com.intellij.codeInsight.intention.IntentionManager;
|
||||
import com.intellij.codeInsight.intention.impl.AddAnnotationIntention;
|
||||
import com.intellij.codeInsight.intention.impl.DeannotateIntentionAction;
|
||||
import com.intellij.codeInsight.intention.impl.config.IntentionActionWrapper;
|
||||
import com.intellij.codeInsight.javadoc.JavaDocInfoGenerator;
|
||||
import com.intellij.codeInspection.dataFlow.EditContractIntention;
|
||||
import com.intellij.icons.AllIcons;
|
||||
@@ -58,7 +59,7 @@ public class ExternalAnnotationsLineMarkerProvider implements LineMarkerProvider
|
||||
|
||||
boolean hasInferred = false;
|
||||
boolean hasExternal = false;
|
||||
for (PsiAnnotation annotation : findSignatureNonCodeAnnotations(owner)) {
|
||||
for (PsiAnnotation annotation : findSignatureNonCodeAnnotations(owner, true)) {
|
||||
hasExternal |= AnnotationUtil.isExternalAnnotation(annotation);
|
||||
hasInferred |= AnnotationUtil.isInferredAnnotation(annotation);
|
||||
}
|
||||
@@ -79,7 +80,8 @@ public class ExternalAnnotationsLineMarkerProvider implements LineMarkerProvider
|
||||
@Override
|
||||
public LineMarkerInfo getLineMarkerInfo(@NotNull final PsiElement element) {
|
||||
PsiModifierListOwner owner = getAnnotationOwner(element);
|
||||
if (owner == null || findSignatureNonCodeAnnotations(owner).isEmpty()) {
|
||||
boolean includeSourceInferred = CodeInsightSettings.getInstance().SHOW_SOURCE_INFERRED_ANNOTATIONS;
|
||||
if (owner == null || findSignatureNonCodeAnnotations(owner, includeSourceInferred).isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -104,19 +106,19 @@ public class ExternalAnnotationsLineMarkerProvider implements LineMarkerProvider
|
||||
return (PsiModifierListOwner)owner;
|
||||
}
|
||||
|
||||
private static List<PsiAnnotation> findSignatureNonCodeAnnotations(PsiModifierListOwner owner) {
|
||||
List<PsiAnnotation> result = ContainerUtil.newArrayList(findOwnNonCodeAnnotations(owner));
|
||||
static List<PsiAnnotation> findSignatureNonCodeAnnotations(PsiModifierListOwner owner, boolean includeSourceInferred) {
|
||||
List<PsiAnnotation> result = ContainerUtil.newArrayList(findOwnNonCodeAnnotations(owner, includeSourceInferred));
|
||||
|
||||
if (owner instanceof PsiMethod) {
|
||||
for (PsiParameter parameter : ((PsiMethod)owner).getParameterList().getParameters()) {
|
||||
result.addAll(findOwnNonCodeAnnotations(parameter));
|
||||
result.addAll(findOwnNonCodeAnnotations(parameter, includeSourceInferred));
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private static List<PsiAnnotation> findOwnNonCodeAnnotations(@NotNull PsiModifierListOwner element) {
|
||||
private static List<PsiAnnotation> findOwnNonCodeAnnotations(@NotNull PsiModifierListOwner element, boolean includeSourceInferred) {
|
||||
List<PsiAnnotation> result = ContainerUtil.newArrayList();
|
||||
Project project = element.getProject();
|
||||
PsiAnnotation[] externalAnnotations = ExternalAnnotationsManager.getInstance(project).findExternalAnnotations(element);
|
||||
@@ -127,14 +129,20 @@ public class ExternalAnnotationsLineMarkerProvider implements LineMarkerProvider
|
||||
}
|
||||
}
|
||||
}
|
||||
for (PsiAnnotation annotation : InferredAnnotationsManager.getInstance(project).findInferredAnnotations(element)) {
|
||||
if (isVisibleAnnotation(annotation)) {
|
||||
result.add(annotation);
|
||||
if (includeSourceInferred || !isSourceCode(element)) {
|
||||
for (PsiAnnotation annotation : InferredAnnotationsManager.getInstance(project).findInferredAnnotations(element)) {
|
||||
if (isVisibleAnnotation(annotation)) {
|
||||
result.add(annotation);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static boolean isSourceCode(PsiModifierListOwner element) {
|
||||
return !(BaseExternalAnnotationsManager.preferCompiledElement(element) instanceof PsiCompiledElement);
|
||||
}
|
||||
|
||||
private static boolean isVisibleAnnotation(@NotNull PsiAnnotation annotation) {
|
||||
PsiJavaCodeReferenceElement ref = annotation.getNameReferenceElement();
|
||||
if (ref == null) return true;
|
||||
@@ -195,7 +203,9 @@ public class ExternalAnnotationsLineMarkerProvider implements LineMarkerProvider
|
||||
return action instanceof AddAnnotationIntention ||
|
||||
action instanceof DeannotateIntentionAction ||
|
||||
action instanceof EditContractIntention ||
|
||||
action instanceof MakeInferredAnnotationExplicit;
|
||||
action instanceof ToggleSourceInferredAnnotations ||
|
||||
action instanceof MakeInferredAnnotationExplicit ||
|
||||
action instanceof IntentionActionWrapper && shouldShowInGutterPopup(((IntentionActionWrapper)action).getDelegate());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.codeInsight;
|
||||
|
||||
import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer;
|
||||
import com.intellij.codeInsight.intention.impl.BaseIntentionAction;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.psi.PsiAnnotation;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiModifierListOwner;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.Nls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static com.intellij.codeInsight.ExternalAnnotationsLineMarkerProvider.*;
|
||||
|
||||
/**
|
||||
* @author peter
|
||||
*/
|
||||
public class ToggleSourceInferredAnnotations extends BaseIntentionAction {
|
||||
|
||||
@Nls
|
||||
@NotNull
|
||||
@Override
|
||||
public String getFamilyName() {
|
||||
return "Show/Hide Annotations Inferred from Source Code";
|
||||
}
|
||||
|
||||
@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), new Condition<PsiAnnotation>() {
|
||||
@Override
|
||||
public boolean value(PsiAnnotation annotation) {
|
||||
return AnnotationUtil.isInferredAnnotation(annotation);
|
||||
}
|
||||
});
|
||||
if (hasSrcInferredAnnotation) {
|
||||
setText((CodeInsightSettings.getInstance().SHOW_SOURCE_INFERRED_ANNOTATIONS ? "Hide" : "Show") + " annotations inferred from source code");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invoke(@NotNull final Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
|
||||
CodeInsightSettings.getInstance().SHOW_SOURCE_INFERRED_ANNOTATIONS = !CodeInsightSettings.getInstance().SHOW_SOURCE_INFERRED_ANNOTATIONS;
|
||||
DaemonCodeAnalyzer.getInstance(project).restart(file);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean startInWriteAction() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -86,6 +86,8 @@ public class CodeInsightSettings implements PersistentStateComponent<Element>, C
|
||||
|
||||
public boolean SHOW_FULL_SIGNATURES_IN_PARAMETER_INFO = false;
|
||||
|
||||
public boolean SHOW_SOURCE_INFERRED_ANNOTATIONS = true;
|
||||
|
||||
@OptionTag
|
||||
private int SMART_BACKSPACE = SmartBackspaceMode.AUTOINDENT.ordinal();
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ import org.jetbrains.annotations.Contract;
|
||||
|
||||
class A {
|
||||
|
||||
<spot>@Contract("any->null")</spot>
|
||||
<spot>@Contract("_->null")</spot>
|
||||
Object getObject() {
|
||||
//do smth
|
||||
return null;
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@ import org.jetbrains.annotations.Contract;
|
||||
|
||||
class A {
|
||||
|
||||
<spot>@Contract("any->null")</spot>
|
||||
<spot>@Contract("_->null")</spot>
|
||||
Object getObject() {
|
||||
//do smth
|
||||
return null;
|
||||
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
class A {
|
||||
|
||||
// An icon for @Contract("_->null") <spot>not</spot> shown in the gutter, but still visible in the intention list
|
||||
Object getObject() {
|
||||
//do smth
|
||||
return null;
|
||||
}
|
||||
} ]
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
class A {
|
||||
|
||||
// An icon for @Contract("_->null") shown in the gutter
|
||||
Object getObject() {
|
||||
//do smth
|
||||
return null;
|
||||
}
|
||||
} ]
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
<html>
|
||||
<body>
|
||||
Enable or disable '@' gutter icon where IntelliJ IDEA has inferred @Nullable/@NotNull/@Contract annotations for source code.
|
||||
<!-- tooltip end -->
|
||||
</body>
|
||||
</html>
|
||||
@@ -796,6 +796,11 @@
|
||||
<category>Java/Annotations</category>
|
||||
<descriptionDirectoryName>MakeInferredAnnotationExplicit</descriptionDirectoryName>
|
||||
</intentionAction>
|
||||
<intentionAction>
|
||||
<className>com.intellij.codeInsight.ToggleSourceInferredAnnotations</className>
|
||||
<category>Java/Annotations</category>
|
||||
<descriptionDirectoryName>ToggleSourceInferredAnnotations</descriptionDirectoryName>
|
||||
</intentionAction>
|
||||
<intentionAction>
|
||||
<className>com.intellij.codeInsight.daemon.impl.quickfix.IterateOverIterableIntention</className>
|
||||
<category>Java/Control Flow</category>
|
||||
|
||||
Reference in New Issue
Block a user