blob: f18820e9dbe76b59517491d8566a9527dd2e7ec0 [file] [log] [blame]
/*
* Copyright (c) 2011 Google Inc.
*
* 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
*/
package com.google.eclipse.protobuf.ui.util;
import static java.lang.Math.max;
import org.eclipse.emf.ecore.EObject;
import com.google.eclipse.protobuf.protobuf.Literal;
import com.google.inject.Singleton;
/**
* Utility methods for instances of <code>{@link Literal}</code>.
*
* @author alruiz@google.com (Alex Ruiz)
*/
@Singleton
public class Literals {
public int calculateIndexOf(Literal l) {
int index = -1;
EObject container = l.eContainer();
for (EObject o : container.eContents()) {
if (o == l || !(o instanceof Literal)) continue;
Literal c = (Literal) o;
index = max(index, c.getIndex());
}
return ++index;
}
}