mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
extract pure PSI-dependent inspections out of InspectionGadgets into InspectionGadgetsAnalysis module
This commit is contained in:
Generated
+1
@@ -4,6 +4,7 @@
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/plugins/ByteCodeViewer/ByteCodeViewer.iml" filepath="$PROJECT_DIR$/plugins/ByteCodeViewer/ByteCodeViewer.iml" group="plugins" />
|
||||
<module fileurl="file://$PROJECT_DIR$/plugins/InspectionGadgets/InspectionGadgetsPlugin.iml" filepath="$PROJECT_DIR$/plugins/InspectionGadgets/InspectionGadgetsPlugin.iml" group="plugins" />
|
||||
<module fileurl="file://$PROJECT_DIR$/plugins/InspectionGadgets/InspectionGadgetsAnalysis/InspectionGadgetsAnalysis.iml" filepath="$PROJECT_DIR$/plugins/InspectionGadgets/InspectionGadgetsAnalysis/InspectionGadgetsAnalysis.iml" group="plugins" />
|
||||
<module fileurl="file://$PROJECT_DIR$/plugins/IntelliLang/IntelliLang.iml" filepath="$PROJECT_DIR$/plugins/IntelliLang/IntelliLang.iml" group="plugins/IntelliLang" />
|
||||
<module fileurl="file://$PROJECT_DIR$/plugins/IntelliLang/IntelliLang-java.iml" filepath="$PROJECT_DIR$/plugins/IntelliLang/IntelliLang-java.iml" group="plugins/IntelliLang" />
|
||||
<module fileurl="file://$PROJECT_DIR$/plugins/IntelliLang/IntelliLang-javaee.iml" filepath="$PROJECT_DIR$/plugins/IntelliLang/IntelliLang-javaee.iml" group="plugins/IntelliLang" />
|
||||
|
||||
+21
-18
@@ -51,7 +51,6 @@ def layoutFull(String home, String targetDirectory, String patchedDescriptorDir
|
||||
List<String> openapiModules = [platformApiModules,
|
||||
"java-psi-api",
|
||||
"java-analysis-api",
|
||||
"analysis-api",
|
||||
"java-indexing-api",
|
||||
"openapi",
|
||||
"testFramework-java",
|
||||
@@ -64,22 +63,21 @@ def layoutFull(String home, String targetDirectory, String patchedDescriptorDir
|
||||
|
||||
//noinspection GroovyAssignabilityCheck
|
||||
List<String> implementationModules = [platformImplementationModules,
|
||||
"testFramework",
|
||||
"tests_bootstrap",
|
||||
"instrumentation-util",
|
||||
"platform-main",
|
||||
"java-psi-impl",
|
||||
"java-indexing-impl",
|
||||
"java-impl",
|
||||
"java-analysis-impl",
|
||||
"analysis-impl",
|
||||
"compiler-impl",
|
||||
"debugger-impl",
|
||||
"dom-impl",
|
||||
"execution-impl",
|
||||
"jsp-spi",
|
||||
"idea-ui",
|
||||
"external-system-impl"
|
||||
"compiler-impl",
|
||||
"debugger-impl",
|
||||
"dom-impl",
|
||||
"execution-impl",
|
||||
"external-system-impl",
|
||||
"idea-ui",
|
||||
"instrumentation-util",
|
||||
"java-analysis-impl",
|
||||
"java-indexing-impl",
|
||||
"java-impl",
|
||||
"java-psi-impl",
|
||||
"jsp-spi",
|
||||
"platform-main",
|
||||
"testFramework",
|
||||
"tests_bootstrap",
|
||||
].flatten()
|
||||
|
||||
ant.patternset(id: "resources.included") {
|
||||
@@ -248,7 +246,11 @@ public def layoutCommunityPlugins(String home) {
|
||||
module("ant-jps-plugin")
|
||||
}
|
||||
}
|
||||
layoutPlugin("InspectionGadgets", "InspectionGadgetsPlugin")
|
||||
layoutPlugin("InspectionGadgets", "InspectionGadgetsPlugin") {
|
||||
jar("InspectionGadgetsAnalysis.jar") {
|
||||
module("InspectionGadgetsAnalysis")
|
||||
}
|
||||
}
|
||||
layoutPlugin("IntentionPowerPack", "IntentionPowerPackPlugin")
|
||||
layoutPlugin("ToString", "generate-tostring", "toString")
|
||||
layoutPlugin("uiDesigner", "ui-designer", "uiDesigner") {
|
||||
@@ -751,6 +753,7 @@ def layout_core_upsource(String home, String target) {
|
||||
module("analysis-impl")
|
||||
module("java-analysis-api")
|
||||
module("java-analysis-impl")
|
||||
module("InspectionGadgetsAnalysis")
|
||||
}
|
||||
|
||||
jar("annotations.jar") {
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="Log4J" level="project" />
|
||||
<orderEntry type="library" name="JDOM" level="project" />
|
||||
<orderEntry type="module" module-name="java-analysis-api" />
|
||||
<orderEntry type="module" module-name="java-analysis-impl" />
|
||||
</component>
|
||||
</module>
|
||||
|
||||
+2
-2
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
package com.siyeh;
|
||||
|
||||
import com.intellij.codeInsight.daemon.impl.analysis.HighlightUtil;
|
||||
import com.intellij.codeInsight.daemon.impl.analysis.HighlightUtilBase;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
|
||||
/**
|
||||
@@ -58,7 +58,7 @@ public class HardcodedMethodConstants {
|
||||
public static final String PRINT_STACK_TRACE = "printStackTrace";
|
||||
public static final String REMOVE = "remove";
|
||||
public static final String RUN = "run";
|
||||
public static final String SERIAL_VERSION_UID = HighlightUtil.SERIAL_VERSION_UID_FIELD_NAME;
|
||||
public static final String SERIAL_VERSION_UID = HighlightUtilBase.SERIAL_VERSION_UID_FIELD_NAME;
|
||||
public static final String SET = "set";
|
||||
public static final String SIZE = "size";
|
||||
public static final String STARTS_WITH = "startsWith";
|
||||
+6
-7
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
package com.siyeh.ig;
|
||||
|
||||
import com.intellij.codeInspection.BaseJavaLocalInspectionTool;
|
||||
import com.intellij.codeInspection.BaseJavaBatchLocalInspectionTool;
|
||||
import com.intellij.codeInspection.LocalInspectionToolSession;
|
||||
import com.intellij.codeInspection.ProblemsHolder;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
@@ -23,6 +23,7 @@ import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.PsiElementVisitor;
|
||||
import com.intellij.ui.DocumentAdapter;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import com.siyeh.ig.telemetry.InspectionGadgetsTelemetry;
|
||||
import org.jetbrains.annotations.Nls;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -36,15 +37,13 @@ import java.text.NumberFormat;
|
||||
import java.text.ParseException;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class BaseInspection extends BaseJavaLocalInspectionTool {
|
||||
|
||||
public abstract class BaseInspection extends BaseJavaBatchLocalInspectionTool {
|
||||
private static final Logger LOG = Logger.getInstance("#com.siyeh.ig.BaseInspection");
|
||||
|
||||
@NonNls private static final String INSPECTION = "Inspection";
|
||||
|
||||
private String m_shortName = null;
|
||||
private long timestamp = -1L;
|
||||
private final InspectionGadgetsPlugin inspectionGadgetsPlugin = InspectionGadgetsPlugin.getInstance();
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
@@ -185,7 +184,7 @@ public abstract class BaseInspection extends BaseJavaLocalInspectionTool {
|
||||
@Override
|
||||
public void inspectionStarted(@NotNull LocalInspectionToolSession session, boolean isOnTheFly) {
|
||||
super.inspectionStarted(session, isOnTheFly);
|
||||
if (inspectionGadgetsPlugin.isTelemetryEnabled()) {
|
||||
if (InspectionGadgetsTelemetry.isEnabled()) {
|
||||
timestamp = System.currentTimeMillis();
|
||||
}
|
||||
}
|
||||
@@ -194,14 +193,14 @@ public abstract class BaseInspection extends BaseJavaLocalInspectionTool {
|
||||
public void inspectionFinished(@NotNull LocalInspectionToolSession session,
|
||||
@NotNull ProblemsHolder problemsHolder) {
|
||||
super.inspectionFinished(session, problemsHolder);
|
||||
if (inspectionGadgetsPlugin.isTelemetryEnabled()) {
|
||||
if (InspectionGadgetsTelemetry.isEnabled()) {
|
||||
if (timestamp < 0L) {
|
||||
LOG.warn("finish reported without corresponding start");
|
||||
return;
|
||||
}
|
||||
final long end = System.currentTimeMillis();
|
||||
final String displayName = getDisplayName();
|
||||
inspectionGadgetsPlugin.getTelemetry().reportRun(displayName, end - timestamp);
|
||||
InspectionGadgetsTelemetry.getInstance().reportRun(displayName, end - timestamp);
|
||||
timestamp = -1L;
|
||||
}
|
||||
}
|
||||
+3
@@ -30,16 +30,19 @@ public class DelegatingFix extends InspectionGadgetsFix {
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getName() {
|
||||
return delegate.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getFamilyName() {
|
||||
return delegate.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doFix(Project project, ProblemDescriptor descriptor)
|
||||
throws IncorrectOperationException {
|
||||
delegate.applyFix(project, descriptor);
|
||||
+15
-17
@@ -15,21 +15,19 @@
|
||||
*/
|
||||
package com.siyeh.ig;
|
||||
|
||||
import com.intellij.codeInsight.FileModificationService;
|
||||
import com.intellij.codeInspection.LocalQuickFix;
|
||||
import com.intellij.codeInspection.ProblemDescriptor;
|
||||
import com.intellij.lang.StdLanguages;
|
||||
import com.intellij.lang.Language;
|
||||
import com.intellij.lang.jsp.JspxFileViewProvider;
|
||||
import com.intellij.lang.java.JavaLanguage;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.openapi.vfs.ReadonlyStatusHandler;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.codeStyle.CodeStyleManager;
|
||||
import com.intellij.psi.codeStyle.JavaCodeStyleManager;
|
||||
import com.intellij.psi.jsp.JspFile;
|
||||
import com.intellij.psi.util.PsiUtilCore;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -46,11 +44,13 @@ public abstract class InspectionGadgetsFix implements LocalQuickFix {
|
||||
/**
|
||||
* To appear in "Apply Fix" statement when multiple Quick Fixes exist
|
||||
*/
|
||||
@Override
|
||||
@NotNull
|
||||
public String getFamilyName() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void applyFix(@NotNull Project project,
|
||||
@NotNull ProblemDescriptor descriptor) {
|
||||
final PsiElement problemElement = descriptor.getPsiElement();
|
||||
@@ -145,6 +145,10 @@ public abstract class InspectionGadgetsFix implements LocalQuickFix {
|
||||
styleManager.reformat(replacementExp);
|
||||
}
|
||||
|
||||
private static boolean isInJsp(PsiElement file) {
|
||||
return PsiUtilCore.getTemplateLanguageFile(file) instanceof ServerPageFile;
|
||||
}
|
||||
|
||||
protected static void replaceStatementAndShortenClassNames(
|
||||
@NotNull PsiStatement statement,
|
||||
@NotNull @NonNls String newStatementText)
|
||||
@@ -154,11 +158,11 @@ public abstract class InspectionGadgetsFix implements LocalQuickFix {
|
||||
CodeStyleManager.getInstance(project);
|
||||
final JavaCodeStyleManager javaStyleManager =
|
||||
JavaCodeStyleManager.getInstance(project);
|
||||
if (JspPsiUtil.isInJspFile(statement)) {
|
||||
if (isInJsp(statement)) {
|
||||
final PsiDocumentManager documentManager =
|
||||
PsiDocumentManager.getInstance(project);
|
||||
final JspFile file = JspPsiUtil.getJspFile(statement);
|
||||
final Document document = documentManager.getDocument(file);
|
||||
final PsiFile jspFile = PsiUtilCore.getTemplateLanguageFile(statement);
|
||||
final Document document = documentManager.getDocument(jspFile);
|
||||
if (document == null) {
|
||||
return;
|
||||
}
|
||||
@@ -167,10 +171,10 @@ public abstract class InspectionGadgetsFix implements LocalQuickFix {
|
||||
document.replaceString(textRange.getStartOffset(),
|
||||
textRange.getEndOffset(), newStatementText);
|
||||
documentManager.commitDocument(document);
|
||||
final JspxFileViewProvider viewProvider = file.getViewProvider();
|
||||
final FileViewProvider viewProvider = jspFile.getViewProvider();
|
||||
PsiElement elementAt =
|
||||
viewProvider.findElementAt(textRange.getStartOffset(),
|
||||
StdLanguages.JAVA);
|
||||
JavaLanguage.INSTANCE);
|
||||
if (elementAt == null) {
|
||||
return;
|
||||
}
|
||||
@@ -211,13 +215,7 @@ public abstract class InspectionGadgetsFix implements LocalQuickFix {
|
||||
if (containingPsiFile == null) {
|
||||
return false;
|
||||
}
|
||||
final VirtualFile virtualFile = containingPsiFile.getVirtualFile();
|
||||
final Project project = problemElement.getProject();
|
||||
final ReadonlyStatusHandler handler =
|
||||
ReadonlyStatusHandler.getInstance(project);
|
||||
final ReadonlyStatusHandler.OperationStatus status =
|
||||
handler.ensureFilesWritable(virtualFile);
|
||||
return status.hasReadonlyFiles();
|
||||
return !FileModificationService.getInstance().prepareFileForWrite(containingPsiFile);
|
||||
}
|
||||
|
||||
protected static String getElementText(@NotNull PsiElement element,
|
||||
+1
-3
@@ -16,8 +16,6 @@
|
||||
package com.siyeh.ig.psiutils;
|
||||
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.impl.source.jsp.jspJava.JspClassLevelDeclarationStatement;
|
||||
import com.intellij.psi.impl.source.jsp.jspJava.JspTemplateStatement;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -94,7 +92,7 @@ public class ControlFlowUtils {
|
||||
else if (statement instanceof PsiSwitchStatement) {
|
||||
return switchStatementMayCompleteNormally((PsiSwitchStatement)statement);
|
||||
}
|
||||
else if (statement instanceof JspTemplateStatement || statement instanceof JspClassLevelDeclarationStatement) {
|
||||
else if (statement instanceof PsiTemplateStatement || statement instanceof PsiClassLevelDeclarationStatement) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
+6
-5
@@ -17,11 +17,12 @@ package com.siyeh.ig.psiutils;
|
||||
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettings;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
|
||||
import com.intellij.psi.codeStyle.JavaCodeStyleSettingsFacade;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.psi.util.*;
|
||||
import com.intellij.psi.util.ClassUtil;
|
||||
import com.intellij.psi.util.InheritanceUtil;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.siyeh.HardcodedMethodConstants;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -424,9 +425,9 @@ public class ImportUtils {
|
||||
return false;
|
||||
}
|
||||
final List<PsiImportStaticStatement> imports = getMatchingImports(importList, qualifiedName);
|
||||
final CodeStyleSettings codeStyleSettings = CodeStyleSettingsManager.getSettings(project);
|
||||
int onDemandCount = JavaCodeStyleSettingsFacade.getInstance(project).getNamesCountToUseImportOnDemand();
|
||||
final PsiElementFactory elementFactory = psiFacade.getElementFactory();
|
||||
if (imports.size() < codeStyleSettings.NAMES_COUNT_TO_USE_IMPORT_ON_DEMAND) {
|
||||
if (imports.size() < onDemandCount) {
|
||||
importList.add(elementFactory.createImportStaticStatement(aClass, memberName));
|
||||
}
|
||||
else {
|
||||
+114
@@ -0,0 +1,114 @@
|
||||
/*
|
||||
* Copyright 2003-2012 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* 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.siyeh.ig.psiutils;
|
||||
|
||||
import com.intellij.openapi.progress.ProgressManager;
|
||||
import com.intellij.psi.CommonClassNames;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiModifier;
|
||||
import com.intellij.psi.PsiTypeParameter;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.psi.search.SearchScope;
|
||||
import com.intellij.psi.search.searches.ClassInheritorsSearch;
|
||||
import com.intellij.util.Processor;
|
||||
import com.intellij.util.Query;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public class InheritanceUtil {
|
||||
|
||||
private InheritanceUtil() {}
|
||||
|
||||
public static boolean existsMutualSubclass(PsiClass class1, final PsiClass class2) {
|
||||
if (class1 instanceof PsiTypeParameter) {
|
||||
final PsiClass[] superClasses = class1.getSupers();
|
||||
for (PsiClass superClass : superClasses) {
|
||||
if (!existsMutualSubclass(superClass, class2)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (class2 instanceof PsiTypeParameter) {
|
||||
return existsMutualSubclass(class2, class1);
|
||||
}
|
||||
|
||||
final String className = class1.getQualifiedName();
|
||||
if (CommonClassNames.JAVA_LANG_OBJECT.equals(className)) {
|
||||
return true;
|
||||
}
|
||||
final String class2Name = class2.getQualifiedName();
|
||||
if (CommonClassNames.JAVA_LANG_OBJECT.equals(class2Name)) {
|
||||
return true;
|
||||
}
|
||||
if (class1.isInheritor(class2, true) ||
|
||||
class2.isInheritor(class1, true)) {
|
||||
return true;
|
||||
}
|
||||
final SearchScope scope = GlobalSearchScope.allScope(class1.getProject());
|
||||
final Query<PsiClass> search = ClassInheritorsSearch.search(class1, scope, true, true);
|
||||
return !search.forEach(new Processor<PsiClass>() {
|
||||
public boolean process(PsiClass inheritor) {
|
||||
return !inheritor.equals(class2) && !inheritor.isInheritor(class2, true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static boolean hasImplementation(PsiClass aClass) {
|
||||
final SearchScope scope = GlobalSearchScope.projectScope(aClass.getProject());
|
||||
final Query<PsiClass> search = ClassInheritorsSearch.search(aClass, scope, true, true);
|
||||
return !search.forEach(new Processor<PsiClass>() {
|
||||
@Override
|
||||
public boolean process(PsiClass inheritor) {
|
||||
return inheritor.isInterface() || inheritor.isAnnotationType() || inheritor.hasModifierProperty(PsiModifier.ABSTRACT);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static boolean hasOneInheritor(final PsiClass aClass) {
|
||||
final CountingProcessor processor = new CountingProcessor(2);
|
||||
ProgressManager.getInstance().runProcess(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ClassInheritorsSearch.search(aClass, aClass.getUseScope(), false).forEach(processor);
|
||||
}
|
||||
}, null);
|
||||
return processor.getCount() == 1;
|
||||
}
|
||||
|
||||
public static class CountingProcessor implements Processor<PsiClass> {
|
||||
|
||||
private final AtomicInteger myCount = new AtomicInteger(0);
|
||||
private final int myLimit;
|
||||
|
||||
public CountingProcessor(int limit) {
|
||||
myLimit = limit;
|
||||
}
|
||||
|
||||
public int getCount() {
|
||||
return myCount.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean process(PsiClass aClass) {
|
||||
if (myCount.get() == myLimit){
|
||||
return false;
|
||||
}
|
||||
myCount.incrementAndGet();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
+23
-3
@@ -15,21 +15,25 @@
|
||||
*/
|
||||
package com.siyeh.ig.telemetry;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class InspectionGadgetsTelemetry {
|
||||
private static final InspectionGadgetsTelemetry telemetry = new InspectionGadgetsTelemetry();
|
||||
private static volatile boolean telemetryEnabled = false;
|
||||
|
||||
private final ConcurrentHashMap<String, InspectionRunTime> inspectionRunTimes =
|
||||
new ConcurrentHashMap();
|
||||
new ConcurrentHashMap<String, InspectionRunTime>();
|
||||
|
||||
public List<InspectionRunTime> buildList() {
|
||||
if (inspectionRunTimes.isEmpty()) {
|
||||
return Collections.EMPTY_LIST;
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return new ArrayList(inspectionRunTimes.values());
|
||||
return new ArrayList<InspectionRunTime>(inspectionRunTimes.values());
|
||||
}
|
||||
|
||||
public void reportRun(String inspectionID, long runTime) {
|
||||
@@ -50,4 +54,20 @@ public class InspectionGadgetsTelemetry {
|
||||
public void reset() {
|
||||
inspectionRunTimes.clear();
|
||||
}
|
||||
|
||||
public static boolean isEnabled() {
|
||||
return telemetryEnabled;
|
||||
}
|
||||
|
||||
public static void setEnabled(boolean enabled) {
|
||||
telemetryEnabled = enabled;
|
||||
if (telemetryEnabled) {
|
||||
telemetry.reset();
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static InspectionGadgetsTelemetry getInstance() {
|
||||
return telemetry;
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,7 @@
|
||||
<orderEntry type="module" module-name="java-impl" />
|
||||
<orderEntry type="module" module-name="testFramework-java" scope="TEST" />
|
||||
<orderEntry type="module" module-name="java-indexing-api" />
|
||||
<orderEntry type="module" module-name="InspectionGadgetsAnalysis" />
|
||||
</component>
|
||||
</module>
|
||||
|
||||
|
||||
@@ -30,11 +30,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
"OverlyLongMethod",
|
||||
"ClassWithTooManyMethods"})
|
||||
public class InspectionGadgetsPlugin implements ApplicationComponent {
|
||||
|
||||
private final InspectionGadgetsTelemetry telemetry = new InspectionGadgetsTelemetry();
|
||||
private volatile boolean telemetryEnabled = false;
|
||||
|
||||
public static boolean getUpToDateTelemetryEnabled(final Consumer<Boolean> consumer, Disposable disposable) {
|
||||
public static boolean getUpToDateTelemetryEnabled(@NotNull final Consumer<Boolean> consumer, @NotNull Disposable disposable) {
|
||||
final RegistryValue registryValue = Registry.get("inspectionGadgets.telemetry.enabled");
|
||||
registryValue.addListener(new RegistryValueListener.Adapter() {
|
||||
@Override
|
||||
@@ -58,24 +54,24 @@ public class InspectionGadgetsPlugin implements ApplicationComponent {
|
||||
return "InspectionGadgets";
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public InspectionGadgetsTelemetry getTelemetry() {
|
||||
return telemetry;
|
||||
return InspectionGadgetsTelemetry.getInstance();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initComponent() {
|
||||
telemetryEnabled = getUpToDateTelemetryEnabled(new Consumer<Boolean>() {
|
||||
boolean telemetryEnabled = getUpToDateTelemetryEnabled(new Consumer<Boolean>() {
|
||||
@Override
|
||||
public void consume(Boolean value) {
|
||||
telemetryEnabled = value.booleanValue();
|
||||
if (telemetryEnabled) {
|
||||
telemetry.reset();
|
||||
}
|
||||
boolean enabled = value.booleanValue();
|
||||
InspectionGadgetsTelemetry.setEnabled(enabled);
|
||||
}
|
||||
}, ApplicationManager.getApplication());
|
||||
InspectionGadgetsTelemetry.setEnabled(telemetryEnabled);
|
||||
}
|
||||
|
||||
public boolean isTelemetryEnabled() {
|
||||
return telemetryEnabled;
|
||||
return InspectionGadgetsTelemetry.isEnabled();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user