Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 232669 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/ocl/ecore/tests/IteratorsTest.java (-1 / +41 lines)
Lines 1-7 Link Here
1
/**
1
/**
2
 * <copyright>
2
 * <copyright>
3
 * 
3
 * 
4
 * Copyright (c) 2006, 2008 IBM Corporation and others.
4
 * Copyright (c) 2006, 2008 IBM Corporation, Zeligsoft Inc. and others.
5
 * All rights reserved. This program and the accompanying materials
5
 * All rights reserved. This program and the accompanying materials
6
 * are made available under the terms of the Eclipse Public License v1.0
6
 * are made available under the terms of the Eclipse Public License v1.0
7
 * which accompanies this distribution, and is available at
7
 * which accompanies this distribution, and is available at
Lines 309-314 Link Here
309
    }
309
    }
310
310
311
    /**
311
    /**
312
     * Tests that parsing fails, in the case of an unknown property in a
313
     * collection navigation, with an appropriate parse failure, not a
314
     * <code>ClassCastException</code>.
315
     */
316
    public void test_implicitCollect_unknownAttribute_232669() {
317
        helper.setContext(EcorePackage.Literals.EPACKAGE);
318
319
        try {
320
            // this shouldn't parse, anyway
321
            helper.createInvariant("eSubpackages.unknownAttribute"); //$NON-NLS-1$
322
323
            fail("Should not have parsed"); //$NON-NLS-1$
324
        } catch (ParserException e) {
325
        	// should have a diagnostic describing the problem if it is a
326
        	// "normal" parse failure
327
        	assertNoException(getDiagnostic(), ClassCastException.class);
328
        }
329
   }
330
331
    /**
332
     * Tests that parsing fails, in the case of an unknown operation in a
333
     * collection navigation, with an appropriate parse failure, not a
334
     * <code>ClassCastException</code>.
335
     */
336
    public void test_implicitCollect_unknownOperation_232669() {
337
        helper.setContext(EcorePackage.Literals.EPACKAGE);
338
339
        try {
340
            // this shouldn't parse, anyway
341
        	helper.createInvariant("eSubpackages.unknownOperation(self)"); //$NON-NLS-1$
342
343
            fail("Should not have parsed"); //$NON-NLS-1$
344
        } catch (ParserException e) {
345
        	// should have a diagnostic describing the problem if it is a
346
        	// "normal" parse failure
347
        	assertNoException(getDiagnostic(), ClassCastException.class);
348
        }
349
   }
350
351
    /**
312
     * Tests that the collect() iterator correctly flattens its result.
352
     * Tests that the collect() iterator correctly flattens its result.
313
     */
353
     */
314
    public void test_collect_flattens_217461() {
354
    public void test_collect_flattens_217461() {
(-)src/org/eclipse/ocl/ecore/tests/AbstractTestSuite.java (-1 / +44 lines)
Lines 1-7 Link Here
1
/**
1
/**
2
 * <copyright>
2
 * <copyright>
3
 * 
3
 * 
4
 * Copyright (c) 2005, 2008 IBM Corporation and others.
4
 * Copyright (c) 2005, 2008 IBM Corporation, Zeligsoft Inc. and others.
5
 * All rights reserved. This program and the accompanying materials
5
 * All rights reserved. This program and the accompanying materials
6
 * are made available under the terms of the Eclipse Public License v1.0
6
 * are made available under the terms of the Eclipse Public License v1.0
7
 * which accompanies this distribution, and is available at
7
 * which accompanies this distribution, and is available at
Lines 28-33 Link Here
28
import junit.framework.TestCase;
28
import junit.framework.TestCase;
29
import junit.framework.TestSuite;
29
import junit.framework.TestSuite;
30
30
31
import org.eclipse.emf.common.util.Diagnostic;
31
import org.eclipse.emf.common.util.URI;
32
import org.eclipse.emf.common.util.URI;
32
import org.eclipse.emf.ecore.EAttribute;
33
import org.eclipse.emf.ecore.EAttribute;
33
import org.eclipse.emf.ecore.EClass;
34
import org.eclipse.emf.ecore.EClass;
Lines 61-67 Link Here
61
import org.eclipse.ocl.helper.Choice;
62
import org.eclipse.ocl.helper.Choice;
62
import org.eclipse.ocl.helper.ChoiceKind;
63
import org.eclipse.ocl.helper.ChoiceKind;
63
import org.eclipse.ocl.helper.OCLHelper;
64
import org.eclipse.ocl.helper.OCLHelper;
65
import org.eclipse.ocl.lpg.ProblemHandler;
66
import org.eclipse.ocl.parser.OCLProblemHandler;
64
import org.eclipse.ocl.types.OCLStandardLibrary;
67
import org.eclipse.ocl.types.OCLStandardLibrary;
68
import org.eclipse.ocl.util.OCLUtil;
65
import org.eclipse.ocl.utilities.OCLFactory;
69
import org.eclipse.ocl.utilities.OCLFactory;
66
import org.eclipse.ocl.utilities.Visitable;
70
import org.eclipse.ocl.utilities.Visitable;
67
71
Lines 602-607 Link Here
602
		assertNull("Choice found: " + name + ", " + kind, //$NON-NLS-1$ //$NON-NLS-2$
606
		assertNull("Choice found: " + name + ", " + kind, //$NON-NLS-1$ //$NON-NLS-2$
603
			findChoice(choices, kind, name));
607
			findChoice(choices, kind, name));
604
	}
608
	}
609
610
	/**
611
	 * Asserts that a exception of the specified kind is not signalled by
612
	 * the a given diagnostic or (recursively) its children.
613
	 * 
614
	 * @param diagnostic a diagnostic
615
	 * @param excType an exception that must not be indicated by the diagnostic
616
	 * 
617
	 * @since 1.2
618
	 */
619
    protected void assertNoException(Diagnostic diagnostic, java.lang.Class<? extends Throwable> excType) {
620
    	if (excType.isInstance(diagnostic.getException())) {
621
    		fail("Diagnostic signals a(n) " + excType.getSimpleName()); //$NON-NLS-1$
622
    	}
623
    	
624
    	for (Diagnostic nested : diagnostic.getChildren()) {
625
    		assertNoException(nested, excType);
626
    	}
627
    }
628
    
629
    /**
630
     * Obtains the diagnostic describing the problem in the last failed parse,
631
     * asserting that it is not <code>null</code>.
632
     * 
633
     * @return the diagnostic
634
     */
635
    protected Diagnostic getDiagnostic() {
636
    	OCLProblemHandler handler = (OCLProblemHandler) OCLUtil.getAdapter(
637
    		ocl.getEnvironment(), ProblemHandler.class);
638
    	
639
    	Diagnostic result = handler.getDiagnostic();
640
    	if (result == null) {
641
    		result = helper.getProblems();
642
    	}
643
    	
644
    	assertNotNull("No diagnostic", result); //$NON-NLS-1$
645
    	
646
    	return result;
647
    }
605
	
648
	
606
	protected OCLStandardLibrary<EClassifier> getOCLStandardLibrary() {
649
	protected OCLStandardLibrary<EClassifier> getOCLStandardLibrary() {
607
		return ocl.getEnvironment().getOCLStandardLibrary();
650
		return ocl.getEnvironment().getOCLStandardLibrary();
(-)src/org/eclipse/ocl/uml/tests/AbstractTestSuite.java (-1 / +44 lines)
Lines 1-7 Link Here
1
/**
1
/**
2
 * <copyright>
2
 * <copyright>
3
 *
3
 *
4
 * Copyright (c) 2005, 2008 IBM Corporation and others.
4
 * Copyright (c) 2005, 2008 IBM Corporation, Zeligsoft Inc. and others.
5
 * All rights reserved.   This program and the accompanying materials
5
 * All rights reserved.   This program and the accompanying materials
6
 * are made available under the terms of the Eclipse Public License v1.0
6
 * are made available under the terms of the Eclipse Public License v1.0
7
 * which accompanies this distribution, and is available at
7
 * which accompanies this distribution, and is available at
Lines 31-36 Link Here
31
import junit.framework.TestSuite;
31
import junit.framework.TestSuite;
32
32
33
import org.eclipse.emf.common.util.BasicEList;
33
import org.eclipse.emf.common.util.BasicEList;
34
import org.eclipse.emf.common.util.Diagnostic;
34
import org.eclipse.emf.common.util.EList;
35
import org.eclipse.emf.common.util.EList;
35
import org.eclipse.emf.common.util.URI;
36
import org.eclipse.emf.common.util.URI;
36
import org.eclipse.emf.ecore.EFactory;
37
import org.eclipse.emf.ecore.EFactory;
Lines 48-57 Link Here
48
import org.eclipse.ocl.helper.Choice;
49
import org.eclipse.ocl.helper.Choice;
49
import org.eclipse.ocl.helper.ChoiceKind;
50
import org.eclipse.ocl.helper.ChoiceKind;
50
import org.eclipse.ocl.helper.OCLHelper;
51
import org.eclipse.ocl.helper.OCLHelper;
52
import org.eclipse.ocl.lpg.ProblemHandler;
53
import org.eclipse.ocl.parser.OCLProblemHandler;
51
import org.eclipse.ocl.types.OCLStandardLibrary;
54
import org.eclipse.ocl.types.OCLStandardLibrary;
52
import org.eclipse.ocl.uml.ExpressionInOCL;
55
import org.eclipse.ocl.uml.ExpressionInOCL;
53
import org.eclipse.ocl.uml.OCL;
56
import org.eclipse.ocl.uml.OCL;
54
import org.eclipse.ocl.uml.util.OCLUMLUtil;
57
import org.eclipse.ocl.uml.util.OCLUMLUtil;
58
import org.eclipse.ocl.util.OCLUtil;
55
import org.eclipse.ocl.utilities.Visitable;
59
import org.eclipse.ocl.utilities.Visitable;
56
import org.eclipse.uml2.uml.Association;
60
import org.eclipse.uml2.uml.Association;
57
import org.eclipse.uml2.uml.AssociationClass;
61
import org.eclipse.uml2.uml.AssociationClass;
Lines 660-665 Link Here
660
		assertNull("Choice found: " + name + ", " + kind, //$NON-NLS-1$ //$NON-NLS-2$
664
		assertNull("Choice found: " + name + ", " + kind, //$NON-NLS-1$ //$NON-NLS-2$
661
			findChoice(choices, kind, name));
665
			findChoice(choices, kind, name));
662
	}
666
	}
667
668
	/**
669
	 * Asserts that a exception of the specified kind is not signalled by
670
	 * the a given diagnostic or (recursively) its children.
671
	 * 
672
	 * @param diagnostic a diagnostic
673
	 * @param excType an exception that must not be indicated by the diagnostic
674
	 * 
675
	 * @since 1.2
676
	 */
677
    protected void assertNoException(Diagnostic diagnostic, java.lang.Class<? extends Throwable> excType) {
678
    	if (excType.isInstance(diagnostic.getException())) {
679
    		fail("Diagnostic signals a(n) " + excType.getSimpleName()); //$NON-NLS-1$
680
    	}
681
    	
682
    	for (Diagnostic nested : diagnostic.getChildren()) {
683
    		assertNoException(nested, excType);
684
    	}
685
    }
686
    
687
    /**
688
     * Obtains the diagnostic describing the problem in the last failed parse,
689
     * asserting that it is not <code>null</code>.
690
     * 
691
     * @return the diagnostic
692
     */
693
    protected Diagnostic getDiagnostic() {
694
    	OCLProblemHandler handler = (OCLProblemHandler) OCLUtil.getAdapter(
695
    		ocl.getEnvironment(), ProblemHandler.class);
696
    	
697
    	Diagnostic result = handler.getDiagnostic();
698
    	if (result == null) {
699
    		result = helper.getProblems();
700
    	}
701
    	
702
    	assertNotNull("No diagnostic", result); //$NON-NLS-1$
703
    	
704
    	return result;
705
    }
663
	
706
	
664
	protected OCLStandardLibrary<Classifier> getOCLStandardLibrary() {
707
	protected OCLStandardLibrary<Classifier> getOCLStandardLibrary() {
665
		return ocl.getEnvironment().getOCLStandardLibrary();
708
		return ocl.getEnvironment().getOCLStandardLibrary();
(-)src/org/eclipse/ocl/uml/tests/IteratorsTest.java (-2 / +22 lines)
Lines 1-7 Link Here
1
/**
1
/**
2
 * <copyright>
2
 * <copyright>
3
 * 
3
 * 
4
 * Copyright (c) 2006, 2007 IBM Corporation and others.
4
 * Copyright (c) 2006, 2008 IBM Corporation, Zeligsoft Inc. and others.
5
 * All rights reserved. This program and the accompanying materials
5
 * All rights reserved. This program and the accompanying materials
6
 * are made available under the terms of the Eclipse Public License v1.0
6
 * are made available under the terms of the Eclipse Public License v1.0
7
 * which accompanies this distribution, and is available at
7
 * which accompanies this distribution, and is available at
Lines 335-340 Link Here
335
    }
335
    }
336
336
337
    /**
337
    /**
338
     * Tests that parsing fails, in the case of an unknown property in a
339
     * collection navigation, with an appropriate parse failure, not a
340
     * <code>ClassCastException</code>.
341
     */
342
    public void test_implicitCollect_unknownAttribute_232669() {
343
        helper.setContext(getMetaclass("Package")); //$NON-NLS-1$
344
345
        try {
346
            // this shouldn't parse, anyway
347
        	helper.createInvariant("nestedPackage.unknownAttribute"); //$NON-NLS-1$
348
349
            fail("Should not have parsed"); //$NON-NLS-1$
350
        } catch (ParserException e) {
351
        	// should have a diagnostic describing the problem if it is a
352
        	// "normal" parse failure
353
        	assertNoException(getDiagnostic(), ClassCastException.class);
354
        }
355
   }
356
357
    /**
338
     * Tests the collectNested() iterator.
358
     * Tests the collectNested() iterator.
339
     */
359
     */
340
    public void test_collectNested() {
360
    public void test_collectNested() {
Lines 882-888 Link Here
882
            fail("Failed to parse or evaluate: " + e.getLocalizedMessage()); //$NON-NLS-1$
902
            fail("Failed to parse or evaluate: " + e.getLocalizedMessage()); //$NON-NLS-1$
883
        }
903
        }
884
    }
904
    }
885
905
    
886
    //
906
    //
887
    // Framework methods
907
    // Framework methods
888
    //
908
    //
(-)src/org/eclipse/ocl/parser/AbstractOCLAnalyzer.java (-3 / +5 lines)
Lines 1-7 Link Here
1
/**
1
/**
2
 * <copyright>
2
 * <copyright>
3
 *
3
 *
4
 * Copyright (c) 2005, 2008 IBM Corporation and others.
4
 * Copyright (c) 2005, 2008 IBM Corporation, Zeligsoft Inc. and others.
5
 * All rights reserved.   This program and the accompanying materials
5
 * All rights reserved.   This program and the accompanying materials
6
 * are made available under the terms of the Eclipse Public License v1.0
6
 * are made available under the terms of the Eclipse Public License v1.0
7
 * which accompanies this distribution, and is available at
7
 * which accompanies this distribution, and is available at
Lines 2285-2293 Link Here
2285
		
2285
		
2286
		/*
2286
		/*
2287
		 * If the source type is a collection, then need there is an implicit COLLECT operator.
2287
		 * If the source type is a collection, then need there is an implicit COLLECT operator.
2288
		 * Note that this rule is not called after "->".
2288
		 * Note that this rule is not called after "->".  Check for FeatureCallExp
2289
		 * in case we created a dummy InvalidLiteralExp.
2289
		 */
2290
		 */
2290
		if ((source != null) && source.getType() instanceof CollectionType) {
2291
		if ((source != null) && (source.getType() instanceof CollectionType)
2292
			&& (astNode instanceof FeatureCallExp)) {
2291
			astNode = createImplicitCollect(
2293
			astNode = createImplicitCollect(
2292
				source,
2294
				source,
2293
				(FeatureCallExp<C>) astNode,
2295
				(FeatureCallExp<C>) astNode,

Return to bug 232669