# This patch file was generated by NetBeans IDE # Following Index: paths are relative to: /Users/samuel/Documents/Java/NetBeans/main-golden/java.hints/src # This patch can be applied using context Tools: Patch action on respective folder. # It uses platform neutral UTF-8 encoding and \n newlines. # Above lines and this line are ignored by the patching process. Index: org/netbeans/modules/java/hints/Bundle.properties --- org/netbeans/modules/java/hints/Bundle.properties Base (BASE) +++ org/netbeans/modules/java/hints/Bundle.properties Locally Modified (Based On LOCAL) @@ -73,7 +73,7 @@ LBL_Imports_DUPLICATE=Multiple Import LBL_Imports_SAME_PACKAGE=Import From The Same Package LBL_Imports_DEFAULT_PACKAGE=Import From java.lang Package -LBL_Imports_FORBIDDEN=Import From Forbidden Package +LBL_Imports_EXCLUDED=Import from Excluded LBL_Imports_STAR=Star import DSC_Imports_DELAGATE=Delegate - non GUI @@ -81,7 +81,7 @@ DSC_Imports_DUPLICATE=Multiple Import DSC_Imports_SAME_PACKAGE=Import From The Same Package DSC_Imports_DEFAULT_PACKAGE=Import From java.lang Package -DSC_Imports_FORBIDDEN=Import From Forbidden Package +DSC_Imports_EXCLUDED=Import from package or class which has been labelled "Excluded" in the Code Completer DSC_Imports_STAR=Star import LBL_Imports_Fix_One_SAME_PACKAGE=Remove import from same package @@ -175,18 +175,7 @@ if(...);
else;
. DSC_Empty_BLOCK=Checks for empty statements in blocks usually represented\ as superfluous semicolon. -ForbiddenImportsCustomizer.btnAdd.text=&Add -ForbiddenImportsCustomizer.btnEdit.text=&Edit -ForbiddenImportsCustomizer.btnRemove.text=&Remove -ForbiddenImportsCustomizer.titleAdd=Add Forbidden Import -ForbiddenImportsCustomizer.titleEdit=Edit Forbidden Import -ForbiddenImportsCustomizer.label=Forbidden import: -ForbiddenImportsCustomizer.btnAdd=Add -ForbiddenImportsCustomizer.btnEdit=Update -ForbiddenImportsCustomizer.btnCancel=Cancel -ForbiddenImportsCustomizer.hint=Use * for a single package, use ** for all packages. - MSG_HiddenField=Field hides another field HINT_HiddenField=Declaration of a field in a class can hide declaration of \ another field in superclasses. Although possible, this is not very good programming style. @@ -272,13 +261,6 @@ DSC_SynchronizationOnNonFinalField=Synchronization on non-final field ERR_SynchronizationOnNonFinalField=Synchronization on non-final field DN_SynchronizationOnNonFinalField=Synchronization on non-final field -ForbiddenImportsCustomizer.listItems.AccessibleContext.accessibleDescription=List of forbidden packages -ForbiddenImportsCustomizer.listItems.AccessibleContext.accessibleName=Forbidden packages list -ForbiddenImportsCustomizer.jScrollPane1.AccessibleContext.accessibleDescription=Forbidden packages pane -ForbiddenImportsCustomizer.jScrollPane1.AccessibleContext.accessibleName=Forbidden packages pane -ForbiddenImportsCustomizer.AccessibleContext.accessibleDescription=Forbidden packages customiser -ForbiddenImportsCustomizer.AccessibleContext.accessibleName=Forbidden packages customiser -ForbiddenImportsCustomizer.btnAdd.AccessibleContext.accessibleDescription=Adds new forbidden package to the list HINT_SuspiciousCall=Suspicious call to {0}:\nExpected type {2}, actual type {1} HINT_SuspiciousCallIncompatibleTypes=Suspicious call to {0}:\nGiven object cannot contain instances of {1} (expected {2}) Index: org/netbeans/modules/java/hints/ForbiddenImportsCustomizer.form --- org/netbeans/modules/java/hints/ForbiddenImportsCustomizer.form Base (BASE) +++ org/netbeans/modules/java/hints/ForbiddenImportsCustomizer.form Locally Deleted @@ -1,135 +0,0 @@ - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Index: org/netbeans/modules/java/hints/ForbiddenImportsCustomizer.java --- org/netbeans/modules/java/hints/ForbiddenImportsCustomizer.java Base (BASE) +++ org/netbeans/modules/java/hints/ForbiddenImportsCustomizer.java Locally Deleted @@ -1,314 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common - * Development and Distribution License("CDDL") (collectively, the - * "License"). You may not use this file except in compliance with the - * License. You can obtain a copy of the License at - * http://www.netbeans.org/cddl-gplv2.html - * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the - * specific language governing permissions and limitations under the - * License. When distributing the software, include this License Header - * Notice in each file and include the License file at - * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this - * particular file as subject to the "Classpath" exception as provided - * by Sun in the GPL Version 2 section of the License file that - * accompanied this code. If applicable, add the following below the - * License Header, with the fields enclosed by brackets [] replaced by - * your own identifying information: - * "Portions Copyrighted [year] [name of copyright owner]" - * - * Contributor(s): - * - * Portions Copyrighted 2007 Sun Microsystems, Inc. - */ -package org.netbeans.modules.java.hints; - -import java.awt.Dialog; -import java.awt.GridBagConstraints; -import java.awt.GridBagLayout; -import java.awt.Insets; -import java.util.ArrayList; -import java.util.List; -import java.util.StringTokenizer; -import java.util.prefs.Preferences; -import javax.swing.BorderFactory; -import javax.swing.DefaultListModel; -import javax.swing.JButton; -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.JTextField; -import javax.swing.event.DocumentEvent; -import javax.swing.event.DocumentListener; -import javax.swing.event.ListSelectionEvent; -import javax.swing.event.ListSelectionListener; -import org.openide.DialogDescriptor; -import org.openide.DialogDisplayer; -import org.openide.util.NbBundle; - -/** - * - * @author phrebejk - */ -public class ForbiddenImportsCustomizer extends javax.swing.JPanel { - - private static String FORBIDDEN_IMPORTS_KEY = "ForbiddenImports"; // NOI18N - private static String FORBIDDEN_IMPORTS_DEFAULT = "sun.**"; // NOI18N - private static String IMPORTS_DELIMITER = ";"; // NOI18N - - private Preferences prefs; - - /** Creates new form ForbiddenImports */ - public ForbiddenImportsCustomizer(Preferences node) { - this.prefs = node; - initComponents(); - DefaultListModel model = new DefaultListModel(); - for( String item : getForbiddenImports(node) ) { - model.addElement( item ); - } - listItems.setModel( model ); - listItems.addListSelectionListener( new ListSelectionListener() { - public void valueChanged(ListSelectionEvent e) { - enableButtons(); - } - }); - enableButtons(); - } - - private void enableButtons() { - int selIndex = listItems.getSelectedIndex(); - btnEdit.setEnabled( selIndex >= 0 ); - btnRemove.setEnabled( selIndex >= 0 ); - } - - private void updatePreferences() { - String[] items = new String[listItems.getModel().getSize()]; - for( int i=0; i<((DefaultListModel)listItems.getModel()).size(); i++ ) { - items[i] = (String)listItems.getModel().getElementAt(i); - } - prefs.put(FORBIDDEN_IMPORTS_KEY, encodeForbiddenImports( items )); - } - - private String showInputDialog( String initialValue ) { - String title = null == initialValue ? NbBundle.getMessage( ForbiddenImportsCustomizer.class, "ForbiddenImportsCustomizer.titleAdd" ) //NOI18N - : NbBundle.getMessage( ForbiddenImportsCustomizer.class, "ForbiddenImportsCustomizer.titleEdit" ); //NOI18N - final JButton btnOk = new JButton( null == initialValue ? NbBundle.getMessage( ForbiddenImportsCustomizer.class, "ForbiddenImportsCustomizer.btnAdd" ) //NOI18N - : NbBundle.getMessage( ForbiddenImportsCustomizer.class, "ForbiddenImportsCustomizer.btnEdit" ) ); //NOI18N - btnOk.setEnabled( null != initialValue ); - JButton btnCancel = new JButton( NbBundle.getMessage( ForbiddenImportsCustomizer.class, "ForbiddenImportsCustomizer.btnCancel" ) ); //NOI18N - - JPanel panel = new JPanel( new GridBagLayout() ); - panel.setBorder( BorderFactory.createEmptyBorder(10, 10, 0, 10) ); - - JTextField input = new JTextField(); - input.setText( null == initialValue ? "" : initialValue ); - input.getDocument().addDocumentListener( new DocumentListener() { - - public void insertUpdate(DocumentEvent e) { - btnOk.setEnabled( e.getDocument().getLength() > 0 ); - } - - public void removeUpdate(DocumentEvent e) { - btnOk.setEnabled( e.getDocument().getLength() > 0 ); - } - - public void changedUpdate(DocumentEvent e) { - btnOk.setEnabled( e.getDocument().getLength() > 0 ); - } - }); - - panel.add( new JLabel(NbBundle.getMessage( ForbiddenImportsCustomizer.class, "ForbiddenImportsCustomizer.label" ) ), //NOI18N - new GridBagConstraints(0,0,1,1,0.0,0.0,GridBagConstraints.WEST,GridBagConstraints.NONE,new Insets(0,0,0,5),0,0) ); - panel.add( input, new GridBagConstraints(1,0,1,1,1.0,0.0,GridBagConstraints.WEST,GridBagConstraints.HORIZONTAL,new Insets(0,0,0,0),0,0) ); - panel.add( new JLabel(NbBundle.getMessage(ForbiddenImportsCustomizer.class, "ForbiddenImportsCustomizer.hint") ), //NOI18N - new GridBagConstraints(1,1,1,1,1.0,0.0,GridBagConstraints.WEST,GridBagConstraints.HORIZONTAL,new Insets(5,0,0,0),0,0) ); - - DialogDescriptor dd = new DialogDescriptor(panel, title, true, - new Object[] { btnOk, btnCancel }, btnOk, - DialogDescriptor.DEFAULT_ALIGN, null, null ); - Dialog dlg = DialogDisplayer.getDefault().createDialog(dd); - dlg.setVisible( true ); - if( btnOk == dd.getValue() ) { - return input.getText(); - } - return null; - } - - /** This method is called from within the constructor to - * initialize the form. - * WARNING: Do NOT modify this code. The content of this method is - * always regenerated by the Form Editor. - */ - // //GEN-BEGIN:initComponents - private void initComponents() { - java.awt.GridBagConstraints gridBagConstraints; - - jScrollPane1 = new javax.swing.JScrollPane(); - listItems = new javax.swing.JList(); - jPanel1 = new javax.swing.JPanel(); - btnAdd = new javax.swing.JButton(); - btnEdit = new javax.swing.JButton(); - btnRemove = new javax.swing.JButton(); - - setOpaque(false); - setLayout(new java.awt.GridBagLayout()); - - listItems.setModel(new javax.swing.AbstractListModel() { - String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" }; - public int getSize() { return strings.length; } - public Object getElementAt(int i) { return strings[i]; } - }); - jScrollPane1.setViewportView(listItems); - listItems.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(ForbiddenImportsCustomizer.class, "ForbiddenImportsCustomizer.listItems.AccessibleContext.accessibleName")); // NOI18N - listItems.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(ForbiddenImportsCustomizer.class, "ForbiddenImportsCustomizer.listItems.AccessibleContext.accessibleDescription")); // NOI18N - - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER; - gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; - gridBagConstraints.weightx = 1.0; - gridBagConstraints.weighty = 1.0; - add(jScrollPane1, gridBagConstraints); - jScrollPane1.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(ForbiddenImportsCustomizer.class, "ForbiddenImportsCustomizer.jScrollPane1.AccessibleContext.accessibleName")); // NOI18N - jScrollPane1.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(ForbiddenImportsCustomizer.class, "ForbiddenImportsCustomizer.jScrollPane1.AccessibleContext.accessibleDescription")); // NOI18N - - jPanel1.setOpaque(false); - jPanel1.setLayout(new java.awt.GridBagLayout()); - - org.openide.awt.Mnemonics.setLocalizedText(btnAdd, org.openide.util.NbBundle.getMessage(ForbiddenImportsCustomizer.class, "ForbiddenImportsCustomizer.btnAdd.text")); // NOI18N - btnAdd.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - addItem(evt); - } - }); - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; - gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; - gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; - gridBagConstraints.weightx = 1.0; - gridBagConstraints.insets = new java.awt.Insets(0, 0, 4, 0); - jPanel1.add(btnAdd, gridBagConstraints); - btnAdd.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(ForbiddenImportsCustomizer.class, "ForbiddenImportsCustomizer.btnAdd.AccessibleContext.accessibleDescription")); // NOI18N - - org.openide.awt.Mnemonics.setLocalizedText(btnEdit, org.openide.util.NbBundle.getMessage(ForbiddenImportsCustomizer.class, "ForbiddenImportsCustomizer.btnEdit.text")); // NOI18N - btnEdit.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - editItem(evt); - } - }); - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; - gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; - gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; - gridBagConstraints.weightx = 1.0; - gridBagConstraints.insets = new java.awt.Insets(0, 0, 4, 0); - jPanel1.add(btnEdit, gridBagConstraints); - - org.openide.awt.Mnemonics.setLocalizedText(btnRemove, org.openide.util.NbBundle.getMessage(ForbiddenImportsCustomizer.class, "ForbiddenImportsCustomizer.btnRemove.text")); // NOI18N - btnRemove.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - removeItem(evt); - } - }); - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; - gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER; - gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; - gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; - gridBagConstraints.weightx = 1.0; - gridBagConstraints.weighty = 1.0; - jPanel1.add(btnRemove, gridBagConstraints); - - gridBagConstraints = new java.awt.GridBagConstraints(); - gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; - gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER; - gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; - gridBagConstraints.insets = new java.awt.Insets(0, 8, 0, 0); - add(jPanel1, gridBagConstraints); - - getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(ForbiddenImportsCustomizer.class, "ForbiddenImportsCustomizer.AccessibleContext.accessibleName")); // NOI18N - getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(ForbiddenImportsCustomizer.class, "ForbiddenImportsCustomizer.AccessibleContext.accessibleDescription")); // NOI18N - }// //GEN-END:initComponents - -private void removeItem(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeItem - int selIndex = listItems.getSelectedIndex();//GEN-LAST:event_removeItem - if( selIndex < 0 ) - return; - ((DefaultListModel)listItems.getModel()).remove( selIndex ); - selIndex++; - if( selIndex > listItems.getModel().getSize()-1 ) - selIndex = listItems.getModel().getSize()-1; - listItems.getSelectionModel().setSelectionInterval( selIndex, selIndex ); - updatePreferences(); -} - -private void editItem(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editItem - int selIndex = listItems.getSelectedIndex();//GEN-LAST:event_editItem - if( selIndex < 0 ) - return; - String initialValue = (String)((DefaultListModel)listItems.getModel()).get( selIndex ); - String newValue = showInputDialog( initialValue ); - if( null != newValue ) { - ((DefaultListModel)listItems.getModel()).set( selIndex, newValue ); - listItems.getSelectionModel().setSelectionInterval( selIndex, selIndex ); - updatePreferences(); - } -} - -private void addItem(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addItem - String newValue = showInputDialog( null );//GEN-LAST:event_addItem - if( null != newValue ) { - ((DefaultListModel)listItems.getModel()).addElement( newValue ); - int count = listItems.getModel().getSize(); - if( count > 0 ) - listItems.getSelectionModel().setSelectionInterval( count-1, count-1 ); - updatePreferences(); - } - -} - - - // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JButton btnAdd; - private javax.swing.JButton btnEdit; - private javax.swing.JButton btnRemove; - private javax.swing.JPanel jPanel1; - private javax.swing.JScrollPane jScrollPane1; - private javax.swing.JList listItems; - // End of variables declaration//GEN-END:variables - - public static String encodeForbiddenImports( String[] forbiddenImports ) { - - StringBuffer sb = new StringBuffer(); - - for( String fi : forbiddenImports ) { - sb.append(fi); - sb.append(IMPORTS_DELIMITER); - } - - return sb.toString(); - } - - public static String[] decodeForbiddenImports( String forbiddenImports ) { - - StringTokenizer st = new StringTokenizer(forbiddenImports, IMPORTS_DELIMITER, false ); - - List imList = new ArrayList(); - - while( st.hasMoreTokens() ) { - String im = st.nextToken(); - imList.add(im); - } - - return imList.toArray(new String[imList.size()]); - - } - - public static String[] getForbiddenImports(Preferences node ) { - String text = node.get(FORBIDDEN_IMPORTS_KEY, FORBIDDEN_IMPORTS_DEFAULT); - return decodeForbiddenImports(text); - } - -} Index: org/netbeans/modules/java/hints/Imports.java --- org/netbeans/modules/java/hints/Imports.java Base (BASE) +++ org/netbeans/modules/java/hints/Imports.java Locally Modified (Based On LOCAL) @@ -44,14 +44,13 @@ import java.util.prefs.PreferenceChangeEvent; import java.util.prefs.PreferenceChangeListener; import java.util.prefs.Preferences; -import java.util.regex.Pattern; -import javax.swing.JComponent; import org.netbeans.api.java.source.Task; import org.netbeans.api.java.source.CompilationInfo; import org.netbeans.api.java.source.JavaSource; import org.netbeans.api.java.source.TreeMaker; import org.netbeans.api.java.source.TreePathHandle; import org.netbeans.api.java.source.WorkingCopy; +import org.netbeans.modules.editor.java.Utilities; import org.netbeans.modules.java.editor.semantic.RemoveUnusedImportFix; import org.netbeans.modules.java.hints.spi.AbstractHint; import org.netbeans.spi.editor.hints.ChangeInfo; @@ -77,7 +76,7 @@ private Imports duplicate; private Imports defaultPackage; private Imports samePackage; - private Imports forbiddenPackage; + private Imports excludedPackage; private Imports unused; private Imports star; @@ -109,10 +108,10 @@ return d.defaultPackage; } - public static Imports createForbidden() { + public static Imports createExcluded() { Imports d = getDelegate(); - d.forbiddenPackage = new Imports( ImportHintKind.FORBIDDEN ); - return d.forbiddenPackage; + d.excludedPackage = new Imports( ImportHintKind.EXCLUDED ); + return d.excludedPackage; } public static Imports createSamePackage() { @@ -223,15 +222,17 @@ } break; - case FORBIDDEN: - Imports forbidPackage = getDelegate().forbiddenPackage; - String[] regexps = getRegexps(forbidPackage.getPreferences(null)); - if (forbidPackage != null && - forbidPackage.isEnabled() && - isForbidden(ms.getExpression().toString(), regexps)) { + case EXCLUDED: + Imports excludePackage = getDelegate().excludedPackage; + String pkg = ms.getExpression().toString(); + String klass = ms.getIdentifier().toString(); + String exp = pkg + "." + (!klass.equals("*") ? klass : ""); //NOI18N + if (excludePackage != null && + excludePackage.isEnabled() && + Utilities.isExcluded(exp)) { result.add(ErrorDescriptionFactory.createErrorDescription( - forbidPackage.getSeverity().toEditorSeverity(), - forbidPackage.getDisplayName(), + excludePackage.getSeverity().toEditorSeverity(), + excludePackage.getDisplayName(), NO_FIXES, ci.getFileObject(), (int) ci.getTrees().getSourcePositions().getStartPosition(ci.getCompilationUnit(), it), @@ -316,16 +317,6 @@ return p; } - @Override - public JComponent getCustomizer(Preferences node) { - if ( kind == ImportHintKind.FORBIDDEN ) { - return new ForbiddenImportsCustomizer( node ); - } - else { - return super.getCustomizer(node); - } - } - public void preferenceChange(PreferenceChangeEvent evt) { if ( kind == ImportHintKind.UNUSED ) { RemoveUnusedImportFix.setEnabled(isEnabled()); @@ -361,52 +352,20 @@ ihk ); } - private String[] getRegexps( Preferences node ) { - - String[] texts = ForbiddenImportsCustomizer.getForbiddenImports(node); - String[] result = new String[texts.length]; - - for (int i = 0; i < texts.length; i++) { - String t = texts[i]; - t = t.replace(".", "\\."); - t = t.replace("**", ";;" ); - t = t.replace("*", "[^\\.]*"); - t = t.replace(";;", ".*"); - result[i] = t; - } - - return result; - } - - private static boolean isForbidden( String pkg, String regexps[] ) { - - Pattern p; - - for( String rg : regexps ) { - - if ( Pattern.matches(rg, pkg)) { - return true; - } - - } - - return false; - } - private static enum ImportHintKind { DELEGATE, UNUSED, DUPLICATE, SAME_PACKAGE, DEFAULT_PACKAGE, - FORBIDDEN, + EXCLUDED, STAR; boolean defaultOn() { switch( this ) { case DELEGATE: - case FORBIDDEN: + case EXCLUDED: case SAME_PACKAGE: case DEFAULT_PACKAGE: case UNUSED: Index: org/netbeans/modules/java/hints/resources/layer.xml --- org/netbeans/modules/java/hints/resources/layer.xml Base (BASE) +++ org/netbeans/modules/java/hints/resources/layer.xml Locally Modified (Based On LOCAL) @@ -174,8 +174,8 @@ - - + +