Search in sources :

Example 1 with PerlVersion

use of com.perl5.lang.perl.internals.PerlVersion in project Perl5-IDEA by Camelcade.

the class PerlVersionUnitTest method testParsing.

public void testParsing() {
    // double constructor
    double doubleVersion = 5.008006;
    processTest(new PerlVersion(doubleVersion), true, true, false, 5, 8, 6, doubleVersion, "v5.8.6");
    doubleVersion = 5;
    processTest(new PerlVersion(doubleVersion), true, true, false, 5, 0, 0, doubleVersion, "v5");
    doubleVersion = 5.1;
    processTest(new PerlVersion(doubleVersion), true, true, false, 5, 100, 0, doubleVersion, "v5.100");
    doubleVersion = 5.0001;
    processTest(new PerlVersion(doubleVersion), true, true, false, 5, 0, 100, doubleVersion, "v5.0.100");
    doubleVersion = -1;
    processTest(new PerlVersion(doubleVersion), false, true, false, 0, 0, 0, 0, "v0");
    processTest(new PerlVersion("1.00"), true, true, false, 1, 0, 0, 1, "v1");
    processTest(new PerlVersion("1000000000000000000000000000000000000000000000000000000000.00"), false, false, false, 0, 0, 0, 0, "v0");
    processTest(new PerlVersion("1.00001"), true, true, false, 1, 0, 10, 1.00001, "v1.0.10");
    processTest(new PerlVersion("0.123"), true, true, false, 0, 123, 0, 0.123, "v0.123");
    processTest(new PerlVersion("12.345"), true, true, false, 12, 345, 0, 12.345, "v12.345");
    processTest(new PerlVersion("12.34_5"), true, false, true, 12, 345, 0, 12.345, "v12.345");
    processTest(new PerlVersion("42"), true, true, false, 42, 0, 0, 42, "v42");
    processTest(new PerlVersion("0"), true, true, false, 0, 0, 0, 0, "v0");
    processTest(new PerlVersion("0.0"), true, true, false, 0, 0, 0, 0, "v0");
    processTest(new PerlVersion("v1.2.3"), true, true, false, 1, 2, 3, 1.002003, "v1.2.3");
    processTest(new PerlVersion("v1.2.3.4"), true, true, false, 1, 2, 3, 1.002003004, "v1.2.3.4");
    processTest(new PerlVersion("v1.2.3.4.5"), true, true, false, 1, 2, 3, 1.002003004005, "v1.2.3.4.5");
    processTest(new PerlVersion("v0.1.2"), true, true, false, 0, 1, 2, 0.001002, "v0.1.2");
    processTest(new PerlVersion("v0.0.0"), true, true, false, 0, 0, 0, 0, "v0");
    processTest(new PerlVersion("01"), false, false, false, 0, 0, 0, 0, "v0");
    processTest(new PerlVersion("01.0203"), false, false, false, 0, 0, 0, 0, "v0");
    processTest(new PerlVersion("v01"), false, false, false, 0, 0, 0, 0, "v0");
    processTest(new PerlVersion("v01.02.03"), false, false, false, 0, 0, 0, 0, "v0");
    processTest(new PerlVersion(".1"), false, false, false, 0, 0, 0, 0, "v0");
    processTest(new PerlVersion(".1.2"), false, false, false, 0, 0, 0, 0, "v0");
    processTest(new PerlVersion("1."), false, false, false, 0, 0, 0, 0, "v0");
    processTest(new PerlVersion("1.a"), false, false, false, 0, 0, 0, 0, "v0");
    processTest(new PerlVersion("1._"), true, false, true, 1, 0, 0, 1, "v1");
    processTest(new PerlVersion("1.02_03"), true, false, true, 1, 20, 300, 1.020300, "v1.20.300");
    processTest(new PerlVersion("v1.2_3"), true, false, true, 1, 2, 3, 1.002003, "v1.2.3");
    processTest(new PerlVersion("v1.02_03"), true, false, true, 1, 2, 3, 1.002003, "v1.2.3");
    processTest(new PerlVersion("v1.2_3_4"), false, false, false, 0, 0, 0, 0, "v0");
    processTest(new PerlVersion("v1.2_3.4"), false, false, false, 0, 0, 0, 0, "v0");
    processTest(new PerlVersion("1.2_3.4"), false, false, false, 0, 0, 0, 0, "v0");
    processTest(new PerlVersion("0_"), false, false, false, 0, 0, 0, 0, "v0");
    processTest(new PerlVersion("1_"), false, false, false, 0, 0, 0, 0, "v0");
    processTest(new PerlVersion("1_."), false, false, false, 0, 0, 0, 0, "v0");
    processTest(new PerlVersion("1.1_"), true, false, true, 1, 100, 0, 1.1, "v1.100");
    processTest(new PerlVersion("1.02_03_04"), true, false, true, 1, 20, 304, 1.020304, "v1.20.304");
    processTest(new PerlVersion("1.2.3"), false, false, false, 0, 0, 0, 0, "v0");
    processTest(new PerlVersion("v1.2"), true, false, false, 1, 2, 0, 1.002, "v1.2");
    processTest(new PerlVersion("v0"), true, false, false, 0, 0, 0, 0, "v0");
    processTest(new PerlVersion("v1"), true, false, false, 1, 0, 0, 1, "v1");
    processTest(new PerlVersion("v.1.2.3"), false, false, false, 0, 0, 0, 0, "v0");
    processTest(new PerlVersion("v"), false, false, false, 0, 0, 0, 0, "v0");
    processTest(new PerlVersion("v1.2345.6"), false, false, false, 0, 0, 0, 0, "v0");
    processTest(new PerlVersion("undef"), false, false, false, 0, 0, 0, 0, "v0");
    processTest(new PerlVersion("1a"), false, false, false, 0, 0, 0, 0, "v0");
    processTest(new PerlVersion("1.2a3"), false, false, false, 0, 0, 0, 0, "v0");
    processTest(new PerlVersion("bar"), false, false, false, 0, 0, 0, 0, "v0");
    processTest(new PerlVersion("_"), false, false, false, 0, 0, 0, 0, "v0");
}
Also used : PerlVersion(com.perl5.lang.perl.internals.PerlVersion)

Example 2 with PerlVersion

use of com.perl5.lang.perl.internals.PerlVersion in project Perl5-IDEA by Camelcade.

the class PerlVersionUnitTest method testComparable.

public void testComparable() {
    PerlVersion version510 = new PerlVersion("v5.10");
    PerlVersion version510x = new PerlVersion("v5.10");
    PerlVersion version514 = new PerlVersion("v5.14");
    assertEquals(version514.compareTo(version510), 1);
    assertEquals(version510.compareTo(version510), 0);
    assertEquals(version510.compareTo(version514), -1);
    assertTrue(version514.greaterThan(version510));
    assertTrue(version510.equals(version510));
    assertTrue(version510.equals(version510x));
    assertTrue(version510.lesserThan(version514));
    assertFalse(version514.lesserThan(version510));
    assertFalse(version510.equals(version514));
    assertFalse(version510.greaterThan(version514));
}
Also used : PerlVersion(com.perl5.lang.perl.internals.PerlVersion)

Example 3 with PerlVersion

use of com.perl5.lang.perl.internals.PerlVersion in project Perl5-IDEA by Camelcade.

the class Perl5ProjectConfigurable method createComponent.

@Nullable
@Override
public JComponent createComponent() {
    FormBuilder builder = FormBuilder.createFormBuilder();
    builder.getPanel().setLayout(new VerticalFlowLayout());
    builder.addComponent(myPerl5SdkConfigurable.createComponent());
    FormBuilder versionBuilder = FormBuilder.createFormBuilder();
    ComboBoxModel<PerlVersion> versionModel = new CollectionComboBoxModel<>(PerlVersion.ALL_VERSIONS);
    myTargetPerlVersionComboBox = new ComboBox<>(versionModel);
    myTargetPerlVersionComboBox.setRenderer(new ColoredListCellRenderer<PerlVersion>() {

        @Override
        protected void customizeCellRenderer(@NotNull JList<? extends PerlVersion> list, PerlVersion value, int index, boolean selected, boolean hasFocus) {
            append(value.getStrictDottedVersion());
            String versionDescription = PerlVersion.PERL_VERSION_DESCRIPTIONS.get(value);
            if (StringUtil.isNotEmpty(versionDescription)) {
                append(" (" + versionDescription + ")");
            }
        }
    });
    versionBuilder.addLabeledComponent(PerlBundle.message("perl.config.language.level"), myTargetPerlVersionComboBox);
    builder.addComponent(versionBuilder.getPanel());
    myLibsModel = new CollectionListModel<>();
    myLibsList = new JBList<>(myLibsModel);
    myLibsList.setVisibleRowCount(ourRowsCount);
    myLibsList.setCellRenderer(new ColoredListCellRenderer<VirtualFile>() {

        @Override
        protected void customizeCellRenderer(@NotNull JList<? extends VirtualFile> list, VirtualFile value, int index, boolean selected, boolean hasFocus) {
            setIcon(PerlIcons.PERL_LANGUAGE_ICON);
            append(FileUtil.toSystemDependentName(value.getPath()));
        }
    });
    builder.addLabeledComponent(PerlBundle.message("perl.settings.external.libs"), ToolbarDecorator.createDecorator(myLibsList).setAddAction(this::doAddExternalLibrary).createPanel());
    simpleMainCheckbox = new JCheckBox(PerlBundle.message("perl.config.simple.main"));
    builder.addComponent(simpleMainCheckbox);
    autoInjectionCheckbox = new JCheckBox(PerlBundle.message("perl.config.heredoc.injections"));
    builder.addComponent(autoInjectionCheckbox);
    allowInjectionWithInterpolation = new JCheckBox(PerlBundle.message("perl.config.heredoc.injections.qq"));
    builder.addComponent(allowInjectionWithInterpolation);
    allowRegexpInjections = new JCheckBox(PerlBundle.message("perl.config.regex.injections"));
    builder.addComponent(allowRegexpInjections);
    allowRegexpInjections.setEnabled(false);
    allowRegexpInjections.setVisible(false);
    perlAnnotatorCheckBox = new JCheckBox(PerlBundle.message("perl.config.annotations.cw"));
    // builder.addComponent(perlAnnotatorCheckBox);
    perlCriticCheckBox = new JCheckBox(PerlBundle.message("perl.config.annotations.critic"));
    builder.addComponent(perlCriticCheckBox);
    enablePerlSwitchCheckbox = new JCheckBox(PerlBundle.message("perl.config.enable.switch"));
    builder.addComponent(enablePerlSwitchCheckbox);
    perlCriticPathInputField = new TextFieldWithBrowseButton();
    perlCriticPathInputField.setEditable(false);
    FileChooserDescriptor perlCriticDescriptor = new FileChooserDescriptor(true, false, false, false, false, false) {

        @Override
        public boolean isFileVisible(VirtualFile file, boolean showHiddenFiles) {
            return super.isFileVisible(file, showHiddenFiles) && (file.isDirectory() || StringUtil.equals(file.getNameWithoutExtension(), PerlCriticAnnotator.PERL_CRITIC_LINUX_NAME));
        }
    };
    // noinspection DialogTitleCapitalization
    perlCriticPathInputField.addBrowseFolderListener(PerlBundle.message("perl.config.select.file.title"), PerlBundle.message("perl.config.select.critic"), // project
    null, perlCriticDescriptor);
    builder.addLabeledComponent(new JLabel(PerlBundle.message("perl.config.path.critic")), perlCriticPathInputField);
    perlCriticArgsInputField = new RawCommandLineEditor();
    builder.addComponent(copyDialogCaption(LabeledComponent.create(perlCriticArgsInputField, PerlBundle.message("perl.config.critic.cmd.arguments")), PerlBundle.message("perl.config.critic.cmd.arguments")));
    perlTidyPathInputField = new TextFieldWithBrowseButton();
    perlTidyPathInputField.setEditable(false);
    FileChooserDescriptor perlTidyDescriptor = new FileChooserDescriptor(true, false, false, false, false, false) {

        @Override
        public boolean isFileVisible(VirtualFile file, boolean showHiddenFiles) {
            return super.isFileVisible(file, showHiddenFiles) && (file.isDirectory() || StringUtil.equals(file.getNameWithoutExtension(), PerlFormatWithPerlTidyAction.PERL_TIDY_LINUX_NAME));
        }
    };
    // noinspection DialogTitleCapitalization
    perlTidyPathInputField.addBrowseFolderListener(PerlBundle.message("perl.config.select.file.title"), PerlBundle.message("perl.config.select.tidy"), // project
    null, perlTidyDescriptor);
    builder.addLabeledComponent(new JLabel(PerlBundle.message("perl.config.path.tidy")), perlTidyPathInputField);
    perlTidyArgsInputField = new RawCommandLineEditor();
    builder.addComponent(copyDialogCaption(LabeledComponent.create(perlTidyArgsInputField, PerlBundle.message("perl.config.tidy.options.label")), PerlBundle.message("perl.config.tidy.options.label.short")));
    deparseArgumentsTextField = new JTextField();
    builder.addLabeledComponent(PerlBundle.message("perl.config.deparse.options.label"), deparseArgumentsTextField);
    selfNamesModel = new CollectionListModel<>();
    JBList selfNamesList = new JBList<>(selfNamesModel);
    selfNamesList.setVisibleRowCount(ourRowsCount);
    builder.addLabeledComponent(new JLabel(PerlBundle.message("perl.config.self.names.label")), ToolbarDecorator.createDecorator(selfNamesList).setAddAction(anActionButton -> {
        String variableName = Messages.showInputDialog(myProject, PerlBundle.message("perl.config.self.add.text"), PerlBundle.message("perl.config.self.add.title"), Messages.getQuestionIcon(), "", null);
        if (StringUtil.isNotEmpty(variableName)) {
            while (variableName.startsWith("$")) {
                variableName = variableName.substring(1);
            }
            if (StringUtil.isNotEmpty(variableName) && !selfNamesModel.getItems().contains(variableName)) {
                selfNamesModel.add(variableName);
            }
        }
    }).createPanel());
    JBScrollPane scrollPane = new JBScrollPane(builder.getPanel(), ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    scrollPane.setBorder(new JBEmptyBorder(JBUI.emptyInsets()));
    return scrollPane;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) JBEmptyBorder(com.intellij.util.ui.JBEmptyBorder) PerlVersion(com.perl5.lang.perl.internals.PerlVersion) FormBuilder(com.intellij.util.ui.FormBuilder) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) JBList(com.intellij.ui.components.JBList) JBScrollPane(com.intellij.ui.components.JBScrollPane) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

PerlVersion (com.perl5.lang.perl.internals.PerlVersion)3 FileChooserDescriptor (com.intellij.openapi.fileChooser.FileChooserDescriptor)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 JBList (com.intellij.ui.components.JBList)1 JBScrollPane (com.intellij.ui.components.JBScrollPane)1 FormBuilder (com.intellij.util.ui.FormBuilder)1 JBEmptyBorder (com.intellij.util.ui.JBEmptyBorder)1 Nullable (org.jetbrains.annotations.Nullable)1