mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
show usages from generated code in separate group (IDEA-97579)
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright 2000-2013 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.openapi.roots;
|
||||
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public class JavaGeneratedSourcesFilter extends GeneratedSourcesFilter {
|
||||
@Override
|
||||
public boolean isGeneratedSource(@NotNull VirtualFile file, @NotNull Project project) {
|
||||
return JavaProjectRootsUtil.isInGeneratedCode(file, project);
|
||||
}
|
||||
}
|
||||
@@ -38,8 +38,7 @@ public class JavaProjectRootsUtil {
|
||||
for (Module module : ModuleManager.getInstance(project).getModules()) {
|
||||
for (ContentEntry entry : ModuleRootManager.getInstance(module).getContentEntries()) {
|
||||
for (SourceFolder sourceFolder : entry.getSourceFolders(JavaModuleSourceRootTypes.SOURCES)) {
|
||||
JavaSourceRootProperties properties = sourceFolder.getJpsElement().getProperties(JavaModuleSourceRootTypes.SOURCES);
|
||||
if (properties != null && !properties.isForGeneratedSources()) {
|
||||
if (!isForGeneratedSources(sourceFolder)) {
|
||||
ContainerUtil.addIfNotNull(roots, sourceFolder.getFile());
|
||||
}
|
||||
}
|
||||
@@ -47,4 +46,27 @@ public class JavaProjectRootsUtil {
|
||||
}
|
||||
return roots;
|
||||
}
|
||||
|
||||
private static boolean isForGeneratedSources(SourceFolder sourceFolder) {
|
||||
JavaSourceRootProperties properties = sourceFolder.getJpsElement().getProperties(JavaModuleSourceRootTypes.SOURCES);
|
||||
return properties != null && properties.isForGeneratedSources();
|
||||
}
|
||||
|
||||
public static boolean isInGeneratedCode(@NotNull VirtualFile file, @NotNull Project project) {
|
||||
ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
|
||||
Module module = fileIndex.getModuleForFile(file);
|
||||
if (module == null) return false;
|
||||
|
||||
VirtualFile sourceRoot = fileIndex.getSourceRootForFile(file);
|
||||
if (sourceRoot == null) return false;
|
||||
|
||||
for (ContentEntry entry : ModuleRootManager.getInstance(module).getContentEntries()) {
|
||||
for (SourceFolder folder : entry.getSourceFolders()) {
|
||||
if (sourceRoot.equals(folder.getFile())) {
|
||||
return isForGeneratedSources(folder);
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user