[78572] Interfaces with multiple extends interfaces on them failed introspection.
diff --git a/tests/org.eclipse.jem.tests/javatests/org/eclipse/jem/tests/beaninfo/AbstractBeanInfoTestCase.java b/tests/org.eclipse.jem.tests/javatests/org/eclipse/jem/tests/beaninfo/AbstractBeanInfoTestCase.java index 51bfaff..7bf77d1 100644 --- a/tests/org.eclipse.jem.tests/javatests/org/eclipse/jem/tests/beaninfo/AbstractBeanInfoTestCase.java +++ b/tests/org.eclipse.jem.tests/javatests/org/eclipse/jem/tests/beaninfo/AbstractBeanInfoTestCase.java
@@ -11,9 +11,11 @@ package org.eclipse.jem.tests.beaninfo; /* * $RCSfile: AbstractBeanInfoTestCase.java,v $ - * $Revision: 1.6 $ $Date: 2004/08/27 15:33:39 $ + * $Revision: 1.7 $ $Date: 2004/11/12 23:11:09 $ */ +import java.util.HashSet; import java.util.Iterator; +import java.util.Set; import junit.framework.TestCase; @@ -25,6 +27,9 @@ import org.eclipse.jem.internal.beaninfo.PropertyDecorator; import org.eclipse.jem.internal.beaninfo.adapters.BeaninfoNature; import org.eclipse.jem.internal.beaninfo.core.Utilities; +import org.eclipse.jem.internal.proxy.core.*; +import org.eclipse.jem.internal.proxy.core.IArrayBeanProxy; +import org.eclipse.jem.internal.proxy.core.ProxyFactoryRegistry; import org.eclipse.jem.tests.JavaProjectUtil; import org.eclipse.jem.java.JavaClass; @@ -62,20 +67,33 @@ assertNotNull(nature); rset = nature.getResourceSet(); assertNotNull(rset); + // We also want to remove any beaninfos from the search path that aren't from testing so that we don't get any weird side-effects. + ProxyFactoryRegistry registry = nature.getRegistry(); + IArrayBeanProxy sp = Utilities.getBeanInfoSearchPath(registry); + // remove any that don't start with org.eclipse.jem.tests. + int len = sp.getLength(); + for (int i = 0; i < len; i++) { + String path = ((IStringBeanProxy) sp.get(i)).stringValue(); + if (!path.startsWith("org.eclipse.jem.tests")) + Utilities.removeBeanInfoPath(registry, path); + } } protected int objFeatures, objNonProperties; // Object features count and Object non-properties count. This is only initialized as needed. + protected Set objFeaturesSet; /** * To initialize the objFeatures and objNonProperties counts when necessary. Not needed for all tests. */ protected void objFeaturesSetup() { // Get the number of features that java.lang.Object has: JavaClass objClass = (JavaClass) rset.getEObject(URI.createURI("java:/java.lang#Object"), true); //$NON-NLS-1$ + objFeaturesSet = new HashSet(); objFeatures = objClass.getProperties().size(); // Find the number of always inherited properties. objNonProperties = 0; for (Iterator itr0 = objClass.getProperties().iterator(); itr0.hasNext();) { EStructuralFeature p = (EStructuralFeature) itr0.next(); + objFeaturesSet.add(p); PropertyDecorator pd = Utilities.getPropertyDecorator(p); if ( pd == null || (pd.isImplicitlyCreated() == FeatureDecorator.NOT_IMPLICIT && !pd.isMergeIntrospection())) objNonProperties++;
diff --git a/tests/org.eclipse.jem.tests/javatests/org/eclipse/jem/tests/beaninfo/TestAWTSwingUI.java b/tests/org.eclipse.jem.tests/javatests/org/eclipse/jem/tests/beaninfo/TestAWTSwingUI.java index 60777a2..dc4e0a6 100644 --- a/tests/org.eclipse.jem.tests/javatests/org/eclipse/jem/tests/beaninfo/TestAWTSwingUI.java +++ b/tests/org.eclipse.jem.tests/javatests/org/eclipse/jem/tests/beaninfo/TestAWTSwingUI.java
@@ -11,19 +11,30 @@ package org.eclipse.jem.tests.beaninfo; /* * $RCSfile: TestAWTSwingUI.java,v $ - * $Revision: 1.5 $ $Date: 2004/08/27 15:33:39 $ + * $Revision: 1.6 $ $Date: 2004/11/12 23:11:09 $ */ +import java.io.BufferedReader; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.PrintWriter; +import java.net.URL; import java.util.Arrays; +import java.util.Collections; +import java.util.HashSet; +import java.util.Iterator; import java.util.List; +import java.util.Set; import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.ecore.ENamedElement; import org.eclipse.emf.ecore.EStructuralFeature; - import org.eclipse.jem.internal.beaninfo.MethodProxy; import org.eclipse.jem.internal.beaninfo.PropertyDecorator; import org.eclipse.jem.internal.beaninfo.core.Utilities; - import org.eclipse.jem.java.JavaClass; +import org.eclipse.jem.tests.JavaTestsPlugin; /** * @author richkulp @@ -46,6 +57,88 @@ super(name); } + /* + * The number of properties keep increasing by version, + * but there is a minimal set. This minimal set will be + * stored in a file and can be loaded by this method. + * This set can be used to make sure that at least the + * required properties are there. + * + * The filename has to be relative to the tests plugin. + */ + protected Set getNames(String filename) throws IOException { + Set names = new HashSet(50); + URL url = JavaTestsPlugin.getPlugin().getBundle().getEntry(filename); + assertNotNull(url); + BufferedReader rdr = new BufferedReader(new InputStreamReader(url.openStream())); + try { + String line = null; + while ((line = rdr.readLine()) != null) + names.add(line); + } finally { + rdr.close(); + } + return names; + } + + /* + * Test the names against the set. Print those not found in the set, + * or those in the againstSet that weren't found. Throw assert error if + * any from against set not found. + * + */ + protected void testIncludesAllNames(String id, List testNames, Set againstSet, Set exclude) { + Set workingAgainst = new HashSet(againstSet.size()); + workingAgainst.addAll(againstSet); // There may be dup testNames (like for operations), so in that case we leave againstSet alone. + boolean wroteAny = false; + for (Iterator itr = testNames.iterator(); itr.hasNext();) { + ENamedElement testName = (ENamedElement) itr.next(); + if (exclude.contains(testName)) + continue; // This is one we want to ignore + if (againstSet.contains(testName.getName())) + workingAgainst.remove(testName.getName()); // Get rid of it since found. + else { + if (!wroteAny) { + wroteAny = true; + System.out.println("Names in list that are new for " + id + ':'); + } + System.out.print(" "); + System.out.println(testName.getName()); + } + } + if (wroteAny) + System.out.println("End of new names."); + + if (!workingAgainst.isEmpty()) { + System.out.println("Names that should of been found, but weren't for " + id + ':'); + for (Iterator itr = workingAgainst.iterator(); itr.hasNext();) { + String name = (String) itr.next(); + System.out.print(" "); + System.out.println(name); + } + System.out.println("End of missing names"); + fail("Missing some required names for "+id+'.'); + } + } + + /* + * Write the names out. Call only when want to update list. Filename must + * be a local file. + */ + protected void writeNames(String filename, List props, Set excluding) throws FileNotFoundException { + PrintWriter pr = new PrintWriter(new FileOutputStream(filename)); + try { + for (Iterator itr = props.iterator(); itr.hasNext();) { + ENamedElement element = (ENamedElement) itr.next(); + if (excluding != null && excluding.contains(element)) + continue; + pr.println(element.getName()); + } + } finally { + pr.close(); + } + } + /** * Reflect the entire super type hierarchy of the class passed in, including the class itself. * @param jclass @@ -103,28 +196,48 @@ return (JavaClass) rset.getEObject(URI.createURI("java:/javax.swing#JLabel"), true); //$NON-NLS-1$ } - public void testExternalJar() { + public void testExternalJar() throws IOException { objFeaturesSetup(); // This tests getting beaninfo out of jar. The jar is within the project. It contains ButtonBeanInfo. JavaClass button = getButton(); reflectHierachy(button); // First reflect all parents (not introspect). // Now cause introspection. - assertEquals(28+objFeatures, button.getAllProperties().size()); - assertEquals(4, button.getEOperations().size()); + + // To write out the names if want new set. +// writeNames("d:/temp/extjarprops.txt", button.getAllProperties(), objFeaturesSet); + + Set names = getNames("testdata/extjarprops.txt"); + testIncludesAllNames("Button", button.getAllProperties(), names, objFeaturesSet); + + // To write out the names if want new set. +// writeNames("d:/temp/extjarops.txt", button.getEOperations(), Collections.EMPTY_SET); + + names = getNames("testdata/extjarops.txt"); + testIncludesAllNames("Button", button.getEOperations(), names, Collections.EMPTY_SET); // showSortedProperties(button); } - public void testJLabel() { + public void testJLabel() throws IOException { objFeaturesSetup(); // This tests JLabel beaninfo out of current project, but through search path. JavaClass jlabel = getJLabel(); reflectHierachy(jlabel); // First reflect all parents (not introspect). // Now cause introspection. - assertEquals(61+objFeatures, jlabel.getAllProperties().size()); - assertEquals(173, jlabel.getEAllOperations().size()); + + // To write out the names if want new set. +// writeNames("d:/temp/jlabelprops.txt", jlabel.getAllProperties(), objFeaturesSet); + + Set names = getNames("testdata/jlabelprops.txt"); + testIncludesAllNames("JLabel", jlabel.getAllProperties(), names, objFeaturesSet); + + // To write out the names if want new set. +// writeNames("d:/temp/jlabelops.txt", jlabel.getEAllOperations(), Collections.EMPTY_SET); + + names = getNames("testdata/jlabelops.txt"); + testIncludesAllNames("JLabel", jlabel.getEAllOperations(), names, Collections.EMPTY_SET); // showSortedProperties(jlabel); // showSortedOperations(jlabel);
diff --git a/tests/org.eclipse.jem.tests/javatests/org/eclipse/jem/tests/beaninfo/TestReflection.java b/tests/org.eclipse.jem.tests/javatests/org/eclipse/jem/tests/beaninfo/TestReflection.java index f492193..36aabc6 100644 --- a/tests/org.eclipse.jem.tests/javatests/org/eclipse/jem/tests/beaninfo/TestReflection.java +++ b/tests/org.eclipse.jem.tests/javatests/org/eclipse/jem/tests/beaninfo/TestReflection.java
@@ -11,15 +11,21 @@ package org.eclipse.jem.tests.beaninfo; /* * $RCSfile: TestReflection.java,v $ - * $Revision: 1.5 $ $Date: 2004/08/27 15:33:39 $ + * $Revision: 1.6 $ $Date: 2004/11/12 23:11:09 $ */ +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Iterator; +import java.util.List; + import org.eclipse.emf.common.util.EList; import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.ecore.EOperation; import org.eclipse.emf.ecore.EStructuralFeature; - import org.eclipse.jem.internal.beaninfo.PropertyDecorator; import org.eclipse.jem.internal.beaninfo.core.Utilities; import org.eclipse.jem.java.JavaClass; +import org.eclipse.jem.java.JavaEvent; import org.eclipse.jem.java.TypeKind; /** @@ -95,4 +101,84 @@ assertEquals("TestInner$Inner", pdType.getName()); assertSame(TypeKind.CLASS_LITERAL, pdType.getKind()); } + + private List getRealProps(List props) { + int size = props.size(); + List newList = new ArrayList(size); + for (int i=0; i<size; i++) { + EStructuralFeature f = (EStructuralFeature) props.get(i); + if (Utilities.getPropertyDecorator(f) != null) + newList.add(f); + } + return newList; + } + + public void testInterfacePropertyReflection() { + // Test the reflection of interfaces with multiple extends on them so that properities are correct. + JavaClass testPropClass = + (JavaClass) rset.getEObject(URI.createURI("java:/org.eclipse.jem.tests.beaninfo.test#NotTopGuy"), true); //$NON-NLS-1$ + + assertTrue(testPropClass.isInterface()); + + // Test that we don't pick up the extends stuff + List props = getRealProps(testPropClass.getProperties()); + // Forgot there may be non-properties properties. + assertEquals(1, props.size()); + assertEquals("number", ((EStructuralFeature) props.get(0)).getName()); + + // Test that we pick up the extends stuff + props = getRealProps(testPropClass.getAllProperties()); + assertEquals(3, props.size()); + List validNames = Arrays.asList(new String[] {"number", "object", "integer"}); + for (Iterator itr = props.iterator(); itr.hasNext();) { + EStructuralFeature feature = (EStructuralFeature) itr.next(); + assertTrue("Extra feature:"+feature.getName(), validNames.contains(feature.getName())); + } + } + + public void testInterfaceEventReflection() { + // Test the reflection of interfaces with multiple extends on them so that events are correct. + JavaClass testEventClass = + (JavaClass) rset.getEObject(URI.createURI("java:/org.eclipse.jem.tests.beaninfo.test#NotTopGuy"), true); //$NON-NLS-1$ + + assertTrue(testEventClass.isInterface()); + + // Test that we don't pick up the extends stuff + List events = testEventClass.getEvents(); + assertTrue(events.isEmpty()); + + // Test that we pick up the extends stuff + events = testEventClass.getAllEvents(); + assertEquals(1, events.size()); + assertEquals("test1ClassEvent", ((JavaEvent) events.get(0)).getName()); + } + + public void testInterfaceOperationsReflection() { + // Test the reflection of interfaces with multiple extends on them so that properities are correct. + JavaClass testOpClass = + (JavaClass) rset.getEObject(URI.createURI("java:/org.eclipse.jem.tests.beaninfo.test#NotTopGuy"), true); //$NON-NLS-1$ + + assertTrue(testOpClass.isInterface()); + + // Test that we don't pick up the extends stuff + List ops = testOpClass.getEOperations(); + assertEquals(2, ops.size()); + List validNames = Arrays.asList(new String[] {"getNumber", "setNumber"}); + for (Iterator itr = ops.iterator(); itr.hasNext();) { + EOperation op = (EOperation) itr.next(); + assertTrue("Extra operation:"+op.getName(), validNames.contains(op.getName())); + } + + + // Test that we pick up the extends stuff + ops = testOpClass.getEAllOperations(); + assertEquals(8, ops.size()); + validNames = Arrays.asList(new String[] {"getNumber", "setNumber", "getObject", "setObject", "getInteger", "setInteger", "addTest1ClassEventListener", "removeTest1ClassEventListener"}); + for (Iterator itr = ops.iterator(); itr.hasNext();) { + EOperation op = (EOperation) itr.next(); + assertTrue("Extra operation:"+op.getName(), validNames.contains(op.getName())); + } + } + + }
diff --git a/tests/org.eclipse.jem.tests/testdata/extjarops.txt b/tests/org.eclipse.jem.tests/testdata/extjarops.txt new file mode 100644 index 0000000..a5cfb7d --- /dev/null +++ b/tests/org.eclipse.jem.tests/testdata/extjarops.txt
@@ -0,0 +1,4 @@ +getActionCommand +getLabel +setActionCommand +setLabel
diff --git a/tests/org.eclipse.jem.tests/testdata/extjarprops.txt b/tests/org.eclipse.jem.tests/testdata/extjarprops.txt new file mode 100644 index 0000000..737ed62 --- /dev/null +++ b/tests/org.eclipse.jem.tests/testdata/extjarprops.txt
@@ -0,0 +1,28 @@ +alignmentX +alignmentY +background +bounds +colorModel +cursor +enabled +focusTraversable +componentOrientation +font +foreground +graphics +locale +location +locationOnScreen +maximumSize +minimumSize +name +parent +preferredSize +showing +size +toolkit +treeLock +valid +visible +actionCommand +label
diff --git a/tests/org.eclipse.jem.tests/testdata/jlabelops.txt b/tests/org.eclipse.jem.tests/testdata/jlabelops.txt new file mode 100644 index 0000000..0dad8d6 --- /dev/null +++ b/tests/org.eclipse.jem.tests/testdata/jlabelops.txt
@@ -0,0 +1,173 @@ +hashCode +notify +notifyAll +wait +wait +wait +getClass +equals +toString +add +addNotify +checkImage +contains +createImage +createImage +dispatchEvent +doLayout +getBackground +getBounds +getColorModel +getCursor +getFont +getFontMetrics +getForeground +getGraphics +getLocale +getLocation +getLocationOnScreen +getMaximumSize +getMinimumSize +getName +getParent +getPreferredSize +getSize +getToolkit +getTreeLock +invalidate +isEnabled +isShowing +isValid +isVisible +list +list +paintAll +prepareImage +printAll +remove +removeNotify +repaint +requestFocus +setBackground +setBounds +setCursor +setEnabled +setForeground +setLocale +setLocation +setLocation +setName +setSize +setSize +transferFocus +validate +add +add +add +add +add +getAlignmentX +getAlignmentY +getComponent +getComponentAt +getComponentAt +getComponentCount +getComponents +getInsets +getLayout +isAncestorOf +list +list +print +remove +remove +removeAll +setLayout +computeVisibleRect +contains +createToolTip +firePropertyChange +firePropertyChange +firePropertyChange +firePropertyChange +firePropertyChange +firePropertyChange +firePropertyChange +getAccessibleContext +getActionForKeyStroke +getAutoscrolls +getBorder +getBounds +getClientProperty +getConditionForKeyStroke +getHeight +getLocation +getNextFocusableComponent +getRegisteredKeyStrokes +getRootPane +getSize +getToolTipText +getTopLevelAncestor +getVisibleRect +getWidth +getX +getY +grabFocus +hasFocus +isDoubleBuffered +isFocusCycleRoot +isFocusTraversable +isManagingFocus +isOpaque +isOptimizedDrawingEnabled +isRequestFocusEnabled +isValidateRoot +paint +paintImmediately +putClientProperty +repaint +requestDefaultFocus +resetKeyboardActions +revalidate +scrollRectToVisible +setAlignmentX +setAlignmentY +setAutoscrolls +setBorder +setBounds +setDebugGraphicsOptions +setDoubleBuffered +setMaximumSize +setMinimumSize +setNextFocusableComponent +setOpaque +setPreferredSize +setRequestFocusEnabled +setToolTipText +setVisible +unregisterKeyboardAction +update +getDisabledIcon +getDisplayedMnemonic +getHorizontalAlignment +getHorizontalTextPosition +getIcon +getIconTextGap +getLabelFor +getText +getUI +getVerticalAlignment +getVerticalTextPosition +setDisabledIcon +setDisplayedMnemonic +setFont +setHorizontalAlignment +setHorizontalTextPosition +setIcon +setIconTextGap +setLabelFor +setText +setUI +setVerticalAlignment +setVerticalTextPosition +updateUI
diff --git a/tests/org.eclipse.jem.tests/testdata/jlabelprops.txt b/tests/org.eclipse.jem.tests/testdata/jlabelprops.txt new file mode 100644 index 0000000..24bc707 --- /dev/null +++ b/tests/org.eclipse.jem.tests/testdata/jlabelprops.txt
@@ -0,0 +1,61 @@ +background +bounds +colorModel +cursor +enabled +focusTraversable +foreground +locale +location +locationOnScreen +componentOrientation +name +parent +showing +size +toolkit +treeLock +valid +visible +componentCount +components +layout +alignmentX +alignmentY +autoscrolls +border +debugGraphicsOptions +doubleBuffered +focusCycleRoot +graphics +height +insets +managingFocus +maximumSize +minimumSize +nextFocusableComponent +opaque +optimizedDrawingEnabled +paintingTile +preferredSize +registeredKeyStrokes +requestFocusEnabled +rootPane +toolTipText +topLevelAncestor +validateRoot +visibleRect +width +x +y +disabledIcon +displayedMnemonic +font +horizontalAlignment +horizontalTextPosition +icon +iconTextGap +labelFor +text +verticalAlignment +verticalTextPosition
diff --git a/tests/org.eclipse.jem.tests/testdata/testbeaninfo.zip b/tests/org.eclipse.jem.tests/testdata/testbeaninfo.zip index c7e5951..813b500 100644 --- a/tests/org.eclipse.jem.tests/testdata/testbeaninfo.zip +++ b/tests/org.eclipse.jem.tests/testdata/testbeaninfo.zip Binary files differ
diff --git a/tests/org.eclipse.jem.tests/testdata/testbeaninfobeaninfos.zip b/tests/org.eclipse.jem.tests/testdata/testbeaninfobeaninfos.zip index 417e6e0..aa69c1a 100644 --- a/tests/org.eclipse.jem.tests/testdata/testbeaninfobeaninfos.zip +++ b/tests/org.eclipse.jem.tests/testdata/testbeaninfobeaninfos.zip Binary files differ
diff --git a/tests/org.eclipse.jem.tests/testdata/testbeaninfopreq.zip b/tests/org.eclipse.jem.tests/testdata/testbeaninfopreq.zip index 1e6f262..77ec5a7 100644 --- a/tests/org.eclipse.jem.tests/testdata/testbeaninfopreq.zip +++ b/tests/org.eclipse.jem.tests/testdata/testbeaninfopreq.zip Binary files differ
diff --git a/tests/org.eclipse.jem.tests/testdata/testbuttonbeaninfoui1projectjar.zip b/tests/org.eclipse.jem.tests/testdata/testbuttonbeaninfoui1projectjar.zip index 269dd66..ac2b587 100644 --- a/tests/org.eclipse.jem.tests/testdata/testbuttonbeaninfoui1projectjar.zip +++ b/tests/org.eclipse.jem.tests/testdata/testbuttonbeaninfoui1projectjar.zip Binary files differ
diff --git a/tests/org.eclipse.jem.tests/testdata/testremoteproject.zip b/tests/org.eclipse.jem.tests/testdata/testremoteproject.zip index 58240cc..4a23022 100644 --- a/tests/org.eclipse.jem.tests/testdata/testremoteproject.zip +++ b/tests/org.eclipse.jem.tests/testdata/testremoteproject.zip Binary files differ