IJPL-219723 [java] JspFileTypeUtil; reduce uses of StdFileTypes

GitOrigin-RevId: a4f8d06f06014596b53b90a754e8f29bae69d16b
This commit is contained in:
Tagir Valeev
2025-11-25 20:03:18 +00:00
committed by intellij-monorepo-bot
parent c48e940089
commit 59c388119a
5 changed files with 108 additions and 10 deletions
@@ -1,10 +1,10 @@
// Copyright 2000-2021 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.refactoring.inline;
import com.intellij.java.util.JspFileTypeUtil;
import com.intellij.lang.Language;
import com.intellij.lang.java.JavaLanguage;
import com.intellij.lang.refactoring.InlineActionHandler;
import com.intellij.openapi.fileTypes.StdFileTypes;
public abstract class JavaInlineActionHandler extends InlineActionHandler {
@@ -15,7 +15,6 @@ public abstract class JavaInlineActionHandler extends InlineActionHandler {
protected static boolean isJavaLanguage(Language l) {
return l instanceof JavaLanguage ||
l.equals(StdFileTypes.JSPX.getLanguage()) ||
l.equals(StdFileTypes.JSP.getLanguage());
JspFileTypeUtil.isJspOrJspX(l);
}
}
@@ -4,8 +4,8 @@ package com.intellij.codeEditor.printing;
import com.intellij.ide.highlighter.JavaFileType;
import com.intellij.java.JavaBundle;
import com.intellij.java.util.JspFileTypeUtil;
import com.intellij.openapi.fileTypes.FileType;
import com.intellij.openapi.fileTypes.StdFileTypes;
import com.intellij.openapi.options.ConfigurationException;
import com.intellij.openapi.options.UnnamedConfigurable;
import com.intellij.psi.*;
@@ -24,7 +24,7 @@ public final class HyperlinksToClassesOption extends PrintOption {
public @Nullable Map<Integer, PsiReference> collectReferences(@NotNull PsiFile psiFile, @NotNull Map<PsiFile, PsiFile> filesMap) {
if (isGenerateHyperlinksToClasses) {
FileType fileType = psiFile.getFileType();
if (JavaFileType.INSTANCE == fileType || StdFileTypes.JSP == fileType) {
if (JavaFileType.INSTANCE == fileType || JspFileTypeUtil.isJsp(fileType)) {
Map<Integer, PsiReference> refMap = new TreeMap<>();
findClassReferences(psiFile, refMap, filesMap, psiFile);
return refMap;
@@ -7,8 +7,8 @@ import com.intellij.codeInsight.lookup.Lookup;
import com.intellij.codeInsight.lookup.LookupElement;
import com.intellij.codeInsight.lookup.VariableLookupItem;
import com.intellij.java.syntax.parser.JavaKeywords;
import com.intellij.java.util.JspFileTypeUtil;
import com.intellij.lang.java.JavaLanguage;
import com.intellij.openapi.fileTypes.StdFileTypes;
import com.intellij.patterns.PsiJavaPatterns;
import com.intellij.pom.java.JavaFeature;
import com.intellij.psi.*;
@@ -29,7 +29,7 @@ public final class JavaCharFilter extends CharFilter {
PsiFile file = lookup.getPsiFile();
if (file == null) return null;
boolean isJava = file.getLanguage().isKindOf(JavaLanguage.INSTANCE);
boolean isJsp = file.getFileType() == StdFileTypes.JSP;
boolean isJsp = JspFileTypeUtil.isJsp(file);
if (!isJava && !isJsp) {
return null;
}
@@ -2,10 +2,10 @@
package com.intellij.lang;
import com.intellij.ide.highlighter.HtmlFileType;
import com.intellij.java.util.JspFileTypeUtil;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.fileTypes.FileType;
import com.intellij.openapi.fileTypes.LanguageFileType;
import com.intellij.openapi.fileTypes.StdFileTypes;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.ProjectFileIndex;
import com.intellij.openapi.util.SimpleModificationTracker;
@@ -126,8 +126,7 @@ public class OuterModelsModificationTracker extends SimpleModificationTracker {
private static boolean isIgnoredFileType(@NotNull FileType type) {
return type.equals(HtmlFileType.INSTANCE) ||
type instanceof LanguageFileType && "JavaScript".equals(((LanguageFileType)type).getLanguage().getID()) ||
type.equals(StdFileTypes.JSP) ||
type.equals(StdFileTypes.JSPX);
JspFileTypeUtil.isJspOrJspX(type);
}
}
@@ -0,0 +1,100 @@
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.java.util;
import com.intellij.lang.Language;
import com.intellij.openapi.fileTypes.FileType;
import com.intellij.psi.PsiFile;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* Utility methods to recognize JSP/JSPX files.
* These are to be used in case if there's no direct dependency to JSP modules.
* <p>
* In general, if your functionality depends on JSP, consider depending on JSP modules directly.
*/
public final class JspFileTypeUtil {
private JspFileTypeUtil() { }
/**
* @param file file to check
* @return true if the file is a JSP file
*/
@Contract(pure = true)
public static boolean isJsp(@NotNull PsiFile file) {
return isJsp(file.getFileType());
}
/**
* @param fileType file type to check
* @return true if the file type is a JSP file type
*/
@Contract(pure = true)
public static boolean isJsp(@Nullable FileType fileType) {
return fileType != null && fileType.getName().equals("JSP");
}
/**
* @param language language to check
* @return true if the language is a JSP language
*/
@Contract(pure = true)
public static boolean isJsp(@Nullable Language language) {
return language != null && language.getID().equals("JSP");
}
/**
* @param file file to check
* @return true if the file is a JSPX file
*/
@Contract(pure = true)
public static boolean isJspX(@NotNull PsiFile file) {
return isJsp(file.getFileType());
}
/**
* @param fileType file type to check
* @return true if the file type is a JSPX file type
*/
@Contract(pure = true)
public static boolean isJspX(@Nullable FileType fileType) {
return fileType != null && fileType.getName().equals("JSPX");
}
/**
* @param language language to check
* @return true if the language is a JSPX language
*/
@Contract(pure = true)
public static boolean isJspX(@Nullable Language language) {
return language != null && language.getID().equals("JSPX");
}
/**
* @param file file to check
* @return true if the file is a JSP file or a JSPX file
*/
@Contract(pure = true)
public static boolean isJspOrJspX(@NotNull PsiFile file) {
return isJspOrJspX(file.getFileType());
}
/**
* @param fileType file type to check
* @return true if the file type is a JSP file type or a JSPX file type
*/
@Contract(pure = true)
public static boolean isJspOrJspX(@Nullable FileType fileType) {
return isJsp(fileType) || isJspX(fileType);
}
/**
* @param language language to check
* @return true if the language is a JSP language or a JSPX language
*/
@Contract(pure = true)
public static boolean isJspOrJspX(@Nullable Language language) {
return isJsp(language) || isJspX(language);
}
}