Get a better error message when accessing a non-static inner class. The old was was simply method not found, which isn't very helpful.
diff --git a/plugins/org.eclipse.jem.proxy/.settings/org.eclipse.core.resources.prefs b/plugins/org.eclipse.jem.proxy/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..2d3cc5c --- /dev/null +++ b/plugins/org.eclipse.jem.proxy/.settings/org.eclipse.core.resources.prefs
@@ -0,0 +1,3 @@ +#Wed Feb 15 12:50:05 EST 2006 +eclipse.preferences.version=1 +encoding//proxyCommon/org/eclipse/jem/internal/proxy/common/messages.properties=8859_1
diff --git a/plugins/org.eclipse.jem.proxy/initParser/org/eclipse/jem/internal/proxy/initParser/Constructor.java b/plugins/org.eclipse.jem.proxy/initParser/org/eclipse/jem/internal/proxy/initParser/Constructor.java index ba88512..13af418 100644 --- a/plugins/org.eclipse.jem.proxy/initParser/org/eclipse/jem/internal/proxy/initParser/Constructor.java +++ b/plugins/org.eclipse.jem.proxy/initParser/org/eclipse/jem/internal/proxy/initParser/Constructor.java
@@ -11,7 +11,7 @@ package org.eclipse.jem.internal.proxy.initParser; /* * $RCSfile: Constructor.java,v $ - * $Revision: 1.4 $ $Date: 2005/08/24 20:39:07 $ + * $Revision: 1.5 $ $Date: 2006/02/15 18:43:38 $ */ @@ -113,6 +113,8 @@ throw new EvaluationException(e); } catch (AmbiguousMethodException e) { throw new EvaluationException(e); + } catch (IllegalAccessException e) { + throw new EvaluationException(e); } } }
diff --git a/plugins/org.eclipse.jem.proxy/initParser/org/eclipse/jem/internal/proxy/initParser/tree/ExpressionProcesser.java b/plugins/org.eclipse.jem.proxy/initParser/org/eclipse/jem/internal/proxy/initParser/tree/ExpressionProcesser.java index a9b3950..f12a023 100644 --- a/plugins/org.eclipse.jem.proxy/initParser/org/eclipse/jem/internal/proxy/initParser/tree/ExpressionProcesser.java +++ b/plugins/org.eclipse.jem.proxy/initParser/org/eclipse/jem/internal/proxy/initParser/tree/ExpressionProcesser.java
@@ -10,7 +10,7 @@ *******************************************************************************/ /* * $RCSfile: ExpressionProcesser.java,v $ - * $Revision: 1.21 $ $Date: 2005/08/24 20:39:07 $ + * $Revision: 1.22 $ $Date: 2006/02/15 18:43:38 $ */ package org.eclipse.jem.internal.proxy.initParser.tree; @@ -2441,29 +2441,26 @@ try { // We need to pull in the arguments. They are stacked in reverse order. Object value = null; // The new instance. - if (argumentCount > 0) { - Object[] args = new Object[argumentCount]; - Class[] argTypes = new Class[argumentCount]; - for (int i = argumentCount - 1; i >= 0; i--) { - args[i] = popExpression(); - argTypes[i] = popExpressionType(false); - } - - // Now we need to find the appropriate constructor. - Constructor ctor; - ctor = MethodHelper.findCompatibleConstructor(type, argTypes); - if (traceOn) { + Object[] args = new Object[argumentCount]; + Class[] argTypes = new Class[argumentCount]; + for (int i = argumentCount - 1; i >= 0; i--) { + args[i] = popExpression(); + argTypes[i] = popExpressionType(false); + } + + // Now we need to find the appropriate constructor. + Constructor ctor; + ctor = MethodHelper.findCompatibleConstructor(type, argTypes); + if (traceOn) { + if (argumentCount == 0) { + // No args, just do default ctor. + System.out.print("Default ctor)"); //$NON-NLS-1$ + } else { System.out.print(ctor); System.out.print(')'); } - value = ctor.newInstance(args); - } else { - // No args, just do default ctor. - if (traceOn) { - System.out.print("Default ctor)"); //$NON-NLS-1$ - } - value = type.newInstance(); } + value = ctor.newInstance(args); pushExpressionValue(value, type); } catch (RuntimeException e) {
diff --git a/plugins/org.eclipse.jem.proxy/proxy/org/eclipse/jem/internal/proxy/core/IBeanTypeProxy.java b/plugins/org.eclipse.jem.proxy/proxy/org/eclipse/jem/internal/proxy/core/IBeanTypeProxy.java index da65767..545aa1e 100644 --- a/plugins/org.eclipse.jem.proxy/proxy/org/eclipse/jem/internal/proxy/core/IBeanTypeProxy.java +++ b/plugins/org.eclipse.jem.proxy/proxy/org/eclipse/jem/internal/proxy/core/IBeanTypeProxy.java
@@ -10,7 +10,7 @@ *******************************************************************************/ /* * $RCSfile: IBeanTypeProxy.java,v $ - * $Revision: 1.8 $ $Date: 2005/08/24 20:39:06 $ + * $Revision: 1.9 $ $Date: 2006/02/15 18:43:38 $ */ package org.eclipse.jem.internal.proxy.core; @@ -30,10 +30,11 @@ * @return * @throws NoSuchMethodException * @throws AmbiguousMethodException + * @throws IllegalAccessException * * @since 1.1.0 */ - public IConstructorProxy getCompatibleConstructor(IBeanTypeProxy[] argumentTypes) throws AmbiguousMethodException, NoSuchMethodException; + public IConstructorProxy getCompatibleConstructor(IBeanTypeProxy[] argumentTypes) throws AmbiguousMethodException, NoSuchMethodException, IllegalAccessException; /** * Find the most compatible public method, including inheritied. This means it will
diff --git a/plugins/org.eclipse.jem.proxy/proxyCommon/org/eclipse/jem/internal/proxy/common/Messages.java b/plugins/org.eclipse.jem.proxy/proxyCommon/org/eclipse/jem/internal/proxy/common/Messages.java new file mode 100644 index 0000000..b91a535 --- /dev/null +++ b/plugins/org.eclipse.jem.proxy/proxyCommon/org/eclipse/jem/internal/proxy/common/Messages.java
@@ -0,0 +1,41 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +/* + * $RCSfile: Messages.java,v $ + * $Revision: 1.1 $ $Date: 2006/02/15 18:43:38 $ + */ +package org.eclipse.jem.internal.proxy.common; + +import java.util.MissingResourceException; +import java.util.ResourceBundle; + +/** + * + * @since 1.2.0 + */ +public class Messages { + + private static final String BUNDLE_NAME = "org.eclipse.jem.internal.proxy.common.messages"; //$NON-NLS-1$ + + private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME); + + private Messages() { + } + + public static String getString(String key) { + // TODO Auto-generated method stub + try { + return RESOURCE_BUNDLE.getString(key); + } catch (MissingResourceException e) { + return '!' + key + '!'; + } + } +}
diff --git a/plugins/org.eclipse.jem.proxy/proxyCommon/org/eclipse/jem/internal/proxy/common/MethodHelper.java b/plugins/org.eclipse.jem.proxy/proxyCommon/org/eclipse/jem/internal/proxy/common/MethodHelper.java index 90772c3..3667c68 100644 --- a/plugins/org.eclipse.jem.proxy/proxyCommon/org/eclipse/jem/internal/proxy/common/MethodHelper.java +++ b/plugins/org.eclipse.jem.proxy/proxyCommon/org/eclipse/jem/internal/proxy/common/MethodHelper.java
@@ -9,8 +9,8 @@ * IBM Corporation - initial API and implementation *******************************************************************************/ package org.eclipse.jem.internal.proxy.common; -import java.lang.reflect.Constructor; -import java.lang.reflect.Method; +import java.lang.reflect.*; +import java.text.MessageFormat; import java.util.ArrayList; import java.util.List; @@ -196,10 +196,21 @@ return ne; } + /** - * Find the most compatible constructor for the given arguments. + * Find the most compatible constructor for the class with the given arguments. + * @param receiver class to get the constructor for + * @param arguments array of argument types + * @return the constructor + * @throws NoSuchMethodException no compatible constructor can be found + * @throws AmbiguousMethodException there is more than one compatible constructor + * @throws IllegalAccessException it can't be accessed. Such as it is a non-static inner class. + * + * @since 1.2.0 */ - public static Constructor findCompatibleConstructor(Class receiver, Class[] arguments) throws NoSuchMethodException, AmbiguousMethodException { + public static Constructor findCompatibleConstructor(Class receiver, Class[] arguments) throws NoSuchMethodException, AmbiguousMethodException, IllegalAccessException { + if (receiver.getDeclaringClass() != null && !Modifier.isStatic(receiver.getModifiers())) + throw new IllegalAccessException(MessageFormat.format(Messages.getString("MethodHelper.NONSTATICINNERCLASS_WARNING"), new Object[] {receiver.getName()})); //$NON-NLS-1$ try { java.lang.reflect.Constructor ctor = receiver.getDeclaredConstructor(arguments); ctor.setAccessible(true); // We allow all access, let ide and compiler handle security.
diff --git a/plugins/org.eclipse.jem.proxy/proxyCommon/org/eclipse/jem/internal/proxy/common/messages.properties b/plugins/org.eclipse.jem.proxy/proxyCommon/org/eclipse/jem/internal/proxy/common/messages.properties new file mode 100644 index 0000000..937eea7 --- /dev/null +++ b/plugins/org.eclipse.jem.proxy/proxyCommon/org/eclipse/jem/internal/proxy/common/messages.properties
@@ -0,0 +1,11 @@ +############################################################################### +# Copyright (c) 2006 IBM Corporation and others. +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Eclipse Public License v1.0 +# which accompanies this distribution, and is available at +# http://www.eclipse.org/legal/epl-v10.html +# +# Contributors: +# IBM Corporation - initial API and implementation +############################################################################### +MethodHelper.NONSTATICINNERCLASS_WARNING=Class {0} is a non-static inner class. These cannot be instantiated at this time.
diff --git a/plugins/org.eclipse.jem.proxy/proxyRemote/org/eclipse/jem/internal/proxy/remote/REMAbstractBeanTypeProxy.java b/plugins/org.eclipse.jem.proxy/proxyRemote/org/eclipse/jem/internal/proxy/remote/REMAbstractBeanTypeProxy.java index 91d15f0..13ac247 100644 --- a/plugins/org.eclipse.jem.proxy/proxyRemote/org/eclipse/jem/internal/proxy/remote/REMAbstractBeanTypeProxy.java +++ b/plugins/org.eclipse.jem.proxy/proxyRemote/org/eclipse/jem/internal/proxy/remote/REMAbstractBeanTypeProxy.java
@@ -10,7 +10,7 @@ *******************************************************************************/ /* * $RCSfile: REMAbstractBeanTypeProxy.java,v $ - * $Revision: 1.15 $ $Date: 2005/08/24 20:39:07 $ + * $Revision: 1.16 $ $Date: 2006/02/15 18:43:38 $ */ package org.eclipse.jem.internal.proxy.remote; @@ -636,7 +636,7 @@ /* (non-Javadoc) * @see org.eclipse.jem.internal.proxy.core.IBeanTypeProxy#getCompatibleConstructor(org.eclipse.jem.internal.proxy.core.IBeanTypeProxy[]) */ - public IConstructorProxy getCompatibleConstructor(IBeanTypeProxy[] argumentTypes) throws NoSuchMethodException, AmbiguousMethodException { + public IConstructorProxy getCompatibleConstructor(IBeanTypeProxy[] argumentTypes) throws NoSuchMethodException, AmbiguousMethodException, IllegalAccessException { if (isInterface()) return null; // Interfaces don't have ctor's. @@ -653,6 +653,8 @@ throw new NoSuchMethodException(e.getProxyLocalizedMessage()); else if (e.getTypeProxy().equals(fRegistry.getBeanTypeProxyFactory().getBeanTypeProxy("org.eclipse.jem.internal.proxy.common.AmbiguousMethodException"))) //$NON-NLS-1$ throw new AmbiguousMethodException(e.getProxyLocalizedMessage()); + else if (e.getTypeProxy().equals(fRegistry.getBeanTypeProxyFactory().getBeanTypeProxy("java.lang.IllegalAccessException"))) //$NON-NLS-1$ + throw new IllegalAccessException(e.getProxyLocalizedMessage()); ProxyPlugin.getPlugin().getLogger().log(e); return null; } finally {
diff --git a/plugins/org.eclipse.jem.proxy/proxyide/org/eclipse/jem/internal/proxy/ide/IDEBeanTypeProxy.java b/plugins/org.eclipse.jem.proxy/proxyide/org/eclipse/jem/internal/proxy/ide/IDEBeanTypeProxy.java index 330c9b9..f31199e 100644 --- a/plugins/org.eclipse.jem.proxy/proxyide/org/eclipse/jem/internal/proxy/ide/IDEBeanTypeProxy.java +++ b/plugins/org.eclipse.jem.proxy/proxyide/org/eclipse/jem/internal/proxy/ide/IDEBeanTypeProxy.java
@@ -9,7 +9,7 @@ * IBM Corporation - initial API and implementation *******************************************************************************/ /* - * $RCSfile: IDEBeanTypeProxy.java,v $ $Revision: 1.14 $ $Date: 2005/08/24 20:39:06 $ + * $RCSfile: IDEBeanTypeProxy.java,v $ $Revision: 1.15 $ $Date: 2006/02/15 18:43:38 $ */ package org.eclipse.jem.internal.proxy.ide; @@ -389,7 +389,7 @@ * * @see org.eclipse.jem.internal.proxy.core.IBeanTypeProxy#getCompatibleConstructor(org.eclipse.jem.internal.proxy.core.IBeanTypeProxy[]) */ - public IConstructorProxy getCompatibleConstructor(IBeanTypeProxy[] argumentTypes) throws AmbiguousMethodException, NoSuchMethodException { + public IConstructorProxy getCompatibleConstructor(IBeanTypeProxy[] argumentTypes) throws AmbiguousMethodException, NoSuchMethodException, IllegalAccessException { Class[] argClasses = new Class[argumentTypes.length]; for (int i = 0; i < argumentTypes.length; i++) {
diff --git a/plugins/org.eclipse.jem.proxy/proxyide/org/eclipse/jem/internal/proxy/ide/IDEMethodProxyFactory.java b/plugins/org.eclipse.jem.proxy/proxyide/org/eclipse/jem/internal/proxy/ide/IDEMethodProxyFactory.java index ecf4f28..4f1a062 100644 --- a/plugins/org.eclipse.jem.proxy/proxyide/org/eclipse/jem/internal/proxy/ide/IDEMethodProxyFactory.java +++ b/plugins/org.eclipse.jem.proxy/proxyide/org/eclipse/jem/internal/proxy/ide/IDEMethodProxyFactory.java
@@ -9,7 +9,7 @@ * IBM Corporation - initial API and implementation *******************************************************************************/ /* - * $RCSfile: IDEMethodProxyFactory.java,v $ $Revision: 1.12 $ $Date: 2005/08/24 20:39:06 $ + * $RCSfile: IDEMethodProxyFactory.java,v $ $Revision: 1.13 $ $Date: 2006/02/15 18:43:38 $ */ package org.eclipse.jem.internal.proxy.ide; @@ -304,7 +304,7 @@ return getMethodProxy(method); } - IConstructorProxy getCompatibleConstructor(Class aClass, Class[] parmTypes) throws AmbiguousMethodException, NoSuchMethodException { + IConstructorProxy getCompatibleConstructor(Class aClass, Class[] parmTypes) throws AmbiguousMethodException, NoSuchMethodException, IllegalAccessException { Constructor method = MethodHelper.findCompatibleConstructor(aClass, parmTypes); return getConstructorProxy(method); }