-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added several validations to fix issue #4
- Loading branch information
Showing
4 changed files
with
125 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,9 +11,14 @@ | |
import static java.lang.Math.max; | ||
|
||
import static org.eclipse.xtext.EcoreUtil2.getAllContentsOfType; | ||
import static org.eclipse.xtext.util.SimpleAttributeResolver.newResolver; | ||
|
||
import java.util.List; | ||
|
||
import org.eclipse.emf.ecore.EObject; | ||
import org.eclipse.emf.ecore.EStructuralFeature; | ||
import org.eclipse.xtext.util.SimpleAttributeResolver; | ||
|
||
import com.google.eclipse.protobuf.protobuf.Literal; | ||
import com.google.inject.Singleton; | ||
|
||
|
@@ -23,6 +28,8 @@ | |
* @author [email protected] (Alex Ruiz) | ||
*/ | ||
@Singleton public class Literals { | ||
private final static SimpleAttributeResolver<EObject, Long> INDEX_RESOLVER = newResolver(long.class, "index"); | ||
|
||
/** | ||
* Calculates the index value for the given literal. The calculated index value is the maximum of all the index values | ||
* of the given literal's siblings, plus one. The minimum index value is zero. | ||
|
@@ -50,4 +57,27 @@ public long calculateNewIndexOf(Literal literal) { | |
} | ||
return ++index; | ||
} | ||
|
||
/** | ||
* Returns the index of the given {@link Literal}, or {@code Long.MIN_VALUE} if the given | ||
* {@code IndexedElement} is {@code null}. | ||
*/ | ||
public long indexOf(Literal e) { | ||
long index = Long.MIN_VALUE; | ||
EStructuralFeature feature = indexFeatureOf(e); | ||
if (feature != null) { | ||
index = (Long) e.eGet(feature); | ||
} | ||
return index; | ||
} | ||
|
||
/** | ||
* Returns the "index" structural feature of the given <code>{@link Literal}</code>. | ||
* @param e the given {@code Literal}. | ||
* @return the "index" structural feature of the given {@code Literal}, or {@code null} if the given | ||
* {@code Literal} is {@code null}. | ||
*/ | ||
public EStructuralFeature indexFeatureOf(Literal e) { | ||
return (e != null) ? INDEX_RESOLVER.getAttribute(e) : null; | ||
} | ||
} |
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 |
---|---|---|
|
@@ -14,9 +14,12 @@ | |
* @author [email protected] (Alex Ruiz) | ||
*/ | ||
public class Messages extends NLS { | ||
public static String duplicateNameConflict; | ||
public static String conflictingExtensions; | ||
public static String conflictingField; | ||
public static String conflictingValue; | ||
public static String conflictingGroup; | ||
public static String conflictingDuplicateName; | ||
public static String conflictingReservedName; | ||
public static String conflictingReservedNumber; | ||
public static String expectedFieldName; | ||
|
3 changes: 3 additions & 0 deletions
3
com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/validation/Messages.properties
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