From 6430ff2915ff2889cfbb24661c54342ae814d2b8 Mon Sep 17 00:00:00 2001 From: Konstantin Kolosovsky Date: Wed, 9 Sep 2015 17:24:04 +0300 Subject: [PATCH] vcs: Refactoring - removed unused PseudoImplementProxy, LearningProxy and corresponding tests --- .../com/intellij/vcsUtil/LearningProxy.java | 123 ------------------ .../vcsUtil/PseudoImplementProxy.java | 56 -------- 2 files changed, 179 deletions(-) delete mode 100644 platform/vcs-api/src/com/intellij/vcsUtil/LearningProxy.java delete mode 100644 platform/vcs-api/src/com/intellij/vcsUtil/PseudoImplementProxy.java diff --git a/platform/vcs-api/src/com/intellij/vcsUtil/LearningProxy.java b/platform/vcs-api/src/com/intellij/vcsUtil/LearningProxy.java deleted file mode 100644 index 381c43e52b0e..000000000000 --- a/platform/vcs-api/src/com/intellij/vcsUtil/LearningProxy.java +++ /dev/null @@ -1,123 +0,0 @@ -/* - * Copyright 2000-2012 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.vcsUtil; - -import org.jetbrains.annotations.NotNull; - -import java.lang.reflect.InvocationHandler; -import java.lang.reflect.Method; -import java.lang.reflect.Proxy; -import java.util.*; - -/** - * Created with IntelliJ IDEA. - * User: Irina.Chernushina - * Date: 10/19/12 - * Time: 12:42 PM - */ -public abstract class LearningProxy { - private final static Map ourDefaultValues = new HashMap(); - static { - ourDefaultValues.put("byte", new Byte((byte) 0)); - ourDefaultValues.put("char", new Character('m')); - ourDefaultValues.put("double", new Double(1)); - ourDefaultValues.put("float", new Float(1f)); - ourDefaultValues.put("int", new Integer(0)); - ourDefaultValues.put("long", new Long(0)); - ourDefaultValues.put("short", new Short((short) 0)); - ourDefaultValues.put("boolean", Boolean.FALSE); - ourDefaultValues.put("void", null); - } - private final Set myTrackedMethods; - private final InvocationHandler myLearn; - - public LearningProxy() { - myTrackedMethods = new HashSet(); - myLearn = new InvocationHandler() { - @Override - public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { - myTrackedMethods.add(new MethodDescriptor(method)); - final Class returnType = method.getReturnType(); - if (returnType.isPrimitive()) { - return ourDefaultValues.get(returnType.getName()); - } - return null; - } - }; - } - - protected abstract void onBefore() throws E; - protected abstract void onAfter() throws E; - - public T create(Class clazz, final T t) { - return (T) Proxy.newProxyInstance(clazz.getClassLoader(), new Class[]{clazz}, new InvocationHandler() { - @Override - public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { - final MethodDescriptor current = new MethodDescriptor(method); - if (myTrackedMethods.contains(current)) { - try { - onBefore(); - method.setAccessible(true); - return method.invoke(t, args); - } finally { - onAfter(); - } - } - return method.invoke(t, args); - } - }); - } - - public T learn(Class clazz) { - return (T) Proxy.newProxyInstance(clazz.getClassLoader(), new Class[]{clazz}, myLearn); - } - - private static class MethodDescriptor { - @NotNull - private final String myMethodName; - @NotNull - private final List myParameters; - - private MethodDescriptor(final Method method) { - myMethodName = method.getName(); - final Class[] types = method.getParameterTypes(); - myParameters = new ArrayList(types.length); - for (Class type : types) { - myParameters.add(type.getName()); - } - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - MethodDescriptor that = (MethodDescriptor)o; - - if (!myMethodName.equals(that.myMethodName)) return false; - if (!myParameters.equals(that.myParameters)) return false; - - return true; - } - - @Override - public int hashCode() { - int result = myMethodName.hashCode(); - result = 31 * result + myParameters.hashCode(); - return result; - } - } -} diff --git a/platform/vcs-api/src/com/intellij/vcsUtil/PseudoImplementProxy.java b/platform/vcs-api/src/com/intellij/vcsUtil/PseudoImplementProxy.java deleted file mode 100644 index 4d9872589264..000000000000 --- a/platform/vcs-api/src/com/intellij/vcsUtil/PseudoImplementProxy.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright 2000-2012 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.vcsUtil; - -import java.lang.reflect.InvocationHandler; -import java.lang.reflect.Method; -import java.lang.reflect.Proxy; - -/** - * Created with IntelliJ IDEA. - * User: Irina.Chernushina - * Date: 10/22/12 - * Time: 10:58 AM - */ -public class PseudoImplementProxy { - public static T create(final Class theInterface, final Impl implementation) { - checkMethodsExist(theInterface, implementation); - final Class implementationClass = implementation.getClass(); - return (T) Proxy.newProxyInstance(theInterface.getClassLoader(), new Class[]{theInterface}, - new InvocationHandler() { - @Override - public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { - final Method implementationClassMethod = - implementationClass.getMethod(method.getName(), method.getParameterTypes()); - implementationClassMethod.setAccessible(true); - return implementationClassMethod.invoke(implementation, args); - } - }); - } - - private static void checkMethodsExist(Class theInterface, Impl implementation) { - final Class implementationClass = implementation.getClass(); - final Method[] methods = theInterface.getDeclaredMethods(); - for (Method method : methods) { - try { - implementationClass.getMethod(method.getName(), method.getParameterTypes()); - } - catch (NoSuchMethodException e) { - throw new UnsupportedOperationException(e); - } - } - } -}