Skip to content

Commit

Permalink
Merge pull request #122 from duemir/jelly-file-instead-of-ext
Browse files Browse the repository at this point in the history
Leverage new JellyFile type in more of the codebase
  • Loading branch information
duemir committed Nov 3, 2022
2 parents 3b78fb0 + 3f338a3 commit c659066
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 27 deletions.
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

0 comments on commit c659066

Please sign in to comment.