Search in sources :

Example 1 with Nls

use of org.jetbrains.annotations.Nls in project Main by SpartanRefactoring.

the class SpartanizerAnnotator method annotate.

@Override
public void annotate(@NotNull final PsiElement e, @NotNull AnnotationHolder h) {
    try {
        if (!Spartanizer.canTip(e) || e.getContainingFile().getName().contains("Spartanizer"))
            return;
        Annotation annotation = h.createInfoAnnotation(e, "Spartanize This!");
        annotation.registerFix(new IntentionAction() {

            @SuppressWarnings("unchecked")
            @Nls
            @NotNull
            @Override
            public String getText() {
                return Toolbox.getInstance().getTipper(e).description(e);
            }

            @Nls
            @NotNull
            @Override
            public String getFamilyName() {
                return "SpartanizerAction";
            }

            @Override
            public boolean isAvailable(@NotNull Project __, Editor e, PsiFile f) {
                return true;
            }

            @Override
            public void invoke(@NotNull Project p, Editor ed, PsiFile f) throws IncorrectOperationException {
                Spartanizer.spartanizeElement(e);
            }

            @Override
            public boolean startInWriteAction() {
                return false;
            }
        });
        TextAttributesKey.createTextAttributesKey("");
        annotation.setEnforcedTextAttributes((new TextAttributes(null, null, JBColor.BLUE, EffectType.WAVE_UNDERSCORE, 0)));
    } catch (Throwable t) {
        Logger l = new Logger(this.getClass());
        l.error("", t);
    }
}
Also used : Logger(il.org.spartan.Leonidas.plugin.utils.logging.Logger) NotNull(org.jetbrains.annotations.NotNull) Annotation(com.intellij.lang.annotation.Annotation) Project(com.intellij.openapi.project.Project) Nls(org.jetbrains.annotations.Nls) IntentionAction(com.intellij.codeInsight.intention.IntentionAction) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) PsiFile(com.intellij.psi.PsiFile) IncorrectOperationException(com.intellij.util.IncorrectOperationException) Editor(com.intellij.openapi.editor.Editor)

Example 2 with Nls

use of org.jetbrains.annotations.Nls in project intellij-community by JetBrains.

the class AnnotateCapitalizationIntention method invoke.

@Override
public void invoke(@NotNull final Project project, final Editor editor, final PsiFile file) throws IncorrectOperationException {
    final PsiModifierListOwner modifierListOwner = getElement(editor, file);
    if (modifierListOwner == null)
        throw new IncorrectOperationException();
    BaseListPopupStep<Nls.Capitalization> step = new BaseListPopupStep<Nls.Capitalization>(null, Nls.Capitalization.Title, Nls.Capitalization.Sentence) {

        @Override
        public PopupStep onChosen(final Nls.Capitalization selectedValue, boolean finalChoice) {
            new WriteCommandAction.Simple(project) {

                @Override
                protected void run() throws Throwable {
                    String nls = Nls.class.getName();
                    PsiAnnotation annotation = JavaPsiFacade.getInstance(project).getElementFactory().createAnnotationFromText("@" + nls + "(capitalization = " + nls + ".Capitalization." + selectedValue.toString() + ")", modifierListOwner);
                    new AddAnnotationFix(Nls.class.getName(), modifierListOwner, annotation.getParameterList().getAttributes()).applyFix();
                }
            }.execute();
            return FINAL_CHOICE;
        }
    };
    JBPopupFactory.getInstance().createListPopup(step).showInBestPositionFor(editor);
}
Also used : WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) Nls(org.jetbrains.annotations.Nls) BaseListPopupStep(com.intellij.openapi.ui.popup.util.BaseListPopupStep) IncorrectOperationException(com.intellij.util.IncorrectOperationException) AddAnnotationFix(com.intellij.codeInsight.intention.AddAnnotationFix)

Example 3 with Nls

use of org.jetbrains.annotations.Nls in project intellij-community by JetBrains.

the class DetectionExcludesConfigurable method createComponent.

@Nls
@Override
@NotNull
public JComponent createComponent() {
    myEnabledDetectionCheckBox = new JCheckBox("Enable framework detection");
    myEnabledDetectionCheckBox.setBorder(new EmptyBorder(10, 10, 0, 0));
    final JBList excludesList = new JBList(myModel);
    final ColoredListCellRenderer renderer = new ColoredListCellRenderer() {

        JPanel panel = new JPanel(new BorderLayout());

        {
            panel.setBorder(new EmptyBorder(2, 10, 2, 0));
            panel.add(this);
        }

        @Override
        protected void customizeCellRenderer(@NotNull JList list, Object value, int index, boolean selected, boolean hasFocus) {
            setIconTextGap(4);
            if (value instanceof ExcludeListItem) {
                ((ExcludeListItem) value).renderItem(this);
                setBorder(new EmptyBorder(0, 10, 0, 0));
            }
        }

        @Override
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean selected, boolean hasFocus) {
            super.getListCellRendererComponent(list, value, index, selected, hasFocus);
            panel.setBackground(UIUtil.getListBackground(selected));
            return panel;
        }
    };
    renderer.setMyBorder(new EmptyBorder(0, 0, 0, 0));
    excludesList.setCellRenderer(renderer);
    final ToolbarDecorator decorator = ToolbarDecorator.createDecorator(excludesList).disableUpAction().disableDownAction().setAddAction(new AnActionButtonRunnable() {

        @Override
        public void run(AnActionButton button) {
            doAddAction(button);
        }
    });
    decorator.setPanelBorder(new CustomLineBorder(1, 0, 0, 0));
    myMainPanel = new JPanel(new BorderLayout(0, 5));
    myMainPanel.add(myEnabledDetectionCheckBox, BorderLayout.NORTH);
    final LabeledComponent<JPanel> excludesComponent = LabeledComponent.create(decorator.createPanel(), "   Exclude from detection:");
    myMainPanel.add(excludesComponent);
    myEnabledDetectionCheckBox.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            GuiUtils.enableChildren(myEnabledDetectionCheckBox.isSelected(), excludesComponent);
        }
    });
    myEnabledDetectionCheckBox.setSelected(true);
    return myMainPanel;
}
Also used : ActionEvent(java.awt.event.ActionEvent) NotNull(org.jetbrains.annotations.NotNull) CustomLineBorder(com.intellij.ui.border.CustomLineBorder) ActionListener(java.awt.event.ActionListener) JBList(com.intellij.ui.components.JBList) EmptyBorder(javax.swing.border.EmptyBorder) Nls(org.jetbrains.annotations.Nls) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with Nls

use of org.jetbrains.annotations.Nls in project intellij-community by JetBrains.

the class GenerateGetterSetterHandlerBase method getHeaderPanel.

protected static JComponent getHeaderPanel(final Project project, final TemplatesManager templatesManager, final String templatesTitle) {
    final JPanel panel = new JPanel(new BorderLayout());
    final JLabel templateChooserLabel = new JLabel(templatesTitle);
    panel.add(templateChooserLabel, BorderLayout.WEST);
    final ComboBox comboBox = new ComboBox();
    templateChooserLabel.setLabelFor(comboBox);
    comboBox.setRenderer(new ListCellRendererWrapper<TemplateResource>() {

        @Override
        public void customize(JList list, TemplateResource value, int index, boolean selected, boolean hasFocus) {
            setText(value.getName());
        }
    });
    final ComponentWithBrowseButton<ComboBox> comboBoxWithBrowseButton = new ComponentWithBrowseButton<>(comboBox, new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            final TemplatesPanel ui = new TemplatesPanel(project, templatesManager) {

                @Override
                protected boolean onMultipleFields() {
                    return false;
                }

                @Nls
                @Override
                public String getDisplayName() {
                    return StringUtil.capitalizeWords(UIUtil.removeMnemonic(StringUtil.trimEnd(templatesTitle, ":")), true);
                }
            };
            ui.setHint("Visibility is applied according to File | Settings | Editor | Code Style | Java | Code Generation");
            ui.selectNodeInTree(templatesManager.getDefaultTemplate());
            if (ShowSettingsUtil.getInstance().editConfigurable(panel, ui)) {
                setComboboxModel(templatesManager, comboBox);
            }
        }
    });
    setComboboxModel(templatesManager, comboBox);
    comboBox.addActionListener(new ActionListener() {

        public void actionPerformed(@NotNull final ActionEvent M) {
            templatesManager.setDefaultTemplate((TemplateResource) comboBox.getSelectedItem());
        }
    });
    panel.add(comboBoxWithBrowseButton, BorderLayout.CENTER);
    return panel;
}
Also used : ComboBox(com.intellij.openapi.ui.ComboBox) ActionEvent(java.awt.event.ActionEvent) TemplatesPanel(org.jetbrains.java.generate.view.TemplatesPanel) ActionListener(java.awt.event.ActionListener) Nls(org.jetbrains.annotations.Nls) ComponentWithBrowseButton(com.intellij.openapi.ui.ComponentWithBrowseButton) TemplateResource(org.jetbrains.java.generate.template.TemplateResource)

Example 5 with Nls

use of org.jetbrains.annotations.Nls in project intellij-community by JetBrains.

the class HighlightSeverityTest method testErrorLikeUnusedSymbol.

public void testErrorLikeUnusedSymbol() throws Exception {
    enableInspectionTool(new LocalInspectionTool() {

        @NotNull
        @Override
        public String getShortName() {
            return getDisplayName();
        }

        @NotNull
        @Override
        public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly, @NotNull LocalInspectionToolSession session) {
            return new JavaElementVisitor() {

                @Override
                public void visitIdentifier(PsiIdentifier identifier) {
                    if (identifier.getText().equals("k")) {
                        holder.registerProblem(identifier, "Variable 'k' is never used");
                    }
                }
            };
        }

        @NotNull
        @Override
        public HighlightDisplayLevel getDefaultLevel() {
            return HighlightDisplayLevel.ERROR;
        }

        @Nls
        @NotNull
        @Override
        public String getDisplayName() {
            return "x";
        }

        @Nls
        @NotNull
        @Override
        public String getGroupDisplayName() {
            return getDisplayName();
        }
    });
    doTest(BASE_PATH + "/" + getTestName(false) + ".java", true, false);
}
Also used : HighlightDisplayLevel(com.intellij.codeHighlighting.HighlightDisplayLevel) JavaElementVisitor(com.intellij.psi.JavaElementVisitor) Nls(org.jetbrains.annotations.Nls) NonNls(org.jetbrains.annotations.NonNls) LocalInspectionToolSession(com.intellij.codeInspection.LocalInspectionToolSession) PsiIdentifier(com.intellij.psi.PsiIdentifier) PsiElementVisitor(com.intellij.psi.PsiElementVisitor) LocalInspectionTool(com.intellij.codeInspection.LocalInspectionTool) NotNull(org.jetbrains.annotations.NotNull) ProblemsHolder(com.intellij.codeInspection.ProblemsHolder)

Aggregations

Nls (org.jetbrains.annotations.Nls)5 NotNull (org.jetbrains.annotations.NotNull)3 IncorrectOperationException (com.intellij.util.IncorrectOperationException)2 ActionEvent (java.awt.event.ActionEvent)2 ActionListener (java.awt.event.ActionListener)2 HighlightDisplayLevel (com.intellij.codeHighlighting.HighlightDisplayLevel)1 AddAnnotationFix (com.intellij.codeInsight.intention.AddAnnotationFix)1 IntentionAction (com.intellij.codeInsight.intention.IntentionAction)1 LocalInspectionTool (com.intellij.codeInspection.LocalInspectionTool)1 LocalInspectionToolSession (com.intellij.codeInspection.LocalInspectionToolSession)1 ProblemsHolder (com.intellij.codeInspection.ProblemsHolder)1 Annotation (com.intellij.lang.annotation.Annotation)1 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)1 Editor (com.intellij.openapi.editor.Editor)1 TextAttributes (com.intellij.openapi.editor.markup.TextAttributes)1 Project (com.intellij.openapi.project.Project)1 ComboBox (com.intellij.openapi.ui.ComboBox)1 ComponentWithBrowseButton (com.intellij.openapi.ui.ComponentWithBrowseButton)1 BaseListPopupStep (com.intellij.openapi.ui.popup.util.BaseListPopupStep)1 JavaElementVisitor (com.intellij.psi.JavaElementVisitor)1