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);
}
}
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);
}
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;
}
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;
}
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);
}
Aggregations