提交 11652016 编写于 作者: J Josh Soref 提交者: Oleg Nenashev

IntelliJ/Java: Duplicate code -- Refactored as ExtensionFinder.getClassFromIndex (#4079)

* IntelliJ/Java: Duplicate code -- Refactored as ExtensionFinder.getClassFromIndex

* Adding braces around throw new AssertionError
上级 5926847d
......@@ -533,8 +533,9 @@ public abstract class ExtensionFinder implements ExtensionPoint {
} else
if (e instanceof Method) {
extType = ((Method)e).getReturnType();
} else
} else {
throw new AssertionError();
}
resolve(extType);
......@@ -697,18 +698,7 @@ public abstract class ExtensionFinder implements ExtensionPoint {
for (IndexItem<Extension,Object> item : indices) {
try {
AnnotatedElement e = item.element();
Class<?> extType;
if (e instanceof Class) {
extType = (Class) e;
} else
if (e instanceof Field) {
extType = ((Field)e).getType();
} else
if (e instanceof Method) {
extType = ((Method)e).getReturnType();
} else
throw new AssertionError();
Class<?> extType = getClassFromIndex(item);
if(type.isAssignableFrom(extType)) {
Object instance = item.instance();
......@@ -733,18 +723,7 @@ public abstract class ExtensionFinder implements ExtensionPoint {
// but we can't synchronize this --- if we do, the one thread that's supposed to load a class
// can block while other threads wait for the entry into the element call().
// looking at the sezpoz code, it should be safe to do so
AnnotatedElement e = item.element();
Class<?> extType;
if (e instanceof Class) {
extType = (Class) e;
} else
if (e instanceof Field) {
extType = ((Field)e).getType();
} else
if (e instanceof Method) {
extType = ((Method)e).getReturnType();
} else
throw new AssertionError();
Class<?> extType = getClassFromIndex(item);
// according to JDK-4993813 this is the only way to force class initialization
Class.forName(extType.getName(),true,extType.getClassLoader());
} catch (Exception | LinkageError e) {
......@@ -758,5 +737,20 @@ public abstract class ExtensionFinder implements ExtensionPoint {
}
}
private static Class<?> getClassFromIndex(IndexItem<Extension, Object> item) throws InstantiationException {
AnnotatedElement e = item.element();
Class<?> extType;
if (e instanceof Class) {
extType = (Class) e;
} else if (e instanceof Field) {
extType = ((Field) e).getType();
} else if (e instanceof Method) {
extType = ((Method) e).getReturnType();
} else {
throw new AssertionError();
}
return extType;
}
private static final Logger LOGGER = Logger.getLogger(ExtensionFinder.class.getName());
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册