@Nullable public static DomInvocationHandler getDomInvocationHandler(DomElement proxy) { if (proxy instanceof DomFileElement) { return null; } if (proxy instanceof DomInvocationHandler) { return (DomInvocationHandler)proxy; } final InvocationHandler handler = AdvancedProxy.getInvocationHandler(proxy); if (handler instanceof StableInvocationHandler) { //noinspection unchecked final DomElement element = ((StableInvocationHandler<DomElement>)handler).getWrappedElement(); return element == null ? null : getDomInvocationHandler(element); } if (handler instanceof DomInvocationHandler) { return (DomInvocationHandler)handler; } return null; }
@Nullable public static DomInvocationHandler getDomInvocationHandler(DomElement proxy) { if (proxy instanceof DomFileElement) { return null; } if (proxy instanceof DomInvocationHandler) { return (DomInvocationHandler)proxy; } final InvocationHandler handler = AdvancedProxy.getInvocationHandler(proxy); if (handler instanceof StableInvocationHandler) { final DomElement element = ((StableInvocationHandler<DomElement>)handler).getWrappedElement(); return element == null ? null : getDomInvocationHandler(element); } if (handler instanceof DomInvocationHandler) { return (DomInvocationHandler)handler; } return null; }
@Nullable public static DomInvocationHandler getDomInvocationHandler(DomElement proxy) { if(proxy instanceof DomFileElement) { return null; } if(proxy instanceof DomInvocationHandler) { return (DomInvocationHandler) proxy; } final InvocationHandler handler = AdvancedProxy.getInvocationHandler(proxy); if(handler instanceof StableInvocationHandler) { //noinspection unchecked final DomElement element = ((StableInvocationHandler<DomElement>) handler).getWrappedElement(); return element == null ? null : getDomInvocationHandler(element); } if(handler instanceof DomInvocationHandler) { return (DomInvocationHandler) handler; } return null; }
private <T> T _mergeModels(final Class<? super T> aClass, final MergingInvocationHandler<T> handler, final T... implementations) { final Set<Class> commonClasses = getCommonClasses(new THashSet<Class>(), implementations); commonClasses.add(MERGED_OBJECT_CLASS); commonClasses.add(aClass); final T t = AdvancedProxy.<T>createProxy(handler, null, commonClasses.toArray(new Class[commonClasses.size()])); return t; }
@NotNull public final DomElement getProxy() { DomElement proxy = myProxy; if (proxy == null) { Class<?> rawType = getRawType(); Class<? extends DomElement> implementation = myManager.getApplicationComponent().getImplementation(rawType); final boolean isInterface = rawType.isInterface(); if (implementation == null && !isInterface) { //noinspection unchecked implementation = (Class<? extends DomElement>)rawType; } myProxy = proxy = AdvancedProxy.createProxy(this, implementation, isInterface ? new Class[]{rawType} : ArrayUtil.EMPTY_CLASS_ARRAY); } return proxy; }
public void testExtendClass() throws Throwable { final List<String> invocations = new ArrayList<String>(); Implementation implementation = AdvancedProxy.createProxy(Implementation.class, new Class[]{Interface3.class}, new InvocationHandler(){ @Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { invocations.add(method.getName()); if (Object.class.equals(method.getDeclaringClass())) { return method.invoke(this, args); } return Implementation.class.getMethod("getField").invoke(proxy); } }, "239"); implementation.hashCode(); implementation.method(); assertEquals("239", implementation.getFoo()); implementation.setField("42"); assertEquals("42", implementation.getBar()); assertEquals("42", implementation.toString()); assertEquals(Arrays.asList("hashCode", "getFoo", "getFoo", "getBar"), invocations); assertEquals("42", Interface1.class.getMethod("getFoo").invoke(implementation)); assertEquals("42", Interface3.class.getMethod("bar").invoke(implementation)); assertEquals("42", Interface1.class.getMethod("foo").invoke(implementation)); assertEquals("42", Interface2.class.getMethod("foo").invoke(implementation)); assertEquals("42", Interface2.class.getMethod("foo").invoke(implementation)); assertEquals("42", Implementation.class.getMethod("foo").invoke(implementation)); }
private <T> T _mergeModels(final Class<? super T> aClass, final MergingInvocationHandler<T> handler, final T... implementations) { final Set<Class> commonClasses = getCommonClasses(new THashSet<Class>(), implementations); commonClasses.add(MERGED_OBJECT_CLASS); commonClasses.add(aClass); final T t = AdvancedProxy.<T>createProxy(handler, null, commonClasses.toArray(new Class[commonClasses.size()])); //myMergedMap.get(aClass).put(implementations, t); return t; }
protected DomInvocationHandler(Type type, DomParentStrategy parentStrategy, @NotNull final EvaluatedXmlName tagName, final T childDescription, final DomManagerImpl manager, boolean dynamic, @Nullable Stub stub) { myManager = manager; myParentStrategy = parentStrategy; myTagName = tagName; myChildDescription = childDescription; myStub = stub; myLastModCount = manager.getPsiModificationCount(); myType = narrowType(type); final Class<?> rawType = getRawType(); myInvocationCache = manager.getApplicationComponent().getInvocationCache(rawType); Class<? extends DomElement> implementation = manager.getApplicationComponent().getImplementation(rawType); final boolean isInterface = ReflectionCache.isInterface(rawType); if (implementation == null && !isInterface) { implementation = (Class<? extends DomElement>)rawType; } myProxy = AdvancedProxy.createProxy(this, implementation, isInterface ? new Class[]{rawType} : ArrayUtil.EMPTY_CLASS_ARRAY); refreshGenericInfo(dynamic); if (stub != null) { stub.setHandler(this); } }
protected DomInvocationHandler(Type type, DomParentStrategy parentStrategy, @NotNull final EvaluatedXmlName tagName, final T childDescription, final DomManagerImpl manager, boolean dynamic, @Nullable Stub stub) { myManager = manager; myParentStrategy = parentStrategy; myTagName = tagName; myChildDescription = childDescription; myStub = stub; myLastModCount = manager.getPsiModificationCount(); myType = narrowType(type); final Class<?> rawType = getRawType(); myInvocationCache = manager.getApplicationComponent().getInvocationCache(rawType); Class<? extends DomElement> implementation = manager.getApplicationComponent().getImplementation(rawType); final boolean isInterface = rawType.isInterface(); if (implementation == null && !isInterface) { implementation = (Class<? extends DomElement>)rawType; } myProxy = AdvancedProxy.createProxy(this, implementation, isInterface ? new Class[]{rawType} : ArrayUtil.EMPTY_CLASS_ARRAY); refreshGenericInfo(dynamic); if (stub != null) { stub.setHandler(this); } }
public static StableInvocationHandler getStableInvocationHandler(Object proxy) { return (StableInvocationHandler)AdvancedProxy.getInvocationHandler(proxy); }
public void testAddInterfaces() throws Throwable { final BaseImpl proxy = AdvancedProxy.createProxy(BaseImpl.class, BaseIEx.class); assertEquals(proxy.sayA(), "a"); assertEquals(((BaseI)proxy).sayA(), "a"); assertEquals(((BaseIEx)proxy).sayA(), "a"); }
public static StableInvocationHandler getStableInvocationHandler(Object proxy) { return (StableInvocationHandler) AdvancedProxy.getInvocationHandler(proxy); }