本文整理汇总了Java中com.google.protobuf.ExtensionRegistry.ExtensionInfo类的典型用法代码示例。如果您正苦于以下问题:Java ExtensionInfo类的具体用法?Java ExtensionInfo怎么用?Java ExtensionInfo使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ExtensionInfo类属于com.google.protobuf.ExtensionRegistry包,在下文中一共展示了ExtensionInfo类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findExtensionByName
import com.google.protobuf.ExtensionRegistry.ExtensionInfo; //导入依赖的package包/类
/**
* Finds extension by its containing type and the dot separated multi-part name.
*/
public static ExtensionInfo findExtensionByName(final ExtensionRegistry registry,
final Descriptor containingType, final String name) {
final int index = name.lastIndexOf(".");
final String nameLastPart = index == -1 ? name : name.substring(index + 1);
return registry.findImmutableExtensionByName(containingType.getFullName() + "." + nameLastPart);
}
示例2: exitField
import com.google.protobuf.ExtensionRegistry.ExtensionInfo; //导入依赖的package包/类
@Override
public void exitField(FieldContext ctx) {
if (ctx.ID() != null && indexPool.contains(ctx.ID().getText())) {
// if we see index but not real field, we have pop ROOT from stack and push index expression instead
stack.pop();
stack.push(indexPool.getIndex(ctx.ID().getText()));
return;
}
// otherwise, it is a field.
Expression indexExpr = null;
if (ctx.index() != null) {
indexExpr = dereference(ctx.getStart(), stack.pop(), null);
}
final ObjectExpression objExpr;
final FieldDescriptor fd;
Expression scopeExpr = dereference(ctx.getStart(), stack.pop(), null);
if (scopeExpr.getType() == OBJECT_REFERENCE) {
objExpr = ObjectExpression.class.cast(scopeExpr);
} else {
throw new SemanticException(ctx.getStart(), "Cannot get field from expression of type " + scopeExpr.getType());
}
if (ctx.ext() != null) {
ExtensionInfo extInfo = registry.findExtensionByName(ctx.ext().extName);
if (extInfo == null) {
throw new SemanticException(ctx.getStart(), "No such extension: " + ctx.ext().extName);
}
fd = extInfo.descriptor;
} else {
String name = ctx.ID().getText();
if (scopeExpr.getType() != OBJECT_REFERENCE) {
throw new SemanticException(ctx.getStart(), "Cannot take field " + name + " from " + scopeExpr.getType());
}
Descriptor descr = ObjectExpression.class.cast(scopeExpr).getDescriptor();
fd = descr.findFieldByName(name);
if (fd == null) {
throw new SemanticException(ctx.getStart(), "Message " + descr.getFullName() + " does not have field " + name);
}
}
if (fd.isRepeated()) {
if (indexExpr != null) {
stack.push(dereference(ctx.getStart(), new FieldArrayReferenceExpression(objExpr, fd), indexExpr));
} else {
stack.push(new FieldArrayReferenceExpression(objExpr, fd));
}
} else {
stack.push(new FieldReferenceExpression(objExpr, fd));
}
}
示例3: findExtensionByName
import com.google.protobuf.ExtensionRegistry.ExtensionInfo; //导入依赖的package包/类
private ExtensionInfo findExtensionByName(final String containingTypeName, final String name) {
if (name.startsWith(".")) {
return registry.findExtensionByName(name.substring(1));
}
ExtensionInfo info;
// try first inner scoped
if (!containingTypeName.isEmpty()) {
info = registry.findExtensionByName(containingTypeName + '.' + name);
if (info != null) {
return info;
}
}
// then outer scoped for empty package
if (file.getPackage().isEmpty()) {
return registry.findExtensionByName(name);
}
// then outer scoped if starts with package
if (name.startsWith(file.getPackage() + '.')) {
info = registry.findExtensionByName(name);
if (info != null) {
return info;
}
// then if contained in a Message with package name?
return registry.findExtensionByName(file.getPackage() + '.' + name);
}
// then try the package prepending the name
info = registry.findExtensionByName(file.getPackage() + '.' + name);
if (info != null) {
return info;
}
// then try for outer file extension
return registry.findExtensionByName(name);
}