1.1 --- a/javahints/nbproject/project.properties Mon Oct 17 12:36:04 2011 -0400
1.2 +++ b/javahints/nbproject/project.properties Thu Oct 27 14:18:11 2011 +0200
1.3 @@ -50,7 +50,7 @@
1.4 auxiliary.org-netbeans-modules-editor-indent.text.x-java.CodeStyle.project.text-limit-width=80
1.5 javac.compilerargs=-Xlint:unchecked
1.6 javac.source=1.5
1.7 -spec.version.base=2.45.0
1.8 +spec.version.base=2.46.0
1.9
1.10 nbm.needs.restart=true
1.11 requires.nb.javac=true
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/javahints/src/org/netbeans/modules/javahints/jdk/AddUnderscores.java Thu Oct 27 14:18:11 2011 +0200
2.3 @@ -0,0 +1,180 @@
2.4 +/*
2.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
2.6 + *
2.7 + * Copyright 2011 Oracle and/or its affiliates. All rights reserved.
2.8 + *
2.9 + * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
2.10 + * Other names may be trademarks of their respective owners.
2.11 + *
2.12 + * The contents of this file are subject to the terms of either the GNU
2.13 + * General Public License Version 2 only ("GPL") or the Common
2.14 + * Development and Distribution License("CDDL") (collectively, the
2.15 + * "License"). You may not use this file except in compliance with the
2.16 + * License. You can obtain a copy of the License at
2.17 + * http://www.netbeans.org/cddl-gplv2.html
2.18 + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
2.19 + * specific language governing permissions and limitations under the
2.20 + * License. When distributing the software, include this License Header
2.21 + * Notice in each file and include the License file at
2.22 + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
2.23 + * particular file as subject to the "Classpath" exception as provided
2.24 + * by Oracle in the GPL Version 2 section of the License file that
2.25 + * accompanied this code. If applicable, add the following below the
2.26 + * License Header, with the fields enclosed by brackets [] replaced by
2.27 + * your own identifying information:
2.28 + * "Portions Copyrighted [year] [name of copyright owner]"
2.29 + *
2.30 + * If you wish your version of this file to be governed by only the CDDL
2.31 + * or only the GPL Version 2, indicate your decision by adding
2.32 + * "[Contributor] elects to include this software in this distribution
2.33 + * under the [CDDL or GPL Version 2] license." If you do not indicate a
2.34 + * single choice of license, a recipient has the option to distribute
2.35 + * your version of this file under either the CDDL, the GPL Version 2 or
2.36 + * to extend the choice of license to its licensees as provided above.
2.37 + * However, if you add GPL Version 2 code and therefore, elected the GPL
2.38 + * Version 2 license, then the option applies only if the new code is
2.39 + * made subject to such option by the copyright holder.
2.40 + *
2.41 + * Contributor(s):
2.42 + *
2.43 + * Portions Copyrighted 2011 Sun Microsystems, Inc.
2.44 + */
2.45 +package org.netbeans.modules.javahints.jdk;
2.46 +
2.47 +import com.sun.source.tree.LiteralTree;
2.48 +import com.sun.source.tree.Tree.Kind;
2.49 +import com.sun.source.util.TreePath;
2.50 +import java.util.prefs.Preferences;
2.51 +import java.util.regex.Pattern;
2.52 +import javax.lang.model.SourceVersion;
2.53 +import javax.swing.JComponent;
2.54 +import org.netbeans.api.java.source.CompilationInfo;
2.55 +import org.netbeans.api.java.source.WorkingCopy;
2.56 +import org.netbeans.modules.java.hints.errors.Utilities;
2.57 +import org.netbeans.modules.java.hints.errors.Utilities.RadixInfo;
2.58 +import org.netbeans.modules.java.hints.jackpot.code.spi.Hint;
2.59 +import org.netbeans.modules.java.hints.jackpot.code.spi.TriggerTreeKind;
2.60 +import org.netbeans.modules.java.hints.jackpot.spi.CustomizerProvider;
2.61 +import org.netbeans.modules.java.hints.jackpot.spi.HintContext;
2.62 +import org.netbeans.modules.java.hints.jackpot.spi.JavaFix;
2.63 +import org.netbeans.modules.java.hints.jackpot.spi.support.ErrorDescriptionFactory;
2.64 +import org.netbeans.modules.javahints.jdk.AddUnderscores.CustomizerProviderImpl;
2.65 +import org.netbeans.modules.java.hints.spi.AbstractHint.HintSeverity;
2.66 +import org.netbeans.spi.editor.hints.ErrorDescription;
2.67 +import org.netbeans.spi.editor.hints.Fix;
2.68 +import org.openide.util.NbBundle;
2.69 +
2.70 +/**
2.71 + *
2.72 + * @author lahvac
2.73 + */
2.74 +@Hint(id=AddUnderscores.ID, category="rules15", enabled=false, severity=HintSeverity.CURRENT_LINE_WARNING, customizerProvider=CustomizerProviderImpl.class)
2.75 +public class AddUnderscores {
2.76 + public static final String ID = "org.netbeans.modules.javahints.jdk.AddUnderscores";
2.77 +
2.78 + @TriggerTreeKind({Kind.INT_LITERAL, Kind.LONG_LITERAL})
2.79 + public static ErrorDescription hint(HintContext ctx) {
2.80 + if (ctx.getInfo().getSourceVersion().compareTo(SourceVersion.RELEASE_7) < 0) return null;
2.81 +
2.82 + TreePath tp = ctx.getPath();
2.83 + int start = (int) ctx.getInfo().getTrees().getSourcePositions().getStartPosition(tp.getCompilationUnit(), tp.getLeaf());
2.84 + int end = (int) ctx.getInfo().getTrees().getSourcePositions().getEndPosition(tp.getCompilationUnit(), tp.getLeaf());
2.85 + String literal = ctx.getInfo().getText().substring(start, end);
2.86 + if (!isReplaceLiteralsWithUnderscores(ctx.getPreferences()) && literal.contains("_")) return null;
2.87 + RadixInfo info = Utilities.radixInfo(literal);
2.88 + String normalized = info.constant.replaceAll(Pattern.quote("_"), "");
2.89 + int separateCount = getSizeForRadix(ctx.getPreferences(), info.radix);
2.90 + StringBuilder split = new StringBuilder();
2.91 + int count = separateCount + 1;
2.92 +
2.93 + for (int i = normalized.length(); i > 0; i--) {
2.94 + if (--count == 0) {
2.95 + split.append("_");
2.96 + count = separateCount;
2.97 + }
2.98 + split.append(normalized.charAt(i - 1));
2.99 + }
2.100 +
2.101 + split.reverse();
2.102 +
2.103 + String result = info.prefix + split.toString() + info.suffix;
2.104 +
2.105 + if (result.equals(literal)) return null;
2.106 +
2.107 + String displayName = NbBundle.getMessage(AddUnderscores.class, "ERR_" + ID);
2.108 + Fix f = JavaFix.toEditorFix(new FixImpl(ctx.getInfo(), tp, result));
2.109 +
2.110 + return ErrorDescriptionFactory.forTree(ctx, tp, displayName, f);
2.111 + }
2.112 +
2.113 + private static final String KEY_SIZE_BINARY = "size-binary";
2.114 + private static final String KEY_SIZE_DECIMAL = "size-decimal";
2.115 + private static final String KEY_SIZE_HEXADECIMAL = "size-hexadecimal";
2.116 + private static final String KEY_ALSO_WITH_UNDERSCORES = "also-with-underscores";
2.117 +
2.118 + static int getSizeForRadix(Preferences prefs, int radix) {
2.119 + String key;
2.120 + int def;
2.121 +
2.122 + switch (radix) {
2.123 + case 2: key = KEY_SIZE_BINARY; def = 4; break;
2.124 + case 10: key = KEY_SIZE_DECIMAL; def = 3; break;
2.125 + case 16: key = KEY_SIZE_HEXADECIMAL; def = 4; break;
2.126 + default: throw new IllegalStateException("radix=" + radix);
2.127 + }
2.128 +
2.129 + return prefs.getInt(key, def);
2.130 + }
2.131 +
2.132 + static boolean isReplaceLiteralsWithUnderscores(Preferences prefs) {
2.133 + return prefs.getBoolean(KEY_ALSO_WITH_UNDERSCORES, false);
2.134 + }
2.135 +
2.136 + static void setSizeForRadix(Preferences prefs, int radix, int size) {
2.137 + String key;
2.138 +
2.139 + switch (radix) {
2.140 + case 2: key = KEY_SIZE_BINARY; break;
2.141 + case 10: key = KEY_SIZE_DECIMAL; break;
2.142 + case 16: key = KEY_SIZE_HEXADECIMAL; break;
2.143 + default: throw new IllegalStateException("radix=" + radix);
2.144 + }
2.145 +
2.146 + prefs.putInt(key, size);
2.147 + }
2.148 +
2.149 + static void setReplaceLiteralsWithUnderscores(Preferences prefs, boolean value) {
2.150 + prefs.putBoolean(KEY_ALSO_WITH_UNDERSCORES, value);
2.151 + }
2.152 +
2.153 + private static final class FixImpl extends JavaFix {
2.154 +
2.155 + private final String target;
2.156 +
2.157 + public FixImpl(CompilationInfo info, TreePath tp, String target) {
2.158 + super(info, tp);
2.159 + this.target = target;
2.160 + }
2.161 +
2.162 +
2.163 + @Override
2.164 + protected String getText() {
2.165 + return NbBundle.getMessage(AddUnderscores.class, "FIX_" + ID, target);
2.166 + }
2.167 +
2.168 + @Override
2.169 + protected void performRewrite(WorkingCopy wc, TreePath tp, boolean canShowUI) {
2.170 + wc.rewrite(tp.getLeaf(), wc.getTreeMaker().Identifier(target));
2.171 + }
2.172 +
2.173 + }
2.174 +
2.175 + public static final class CustomizerProviderImpl implements CustomizerProvider {
2.176 +
2.177 + @Override
2.178 + public JComponent getCustomizer(Preferences prefs) {
2.179 + return new AddUnderscoresPanel(prefs);
2.180 + }
2.181 +
2.182 + }
2.183 +}
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/javahints/src/org/netbeans/modules/javahints/jdk/AddUnderscoresPanel.form Thu Oct 27 14:18:11 2011 +0200
3.3 @@ -0,0 +1,114 @@
3.4 +<?xml version="1.0" encoding="UTF-8" ?>
3.5 +
3.6 +<Form version="1.5" maxVersion="1.8" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
3.7 + <AuxValues>
3.8 + <AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="1"/>
3.9 + <AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
3.10 + <AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
3.11 + <AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="true"/>
3.12 + <AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="true"/>
3.13 + <AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
3.14 + <AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
3.15 + <AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
3.16 + <AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
3.17 + </AuxValues>
3.18 +
3.19 + <Layout>
3.20 + <DimensionLayout dim="0">
3.21 + <Group type="103" groupAlignment="0" attributes="0">
3.22 + <Group type="102" attributes="0">
3.23 + <EmptySpace max="-2" attributes="0"/>
3.24 + <Group type="103" groupAlignment="0" attributes="0">
3.25 + <Component id="replaceExisting" alignment="0" min="-2" max="-2" attributes="0"/>
3.26 + <Group type="102" alignment="0" attributes="0">
3.27 + <Group type="103" groupAlignment="0" attributes="0">
3.28 + <Component id="jLabel3" alignment="0" min="-2" max="-2" attributes="0"/>
3.29 + <Component id="jLabel2" alignment="0" min="-2" max="-2" attributes="0"/>
3.30 + <Component id="jLabel1" alignment="0" min="-2" max="-2" attributes="0"/>
3.31 + </Group>
3.32 + <EmptySpace max="-2" attributes="0"/>
3.33 + <Group type="103" groupAlignment="0" attributes="0">
3.34 + <Component id="binary" min="-2" max="-2" attributes="0"/>
3.35 + <Component id="decimal" min="-2" max="-2" attributes="0"/>
3.36 + <Component id="hexa" min="-2" max="-2" attributes="0"/>
3.37 + </Group>
3.38 + </Group>
3.39 + </Group>
3.40 + <EmptySpace max="32767" attributes="0"/>
3.41 + </Group>
3.42 + </Group>
3.43 + </DimensionLayout>
3.44 + <DimensionLayout dim="1">
3.45 + <Group type="103" groupAlignment="0" attributes="0">
3.46 + <Group type="102" alignment="0" attributes="0">
3.47 + <EmptySpace max="-2" attributes="0"/>
3.48 + <Group type="103" groupAlignment="3" attributes="0">
3.49 + <Component id="jLabel1" alignment="3" min="-2" max="-2" attributes="0"/>
3.50 + <Component id="binary" alignment="3" min="-2" max="-2" attributes="0"/>
3.51 + </Group>
3.52 + <EmptySpace type="separate" max="-2" attributes="0"/>
3.53 + <Group type="103" groupAlignment="3" attributes="0">
3.54 + <Component id="jLabel2" alignment="3" min="-2" max="-2" attributes="0"/>
3.55 + <Component id="decimal" alignment="3" min="-2" max="-2" attributes="0"/>
3.56 + </Group>
3.57 + <EmptySpace type="separate" max="-2" attributes="0"/>
3.58 + <Group type="103" groupAlignment="3" attributes="0">
3.59 + <Component id="jLabel3" alignment="3" min="-2" max="-2" attributes="0"/>
3.60 + <Component id="hexa" alignment="3" min="-2" max="-2" attributes="0"/>
3.61 + </Group>
3.62 + <EmptySpace type="separate" max="-2" attributes="0"/>
3.63 + <Component id="replaceExisting" min="-2" max="-2" attributes="0"/>
3.64 + <EmptySpace max="32767" attributes="0"/>
3.65 + </Group>
3.66 + </Group>
3.67 + </DimensionLayout>
3.68 + </Layout>
3.69 + <SubComponents>
3.70 + <Component class="javax.swing.JLabel" name="jLabel1">
3.71 + <Properties>
3.72 + <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
3.73 + <ResourceString bundle="org/netbeans/modules/javahints/jdk/Bundle.properties" key="AddUnderscoresPanel.jLabel1.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, "{key}")"/>
3.74 + </Property>
3.75 + </Properties>
3.76 + </Component>
3.77 + <Component class="javax.swing.JLabel" name="jLabel2">
3.78 + <Properties>
3.79 + <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
3.80 + <ResourceString bundle="org/netbeans/modules/javahints/jdk/Bundle.properties" key="AddUnderscoresPanel.jLabel2.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, "{key}")"/>
3.81 + </Property>
3.82 + </Properties>
3.83 + </Component>
3.84 + <Component class="javax.swing.JLabel" name="jLabel3">
3.85 + <Properties>
3.86 + <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
3.87 + <ResourceString bundle="org/netbeans/modules/javahints/jdk/Bundle.properties" key="AddUnderscoresPanel.jLabel3.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, "{key}")"/>
3.88 + </Property>
3.89 + </Properties>
3.90 + </Component>
3.91 + <Component class="javax.swing.JSpinner" name="binary">
3.92 + <Events>
3.93 + <EventHandler event="stateChanged" listener="javax.swing.event.ChangeListener" parameters="javax.swing.event.ChangeEvent" handler="binaryStateChanged"/>
3.94 + </Events>
3.95 + </Component>
3.96 + <Component class="javax.swing.JSpinner" name="decimal">
3.97 + <Events>
3.98 + <EventHandler event="stateChanged" listener="javax.swing.event.ChangeListener" parameters="javax.swing.event.ChangeEvent" handler="decimalStateChanged"/>
3.99 + </Events>
3.100 + </Component>
3.101 + <Component class="javax.swing.JSpinner" name="hexa">
3.102 + <Events>
3.103 + <EventHandler event="stateChanged" listener="javax.swing.event.ChangeListener" parameters="javax.swing.event.ChangeEvent" handler="hexaStateChanged"/>
3.104 + </Events>
3.105 + </Component>
3.106 + <Component class="javax.swing.JCheckBox" name="replaceExisting">
3.107 + <Properties>
3.108 + <Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
3.109 + <ResourceString bundle="org/netbeans/modules/javahints/jdk/Bundle.properties" key="AddUnderscoresPanel.replaceExisting.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, "{key}")"/>
3.110 + </Property>
3.111 + </Properties>
3.112 + <Events>
3.113 + <EventHandler event="stateChanged" listener="javax.swing.event.ChangeListener" parameters="javax.swing.event.ChangeEvent" handler="replaceExistingStateChanged"/>
3.114 + </Events>
3.115 + </Component>
3.116 + </SubComponents>
3.117 +</Form>
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
4.2 +++ b/javahints/src/org/netbeans/modules/javahints/jdk/AddUnderscoresPanel.java Thu Oct 27 14:18:11 2011 +0200
4.3 @@ -0,0 +1,181 @@
4.4 +/*
4.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4.6 + *
4.7 + * Copyright 2011 Oracle and/or its affiliates. All rights reserved.
4.8 + *
4.9 + * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
4.10 + * Other names may be trademarks of their respective owners.
4.11 + *
4.12 + * The contents of this file are subject to the terms of either the GNU
4.13 + * General Public License Version 2 only ("GPL") or the Common
4.14 + * Development and Distribution License("CDDL") (collectively, the
4.15 + * "License"). You may not use this file except in compliance with the
4.16 + * License. You can obtain a copy of the License at
4.17 + * http://www.netbeans.org/cddl-gplv2.html
4.18 + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
4.19 + * specific language governing permissions and limitations under the
4.20 + * License. When distributing the software, include this License Header
4.21 + * Notice in each file and include the License file at
4.22 + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
4.23 + * particular file as subject to the "Classpath" exception as provided
4.24 + * by Oracle in the GPL Version 2 section of the License file that
4.25 + * accompanied this code. If applicable, add the following below the
4.26 + * License Header, with the fields enclosed by brackets [] replaced by
4.27 + * your own identifying information:
4.28 + * "Portions Copyrighted [year] [name of copyright owner]"
4.29 + *
4.30 + * If you wish your version of this file to be governed by only the CDDL
4.31 + * or only the GPL Version 2, indicate your decision by adding
4.32 + * "[Contributor] elects to include this software in this distribution
4.33 + * under the [CDDL or GPL Version 2] license." If you do not indicate a
4.34 + * single choice of license, a recipient has the option to distribute
4.35 + * your version of this file under either the CDDL, the GPL Version 2 or
4.36 + * to extend the choice of license to its licensees as provided above.
4.37 + * However, if you add GPL Version 2 code and therefore, elected the GPL
4.38 + * Version 2 license, then the option applies only if the new code is
4.39 + * made subject to such option by the copyright holder.
4.40 + *
4.41 + * Contributor(s):
4.42 + *
4.43 + * Portions Copyrighted 2011 Sun Microsystems, Inc.
4.44 + */
4.45 +package org.netbeans.modules.javahints.jdk;
4.46 +
4.47 +import java.util.prefs.Preferences;
4.48 +
4.49 +/**
4.50 + *
4.51 + * @author lahvac
4.52 + */
4.53 +public class AddUnderscoresPanel extends javax.swing.JPanel {
4.54 +
4.55 + private final Preferences prefs;
4.56 +
4.57 + /**
4.58 + * Creates new form AddUnderscoresPanel
4.59 + */
4.60 + public AddUnderscoresPanel(Preferences prefs) {
4.61 + initComponents();
4.62 + this.prefs = prefs;
4.63 +
4.64 + binary.setValue(AddUnderscores.getSizeForRadix(prefs, 2));
4.65 + decimal.setValue(AddUnderscores.getSizeForRadix(prefs, 10));
4.66 + hexa.setValue(AddUnderscores.getSizeForRadix(prefs, 16));
4.67 + replaceExisting.setSelected(AddUnderscores.isReplaceLiteralsWithUnderscores(prefs));
4.68 + }
4.69 +
4.70 + /**
4.71 + * This method is called from within the constructor to initialize the form.
4.72 + * WARNING: Do NOT modify this code. The content of this method is always
4.73 + * regenerated by the Form Editor.
4.74 + */
4.75 + @SuppressWarnings("unchecked")
4.76 + // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
4.77 + private void initComponents() {
4.78 +
4.79 + jLabel1 = new javax.swing.JLabel();
4.80 + jLabel2 = new javax.swing.JLabel();
4.81 + jLabel3 = new javax.swing.JLabel();
4.82 + binary = new javax.swing.JSpinner();
4.83 + decimal = new javax.swing.JSpinner();
4.84 + hexa = new javax.swing.JSpinner();
4.85 + replaceExisting = new javax.swing.JCheckBox();
4.86 +
4.87 + org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getMessage(AddUnderscoresPanel.class, "AddUnderscoresPanel.jLabel1.text")); // NOI18N
4.88 +
4.89 + org.openide.awt.Mnemonics.setLocalizedText(jLabel2, org.openide.util.NbBundle.getMessage(AddUnderscoresPanel.class, "AddUnderscoresPanel.jLabel2.text")); // NOI18N
4.90 +
4.91 + org.openide.awt.Mnemonics.setLocalizedText(jLabel3, org.openide.util.NbBundle.getMessage(AddUnderscoresPanel.class, "AddUnderscoresPanel.jLabel3.text")); // NOI18N
4.92 +
4.93 + binary.addChangeListener(new javax.swing.event.ChangeListener() {
4.94 + public void stateChanged(javax.swing.event.ChangeEvent evt) {
4.95 + binaryStateChanged(evt);
4.96 + }
4.97 + });
4.98 +
4.99 + decimal.addChangeListener(new javax.swing.event.ChangeListener() {
4.100 + public void stateChanged(javax.swing.event.ChangeEvent evt) {
4.101 + decimalStateChanged(evt);
4.102 + }
4.103 + });
4.104 +
4.105 + hexa.addChangeListener(new javax.swing.event.ChangeListener() {
4.106 + public void stateChanged(javax.swing.event.ChangeEvent evt) {
4.107 + hexaStateChanged(evt);
4.108 + }
4.109 + });
4.110 +
4.111 + org.openide.awt.Mnemonics.setLocalizedText(replaceExisting, org.openide.util.NbBundle.getMessage(AddUnderscoresPanel.class, "AddUnderscoresPanel.replaceExisting.text")); // NOI18N
4.112 + replaceExisting.addChangeListener(new javax.swing.event.ChangeListener() {
4.113 + public void stateChanged(javax.swing.event.ChangeEvent evt) {
4.114 + replaceExistingStateChanged(evt);
4.115 + }
4.116 + });
4.117 +
4.118 + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
4.119 + this.setLayout(layout);
4.120 + layout.setHorizontalGroup(
4.121 + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
4.122 + .addGroup(layout.createSequentialGroup()
4.123 + .addContainerGap()
4.124 + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
4.125 + .addComponent(replaceExisting)
4.126 + .addGroup(layout.createSequentialGroup()
4.127 + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
4.128 + .addComponent(jLabel3)
4.129 + .addComponent(jLabel2)
4.130 + .addComponent(jLabel1))
4.131 + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
4.132 + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
4.133 + .addComponent(binary, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
4.134 + .addComponent(decimal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
4.135 + .addComponent(hexa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
4.136 + .addContainerGap())
4.137 + );
4.138 + layout.setVerticalGroup(
4.139 + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
4.140 + .addGroup(layout.createSequentialGroup()
4.141 + .addContainerGap()
4.142 + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
4.143 + .addComponent(jLabel1)
4.144 + .addComponent(binary, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
4.145 + .addGap(18, 18, 18)
4.146 + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
4.147 + .addComponent(jLabel2)
4.148 + .addComponent(decimal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
4.149 + .addGap(18, 18, 18)
4.150 + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
4.151 + .addComponent(jLabel3)
4.152 + .addComponent(hexa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
4.153 + .addGap(18, 18, 18)
4.154 + .addComponent(replaceExisting)
4.155 + .addContainerGap())
4.156 + );
4.157 + }// </editor-fold>//GEN-END:initComponents
4.158 +
4.159 + private void binaryStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_binaryStateChanged
4.160 + AddUnderscores.setSizeForRadix(prefs, 2, (Integer) binary.getValue());
4.161 + }//GEN-LAST:event_binaryStateChanged
4.162 +
4.163 + private void decimalStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_decimalStateChanged
4.164 + AddUnderscores.setSizeForRadix(prefs, 10, (Integer) decimal.getValue());
4.165 + }//GEN-LAST:event_decimalStateChanged
4.166 +
4.167 + private void hexaStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_hexaStateChanged
4.168 + AddUnderscores.setSizeForRadix(prefs, 16, (Integer) hexa.getValue());
4.169 + }//GEN-LAST:event_hexaStateChanged
4.170 +
4.171 + private void replaceExistingStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_replaceExistingStateChanged
4.172 + AddUnderscores.setReplaceLiteralsWithUnderscores(prefs, replaceExisting.isSelected());
4.173 + }//GEN-LAST:event_replaceExistingStateChanged
4.174 +
4.175 + // Variables declaration - do not modify//GEN-BEGIN:variables
4.176 + private javax.swing.JSpinner binary;
4.177 + private javax.swing.JSpinner decimal;
4.178 + private javax.swing.JSpinner hexa;
4.179 + private javax.swing.JLabel jLabel1;
4.180 + private javax.swing.JLabel jLabel2;
4.181 + private javax.swing.JLabel jLabel3;
4.182 + private javax.swing.JCheckBox replaceExisting;
4.183 + // End of variables declaration//GEN-END:variables
4.184 +}
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
5.2 +++ b/javahints/src/org/netbeans/modules/javahints/jdk/Bundle.properties Thu Oct 27 14:18:11 2011 +0200
5.3 @@ -0,0 +1,48 @@
5.4 +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
5.5 +#
5.6 +# Copyright 2011 Oracle and/or its affiliates. All rights reserved.
5.7 +#
5.8 +# Oracle and Java are registered trademarks of Oracle and/or its affiliates.
5.9 +# Other names may be trademarks of their respective owners.
5.10 +#
5.11 +# The contents of this file are subject to the terms of either the GNU
5.12 +# General Public License Version 2 only ("GPL") or the Common
5.13 +# Development and Distribution License("CDDL") (collectively, the
5.14 +# "License"). You may not use this file except in compliance with the
5.15 +# License. You can obtain a copy of the License at
5.16 +# http://www.netbeans.org/cddl-gplv2.html
5.17 +# or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
5.18 +# specific language governing permissions and limitations under the
5.19 +# License. When distributing the software, include this License Header
5.20 +# Notice in each file and include the License file at
5.21 +# nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
5.22 +# particular file as subject to the "Classpath" exception as provided
5.23 +# by Oracle in the GPL Version 2 section of the License file that
5.24 +# accompanied this code. If applicable, add the following below the
5.25 +# License Header, with the fields enclosed by brackets [] replaced by
5.26 +# your own identifying information:
5.27 +# "Portions Copyrighted [year] [name of copyright owner]"
5.28 +#
5.29 +# If you wish your version of this file to be governed by only the CDDL
5.30 +# or only the GPL Version 2, indicate your decision by adding
5.31 +# "[Contributor] elects to include this software in this distribution
5.32 +# under the [CDDL or GPL Version 2] license." If you do not indicate a
5.33 +# single choice of license, a recipient has the option to distribute
5.34 +# your version of this file under either the CDDL, the GPL Version 2 or
5.35 +# to extend the choice of license to its licensees as provided above.
5.36 +# However, if you add GPL Version 2 code and therefore, elected the GPL
5.37 +# Version 2 license, then the option applies only if the new code is
5.38 +# made subject to such option by the copyright holder.
5.39 +#
5.40 +# Contributor(s):
5.41 +#
5.42 +# Portions Copyrighted 2011 Sun Microsystems, Inc.
5.43 +
5.44 +DN_org.netbeans.modules.javahints.jdk.AddUnderscores=Add Underscores
5.45 +DESC_org.netbeans.modules.javahints.jdk.AddUnderscores=Proposed to add underscores to integer literals to improve their readability
5.46 +ERR_org.netbeans.modules.javahints.jdk.AddUnderscores=Underscores could be used to improve readability
5.47 +FIX_org.netbeans.modules.javahints.jdk.AddUnderscores=Change the literal to: {0}
5.48 +AddUnderscoresPanel.jLabel1.text=&Binary:
5.49 +AddUnderscoresPanel.jLabel3.text=&Hexadecimal:
5.50 +AddUnderscoresPanel.jLabel2.text=&Decimal:
5.51 +AddUnderscoresPanel.replaceExisting.text=&Also transform literals with underscores
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
6.2 +++ b/javahints/test/unit/src/org/netbeans/modules/javahints/jdk/AddUnderscoresTest.java Thu Oct 27 14:18:11 2011 +0200
6.3 @@ -0,0 +1,148 @@
6.4 +/*
6.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
6.6 + *
6.7 + * Copyright 2011 Oracle and/or its affiliates. All rights reserved.
6.8 + *
6.9 + * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
6.10 + * Other names may be trademarks of their respective owners.
6.11 + *
6.12 + * The contents of this file are subject to the terms of either the GNU
6.13 + * General Public License Version 2 only ("GPL") or the Common
6.14 + * Development and Distribution License("CDDL") (collectively, the
6.15 + * "License"). You may not use this file except in compliance with the
6.16 + * License. You can obtain a copy of the License at
6.17 + * http://www.netbeans.org/cddl-gplv2.html
6.18 + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
6.19 + * specific language governing permissions and limitations under the
6.20 + * License. When distributing the software, include this License Header
6.21 + * Notice in each file and include the License file at
6.22 + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
6.23 + * particular file as subject to the "Classpath" exception as provided
6.24 + * by Oracle in the GPL Version 2 section of the License file that
6.25 + * accompanied this code. If applicable, add the following below the
6.26 + * License Header, with the fields enclosed by brackets [] replaced by
6.27 + * your own identifying information:
6.28 + * "Portions Copyrighted [year] [name of copyright owner]"
6.29 + *
6.30 + * If you wish your version of this file to be governed by only the CDDL
6.31 + * or only the GPL Version 2, indicate your decision by adding
6.32 + * "[Contributor] elects to include this software in this distribution
6.33 + * under the [CDDL or GPL Version 2] license." If you do not indicate a
6.34 + * single choice of license, a recipient has the option to distribute
6.35 + * your version of this file under either the CDDL, the GPL Version 2 or
6.36 + * to extend the choice of license to its licensees as provided above.
6.37 + * However, if you add GPL Version 2 code and therefore, elected the GPL
6.38 + * Version 2 license, then the option applies only if the new code is
6.39 + * made subject to such option by the copyright holder.
6.40 + *
6.41 + * Contributor(s):
6.42 + *
6.43 + * Portions Copyrighted 2011 Sun Microsystems, Inc.
6.44 + */
6.45 +package org.netbeans.modules.javahints.jdk;
6.46 +
6.47 +import org.netbeans.modules.javahints.jdk.AddUnderscores;
6.48 +import java.util.Collections;
6.49 +import java.util.prefs.Preferences;
6.50 +import org.netbeans.junit.internal.MemoryPreferencesFactory;
6.51 +import org.netbeans.modules.java.hints.analyzer.OverridePreferences;
6.52 +import org.netbeans.modules.java.hints.jackpot.code.spi.TestBase;
6.53 +import org.netbeans.modules.java.hints.jackpot.impl.RulesManager;
6.54 +import org.netbeans.modules.java.hints.options.HintsSettings;
6.55 +
6.56 +/**
6.57 + *
6.58 + * @author lahvac
6.59 + */
6.60 +public class AddUnderscoresTest extends TestBase {
6.61 + public AddUnderscoresTest(String name) {
6.62 + super(name, AddUnderscores.class);
6.63 + }
6.64 +
6.65 + public void testSimpleAdd() throws Exception {
6.66 + performFixTest("test/Test.java",
6.67 + "package test;\n" +
6.68 + "public class Test {\n" +
6.69 + " private static final int CONST = 12345678;\n" +
6.70 + "}\n",
6.71 + "2:37-2:45:hint:ERR_org.netbeans.modules.javahints.jdk.AddUnderscores",
6.72 + "FixImpl",
6.73 + ("package test;\n" +
6.74 + "public class Test {\n" +
6.75 + " private static final int CONST = 12_345_678;\n" +
6.76 + "}\n").replaceAll("[ \t\n]+", " "));
6.77 + }
6.78 +
6.79 + public void testSettings() throws Exception {
6.80 + AddUnderscores.setSizeForRadix(prefs, 2, 5);
6.81 + performFixTest("test/Test.java",
6.82 + "package test;\n" +
6.83 + "public class Test {\n" +
6.84 + " private static final int CONST = 0B1010101010101010;\n" +
6.85 + "}\n",
6.86 + "2:37-2:55:hint:ERR_org.netbeans.modules.javahints.jdk.AddUnderscores",
6.87 + "FixImpl",
6.88 + ("package test;\n" +
6.89 + "public class Test {\n" +
6.90 + " private static final int CONST = 0B1_01010_10101_01010;\n" +
6.91 + "}\n").replaceAll("[ \t\n]+", " "));
6.92 + }
6.93 +
6.94 + public void testHexLong() throws Exception {
6.95 + AddUnderscores.setSizeForRadix(prefs, 16, 3);
6.96 + performFixTest("test/Test.java",
6.97 + "package test;\n" +
6.98 + "public class Test {\n" +
6.99 + " private static final int CONST = 0xA5A5A5A5A5A5A5A5L;\n" +
6.100 + "}\n",
6.101 + "2:37-2:56:hint:ERR_org.netbeans.modules.javahints.jdk.AddUnderscores",
6.102 + "FixImpl",
6.103 + ("package test;\n" +
6.104 + "public class Test {\n" +
6.105 + " private static final int CONST = 0xA_5A5_A5A_5A5_A5A_5A5L;\n" +
6.106 + "}\n").replaceAll("[ \t\n]+", " "));
6.107 + }
6.108 +
6.109 + public void testAlreadyHasUnderscores1() throws Exception {
6.110 + performAnalysisTest("test/Test.java",
6.111 + "package test;\n" +
6.112 + "public class Test {\n" +
6.113 + " private static final int CONST = 0xA5A5A5A5_A5A5A5A5L;\n" +
6.114 + "}\n");
6.115 + }
6.116 +
6.117 + public void testAlreadyHasUnderscores2() throws Exception {
6.118 + AddUnderscores.setReplaceLiteralsWithUnderscores(prefs, true);
6.119 + performFixTest("test/Test.java",
6.120 + "package test;\n" +
6.121 + "public class Test {\n" +
6.122 + " private static final int CONST = 0xA5A5A5A5A5A5A5A_5L;\n" +
6.123 + "}\n",
6.124 + "2:37-2:57:hint:ERR_org.netbeans.modules.javahints.jdk.AddUnderscores",
6.125 + "FixImpl",
6.126 + ("package test;\n" +
6.127 + "public class Test {\n" +
6.128 + " private static final int CONST = 0xA5A5_A5A5_A5A5_A5A5L;\n" +
6.129 + "}\n").replaceAll("[ \t\n]+", " "));
6.130 + }
6.131 +
6.132 + private Preferences prefs;
6.133 +
6.134 + @Override
6.135 + protected void setUp() throws Exception {
6.136 + super.setUp();
6.137 +
6.138 + prefs = new OverridePreferences(RulesManager.getPreferences(AddUnderscores.ID, HintsSettings.getCurrentProfileId()));
6.139 + HintsSettings.setPreferencesOverride(Collections.singletonMap(AddUnderscores.ID, prefs));
6.140 +
6.141 + setSourceLevel("1.7");
6.142 + }
6.143 +
6.144 + @Override
6.145 + protected void tearDown() throws Exception {
6.146 + HintsSettings.setPreferencesOverride(Collections.<String, Preferences>emptyMap());
6.147 + prefs = null;
6.148 + super.tearDown();
6.149 + }
6.150 +
6.151 +}
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
7.2 +++ b/javahints/test/unit/src/org/netbeans/modules/javahints/jdk/Bundle_test.properties Thu Oct 27 14:18:11 2011 +0200
7.3 @@ -0,0 +1,44 @@
7.4 +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
7.5 +#
7.6 +# Copyright 2011 Oracle and/or its affiliates. All rights reserved.
7.7 +#
7.8 +# Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7.9 +# Other names may be trademarks of their respective owners.
7.10 +#
7.11 +# The contents of this file are subject to the terms of either the GNU
7.12 +# General Public License Version 2 only ("GPL") or the Common
7.13 +# Development and Distribution License("CDDL") (collectively, the
7.14 +# "License"). You may not use this file except in compliance with the
7.15 +# License. You can obtain a copy of the License at
7.16 +# http://www.netbeans.org/cddl-gplv2.html
7.17 +# or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
7.18 +# specific language governing permissions and limitations under the
7.19 +# License. When distributing the software, include this License Header
7.20 +# Notice in each file and include the License file at
7.21 +# nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
7.22 +# particular file as subject to the "Classpath" exception as provided
7.23 +# by Oracle in the GPL Version 2 section of the License file that
7.24 +# accompanied this code. If applicable, add the following below the
7.25 +# License Header, with the fields enclosed by brackets [] replaced by
7.26 +# your own identifying information:
7.27 +# "Portions Copyrighted [year] [name of copyright owner]"
7.28 +#
7.29 +# If you wish your version of this file to be governed by only the CDDL
7.30 +# or only the GPL Version 2, indicate your decision by adding
7.31 +# "[Contributor] elects to include this software in this distribution
7.32 +# under the [CDDL or GPL Version 2] license." If you do not indicate a
7.33 +# single choice of license, a recipient has the option to distribute
7.34 +# your version of this file under either the CDDL, the GPL Version 2 or
7.35 +# to extend the choice of license to its licensees as provided above.
7.36 +# However, if you add GPL Version 2 code and therefore, elected the GPL
7.37 +# Version 2 license, then the option applies only if the new code is
7.38 +# made subject to such option by the copyright holder.
7.39 +#
7.40 +# Contributor(s):
7.41 +#
7.42 +# Portions Copyrighted 2011 Sun Microsystems, Inc.
7.43 +
7.44 +DN_org.netbeans.modules.javahints.jdk.AddUnderscores=DN_org.netbeans.modules.javahints.jdk.AddUnderscores
7.45 +DESC_org.netbeans.modules.javahints.jdk.AddUnderscores=DESC_org.netbeans.modules.javahints.jdk.AddUnderscores
7.46 +ERR_org.netbeans.modules.javahints.jdk.AddUnderscores=ERR_org.netbeans.modules.javahints.jdk.AddUnderscores
7.47 +FIX_org.netbeans.modules.javahints.jdk.AddUnderscores=FIX_org.netbeans.modules.javahints.jdk.AddUnderscores{0}