/** Returns the proto file in which this element lives. */ public ProtoFile getFile() { // Don't need to care about root case as that overrides. return parent.getFile(); }
private List<String> getClassNamePath(ProtoElement elem) { List<String> path = new LinkedList<>(); for (ProtoElement elt = elem; elt.getParent() != null; elt = elt.getParent()) { path.add(0, elt.getSimpleName()); } return path; }
private static String getShortName(ProtoElement elem) { return elem.getFullName().substring(elem.getFile().getFullName().length() + 1); }
/** * Returns the full name of this element, including package and outer messages for nested * elements. For a file, this will return the package name of the file. */ @Override public String getFullName() { // Don't need to care about root case as that overrides. if (Strings.isNullOrEmpty(parent.getFullName())) { return getSimpleName(); } return parent.getFullName() + "." + getSimpleName(); }
/** * Given a proto element, returns its associated description. Returns {@code defaultText} if no * description is available. */ public static String getDescription(ProtoElement element, String defaultText) { return element.hasAttribute(ElementDocumentationAttribute.KEY) ? element.getAttribute(ElementDocumentationAttribute.KEY).documentation() : defaultText; }
rule.getDescription(), ResolvedLocation.create(element.getLocation()), element); if (element.hasAttribute(PageAttribute.KEY) && !element.getFile().hasAttribute(PageAttribute.KEY)) { element.getFile().putAttribute(PageAttribute.KEY, element.getAttribute(PageAttribute.KEY)); processorSet.process( rule.getDeprecationDescription(), ResolvedLocation.create(element.getLocation()), element); && element.hasAttribute(DeprecationDescriptionAttribute.KEY)) { deprecationDesc = processorSet.process( element.getAttribute(DeprecationDescriptionAttribute.KEY).deprecationDescription(), ResolvedLocation.create(element.getLocation()), element);
@Override public TypeName getTypeName(ProtoElement elem) { // Handle special wrapper types first String wrapper = WRAPPER_TYPE_MAP.getOrDefault(elem.getFullName(), null); if (wrapper != null) { return typeNameConverter.getTypeName(wrapper); } // Handle nested types, construct the required type prefix ProtoElement parentEl = elem.getParent(); String shortNamePrefix = ""; while (parentEl != null && parentEl instanceof MessageType) { shortNamePrefix = parentEl.getSimpleName() + "+Types+" + shortNamePrefix; parentEl = parentEl.getParent(); } String prefix = ""; if (parentEl instanceof ProtoFile) { ProtoFile protoFile = (ProtoFile) parentEl; String namespace = protoFile.getProto().getOptions().getCsharpNamespace(); if (Strings.isNullOrEmpty(namespace)) { for (String name : Splitter.on('.').split(parentEl.getFullName())) { prefix += Name.from(name).toUpperCamelAndDigits() + "."; } } else { prefix = namespace + "."; } } String shortName = shortNamePrefix + elem.getSimpleName(); return typeNameConverter.getTypeName(prefix + shortName); }
public String getLinkedElementName(ProtoElement element) { String simpleName = element.getSimpleName(); String packageName = element.getFile().getFullName(); return String.format("[%s]{@link %s.%s}", simpleName, packageName, simpleName); } }
private void markAsReachable(ProtoElement elem) { reachable.add(elem); ProtoElement parent = elem.getParent(); while (parent != null) { if (reachable.add(parent)) { // Parent was not reachable, check whether it is inScope and produce an error if not. if (!inScope(parent)) { errorSince( 2, parent, "Parent '%s' of visible element '%s' cannot be hidden. %s.", parent.getFullName(), elem.getFullName(), reasonForUnreachable(parent)); } } parent = parent.getParent(); } } }
private boolean hasEmptySelector(ProtoElement element) { // In case of proto files without package name, the generated selector will be empty, // we do not want to normalize such rules. return Strings.isNullOrEmpty(element.getFullName()); } }
@Override public String getParentSimpleName() { return method.getParent().getSimpleName(); }
@Override public void normalize(ProtoElement element, Service.Builder builder) { if (!isApplicable(element) || hasEmptySelector(element)) { return; } AttributeType attribute = element.getAttribute(key); if (attribute != null) { addToRuleBuilder(builder, element.getFullName(), attribute); } }
@SuppressWarnings("unchecked") @Nullable private <T, O extends Message, E extends ProtoElement> T getProtoExtension( E element, GeneratedExtension<O, T> extension) { // Use this method as the chokepoint for all annotations processing, so we can toggle on/off // annotations processing in one place. if (enableProtoAnnotations) { return (T) element.getOptionFields().get(extension.getDescriptor()); } else { return null; } }
private static boolean inEndpoint(Model model, ProtoElement element) { String endpoint = model.getAttribute(ENDPOINT_FILTER_KEY); if (element instanceof ProtoFile) { return true; } else if (element instanceof Interface) { Endpoint endpointConfig = getEndpointConfig(model, endpoint); if (endpointConfig != null) { return true; } return false; } else { return inEndpoint(model, element.getParent()); } }
public static String getScopedDescription(ProtoElement element, boolean reportWarning) { Model model = element.getModel(); LocationContext location = ResolvedLocation.create(element.getLocation()); String internalCommentFilteredString = new CommentFilter(model.getDiagReporter(), location, model.getVisibilityLabels()) .process(getDescription(element)); return sanitizeTodos( model.getDiagReporter(), location, internalCommentFilteredString, reportWarning); }
/** Returns the model. */ @Override public Model getModel() { // Don't need to care about root case as that overrides. return parent.getModel(); }
private ImmutableList<String> getOauthScopes(ProtoElement element) { AuthAttribute auth = element.getAttribute(AuthAttribute.KEY); return auth != null && auth.getAuthenticationRule().hasOauth() ? ImmutableList.copyOf( OAUTH_SCOPE_SPLITTER.split( auth.getAuthenticationRule().getOauth().getCanonicalScopes())) : EMPTY_STRING_LIST; }
/** * Package private helper to get the location backed up by this proto file for the given element. */ Location getLocation(ProtoElement element) { if (protoToLocation.containsKey(element)) { return protoToLocation.get(element); } Location location = ProtoLocation.convertFrom(getSourceCodeLocation(element.getPath()), element); protoToLocation.put(element, location); return location; }
/** Gets the syntax in which the element was defined. */ public Syntax getSyntax() { return parent.getSyntax(); }
rule.getDescription(), ResolvedLocation.create(element.getLocation()), element); if (element.hasAttribute(PageAttribute.KEY) && !element.getFile().hasAttribute(PageAttribute.KEY)) { element.getFile().putAttribute(PageAttribute.KEY, element.getAttribute(PageAttribute.KEY)); processorSet.process( rule.getDeprecationDescription(), ResolvedLocation.create(element.getLocation()), element); && element.hasAttribute(DeprecationDescriptionAttribute.KEY)) { deprecationDesc = processorSet.process( element.getAttribute(DeprecationDescriptionAttribute.KEY).deprecationDescription(), ResolvedLocation.create(element.getLocation()), element);