Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Primitive wrapper property editors should use valueOf #7864

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

package org.netbeans.beaninfo.editors;

import java.beans.*;

/**
* Editor for property of type java.lang.Boolean
Expand All @@ -29,9 +28,10 @@
public class BooleanEditor extends WrappersEditor {

public BooleanEditor() {
super(java.lang.Boolean.TYPE);
super(Boolean.TYPE);
}

@Override
public String getJavaInitializationString() {
Boolean val = (Boolean) getValue();
return Boolean.TRUE.equals(val) ? "java.lang.Boolean.TRUE" :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

package org.netbeans.beaninfo.editors;

import java.beans.*;

/**
* Editor for property of type java.lang.Byte
Expand All @@ -29,13 +28,9 @@
public class ByteEditor extends WrappersEditor {

public ByteEditor() {
super(java.lang.Byte.TYPE);
super(Byte.TYPE);
}


//----------------------------------------------------------------------


/**
* This method is intended for use when generating Java code to set
* the value of the property. It should return a fragment of Java code
Expand All @@ -47,8 +42,9 @@ public ByteEditor() {
* @return A fragment of Java code representing an initializer for the
* current value.
*/
@Override
public String getJavaInitializationString() {
return "new java.lang.Byte((byte)" + getAsText() + ")"; // NOI18N
return "Byte.valueOf((byte)" + getAsText() + ")"; // NOI18N
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

package org.netbeans.beaninfo.editors;

import java.beans.*;

/**
* Editor for property of type java.lang.Character
Expand All @@ -29,13 +28,9 @@
public class CharacterEditor extends WrappersEditor {

public CharacterEditor() {
super(java.lang.Character.TYPE);
super(Character.TYPE);
}


//----------------------------------------------------------------------


/**
* This method is intended for use when generating Java code to set
* the value of the property. It should return a fragment of Java code
Expand All @@ -47,11 +42,12 @@ public CharacterEditor() {
* @return A fragment of Java code representing an initializer for the
* current value.
*/
@Override
public String getJavaInitializationString() {
if ( ((Character)getValue()).charValue() == '\'' )
return "new java.lang.Character('\\'')"; // NOI18N
if ((Character)getValue() == '\'')
return "Character.valueOf('\\'')"; // NOI18N
else
return "new java.lang.Character('" + getAsText() + "')"; // NOI18N
return "Character.valueOf('" + getAsText() + "')"; // NOI18N
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@

package org.netbeans.beaninfo.editors;

import java.beans.*;

/**
* Editor for property of type java.lang.Double
*
Expand All @@ -29,13 +27,9 @@
public class DoubleEditor extends WrappersEditor {

public DoubleEditor() {
super(java.lang.Double.TYPE);
super(Double.TYPE);
}


//----------------------------------------------------------------------


/**
* This method is intended for use when generating Java code to set
* the value of the property. It should return a fragment of Java code
Expand All @@ -47,8 +41,9 @@ public DoubleEditor() {
* @return A fragment of Java code representing an initializer for the
* current value.
*/
@Override
public String getJavaInitializationString() {
return "new java.lang.Double(" + getAsText() + ")"; // NOI18N
return "Double.valueOf(" + getAsText() + "D)"; // NOI18N
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@

package org.netbeans.beaninfo.editors;

import java.beans.*;

/**
* Editor for property of type java.lang.Float
*
Expand All @@ -29,13 +27,9 @@
public class FloatEditor extends WrappersEditor {

public FloatEditor() {
super(java.lang.Float.TYPE);
super(Float.TYPE);
}


//----------------------------------------------------------------------


/**
* This method is intended for use when generating Java code to set
* the value of the property. It should return a fragment of Java code
Expand All @@ -47,8 +41,9 @@ public FloatEditor() {
* @return A fragment of Java code representing an initializer for the
* current value.
*/
@Override
public String getJavaInitializationString() {
return "new java.lang.Float(" + getAsText() + "F)"; // NOI18N
return "Float.valueOf(" + getAsText() + "F)"; // NOI18N
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@

package org.netbeans.beaninfo.editors;

import java.beans.*;
import org.openide.explorer.propertysheet.PropertyEnv;
import org.openide.explorer.propertysheet.ExPropertyEditor;

/**
* Editor for property of type java.lang.Integer
Expand All @@ -31,13 +28,15 @@
public class IntegerEditor extends WrappersEditor {

public IntegerEditor() {
super(java.lang.Integer.TYPE);
super(Integer.TYPE);
}

@Override
public String getJavaInitializationString() {
return "new java.lang.Integer(" + pe.getJavaInitializationString() + ")"; // NOI18N
return "Integer.valueOf(" + pe.getJavaInitializationString() + ")"; // NOI18N
}

@Override
public void setAsText(String text) throws IllegalArgumentException {
super.setAsText (text.trim());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@

package org.netbeans.beaninfo.editors;

import java.beans.*;

/**
* Editor for property of type java.lang.Long
*
Expand All @@ -29,11 +27,12 @@
public class LongEditor extends WrappersEditor {

public LongEditor() {
super(java.lang.Long.TYPE);
super(Long.TYPE);
}

@Override
public String getJavaInitializationString() {
return "new java.lang.Long(" + getAsText() + "L)"; // NOI18N
return "Long.valueOf(" + getAsText() + "L)"; // NOI18N
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@

package org.netbeans.beaninfo.editors;

import java.beans.*;

/**
* Editor for property of type java.lang.Short
*
Expand All @@ -29,13 +27,9 @@
public class ShortEditor extends WrappersEditor {

public ShortEditor() {
super(java.lang.Short.TYPE);
super(Short.TYPE);
}


//----------------------------------------------------------------------


/**
* This method is intended for use when generating Java code to set
* the value of the property. It should return a fragment of Java code
Expand All @@ -47,8 +41,9 @@ public ShortEditor() {
* @return A fragment of Java code representing an initializer for the
* current value.
*/
@Override
public String getJavaInitializationString() {
return "new java.lang.Short((short)" + getAsText() + ")"; // NOI18N
return "Short.valueOf((short)" + getAsText() + ")"; // NOI18N
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@

package org.netbeans.beaninfo.editors;

import java.beans.*;
import java.beans.PropertyChangeListener;
import java.beans.PropertyEditor;
import java.beans.PropertyEditorManager;
import java.text.MessageFormat;
import org.netbeans.core.UIExceptions;
import org.openide.explorer.propertysheet.ExPropertyEditor;
Expand All @@ -41,31 +43,39 @@ public WrappersEditor(Class type) {
pe = PropertyEditorManager.findEditor(type);
}

@Override
public void setValue(Object newValue) throws IllegalArgumentException {
pe.setValue(newValue);
}

@Override
public Object getValue() {
return pe.getValue();
}

@Override
public boolean isPaintable() {
return pe.isPaintable();
}

@Override
public void paintValue(java.awt.Graphics gfx, java.awt.Rectangle box) {
pe.paintValue(gfx, box);
}

@Override
public String getAsText () {
if ( pe.getValue() == null )
return "null"; // NOI18N
return pe.getAsText();
}

@Override
public void setAsText(String text) throws IllegalArgumentException {
if ( "null".equals( text ) ) // NOI18N
if ( "null".equals( text ) ) { // NOI18N
pe.setValue(null);
return;
}
try {
pe.setAsText(text);
} catch (Exception e) {
Expand All @@ -83,26 +93,32 @@ public void setAsText(String text) throws IllegalArgumentException {
}
}

@Override
public String[] getTags() {
return pe.getTags();
}

@Override
public java.awt.Component getCustomEditor() {
return pe.getCustomEditor();
}

@Override
public boolean supportsCustomEditor() {
return pe.supportsCustomEditor();
}

@Override
public synchronized void addPropertyChangeListener(PropertyChangeListener listener) {
pe.addPropertyChangeListener(listener);
}

@Override
public synchronized void removePropertyChangeListener(PropertyChangeListener listener) {
pe.removePropertyChangeListener(listener);
}

@Override
public void attachEnv(PropertyEnv env) {
//Delegate if the primitive editor is an ExPropertyEditor -
//boolean and int editors will be
Expand Down
Loading