-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #761 from eclipse-passage/573296-4
Bug 573296 - [Passage] rework EMF migration facilities, part 4
- Loading branch information
Showing
8 changed files
with
78 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
...org.eclipse.passage.lic.emf/src/org/eclipse/passage/lic/emf/validation/ErrorMessages.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2021 ArSysOp | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* https://www.eclipse.org/legal/epl-2.0/. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* ArSysOp - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.passage.lic.emf.validation; | ||
|
||
import java.util.Optional; | ||
import java.util.function.Function; | ||
|
||
import org.eclipse.emf.common.util.Diagnostic; | ||
import org.eclipse.emf.ecore.EObject; | ||
import org.eclipse.emf.ecore.util.Diagnostician; | ||
import org.eclipse.passage.lic.internal.emf.i18n.EmfMessages; | ||
|
||
/** | ||
* Summarizes validation errors for the given {@link EObject} | ||
* | ||
* @since 2.0 | ||
*/ | ||
public final class ErrorMessages implements Function<EObject, Optional<String>> { | ||
|
||
@Override | ||
public Optional<String> apply(EObject input) { | ||
if (input == null) { | ||
return Optional.of(EmfMessages.LicensingEcore_input_invalid); | ||
} | ||
final Diagnostic result = Diagnostician.INSTANCE.validate(input); | ||
if (result.getSeverity() == Diagnostic.OK) { | ||
return Optional.empty(); | ||
} | ||
// Get the error count and create an appropriate Error message: | ||
final int errorCount = result.getChildren().size(); | ||
final String header = EmfMessages.LicensingEcore_inpur_header; | ||
final String entry = EmfMessages.LicensingEcore_input_entry; | ||
final StringBuilder sb = new StringBuilder(); | ||
sb.append(String.format(header, errorCount)); | ||
sb.append('\n'); | ||
int messageCount = 0; | ||
for (final Diagnostic d : result.getChildren()) { | ||
sb.append('\n'); | ||
sb.append(String.format(entry, ++messageCount, d.getMessage())); | ||
} | ||
return Optional.of(sb.toString()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters