blob: b3110e2a154f6a59b15565092de4ea4873fc9147 [file]
/*
* 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.model.util;
import com.google.eclipse.protobuf.protobuf.*;
import com.google.inject.Singleton;
/**
* Utility methods related to fields in <code>{@link Option}</code>s
*
* @author alruiz@google.com (Alex Ruiz)
*/
@Singleton
public class OptionFields {
/**
* Returns the field the given option field is referring to.
* @param fieldSource the given option field.
* @return the field the given option field is referring to, or {@code null} if one cannot be found.
*/
public Field sourceOf(OptionFieldSource fieldSource) {
if (fieldSource instanceof OptionMessageFieldSource) {
OptionMessageFieldSource source = (OptionMessageFieldSource) fieldSource;
return source.getOptionMessageField();
}
if (fieldSource instanceof OptionExtendMessageFieldSource) {
OptionExtendMessageFieldSource source = (OptionExtendMessageFieldSource) fieldSource;
return source.getOptionExtendMessageField();
}
return null;
}
}