Skip to main content
summaryrefslogtreecommitdiffstats
blob: e88c76a58bb9759ef7f9bc3e52a46657faa87981 (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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
/**
 */
package org.eclipse.emf.cdo.releng.projectconfig.util;

import org.eclipse.emf.cdo.releng.preferences.PreferenceNode;
import org.eclipse.emf.cdo.releng.projectconfig.*;
import org.eclipse.emf.cdo.releng.projectconfig.impl.ProjectConfigPlugin;
import org.eclipse.emf.common.util.Diagnostic;
import org.eclipse.emf.common.util.DiagnosticChain;
import org.eclipse.emf.common.util.ResourceLocator;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.util.EObjectValidator;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;

/**
 * <!-- begin-user-doc -->
 * The <b>Validator</b> for the model.
 * <!-- end-user-doc -->
 * @see org.eclipse.emf.cdo.releng.projectconfig.ProjectConfigPackage
 * @generated
 */
public class ProjectConfigValidator extends EObjectValidator
{
  /**
   * The cached model package
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public static final ProjectConfigValidator INSTANCE = new ProjectConfigValidator();

  /**
   * A constant for the {@link org.eclipse.emf.common.util.Diagnostic#getSource() source} of diagnostic {@link org.eclipse.emf.common.util.Diagnostic#getCode() codes} from this package.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see org.eclipse.emf.common.util.Diagnostic#getSource()
   * @see org.eclipse.emf.common.util.Diagnostic#getCode()
   * @generated
   */
  public static final String DIAGNOSTIC_SOURCE = "org.eclipse.emf.cdo.releng.projectconfig";

  /**
   * A constant with a fixed name that can be used as the base value for additional hand written constants.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  private static final int GENERATED_DIAGNOSTIC_CODE_COUNT = 0;

  /**
   * A constant with a fixed name that can be used as the base value for additional hand written constants in a derived class.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  protected static final int DIAGNOSTIC_CODE_COUNT = GENERATED_DIAGNOSTIC_CODE_COUNT;

  /**
   * Creates an instance of the switch.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public ProjectConfigValidator()
  {
    super();
  }

  /**
   * Returns the package of this validator switch.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  protected EPackage getEPackage()
  {
    return ProjectConfigPackage.eINSTANCE;
  }

  /**
   * Calls <code>validateXXX</code> for the corresponding classifier of the model.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  protected boolean validate(int classifierID, Object value, DiagnosticChain diagnostics, Map<Object, Object> context)
  {
    switch (classifierID)
    {
      case ProjectConfigPackage.WORKSPACE_CONFIGURATION:
        return validateWorkspaceConfiguration((WorkspaceConfiguration)value, diagnostics, context);
      case ProjectConfigPackage.PROJECT:
        return validateProject((Project)value, diagnostics, context);
      case ProjectConfigPackage.PREFERENCE_PROFILE:
        return validatePreferenceProfile((PreferenceProfile)value, diagnostics, context);
      case ProjectConfigPackage.PREFERENCE_FILTER:
        return validatePreferenceFilter((PreferenceFilter)value, diagnostics, context);
      case ProjectConfigPackage.PATTERN:
        return validatePattern((Pattern)value, diagnostics, context);
      default:
        return true;
    }
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public boolean validateWorkspaceConfiguration(WorkspaceConfiguration workspaceConfiguration,
      DiagnosticChain diagnostics, Map<Object, Object> context)
  {
    return validate_EveryDefaultConstraint(workspaceConfiguration, diagnostics, context);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public boolean validateProject(Project project, DiagnosticChain diagnostics, Map<Object, Object> context)
  {
    if (!validate_NoCircularContainment(project, diagnostics, context)) return false;
    boolean result = validate_EveryMultiplicityConforms(project, diagnostics, context);
    if (result || diagnostics != null) result &= validate_EveryDataValueConforms(project, diagnostics, context);
    if (result || diagnostics != null) result &= validate_EveryReferenceIsContained(project, diagnostics, context);
    if (result || diagnostics != null) result &= validate_EveryBidirectionalReferenceIsPaired(project, diagnostics, context);
    if (result || diagnostics != null) result &= validate_EveryProxyResolves(project, diagnostics, context);
    if (result || diagnostics != null) result &= validate_UniqueID(project, diagnostics, context);
    if (result || diagnostics != null) result &= validate_EveryKeyUnique(project, diagnostics, context);
    if (result || diagnostics != null) result &= validate_EveryMapEntryUnique(project, diagnostics, context);
    if (result || diagnostics != null) result &= validateProject_AllPreferencesManaged(project, diagnostics, context);
    return result;
  }

  static Map<String, PreferenceNode> collectUnmanagedPreferences(Project project)
  {
    Map<String, PreferenceNode> result = new LinkedHashMap<String, PreferenceNode>();
    PreferenceNode preferenceNode = project.getPreferenceNode();
    if (preferenceNode != null)
    {
      for (PreferenceNode child : preferenceNode.getChildren())
      {
        if (!child.getProperties().isEmpty())
        {
          result.put(child.getName(), child);
        }
      }

      result.remove(ProjectConfigUtil.PROJECT_CONF_NODE_NAME);

      for (PreferenceProfile preferenceProfile : project.getPreferenceProfiles())
      {
        for (PreferenceFilter preferenceFilter : preferenceProfile.getPreferenceFilters())
        {
          PreferenceNode otherPreferenceNode = preferenceFilter.getPreferenceNode();
          if (otherPreferenceNode != null)
          {
            result.remove(otherPreferenceNode.getName());
          }
        }
      }

      for (PreferenceProfile preferenceProfile : project.getPreferenceProfileReferences())
      {
        for (PreferenceFilter preferenceFilter : preferenceProfile.getPreferenceFilters())
        {
          PreferenceNode otherPreferenceNode = preferenceFilter.getPreferenceNode();
          if (otherPreferenceNode != null)
          {
            result.remove(otherPreferenceNode.getName());
          }
        }
      }
    }
    return result;
  }

  /**
   * Validates the AllPreferencesManaged constraint of '<em>Project</em>'.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated NOT
   */
  public boolean validateProject_AllPreferencesManaged(Project project, DiagnosticChain diagnostics,
      Map<Object, Object> context)
  {
    Map<String, PreferenceNode> unmanagedPreferences = collectUnmanagedPreferences(project);

    if (!unmanagedPreferences.isEmpty())
    {
      if (diagnostics != null)
      {
        String substitution = unmanagedPreferences.keySet().toString();
        substitution = substitution.substring(1, substitution.length() - 1);
        int lastComma = substitution.lastIndexOf(',');
        if (lastComma != -1)
        {
          substitution = substitution.substring(0, lastComma) + " and " + substitution.substring(lastComma + 1);
        }
        List<Object> data = new ArrayList<Object>();
        data.add(project);
        data.add(ProjectConfigPackage.Literals.PROJECT__PREFERENCE_PROFILE_REFERENCES);
        data.addAll(unmanagedPreferences.values());
        diagnostics.add(createDiagnostic(Diagnostic.ERROR, DIAGNOSTIC_SOURCE, 0,
            "_UI_AllPreferencesManaged_diagnostic", new Object[] { substitution }, data.toArray(), context));
      }
      return false;
    }
    return true;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public boolean validatePreferenceProfile(PreferenceProfile preferenceProfile, DiagnosticChain diagnostics,
      Map<Object, Object> context)
  {
    return validate_EveryDefaultConstraint(preferenceProfile, diagnostics, context);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public boolean validatePreferenceFilter(PreferenceFilter preferenceFilter, DiagnosticChain diagnostics,
      Map<Object, Object> context)
  {
    return validate_EveryDefaultConstraint(preferenceFilter, diagnostics, context);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public boolean validatePattern(Pattern pattern, DiagnosticChain diagnostics, Map<Object, Object> context)
  {
    return true;
  }

  /**
   * Returns the resource locator that will be used to fetch messages for this validator's diagnostics.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public ResourceLocator getResourceLocator()
  {
    return ProjectConfigPlugin.INSTANCE;
  }

} // ProjectConfigValidator

Back to the top