View | Details | Raw Unified | Return to bug 131355 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/gmf/codegen/reconciler/ReconcilerConfig.java (+20 lines)
Added Link Here
1
/*
2
 * Copyright (c) 2006 Borland Software Corporation
3
 * 
4
 * All rights reserved. This program and the accompanying materials
5
 * are made available under the terms of the Eclipse Public License v1.0
6
 * which accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 *
9
 * Contributors:
10
 *    Michael Golubev (Borland) - initial API and implementation
11
 */
12
13
package org.eclipse.gmf.codegen.reconciler;
14
15
import org.eclipse.emf.ecore.EClass;
16
17
public interface ReconcilerConfig {
18
	Matcher getMatcher(EClass eClass); 
19
	DecisionMaker[] getDecisionMakers(EClass eClass);
20
}
(-)build.properties (+4 lines)
Added Link Here
1
source.. = src/
2
output.. = bin/
3
bin.includes = META-INF/,\
4
               .
(-)src/org/eclipse/gmf/codegen/reconciler/StringPatternDecisionMaker.java (+48 lines)
Added Link Here
1
/*
2
 * Copyright (c) 2006 Borland Software Corporation
3
 * 
4
 * All rights reserved. This program and the accompanying materials
5
 * are made available under the terms of the Eclipse Public License v1.0
6
 * which accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 *
9
 * Contributors:
10
 *    Michael Golubev (Borland) - initial API and implementation
11
 */
12
13
package org.eclipse.gmf.codegen.reconciler;
14
15
import java.util.regex.Pattern;
16
17
import org.eclipse.emf.ecore.EAttribute;
18
import org.eclipse.emf.ecore.EObject;
19
import org.eclipse.emf.ecore.EcorePackage;
20
21
public class StringPatternDecisionMaker extends DecisionMaker {
22
	private Pattern myPattern;
23
	
24
	public StringPatternDecisionMaker(String valuePattern, EAttribute attribute){
25
		this(Pattern.compile(valuePattern), attribute);
26
	}
27
	
28
	public StringPatternDecisionMaker(Pattern valuePattern, EAttribute attribute){
29
		super(attribute);
30
		if (attribute.getEAttributeType() != EcorePackage.eINSTANCE.getEString()){
31
			throw new IllegalArgumentException("Expected string attribute");
32
		}
33
		if (attribute.getUpperBound() != 1){
34
			throw new IllegalArgumentException("Expected multiplicity [0..1] or [1]");
35
		}
36
		myPattern = valuePattern;
37
	}
38
	
39
	public Decision makeDecision(EObject current, EObject old) {
40
		String oldValue = (String)old.eGet(getFeature());
41
		if (oldValue != null && !myPattern.matcher(oldValue).matches()){
42
			return Decision.PRESERVE_OLD;
43
		} else {
44
			return Decision.ACCEPT_NEW;
45
		}
46
	}
47
48
}
(-)src/org/eclipse/gmf/codegen/reconciler/AttributeMatcher.java (+62 lines)
Added Link Here
1
/*
2
 * Copyright (c) 2006 Borland Software Corporation
3
 * 
4
 * All rights reserved. This program and the accompanying materials
5
 * are made available under the terms of the Eclipse Public License v1.0
6
 * which accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 *
9
 * Contributors:
10
 *    Michael Golubev (Borland) - initial API and implementation
11
 */
12
13
package org.eclipse.gmf.codegen.reconciler;
14
15
import java.text.MessageFormat;
16
17
import org.eclipse.emf.ecore.EClass;
18
import org.eclipse.emf.ecore.EObject;
19
import org.eclipse.emf.ecore.EStructuralFeature;
20
21
public class AttributeMatcher implements Matcher {
22
	private final String myFeatureName;
23
	private EClass myCachedFeatureOwner;
24
	private EStructuralFeature myCachedFeature;
25
26
	public AttributeMatcher(String featureName){
27
		myFeatureName = featureName;
28
	}
29
	
30
	public AttributeMatcher(EStructuralFeature feature){
31
		this(feature.getName());
32
	}
33
	
34
	public boolean match(EObject current, EObject old) {
35
		assertCompatible(current, old);
36
		EStructuralFeature feature = findFeature(current.eClass());
37
		return safeEquals(current.eGet(feature), old.eGet(feature));
38
	}
39
	
40
	private void assertCompatible(EObject current, EObject old){
41
		if (!current.eClass().equals(old.eClass())){
42
			throw new IllegalStateException(MessageFormat.format("Objects not compatible: {0}, {1}", new Object[] {current, old}));
43
		}
44
	}
45
	
46
	private EStructuralFeature findFeature(EClass eClass){
47
		if (!eClass.equals(myCachedFeatureOwner)){
48
			EStructuralFeature result = eClass.getEStructuralFeature(myFeatureName);
49
			if (result == null){
50
				throw new IllegalStateException(MessageFormat.format("Unknown feature {0} in EClass {1}", new Object[] {myFeatureName, eClass}));
51
			}
52
			myCachedFeatureOwner = eClass;
53
			myCachedFeature = result;
54
		}
55
		return myCachedFeature;
56
	}
57
	
58
	private boolean safeEquals(Object first, Object second){
59
		return first == null ? second == null : first.equals(second);
60
	}
61
62
}
(-)src/org/eclipse/gmf/codegen/reconciler/ReconcilerConfigBase.java (+112 lines)
Added Link Here
1
/*
2
 * Copyright (c) 2006 Borland Software Corporation
3
 * 
4
 * All rights reserved. This program and the accompanying materials
5
 * are made available under the terms of the Eclipse Public License v1.0
6
 * which accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 *
9
 * Contributors:
10
 *    Michael Golubev (Borland) - initial API and implementation
11
 */
12
13
package org.eclipse.gmf.codegen.reconciler;
14
15
import java.text.MessageFormat;
16
import java.util.HashMap;
17
import java.util.LinkedList;
18
import java.util.List;
19
20
import org.eclipse.emf.ecore.EAttribute;
21
import org.eclipse.emf.ecore.EClass;
22
import org.eclipse.emf.ecore.EReference;
23
24
public class ReconcilerConfigBase implements ReconcilerConfig {
25
	private static final EClassRecord EMPTY_RECORD = new EClassRecord();
26
	private final HashMap myEClass2Record;
27
	
28
	public ReconcilerConfigBase(){
29
		myEClass2Record = new HashMap();
30
	}
31
	
32
	public final Matcher getMatcher(EClass eClass) {
33
		return getRecord(eClass, false).getMatcher();
34
	}
35
36
	public final DecisionMaker[] getDecisionMakers(EClass eClass) {
37
		return getRecord(eClass, false).getDecisionMakers();
38
	}
39
	
40
	protected final void setMatcher(EClass eClass, Matcher matcher){
41
		getRecord(eClass, true).setMatcher(matcher);
42
	}
43
	
44
	protected final void addDecisionMaker(EClass eClass, DecisionMaker decisionMaker){
45
		getRecord(eClass, true).addDecisionMaker(decisionMaker);
46
	}
47
	
48
	protected final void setMatcher(EClass eClass, EAttribute attribute){  
49
		checkStructuralFeature(eClass, attribute);
50
		Matcher matcher = new AttributeMatcher(attribute);
51
		setMatcher(eClass, matcher);
52
	}
53
	
54
	protected final void setMatcher(EClass eClass, EReference reference){
55
		if (eClass.getEPackage().equals(reference.eClass().getEPackage())){
56
			//XXX: use lazyly resolved matcher??? 
57
			setMatcher(eClass, new AttributeMatcher(reference));
58
		} else {
59
			setMatcher(eClass, new AttributeMatcher(reference));
60
		}
61
	}
62
63
	private EClassRecord getRecord(EClass eClass, boolean force){
64
		EClassRecord result = (EClassRecord) myEClass2Record.get(eClass);
65
		if (result == null){
66
			if (force){
67
				result = new EClassRecord();
68
				myEClass2Record.put(eClass, result);
69
			} else {
70
				result = EMPTY_RECORD;
71
			}
72
		}
73
		return result;
74
	}
75
	
76
	private void checkStructuralFeature(EClass expectedClass, EAttribute feature) {
77
		if (expectedClass.getEStructuralFeature(feature.getFeatureID()) != feature){
78
			throw new IllegalArgumentException(MessageFormat.format("Alien feature {0} for EClass {1}", new Object[] {feature, expectedClass}));
79
		}
80
	}
81
82
	private static class EClassRecord {
83
		private Matcher myMatcher = Matcher.FALSE; 
84
		private final List myDecisionMakers = new LinkedList();
85
		private DecisionMaker[] myMakersArray;
86
		
87
		public void addDecisionMaker(DecisionMaker maker){
88
			myDecisionMakers.add(maker);
89
			makersSetChanged();
90
		}
91
		
92
		public DecisionMaker[] getDecisionMakers(){
93
			if (myMakersArray == null){
94
				myMakersArray = (DecisionMaker[]) myDecisionMakers.toArray(new DecisionMaker[myDecisionMakers.size()]);
95
			}
96
			return myMakersArray;
97
		}
98
		
99
		public void setMatcher(Matcher matcher) {
100
			myMatcher = matcher;
101
		}
102
		
103
		public Matcher getMatcher() {
104
			return myMatcher;
105
		}
106
		
107
		private void makersSetChanged(){
108
			myMakersArray = null;
109
		}
110
	}
111
112
}
(-).project (+28 lines)
Added Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
<projectDescription>
3
	<name>org.eclipse.gmf.codegen.reconciler</name>
4
	<comment></comment>
5
	<projects>
6
	</projects>
7
	<buildSpec>
8
		<buildCommand>
9
			<name>org.eclipse.jdt.core.javabuilder</name>
10
			<arguments>
11
			</arguments>
12
		</buildCommand>
13
		<buildCommand>
14
			<name>org.eclipse.pde.ManifestBuilder</name>
15
			<arguments>
16
			</arguments>
17
		</buildCommand>
18
		<buildCommand>
19
			<name>org.eclipse.pde.SchemaBuilder</name>
20
			<arguments>
21
			</arguments>
22
		</buildCommand>
23
	</buildSpec>
24
	<natures>
25
		<nature>org.eclipse.pde.PluginNature</nature>
26
		<nature>org.eclipse.jdt.core.javanature</nature>
27
	</natures>
28
</projectDescription>
(-)META-INF/MANIFEST.MF (+11 lines)
Added Link Here
1
Manifest-Version: 1.0
2
Bundle-ManifestVersion: 2
3
Bundle-Name: %pluginName
4
Bundle-SymbolicName: org.eclipse.gmf.codegen.reconciler
5
Bundle-Version: 1.0.0.version
6
Bundle-Vendor: %providerName
7
Bundle-Localization: plugin
8
Require-Bundle: org.eclipse.emf.ecore,
9
 org.eclipse.gmf.codegen
10
Export-Package: org.eclipse.gmf.codegen.reconciler,
11
 org.eclipse.gmf.internal.codegen.reconciler
(-)src/org/eclipse/gmf/codegen/reconciler/DefaultDecisionMaker.java (+28 lines)
Added Link Here
1
/*
2
 * Copyright (c) 2006 Borland Software Corporation
3
 * 
4
 * All rights reserved. This program and the accompanying materials
5
 * are made available under the terms of the Eclipse Public License v1.0
6
 * which accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 *
9
 * Contributors:
10
 *    Michael Golubev (Borland) - initial API and implementation
11
 */
12
13
package org.eclipse.gmf.codegen.reconciler;
14
15
import org.eclipse.emf.ecore.EObject;
16
import org.eclipse.emf.ecore.EStructuralFeature;
17
18
public class DefaultDecisionMaker extends DecisionMaker {
19
	public DefaultDecisionMaker(EStructuralFeature feature){
20
		super(feature);
21
	}
22
	
23
	public Decision makeDecision(EObject current, EObject old) {
24
		assert current.eClass().equals(old.eClass());
25
		return (!current.eIsSet(getFeature()) && old.eIsSet(getFeature())) ? Decision.PRESERVE_OLD : Decision.ACCEPT_NEW;
26
	}
27
28
}
(-)src/org/eclipse/gmf/codegen/reconciler/Matcher.java (+68 lines)
Added Link Here
1
/*
2
 * Copyright (c) 2006 Borland Software Corporation
3
 * 
4
 * All rights reserved. This program and the accompanying materials
5
 * are made available under the terms of the Eclipse Public License v1.0
6
 * which accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 *
9
 * Contributors:
10
 *    Michael Golubev (Borland) - initial API and implementation
11
 */
12
13
package org.eclipse.gmf.codegen.reconciler;
14
15
import java.util.Collection;
16
17
import org.eclipse.emf.ecore.EObject;
18
19
public interface Matcher {
20
	public boolean match(EObject current, EObject old);
21
	
22
	public static final Matcher FALSE = new Matcher() {
23
		public boolean match(EObject current, EObject old) {
24
			return false;
25
		}
26
	};
27
28
	public static class OR implements Matcher {
29
		private final Matcher[] myMatchers;
30
31
		public OR(Matcher[] matchers){
32
			myMatchers = matchers;
33
		}
34
		
35
		public OR(Collection matchers){
36
			this((Matcher[])matchers.toArray(new Matcher[matchers.size()]));
37
		}
38
		
39
		public boolean match(EObject current, EObject old) {
40
			boolean result = false;
41
			for (int i = 0; !result && i < myMatchers.length; i++){
42
				result = myMatchers[i].match(current, old);
43
			}
44
			return result;
45
		}
46
	}
47
48
	public static class AND implements Matcher {
49
		private final Matcher[] myMatchers;
50
51
		public AND(Matcher[] matchers){
52
			myMatchers = matchers;
53
		}
54
		
55
		public AND(Collection matchers){
56
			this((Matcher[])matchers.toArray(new Matcher[matchers.size()]));
57
		}
58
		
59
		public boolean match(EObject current, EObject old) {
60
			boolean result = true;
61
			for (int i = 0; result && i < myMatchers.length; i++){
62
				result = myMatchers[i].match(current, old);
63
			}
64
			return result;
65
		}
66
	}
67
68
}
(-)src/org/eclipse/gmf/codegen/reconciler/Reconciler.java (+80 lines)
Added Link Here
1
/*
2
 * Copyright (c) 2006 Borland Software Corporation
3
 * 
4
 * All rights reserved. This program and the accompanying materials
5
 * are made available under the terms of the Eclipse Public License v1.0
6
 * which accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 *
9
 * Contributors:
10
 *    Michael Golubev (Borland) - initial API and implementation
11
 */
12
13
package org.eclipse.gmf.codegen.reconciler;
14
15
import java.util.Collection;
16
import java.util.Iterator;
17
18
import org.eclipse.emf.ecore.EClass;
19
import org.eclipse.emf.ecore.EObject;
20
import org.eclipse.emf.ecore.resource.Resource;
21
22
public class Reconciler {
23
	private final ReconcilerConfig myConfig;
24
25
	public Reconciler(ReconcilerConfig config){
26
		myConfig = config;
27
	}
28
	
29
	protected void handleNotMatchedCurrent(EObject current){
30
		//FIXME ??? Is it user escape -- check history ???
31
		//FIXME How to handle not macthed old ???
32
	}
33
	
34
	public void reconcileResource(Resource current, Resource old){
35
		reconcileContents(current.getContents(), old.getContents());
36
	}
37
	
38
	public void reconcileTree(EObject currentRoot, EObject oldRoot){
39
		reconcileVertex(currentRoot, oldRoot);
40
		reconcileContents(currentRoot.eContents(), oldRoot.eContents());
41
	}
42
	
43
	private void reconcileVertex(EObject current, EObject old){
44
		assert current.eClass().equals(old.eClass());
45
		DecisionMaker[] decisionMakers = myConfig.getDecisionMakers(current.eClass());
46
		for (int i = 0; i < decisionMakers.length; i++){
47
			DecisionMaker next = decisionMakers[i];
48
			Decision decision = next.makeDecision(current, old);
49
			decision.apply(current, old, next.getFeature());
50
		}
51
	}
52
	
53
	private void reconcileContents(Collection allCurrents, Collection allOlds){
54
		for (Iterator currentContents = allCurrents.iterator(); currentContents.hasNext();){
55
			EObject nextCurrent = (EObject) currentContents.next();
56
			EObject nextOld = findMatched(nextCurrent, allOlds);
57
			if (nextOld == null){
58
				handleNotMatchedCurrent(nextCurrent);
59
			} else {
60
				reconcileTree(nextCurrent, nextOld);
61
			}
62
		}
63
	}
64
	
65
	private EObject findMatched(EObject current, Collection allOld){
66
		EClass eClass = current.eClass();
67
		Matcher matcher = myConfig.getMatcher(eClass);
68
		EObject result = null;
69
		if (matcher != Matcher.FALSE){
70
			for (Iterator all = allOld.iterator(); result == null && all.hasNext();){
71
				EObject next = (EObject)all.next();
72
				if (eClass.equals(eClass) && matcher.match(current, next)){
73
					result = next;
74
				}
75
			}
76
		}
77
		return result;
78
	}
79
80
}
(-)plugin.properties (+20 lines)
Added Link Here
1
# <copyright>
2
# </copyright>
3
#
4
# $Id$
5
6
# ====================================================================
7
# To code developer:
8
#   Do NOT change the properties between this line and the
9
#   "%%% END OF TRANSLATED PROPERTIES %%%" line.
10
#   Make a new property name, append to the end of the file and change
11
#   the code to use the new property.
12
# ====================================================================
13
14
# ====================================================================
15
# %%% END OF TRANSLATED PROPERTIES %%%
16
# ====================================================================
17
18
pluginName = GMFGen Reconciler Plugin
19
providerName = Eclipse.org
20
(-)src/org/eclipse/gmf/codegen/reconciler/DecisionMaker.java (+51 lines)
Added Link Here
1
/*
2
 * Copyright (c) 2006 Borland Software Corporation
3
 * 
4
 * All rights reserved. This program and the accompanying materials
5
 * are made available under the terms of the Eclipse Public License v1.0
6
 * which accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 *
9
 * Contributors:
10
 *    Michael Golubev (Borland) - initial API and implementation
11
 */
12
13
package org.eclipse.gmf.codegen.reconciler;
14
15
import org.eclipse.emf.ecore.EObject;
16
import org.eclipse.emf.ecore.EStructuralFeature;
17
18
public abstract class DecisionMaker {
19
	private final EStructuralFeature myFeature;
20
21
	public abstract Decision makeDecision(EObject current, EObject old);
22
	
23
	public DecisionMaker(EStructuralFeature feature){
24
		myFeature = feature;
25
	}
26
	
27
	public final EStructuralFeature getFeature(){
28
		return myFeature;
29
	}
30
	
31
	public static class ALWAYS_OLD extends DecisionMaker {
32
		public ALWAYS_OLD(EStructuralFeature feature){
33
			super(feature);
34
		}
35
		
36
		public Decision makeDecision(EObject current, EObject old) {
37
			return Decision.PRESERVE_OLD;
38
		}
39
	}
40
	
41
	public static class ALWAYS_NEW extends DecisionMaker {
42
		public ALWAYS_NEW(EStructuralFeature feature){
43
			super(feature);
44
		}
45
		
46
		public Decision makeDecision(EObject current, EObject old) {
47
			return Decision.ACCEPT_NEW;
48
		}
49
	}
50
	
51
}
(-)src/org/eclipse/gmf/codegen/reconciler/Decision.java (+33 lines)
Added Link Here
1
/*
2
 * Copyright (c) 2006 Borland Software Corporation
3
 * 
4
 * All rights reserved. This program and the accompanying materials
5
 * are made available under the terms of the Eclipse Public License v1.0
6
 * which accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 *
9
 * Contributors:
10
 *    Michael Golubev (Borland) - initial API and implementation
11
 */
12
13
package org.eclipse.gmf.codegen.reconciler;
14
15
import org.eclipse.emf.ecore.EObject;
16
import org.eclipse.emf.ecore.EStructuralFeature;
17
18
public interface Decision {
19
	public void apply(EObject current, EObject old, EStructuralFeature feature);
20
	
21
	public static final Decision PRESERVE_OLD = new Decision(){
22
		public void apply(EObject current, EObject old, EStructuralFeature feature) {
23
			Object oldValue = old.eGet(feature, true);
24
			current.eSet(feature, oldValue);
25
		}
26
	};
27
	
28
	public static final Decision ACCEPT_NEW = new Decision(){
29
		public void apply(EObject current, EObject old, EStructuralFeature feature) {
30
			//do nothing
31
		}
32
	};
33
}
(-)src/org/eclipse/gmf/internal/codegen/reconciler/GMFGenConfig.java (+49 lines)
Added Link Here
1
/*
2
 * Copyright (c) 2006 Borland Software Corporation
3
 * 
4
 * All rights reserved. This program and the accompanying materials
5
 * are made available under the terms of the Eclipse Public License v1.0
6
 * which accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 *
9
 * Contributors:
10
 *    Michael Golubev (Borland) - initial API and implementation
11
 */
12
13
package org.eclipse.gmf.internal.codegen.reconciler;
14
15
import org.eclipse.emf.ecore.EAttribute;
16
import org.eclipse.emf.ecore.EClass;
17
import org.eclipse.emf.ecore.EObject;
18
import org.eclipse.gmf.codegen.gmfgen.GMFGenPackage;
19
import org.eclipse.gmf.codegen.reconciler.DefaultDecisionMaker;
20
import org.eclipse.gmf.codegen.reconciler.Matcher;
21
import org.eclipse.gmf.codegen.reconciler.ReconcilerConfigBase;
22
23
public class GMFGenConfig extends ReconcilerConfigBase {
24
	private static final GMFGenPackage GMFGEN = GMFGenPackage.eINSTANCE;
25
	
26
	public GMFGenConfig(){
27
		setMatcher(GMFGEN.getGenEditorGenerator(), ALWAYS_MATCH);
28
		preserveIfSet(GMFGEN.getGenEditorGenerator(), GMFGEN.getGenEditorGenerator_CopyrightText());
29
		preserveIfSet(GMFGEN.getGenEditorGenerator(), GMFGEN.getGenEditorGenerator_PackageNamePrefix());
30
		preserveIfSet(GMFGEN.getGenEditorGenerator(), GMFGEN.getGenEditorGenerator_DiagramFileExtension());
31
		preserveIfSet(GMFGEN.getGenEditorGenerator(), GMFGEN.getGenEditorGenerator_SameFileForDiagramAndModel());
32
		
33
		setMatcher(GMFGEN.getGenPlugin(), ALWAYS_MATCH); //exactly one feature for ALWAYS_MATCH GenEditorGenerator
34
		preserveIfSet(GMFGEN.getGenPlugin(), GMFGEN.getGenPlugin_Provider());
35
		preserveIfSet(GMFGEN.getGenPlugin(), GMFGEN.getGenPlugin_Version());
36
	}
37
	
38
	private void preserveIfSet(EClass eClass, EAttribute feature){
39
		//FIXME: only attributes for now, allow references
40
		addDecisionMaker(eClass, new DefaultDecisionMaker(feature));
41
	}
42
	
43
	private static final Matcher ALWAYS_MATCH = new Matcher(){
44
		public boolean match(EObject current, EObject old) {
45
			return current.eClass().equals(old.eClass());
46
		}
47
	};
48
	
49
}
(-).classpath (+7 lines)
Added Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
<classpath>
3
	<classpathentry kind="src" path="src"/>
4
	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
5
	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
6
	<classpathentry kind="output" path="bin"/>
7
</classpath>
(-)src/org/eclipse/gmf/internal/codegen/popup/actions/TransformToGenModel.java (-1 / +37 lines)
Lines 15-20 Link Here
15
import java.util.HashMap;
15
import java.util.HashMap;
16
import java.util.HashSet;
16
import java.util.HashSet;
17
import java.util.Iterator;
17
import java.util.Iterator;
18
import java.util.List;
18
import java.util.Map;
19
import java.util.Map;
19
20
20
import org.eclipse.core.resources.IFile;
21
import org.eclipse.core.resources.IFile;
Lines 45-52 Link Here
45
import org.eclipse.gmf.bridge.genmodel.GenModelAccess;
46
import org.eclipse.gmf.bridge.genmodel.GenModelAccess;
46
import org.eclipse.gmf.bridge.genmodel.SpecificDiagramRunTimeModelHelper;
47
import org.eclipse.gmf.bridge.genmodel.SpecificDiagramRunTimeModelHelper;
47
import org.eclipse.gmf.codegen.gmfgen.GenEditorGenerator;
48
import org.eclipse.gmf.codegen.gmfgen.GenEditorGenerator;
49
import org.eclipse.gmf.codegen.reconciler.Reconciler;
48
import org.eclipse.gmf.internal.bridge.naming.gen.GenModelNamingMediatorImpl;
50
import org.eclipse.gmf.internal.bridge.naming.gen.GenModelNamingMediatorImpl;
49
import org.eclipse.gmf.internal.codegen.CodeGenUIPlugin;
51
import org.eclipse.gmf.internal.codegen.CodeGenUIPlugin;
52
import org.eclipse.gmf.internal.codegen.reconciler.GMFGenConfig;
50
import org.eclipse.gmf.mappings.Mapping;
53
import org.eclipse.gmf.mappings.Mapping;
51
import org.eclipse.jface.action.IAction;
54
import org.eclipse.jface.action.IAction;
52
import org.eclipse.jface.dialogs.ErrorDialog;
55
import org.eclipse.jface.dialogs.ErrorDialog;
Lines 131-143 Link Here
131
			}
134
			}
132
135
133
			protected IStatus run(IProgressMonitor monitor) {
136
			protected IStatus run(IProgressMonitor monitor) {
134
				monitor.beginTask(getName(), 3);
137
				monitor.beginTask(getName(), 4);
135
				try {
138
				try {
136
					GenEditorGenerator genEditor = transform(mapping);
139
					GenEditorGenerator genEditor = transform(mapping);
137
					monitor.worked(1);
140
					monitor.worked(1);
138
					if (monitor.isCanceled()) {
141
					if (monitor.isCanceled()) {
139
						return Status.CANCEL_STATUS;
142
						return Status.CANCEL_STATUS;
140
					}
143
					}
144
					
145
					reconcile(genEditor);
146
					monitor.worked(1);
147
					if (monitor.isCanceled()) {
148
						return Status.CANCEL_STATUS;
149
					}
141
150
142
					save(genEditor);
151
					save(genEditor);
143
					monitor.worked(1);
152
					monitor.worked(1);
Lines 172-177 Link Here
172
				dgmmRes.getContents().add(genBurdern);				
181
				dgmmRes.getContents().add(genBurdern);				
173
				dgmmRes.save(getSaveOptions());
182
				dgmmRes.save(getSaveOptions());
174
			}
183
			}
184
			
185
			private void reconcile(GenEditorGenerator genBurdern) {
186
				GenEditorGenerator old = null;
187
				Resource resource = null;
188
				try {
189
					resource = resSet.getResource(getGenModelURI(), false);
190
					if (resource != null && !resource.isLoaded()){
191
						resource.load(null);
192
						List contents = resource.getContents();
193
						if (!contents.isEmpty() && contents.get(0) instanceof GenEditorGenerator){
194
							old = (GenEditorGenerator)contents.get(0);
195
						}
196
					}
197
				} catch (RuntimeException e){
198
					old = null;
199
				} catch (IOException e){
200
					old = null;
201
				} finally {
202
					if (resource != null){
203
						resource.unload();
204
					}
205
				}
206
				
207
				if (old != null){
208
					new Reconciler(new GMFGenConfig()).reconcileTree(genBurdern, old);
209
				}
210
			}
175
		}.schedule();
211
		}.schedule();
176
	}
212
	}
177
213
(-)META-INF/MANIFEST.MF (-1 / +2 lines)
Lines 9-15 Link Here
9
 org.eclipse.core.runtime,
9
 org.eclipse.core.runtime,
10
 org.eclipse.core.resources,
10
 org.eclipse.core.resources,
11
 org.eclipse.gmf.bridge,
11
 org.eclipse.gmf.bridge,
12
 org.eclipse.gmf.codegen.edit
12
 org.eclipse.gmf.codegen.edit,
13
 org.eclipse.gmf.codegen.reconciler
13
Eclipse-LazyStart: true
14
Eclipse-LazyStart: true
14
Bundle-Vendor: %providerName
15
Bundle-Vendor: %providerName
15
Export-Package: org.eclipse.gmf.internal.codegen.popup.actions;x-friends:="org.eclipse.gmf.bridge.ui.dashboard"
16
Export-Package: org.eclipse.gmf.internal.codegen.popup.actions;x-friends:="org.eclipse.gmf.bridge.ui.dashboard"
(-)build.properties (+4 lines)
Added Link Here
1
source.. = src/
2
output.. = bin/
3
bin.includes = META-INF/,\
4
               .
(-).classpath (+7 lines)
Added Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
<classpath>
3
	<classpathentry kind="src" path="src"/>
4
	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
5
	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
6
	<classpathentry kind="output" path="bin"/>
7
</classpath>
(-)META-INF/MANIFEST.MF (+14 lines)
Added Link Here
1
Manifest-Version: 1.0
2
Bundle-ManifestVersion: 2
3
Bundle-Name: Reconciler Tests Plugin
4
Bundle-SymbolicName: org.eclipse.gmf.codegen.reconciler.test.taipan
5
Bundle-Version: 1.0.0.version
6
Bundle-Vendor: Eclipse.org
7
Bundle-Localization: plugin
8
Require-Bundle: org.eclipse.gmf.codegen,
9
 org.eclipse.gmf.codegen.reconciler,
10
 org.eclipse.gmf.examples.taipan,
11
 org.junit,
12
 org.eclipse.osgi,
13
 org.eclipse.core.runtime,
14
 org.eclipse.gmf.bridge
(-)src/org/eclipse/gmf/codegen/reconciler/test/ReconcileTaipanTest.java (+96 lines)
Added Link Here
1
/*
2
 * Copyright (c) 2006 Borland Software Corporation
3
 * 
4
 * All rights reserved. This program and the accompanying materials
5
 * are made available under the terms of the Eclipse Public License v1.0
6
 * which accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 *
9
 * Contributors:
10
 *    Michael Golubev (Borland) - initial API and implementation
11
 */
12
13
package org.eclipse.gmf.codegen.reconciler.test;
14
15
import java.io.IOException;
16
17
import junit.framework.TestCase;
18
19
import org.eclipse.gmf.codegen.gmfgen.GenEditorGenerator;
20
import org.eclipse.gmf.codegen.gmfgen.GenPlugin;
21
import org.eclipse.gmf.codegen.reconciler.Reconciler;
22
import org.eclipse.gmf.internal.codegen.reconciler.GMFGenConfig;
23
24
public class ReconcileTaipanTest extends TestCase {
25
	public void testLoadGMFGen() throws Exception {
26
		GenEditorGenerator original = loadTaipanGMFGen();
27
		assertNotNull(original);
28
		GenEditorGenerator copy = loadTaipanGMFGen();
29
		assertNotNull(copy);
30
		
31
		assertFalse(original == copy);
32
		assertFalse(original.equals(copy));
33
		
34
		assertEquals(original.getCopyrightText(), copy.getCopyrightText());
35
		assertEquals(original.isSameFileForDiagramAndModel(), copy.isSameFileForDiagramAndModel());
36
		assertEquals(original.getPackageNamePrefix(), copy.getPackageNamePrefix());
37
		
38
		final String NEW_VALUE = "New Value";
39
		copy.setCopyrightText(NEW_VALUE);
40
		assertEquals(copy.getCopyrightText(), NEW_VALUE);
41
		assertFalse(copy.getCopyrightText().equals(original.getCopyrightText()));
42
	}
43
	
44
	public void testReconcileDeepElementWithAlwaysMatcher() throws Exception {
45
		GenPlugin old = loadTaipanGMFGen().getPlugin();
46
		GenPlugin current = loadTaipanGMFGen().getPlugin();
47
		
48
		assertNotNull(old.getProvider());
49
		assertNotNull(old.getVersion());
50
		
51
		final String NEW_PROVIDER = "NewProviderValue";
52
		final String NEW_VERSION = "NewVersionValue";
53
		
54
		old.setProvider(NEW_PROVIDER);
55
		old.setVersion(NEW_VERSION);
56
		
57
		getReconciler().reconcileTree(current, old);
58
		
59
		assertEquals(NEW_PROVIDER, current.getProvider());
60
		assertEquals(NEW_VERSION, current.getVersion());
61
	}
62
	
63
	public void testReconcileGenEditorGenerator() throws Exception {
64
		GenEditorGenerator old = loadTaipanGMFGen();
65
		GenEditorGenerator current = loadTaipanGMFGen();
66
		
67
		old.setCopyrightText("AAA");
68
		old.setPackageNamePrefix("BBB");
69
		old.setDiagramFileExtension("CCC");
70
		
71
		boolean sameFile = !old.isSameFileForDiagramAndModel();
72
		old.setSameFileForDiagramAndModel(sameFile);
73
		
74
		//we do not reconcile this now
75
		old.setTemplateDirectory("DDD");
76
		assertEquals("DDD", old.getTemplateDirectory());
77
		
78
		getReconciler().reconcileTree(current, old);
79
		
80
		assertEquals("AAA", current.getCopyrightText());
81
		assertEquals("BBB", current.getPackageNamePrefix());
82
		assertEquals("CCC", current.getDiagramFileExtension());
83
		assertEquals(sameFile, current.isSameFileForDiagramAndModel());
84
		
85
		assertEquals("DDD", old.getTemplateDirectory());
86
		assertFalse("DDD".equals(current.getTemplateDirectory()));
87
	}
88
	
89
	private Reconciler getReconciler(){
90
		return new Reconciler(new GMFGenConfig());
91
	}
92
	
93
	private GenEditorGenerator loadTaipanGMFGen() throws IOException{
94
		return new TaipanSuite().createTaipanEditorGenerator();
95
	}
96
}
(-).project (+28 lines)
Added Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
<projectDescription>
3
	<name>org.eclipse.gmf.codegen.reconciler.test.taipan</name>
4
	<comment></comment>
5
	<projects>
6
	</projects>
7
	<buildSpec>
8
		<buildCommand>
9
			<name>org.eclipse.jdt.core.javabuilder</name>
10
			<arguments>
11
			</arguments>
12
		</buildCommand>
13
		<buildCommand>
14
			<name>org.eclipse.pde.ManifestBuilder</name>
15
			<arguments>
16
			</arguments>
17
		</buildCommand>
18
		<buildCommand>
19
			<name>org.eclipse.pde.SchemaBuilder</name>
20
			<arguments>
21
			</arguments>
22
		</buildCommand>
23
	</buildSpec>
24
	<natures>
25
		<nature>org.eclipse.pde.PluginNature</nature>
26
		<nature>org.eclipse.jdt.core.javanature</nature>
27
	</natures>
28
</projectDescription>
(-)src/org/eclipse/gmf/codegen/reconciler/test/TaipanSuite.java (+99 lines)
Added Link Here
1
/*
2
 * Copyright (c) 2006 Borland Software Corporation
3
 * 
4
 * All rights reserved. This program and the accompanying materials
5
 * are made available under the terms of the Eclipse Public License v1.0
6
 * which accompanies this distribution, and is available at
7
 * http://www.eclipse.org/legal/epl-v10.html
8
 *
9
 * Contributors:
10
 *    Michael Golubev (Borland) - initial API and implementation
11
 */
12
13
package org.eclipse.gmf.codegen.reconciler.test;
14
15
import java.io.IOException;
16
import java.net.URL;
17
import java.util.HashSet;
18
import java.util.Iterator;
19
20
import org.eclipse.core.runtime.FileLocator;
21
import org.eclipse.core.runtime.Platform;
22
import org.eclipse.emf.codegen.ecore.genmodel.GenModel;
23
import org.eclipse.emf.common.util.URI;
24
import org.eclipse.emf.ecore.EClass;
25
import org.eclipse.emf.ecore.EPackage;
26
import org.eclipse.emf.ecore.resource.Resource;
27
import org.eclipse.emf.ecore.resource.ResourceSet;
28
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
29
import org.eclipse.emf.ecore.util.EcoreUtil;
30
import org.eclipse.gmf.bridge.genmodel.BasicDiagramRunTimeModelHelper;
31
import org.eclipse.gmf.bridge.genmodel.BasicGenModelAccess;
32
import org.eclipse.gmf.bridge.genmodel.DiagramGenModelTransformer;
33
import org.eclipse.gmf.bridge.genmodel.DiagramRunTimeModelHelper;
34
import org.eclipse.gmf.codegen.gmfgen.GenEditorGenerator;
35
import org.eclipse.gmf.internal.bridge.naming.gen.GenModelNamingMediatorImpl;
36
import org.eclipse.gmf.mappings.Mapping;
37
import org.osgi.framework.Bundle;
38
39
public class TaipanSuite {
40
	private static final String TAIPAN = "org.eclipse.gmf.examples.taipan";
41
	
42
	private final Bundle myBundle;
43
	private final ResourceSet myResourceSet;
44
	
45
	public TaipanSuite(){
46
		myResourceSet = new ResourceSetImpl();
47
		myBundle = Platform.getBundle(TAIPAN);
48
		if (myBundle == null){
49
			throw new IllegalStateException();
50
		}
51
	}
52
	
53
	public GenEditorGenerator createTaipanEditorGenerator() throws IOException{
54
		Mapping mapping = (Mapping) loadResource("/models/taipan.gmfmap").getContents().get(0);
55
		BasicGenModelAccess gma = getGenModelAccess(mapping);
56
		gma.initDefault();
57
		gma.load(myResourceSet);
58
		GenModel domainGenModel = gma.model();
59
		DiagramRunTimeModelHelper drtHelper = new BasicDiagramRunTimeModelHelper();
60
		DiagramGenModelTransformer transformer = new DiagramGenModelTransformer(drtHelper, new GenModelNamingMediatorImpl());
61
		if (domainGenModel != null) {
62
			transformer.setEMFGenModel(domainGenModel);
63
		}
64
		transformer.transform(mapping);
65
		GenEditorGenerator result = transformer.getResult();
66
		return result;
67
	}
68
	
69
	public Resource loadResource(String relativePath) throws IOException{
70
		URL resolvedUrl = FileLocator.resolve(myBundle.getEntry(relativePath));
71
		URI uri = URI.createURI(resolvedUrl.toString()); 
72
		return myResourceSet.getResource(uri, true);
73
	}
74
75
	public BasicGenModelAccess getGenModelAccess(Mapping mapping) { 
76
		HashSet packages = new HashSet();
77
		for (Iterator it = EcoreUtil.ExternalCrossReferencer.find(mapping).keySet().iterator(); it.hasNext();) {
78
			Object next = it.next();
79
			if (next instanceof EClass) {
80
				packages.add(((EClass) next).getEPackage());
81
			}
82
		}
83
		for (Iterator it = packages.iterator(); it.hasNext();) {
84
			EPackage next = (EPackage) it.next();
85
			if (next.getESuperPackage() != null && EcoreUtil.isAncestor(packages, next.getESuperPackage())) {
86
				it.remove();
87
			}
88
		}
89
		if (packages.isEmpty()) {
90
			throw new IllegalStateException("Mapping without domain model");
91
		} 
92
		if (packages.size() != 1) {
93
			throw new IllegalStateException("Too many packages");
94
		}
95
		EPackage theOnly = (EPackage) packages.iterator().next();
96
		return new BasicGenModelAccess(theOnly);
97
	}
98
	
99
}

Return to bug 131355