blob: 2a670c423aa9a9a4cc6801bc00d950d392a6ef60 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
/**
* Copyright (c) 2014 CEA LIST 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:
* CEA LIST - Initial API and implementation
*/
package org.eclipse.papyrus.dsml.validation.generator.xtend;
import com.google.common.collect.Iterators;
import java.util.Iterator;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.papyrus.dsml.validation.model.profilenames.Utils;
import org.eclipse.papyrus.infra.tools.file.IPFileSystemAccess;
import org.eclipse.uml2.uml.Stereotype;
import org.eclipse.xtend2.lib.StringConcatenation;
/**
* Generator for producing client selector files: Java files that filter the stereotype
* for validation
*/
@SuppressWarnings("all")
public class ClientSelectorGen {
public static CharSequence generateValidationContext(final Stereotype stereotype) {
StringConcatenation _builder = new StringConcatenation();
_builder.append("/**");
_builder.newLine();
_builder.append(" ");
_builder.append("* Created by the Papyrus DSML plugin generator");
_builder.newLine();
_builder.append(" ");
_builder.append("*/");
_builder.newLine();
_builder.newLine();
_builder.append("package ");
String _topPkg = Utils.getTopPkg();
_builder.append(_topPkg);
_builder.append(".selectors;");
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.append("import org.eclipse.emf.validation.model.IClientSelector;");
_builder.newLine();
_builder.append("import org.eclipse.papyrus.uml.service.validation.StereotypeUtil;");
_builder.newLine();
_builder.newLine();
_builder.append("/**");
_builder.newLine();
_builder.append(" ");
_builder.append("* This class filters (selects) passed stereotype applications. It returns true, if the");
_builder.newLine();
_builder.append(" ");
_builder.append("* associated stereotype (or one of its super-stereotypes) has the name \'[stereotype.name/]\'.");
_builder.newLine();
_builder.append(" ");
_builder.append("*");
_builder.newLine();
_builder.append(" ");
_builder.append("* @generated");
_builder.newLine();
_builder.append(" ");
_builder.append("*/");
_builder.newLine();
_builder.append("public class ");
String _name = stereotype.getName();
_builder.append(_name);
_builder.append("ClientSelector implements IClientSelector {");
_builder.newLineIfNotEmpty();
_builder.newLine();
_builder.append("\t");
_builder.append("public boolean selects(Object stereoApplicationObj) {");
_builder.newLine();
_builder.append("\t\t");
_builder.append("return StereotypeUtil.checkStereoApplication(stereoApplicationObj, \"");
String _name_1 = stereotype.getName();
_builder.append(_name_1, "\t\t");
_builder.append("\"); //$NON-NLS-1$");
_builder.newLineIfNotEmpty();
_builder.append("\t");
_builder.append("}");
_builder.newLine();
_builder.append("}");
_builder.newLine();
return _builder;
}
/**
* @see org.eclipse.xtext.generator.IGenerator#doGenerate(org.eclipse.emf.ecore.resource.Resource, org.eclipse.xtext.generator.IFileSystemAccess)
*
* @param input
* @param fsa
*/
public static void generate(final Resource input, final IPFileSystemAccess fsa) {
final Iterator<Stereotype> contentIterator = Iterators.<Stereotype>filter(input.getAllContents(), Stereotype.class);
while (contentIterator.hasNext()) {
{
final Stereotype stereotype = contentIterator.next();
String _replaceAll = Utils.getTopPkg().replaceAll("\\.", "/");
String _plus = (_replaceAll + "/selectors/");
String _name = stereotype.getName();
String _plus_1 = (_plus + _name);
final String fileName = (_plus_1 + "ClientSelector.java");
fsa.generateFile(fileName, ClientSelectorGen.generateValidationContext(stereotype).toString());
}
}
}
}
|