From 4d0a02e3de38b19b2430651142b51a538ddd74a2 Mon Sep 17 00:00:00 2001 From: Anastasia Ivanova Date: Wed, 12 Aug 2020 12:16:58 +0200 Subject: [PATCH] FUS-450 add project as parameter to FileTypeUsageSchemaDescriptor GitOrigin-RevId: 28b6ef12d52f44fe9f4eca2b4fd3c42d075af47c --- .../lookup/impl/LookupUsageTracker.java | 2 +- .../FileTypeUsageCounterCollector.java | 16 +++++++++------- .../FileTypeUsageSchemaDescriptor.java | 15 +++++++++++++-- .../src/config/GradleScriptTypeDetector.java | 5 +++-- .../javaFX/fxml/JavaFxFileTypeFactory.java | 3 ++- .../groovy/MavenGroovyScriptTypeDetector.java | 19 +++---------------- .../maven/utils/MavenFileTypeFactory.java | 19 +++---------------- 7 files changed, 34 insertions(+), 45 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupUsageTracker.java b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupUsageTracker.java index 27d9fdfab15e..e774389315aa 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupUsageTracker.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupUsageTracker.java @@ -120,7 +120,7 @@ final class LookupUsageTracker { if (file != null) { VirtualFile vFile = file.getVirtualFile(); if (vFile != null) { - String schema = FileTypeUsageCounterCollector.findSchema(vFile); + String schema = FileTypeUsageCounterCollector.findSchema(myLookup.getProject(), vFile); if (schema != null) { data.addData("schema", schema); } diff --git a/platform/platform-impl/src/com/intellij/internal/statistic/collectors/fus/fileTypes/FileTypeUsageCounterCollector.java b/platform/platform-impl/src/com/intellij/internal/statistic/collectors/fus/fileTypes/FileTypeUsageCounterCollector.java index 8ead46103e52..7f02f8d4f44a 100644 --- a/platform/platform-impl/src/com/intellij/internal/statistic/collectors/fus/fileTypes/FileTypeUsageCounterCollector.java +++ b/platform/platform-impl/src/com/intellij/internal/statistic/collectors/fus/fileTypes/FileTypeUsageCounterCollector.java @@ -76,30 +76,32 @@ public class FileTypeUsageCounterCollector extends CounterUsagesCollector { } public static void triggerOpen(@NotNull Project project, @NotNull VirtualFile file) { - OPEN.log(project, ArrayUtil.append(buildCommonEventPairs(file), IS_WRITABLE.with(file.isWritable()))); + OPEN.log(project, ArrayUtil.append(buildCommonEventPairs(project, file), IS_WRITABLE.with(file.isWritable()))); } public static void triggerClosed(@NotNull Project project, @NotNull VirtualFile file) { - CLOSE.log(project, ArrayUtil.append(buildCommonEventPairs(file), IS_WRITABLE.with(file.isWritable()))); + CLOSE.log(project, ArrayUtil.append(buildCommonEventPairs(project, file), IS_WRITABLE.with(file.isWritable()))); } private static void log(@NotNull VarargEventId eventId, @NotNull Project project, @NotNull VirtualFile file) { - eventId.log(project, buildCommonEventPairs(file)); + eventId.log(project, buildCommonEventPairs(project, file)); } - private static EventPair @NotNull [] buildCommonEventPairs(@NotNull VirtualFile file) { + private static EventPair @NotNull [] buildCommonEventPairs(@NotNull Project project, + @NotNull VirtualFile file) { FileType fileType = file.getFileType(); return new EventPair[]{EventFields.PluginInfoFromInstance.with(fileType), FILE_TYPE.with(FileTypeUsagesCollector.getSafeFileTypeName(fileType)), EventFields.AnonymizedPath.with(file.getPath()), - SCHEMA.with(findSchema(file))}; + SCHEMA.with(findSchema(project, file))}; } private static void logEmptyFile() { SELECT.log(EventFields.AnonymizedPath.with(null)); } - public static @Nullable String findSchema(@NotNull VirtualFile file) { + public static @Nullable String findSchema(@NotNull Project project, + @NotNull VirtualFile file) { for (FileTypeUsageSchemaDescriptorEP ext : EP.getExtensionList()) { FileTypeUsageSchemaDescriptor instance = ext.getInstance(); if (ext.schema == null) { @@ -107,7 +109,7 @@ public class FileTypeUsageCounterCollector extends CounterUsagesCollector { continue; } - if(instance.describes(file)) { + if (instance.describes(project, file)) { return getPluginInfo(instance.getClass()).isSafeToReport() ? ext.schema : "third.party"; } } diff --git a/platform/platform-impl/src/com/intellij/internal/statistic/collectors/fus/fileTypes/FileTypeUsageSchemaDescriptor.java b/platform/platform-impl/src/com/intellij/internal/statistic/collectors/fus/fileTypes/FileTypeUsageSchemaDescriptor.java index b311ba159886..ba892f372d8b 100644 --- a/platform/platform-impl/src/com/intellij/internal/statistic/collectors/fus/fileTypes/FileTypeUsageSchemaDescriptor.java +++ b/platform/platform-impl/src/com/intellij/internal/statistic/collectors/fus/fileTypes/FileTypeUsageSchemaDescriptor.java @@ -1,15 +1,26 @@ -// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.internal.statistic.collectors.fus.fileTypes; +import com.intellij.openapi.project.Project; import com.intellij.openapi.vfs.VirtualFile; import org.jetbrains.annotations.NotNull; public interface FileTypeUsageSchemaDescriptor { + /** + * @deprecated use {@link FileTypeUsageSchemaDescriptor#describes(Project, VirtualFile)} + */ + @Deprecated + default boolean describes(@NotNull VirtualFile file) { + return false; + } + /** * Is used to categorise file types usage statistics. * If a file has some generic file type (e.g. XML), this method allow specifying its 'schema' more precisely, e.g `Maven` or `Spring`. * * @return true if the given file has the schema name, given in the `schema` attribute of the `FileTypeUsageSchemaDescriptor` extension. */ - boolean describes(@NotNull VirtualFile file); + default boolean describes(@NotNull Project project, @NotNull VirtualFile file) { + return describes(file); + } } diff --git a/plugins/gradle/java/src/config/GradleScriptTypeDetector.java b/plugins/gradle/java/src/config/GradleScriptTypeDetector.java index bbc90d914ce6..25643d083893 100644 --- a/plugins/gradle/java/src/config/GradleScriptTypeDetector.java +++ b/plugins/gradle/java/src/config/GradleScriptTypeDetector.java @@ -1,8 +1,9 @@ -// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package org.jetbrains.plugins.gradle.config; import com.intellij.internal.statistic.collectors.fus.fileTypes.FileTypeUsageSchemaDescriptor; import com.intellij.openapi.fileTypes.FileTypeRegistry; +import com.intellij.openapi.project.Project; import com.intellij.openapi.vfs.VirtualFile; import org.jetbrains.annotations.NotNull; import org.jetbrains.plugins.gradle.util.GradleConstants; @@ -25,7 +26,7 @@ public class GradleScriptTypeDetector extends GroovyScriptTypeDetector implement } @Override - public boolean describes(@NotNull VirtualFile file) { + public boolean describes(@NotNull Project project, @NotNull VirtualFile file) { String name = file.getName(); return FileTypeRegistry.getInstance().isFileOfType(file, GroovyFileType.GROOVY_FILE_TYPE) && (name.equals(GradleConstants.DEFAULT_SCRIPT_NAME) || name.equals(GradleConstants.SETTINGS_FILE_NAME)); diff --git a/plugins/javaFX/src/org/jetbrains/plugins/javaFX/fxml/JavaFxFileTypeFactory.java b/plugins/javaFX/src/org/jetbrains/plugins/javaFX/fxml/JavaFxFileTypeFactory.java index 5c20fbd0ac51..b67e0ef9a6d0 100644 --- a/plugins/javaFX/src/org/jetbrains/plugins/javaFX/fxml/JavaFxFileTypeFactory.java +++ b/plugins/javaFX/src/org/jetbrains/plugins/javaFX/fxml/JavaFxFileTypeFactory.java @@ -4,6 +4,7 @@ package org.jetbrains.plugins.javaFX.fxml; import com.intellij.internal.statistic.collectors.fus.fileTypes.FileTypeUsageSchemaDescriptor; import com.intellij.openapi.fileTypes.FileType; import com.intellij.openapi.fileTypes.FileTypeManager; +import com.intellij.openapi.project.Project; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiFile; import org.jetbrains.annotations.NonNls; @@ -11,7 +12,7 @@ import org.jetbrains.annotations.NotNull; public final class JavaFxFileTypeFactory implements FileTypeUsageSchemaDescriptor { @Override - public boolean describes(@NotNull VirtualFile file) { + public boolean describes(@NotNull Project project, @NotNull VirtualFile file) { return isFxml(file); } diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/plugins/groovy/MavenGroovyScriptTypeDetector.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/plugins/groovy/MavenGroovyScriptTypeDetector.java index 0c8504f839c8..fb205eda80d9 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/plugins/groovy/MavenGroovyScriptTypeDetector.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/plugins/groovy/MavenGroovyScriptTypeDetector.java @@ -1,22 +1,9 @@ -/* - * Copyright 2000-2016 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. - */ +// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package org.jetbrains.idea.maven.plugins.groovy; import com.intellij.internal.statistic.collectors.fus.fileTypes.FileTypeUsageSchemaDescriptor; import com.intellij.openapi.fileTypes.FileTypeRegistry; +import com.intellij.openapi.project.Project; import com.intellij.openapi.vfs.VirtualFile; import org.jetbrains.annotations.NotNull; import org.jetbrains.plugins.groovy.GroovyFileType; @@ -37,7 +24,7 @@ public class MavenGroovyScriptTypeDetector extends GroovyScriptTypeDetector impl } @Override - public boolean describes(@NotNull VirtualFile file) { + public boolean describes(@NotNull Project project, @NotNull VirtualFile file) { return isMavenGroovyScript(file); } diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/MavenFileTypeFactory.java b/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/MavenFileTypeFactory.java index 8344ba3d60ae..e0ac5cba9638 100644 --- a/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/MavenFileTypeFactory.java +++ b/plugins/maven/src/main/java/org/jetbrains/idea/maven/utils/MavenFileTypeFactory.java @@ -1,23 +1,10 @@ -/* - * Copyright 2000-2012 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. - */ +// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package org.jetbrains.idea.maven.utils; import com.intellij.ide.highlighter.XmlFileType; import com.intellij.internal.statistic.collectors.fus.fileTypes.FileTypeUsageSchemaDescriptor; import com.intellij.openapi.fileTypes.FileTypeRegistry; +import com.intellij.openapi.project.Project; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.vfs.VirtualFile; import org.jetbrains.annotations.NotNull; @@ -28,7 +15,7 @@ import org.jetbrains.idea.maven.model.MavenConstants; */ public class MavenFileTypeFactory implements FileTypeUsageSchemaDescriptor { @Override - public boolean describes(@NotNull VirtualFile file) { + public boolean describes(@NotNull Project project, @NotNull VirtualFile file) { return FileTypeRegistry.getInstance().isFileOfType(file, XmlFileType.INSTANCE) && FileUtil.namesEqual(file.getName(), MavenConstants.POM_XML); } } -- 2.32.0