Changeset 33118 in osm for applications/editors/josm/plugins
- Timestamp:
- 2017-01-19T00:08:10+01:00 (8 years ago)
- Location:
- applications/editors/josm/plugins/print
- Files:
-
- 8 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/print/.classpath
r32680 r33118 2 2 <classpath> 3 3 <classpathentry kind="src" path="src"/> 4 <classpathentry kind="src" path="test/unit"/> 4 5 <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/> 5 6 <classpathentry combineaccessrules="false" kind="src" path="/JOSM"/> 7 <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/> 6 8 <classpathentry kind="output" path="bin"/> 7 9 </classpath> -
applications/editors/josm/plugins/print/src/org/openstreetmap/josm/plugins/print/PrintDialog.java
r33062 r33118 15 15 import java.awt.print.PrinterException; 16 16 import java.awt.print.PrinterJob; 17 import java.lang.reflect.Constructor; 17 18 import java.lang.reflect.Field; 18 19 import java.lang.reflect.InvocationTargetException; 20 import java.lang.reflect.Method; 19 21 import java.lang.reflect.Modifier; 20 22 import java.text.ParseException; … … 58 60 import org.openstreetmap.josm.Main; 59 61 import org.openstreetmap.josm.tools.GBC; 62 import org.openstreetmap.josm.tools.Utils; 60 63 import org.openstreetmap.josm.tools.WindowGeometry; 61 64 … … 490 493 491 494 @SuppressWarnings("unchecked") 492 protectedAttribute unmarshallPrintSetting(Collection<String> setting) throws495 static Attribute unmarshallPrintSetting(Collection<String> setting) throws 493 496 ClassNotFoundException, NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException { 494 497 … … 505 508 } else if (syntax.equals(EnumSyntax.class)) { 506 509 int intValue = Integer.parseInt(value); 510 // First method - access static enum fields by reflection for classes that do not implement getEnumValueTable 507 511 for (Field f : realClass.getFields()) { 508 512 if (Modifier.isStatic(f.getModifiers()) && category.isAssignableFrom(f.getType())) { … … 513 517 } 514 518 } 515 throw new IllegalArgumentException("Invalid enum: "+realClass+" - "+value); 519 // Second method - get instance from getEnumValueTable by reflection 520 try { 521 Method getEnumValueTable = realClass.getDeclaredMethod("getEnumValueTable"); 522 Constructor<? extends Attribute> constructor = realClass.getDeclaredConstructor(int.class); 523 Utils.setObjectsAccessible(getEnumValueTable, constructor); 524 Attribute fakeInstance = constructor.newInstance(Integer.MAX_VALUE); 525 EnumSyntax[] enumTable = (EnumSyntax[]) getEnumValueTable.invoke(fakeInstance); 526 return (Attribute) enumTable[intValue]; 527 } catch (ReflectiveOperationException | ArrayIndexOutOfBoundsException e) { 528 throw new IllegalArgumentException("Invalid enum: "+realClass+" - "+value, e); 529 } 516 530 } else if (syntax.equals(IntegerSyntax.class)) { 517 531 return realClass.getConstructor(int.class).newInstance(Integer.parseInt(value));
Note:
See TracChangeset
for help on using the changeset viewer.