8163362: Reconsider reflection usage in java.awt.font.JavaAWTFontAccessImpl class

Reviewed-by: naoto, okutsu, prr
This commit is contained in:
Rachna Goel 2016-08-23 15:35:44 +09:00
parent 82a6f08720
commit f423e1290f

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2016 Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -25,7 +25,6 @@
package java.awt.font;
import java.lang.reflect.Field;
import jdk.internal.misc.JavaAWTFontAccess;
class JavaAWTFontAccessImpl implements JavaAWTFontAccess {
@ -33,19 +32,17 @@ class JavaAWTFontAccessImpl implements JavaAWTFontAccess {
// java.awt.font.TextAttribute constants
public Object getTextAttributeConstant(String name) {
switch (name) {
case "RUN_DIRECTION":
case "NUMERIC_SHAPING":
case "BIDI_EMBEDDING":
case "RUN_DIRECTION_LTR":
try {
Field f = TextAttribute.class.getField(name);
return f.get(null);
} catch (NoSuchFieldException | IllegalAccessException x) {
throw new AssertionError(x);
}
case "RUN_DIRECTION":
return TextAttribute.RUN_DIRECTION;
case "NUMERIC_SHAPING":
return TextAttribute.NUMERIC_SHAPING;
case "BIDI_EMBEDDING":
return TextAttribute.BIDI_EMBEDDING;
case "RUN_DIRECTION_LTR":
return TextAttribute.RUN_DIRECTION_LTR;
default:
throw new AssertionError("Constant name is not recognized");
}
throw new AssertionError("Constant name is not recognized");
}
// java.awt.font.NumericShaper