Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Leverage new JellyFile type in more of the codebase #122

Merged
merged 2 commits into from
Nov 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.intellij.internal.statistic.collectors.fus.fileTypes.FileTypeUsageSchemaDescriptor;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiFile;
import org.jetbrains.annotations.NotNull;

public class JellyFileTypeSchema implements FileTypeUsageSchemaDescriptor {
Expand All @@ -21,14 +20,6 @@ public class JellyFileTypeSchema implements FileTypeUsageSchemaDescriptor {

@Override
public boolean describes(@NotNull Project project, @NotNull VirtualFile file) {
return isJelly(file);
}

public static boolean isJelly(@NotNull PsiFile file) {
return isJelly(file.getViewProvider().getVirtualFile());
}

public static boolean isJelly(@NotNull VirtualFile file) {
String fileExtension = file.getExtension();
return JELLY_EXTENSION.equals(fileExtension) || STAPLER_JELLY_TAG_EXTENSION.equals(fileExtension);
}
Expand Down
5 changes: 0 additions & 5 deletions src/main/java/org/kohsuke/stapler/idea/JellyAnnotator.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import com.intellij.xml.impl.schema.AnyXmlElementDescriptor;
import org.jetbrains.annotations.NotNull;

import static io.jenkins.stapler.idea.jelly.JellyFileTypeSchema.isJelly;

/**
* Additional Jelly-specific {@link Annotator}.
Expand All @@ -30,10 +29,6 @@ public class JellyAnnotator implements Annotator {
public void annotate(@NotNull PsiElement psi, @NotNull AnnotationHolder holder) {
if (psi instanceof XmlTag) {
XmlTag tag = (XmlTag) psi;

if(!isJelly(tag.getContainingFile()))
return; // only do this in Jelly files

// for elements
XmlNSDescriptor ns = tag.getDescriptor().getNSDescriptor();
XmlElementDescriptor e = ns.getElementDescriptor(tag);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.jetbrains.annotations.NotNull;
import org.kohsuke.stapler.idea.descriptor.StaplerCustomJellyTagLibraryXmlNSDescriptor;

import static io.jenkins.stapler.idea.jelly.JellyFileTypeSchema.isJelly;

/**
* Tag name completion for Jelly tag libraries defined as tag files.
Expand Down Expand Up @@ -75,10 +74,6 @@ public JellyCompletionContributor() {
protected void addCompletions(@NotNull CompletionParameters parameters, @NotNull ProcessingContext context, @NotNull CompletionResultSet result) {
XmlElement name = (XmlElement)parameters.getPosition();

// do this only inside Jelly files
if(!isJelly(name.getContainingFile()))
return;

// this pseudo-tag represents the tag being completed.
XmlTag tag = (XmlTag) name.getParent();
Module module = ModuleUtil.findModuleForPsiElement(tag);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
import com.intellij.psi.xml.XmlTag;
import com.intellij.psi.xml.XmlText;
import org.jetbrains.annotations.NotNull;
import org.kohsuke.stapler.idea.psi.JellyFile;

import java.util.Arrays;
import java.util.List;

import static io.jenkins.stapler.idea.jelly.JellyFileTypeSchema.isJelly;

/**
* Injects CSS and JavaScript to suitable places
Expand All @@ -27,7 +27,7 @@
public class JellyLanguageInjector implements MultiHostInjector {
@Override
public void getLanguagesToInject(@NotNull final MultiHostRegistrar registrar, @NotNull PsiElement context) {
if(!isJelly(context.getContainingFile()))
if(!(context.getContainingFile() instanceof JellyFile))
return; // not a jelly file

// inject CSS to @style
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/kohsuke/stapler/idea/JexlInspection.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import com.intellij.psi.xml.XmlText;
import org.apache.commons.jexl.ExpressionFactory;
import org.apache.commons.jexl.parser.ParseException;
import org.kohsuke.stapler.idea.psi.JellyFile;

import static io.jenkins.stapler.idea.jelly.JellyFileTypeSchema.isJelly;

/**
* @author Kohsuke Kawaguchi
Expand Down Expand Up @@ -51,7 +51,7 @@ protected ProblemDescriptor[] checkXmlText(XmlText xmlText, InspectionManager ma
* @param onTheFly
*/
protected ProblemDescriptor[] check(XmlElement psi, InspectionManager manager, String text, TextRange range, boolean onTheFly) {
if(!isJelly(psi.getContainingFile()))
if(!(psi.getContainingFile() instanceof JellyFile))
return EMPTY_ARRAY; // not a jelly script
if(!shouldCheck(psi))
return EMPTY_ARRAY; // stapler not enabled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
import com.intellij.xml.XmlNSDescriptorEx;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.kohsuke.stapler.idea.psi.JellyFile;

import java.util.ArrayList;
import java.util.List;

import static io.jenkins.stapler.idea.jelly.JellyFileTypeSchema.JELLY_EXTENSION;
import static io.jenkins.stapler.idea.jelly.JellyFileTypeSchema.STAPLER_JELLY_TAG_EXTENSION;
import static io.jenkins.stapler.idea.jelly.JellyFileTypeSchema.isJelly;

/**
* @author Kohsuke Kawaguchi
Expand Down Expand Up @@ -150,7 +150,7 @@ public void init(PsiElement element) {
}

public static StaplerCustomJellyTagLibraryXmlNSDescriptor get(XmlTag tag) {
if(!isJelly(tag.getContainingFile()))
if(!(tag.getContainingFile() instanceof JellyFile))
return null; // this tag is not in a jelly script

String nsUri = tag.getNamespace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
import com.intellij.xml.XmlSchemaProvider;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.kohsuke.stapler.idea.psi.JellyFile;

import static io.jenkins.stapler.idea.jelly.JellyFileTypeSchema.isJelly;

/**
* This is not to be confused with W3C XML Schema. Rather,
Expand Down Expand Up @@ -44,7 +44,7 @@ public XmlFile getSchema(@NotNull String url, @Nullable Module module, @NotNull
*/
@Override
public boolean isAvailable(@NotNull XmlFile file) {
return isJelly(file);
return file instanceof JellyFile;
}

/*package*/ static final Key<PsiDirectory> MODULE = Key.create(PsiDirectory.class.getName());
Expand Down