Skip to content

Commit

Permalink
Merge pull request #196 from janfaracik/lint
Browse files Browse the repository at this point in the history
Format the plugin via Spotless
  • Loading branch information
duemir authored Dec 3, 2024
2 parents 42663ad + 41fb12b commit 53e90d5
Show file tree
Hide file tree
Showing 34 changed files with 697 additions and 720 deletions.
34 changes: 34 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Handle line endings automatically for files detected as text
# and leave all files detected as binary untouched.
* text=auto

#
# The above will handle all files NOT found below
#
# These files are text and should be normalized (Convert crlf => lf)
*.html text
*.java text
*.json text
*.jelly text
*.jellytag text
*.properties text
*.rb text
*.sh text
*.txt text
*.xml text

# These files are binary and should be left untouched
# (binary is a macro for -text -diff)
*.class binary
*.gz binary
*.tgz binary
*.ear binary
*.gif binary
*.hpi binary
*.ico binary
*.jar binary
*.jpg binary
*.jpeg binary
*.png binary
*.war binary
*.zip binary
13 changes: 12 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import java.util.stream.Collectors
plugins {
id 'java'
id 'org.jetbrains.intellij' version '1.17.4'
id 'com.diffplug.spotless' version '6.25.0'
}

group = "org.kohsuke.stapler.idea"
Expand Down Expand Up @@ -134,4 +135,14 @@ String extractPluginDescription() {
}
return description
}
}
}

spotless {
java {
palantirJavaFormat('2.39.0').formatJavadoc(true)
indentWithSpaces()
removeUnusedImports()
trimTrailingWhitespace()
endWithNewline()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,13 @@ public class DeprecatedStaplerJellyCustomTagAttributeInspection extends LocalIns
return new XmlElementVisitor() {
@Override
public void visitXmlAttribute(@NotNull XmlAttribute attribute) {
if (attribute.getDescriptor() instanceof StaplerCustomJellyTagfileXmlAttributeDescriptor descriptor && descriptor.getModel().isDeprecated()) {
holder.registerProblem(attribute, String.format("Attribute '%s' is deprecated. Use \"Go to declaration\" to find the recommended solution.", attribute.getName()));
if (attribute.getDescriptor() instanceof StaplerCustomJellyTagfileXmlAttributeDescriptor descriptor
&& descriptor.getModel().isDeprecated()) {
holder.registerProblem(
attribute,
String.format(
"Attribute '%s' is deprecated. Use \"Go to declaration\" to find the recommended solution.",
attribute.getName()));
}
}
};
Expand Down
63 changes: 32 additions & 31 deletions src/main/java/org/kohsuke/stapler/idea/GotoViewAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,10 @@
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.psi.util.PsiUtilBase;
import com.intellij.util.ArrayUtil;
import org.jetbrains.annotations.NotNull;

import javax.swing.*;
import java.util.ArrayList;
import java.util.List;
import javax.swing.*;
import org.jetbrains.annotations.NotNull;

/**
* Select stapler views from a Java class.
Expand All @@ -42,32 +41,33 @@ public void gotoActionPerformed(@NotNull AnActionEvent anactionevent) {

final Project project = anactionevent.getData(PlatformDataKeys.PROJECT);
Editor editor = anactionevent.getData(PlatformDataKeys.EDITOR);
if(editor == null || project == null) return;
if (editor == null || project == null) return;

PsiFile file = PsiUtilBase.getPsiFileInEditor(editor, project);
if(!(file instanceof PsiJavaFile)) return; // not a Java file
if (!(file instanceof PsiJavaFile)) return; // not a Java file

JavaPsiFacade facade = JavaPsiFacade.getInstance(project);

// from which class are we invoked?
PsiElement e = PsiUtilBase.getElementAtOffset(file, editor.getCaretModel().getOffset());
PsiElement e =
PsiUtilBase.getElementAtOffset(file, editor.getCaretModel().getOffset());
PsiClass clazz = PsiTreeUtil.getParentOfType(e, PsiClass.class);

// if we are invoked from inside anonymous class, go up the tree
// until we find a named class.
while(clazz!=null && clazz.getQualifiedName()==null)
clazz = PsiTreeUtil.getParentOfType(clazz,PsiClass.class);
while (clazz != null && clazz.getQualifiedName() == null)
clazz = PsiTreeUtil.getParentOfType(clazz, PsiClass.class);

// build up packages that contain jelly views, in the order of preference
// through inheritance hierarchy of the class
final List<PsiPackage> viewPackages = new ArrayList<>();
while(clazz!=null) {
while (clazz != null) {
PsiPackage pkg = facade.findPackage(clazz.getQualifiedName());
if(pkg!=null) viewPackages.add(pkg);
if (pkg != null) viewPackages.add(pkg);
clazz = clazz.getSuperClass();
}

if(viewPackages.isEmpty()) return; // no views
if (viewPackages.isEmpty()) return; // no views

ChooseByNameModel model = new ChooseByNameModel() {
@Override
Expand All @@ -92,7 +92,7 @@ public String getPromptText() {

@Override
public String getCheckBoxName() {
return null; // no check box
return null; // no check box
}

@Override
Expand Down Expand Up @@ -120,8 +120,8 @@ public void saveInitialCheckBoxState(boolean state) {
for (PsiDirectory dir : pkg.getDirectories()) {
for (PsiFile file : dir.getFiles()) {
String name = file.getName();
if(name.endsWith(".jelly") || name.endsWith(".groovy"))
r.add(name.substring(0,name.lastIndexOf('.')));
if (name.endsWith(".jelly") || name.endsWith(".groovy"))
r.add(name.substring(0, name.lastIndexOf('.')));
}
}
}
Expand All @@ -130,12 +130,13 @@ public void saveInitialCheckBoxState(boolean state) {

@Override
@NotNull
public Object @NotNull [] getElementsByName(@NotNull String name, boolean checkBoxState, @NotNull String pattern) {
public Object @NotNull [] getElementsByName(
@NotNull String name, boolean checkBoxState, @NotNull String pattern) {
for (PsiPackage pkg : viewPackages) {
for (PsiDirectory dir : pkg.getDirectories()) {
for (PsiFile file : dir.getFiles()) {
if(file.getName().equals(name+".jelly") || file.getName().equals(name+".groovy"))
return new Object[]{file};
if (file.getName().equals(name + ".jelly")
|| file.getName().equals(name + ".groovy")) return new Object[] {file};
}
}
}
Expand Down Expand Up @@ -179,20 +180,20 @@ public boolean willOpenEditor() {
};

PsiDocumentManager.getInstance(project).commitAllDocuments();
ChooseByNamePopup choosebynamepopup = ChooseByNamePopup.createPopup(project,
model, context);
choosebynamepopup.invoke(new Callback() {
@Override
public void onClose() {
if (GotoActionBase.myInAction==GotoViewAction.class)
GotoActionBase.myInAction = null;
}
ChooseByNamePopup choosebynamepopup = ChooseByNamePopup.createPopup(project, model, context);
choosebynamepopup.invoke(
new Callback() {
@Override
public void onClose() {
if (GotoActionBase.myInAction == GotoViewAction.class) GotoActionBase.myInAction = null;
}

@Override
public void elementChosen(Object obj) {
((NavigationItem) obj).navigate(true);
}
}, ModalityState.current(), true);
@Override
public void elementChosen(Object obj) {
((NavigationItem) obj).navigate(true);
}
},
ModalityState.current(),
true);
}
}

14 changes: 8 additions & 6 deletions src/main/java/org/kohsuke/stapler/idea/I18nInspection.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,18 @@
import com.intellij.codeInspection.ProblemHighlightType;
import com.intellij.psi.xml.XmlText;

/**
* @author Kohsuke Kawaguchi
*/
/** @author Kohsuke Kawaguchi */
public class I18nInspection extends LocalXmlInspectionTool {
@Override
protected ProblemDescriptor[] checkXmlText(XmlText text, InspectionManager manager, boolean onTheFly) {
if(text.getText().equals("foo")) {
if (text.getText().equals("foo")) {
return new ProblemDescriptor[] {
manager.createProblemDescriptor(text,"Can't be foo", onTheFly, LocalQuickFix.EMPTY_ARRAY,
ProblemHighlightType.GENERIC_ERROR_OR_WARNING )
manager.createProblemDescriptor(
text,
"Can't be foo",
onTheFly,
LocalQuickFix.EMPTY_ARRAY,
ProblemHighlightType.GENERIC_ERROR_OR_WARNING)
};
}
return EMPTY_ARRAY;
Expand Down
Loading

0 comments on commit 53e90d5

Please sign in to comment.