code stringlengths 73 34.1k | label stringclasses 1
value |
|---|---|
private static String embedCssIntoHtmlSlow(
String css, int nextReplacement, boolean searchForEndCData, boolean searchForEndTag) {
// use an array instead of a stringbuilder so we can take advantage of the bulk copying
// routine (String.getChars). For some reason StringBuilder doesn't do this.
char[... | java |
public ImmutableList<SoyMsgPart> getMsgParts(long msgId) {
SoyMsg msg = getMsg(msgId);
return msg == null ? ImmutableList.of() : msg.getParts();
} | java |
public static PyExpr concatPyExprs(List<? extends PyExpr> pyExprs) {
if (pyExprs.isEmpty()) {
return EMPTY_STRING;
}
if (pyExprs.size() == 1) {
// If there's only one element, simply return the expression as a String.
return pyExprs.get(0).toPyString();
}
StringBuilder resultSb ... | java |
public static PyExpr maybeProtect(PyExpr expr, int minSafePrecedence) {
// all python operators are left associative, so if this has equivalent precedence we don't need
// to wrap
if (expr.getPrecedence() >= minSafePrecedence) {
return expr;
} else {
return new PyExpr("(" + expr.getText() + ... | java |
public static PyExpr convertMapToOrderedDict(Map<PyExpr, PyExpr> dict) {
List<String> values = new ArrayList<>();
for (Map.Entry<PyExpr, PyExpr> entry : dict.entrySet()) {
values.add("(" + entry.getKey().getText() + ", " + entry.getValue().getText() + ")");
}
Joiner joiner = Joiner.on(", ");
... | java |
public static String genExprWithNewToken(
Operator op, List<? extends TargetExpr> operandExprs, String newToken) {
int opPrec = op.getPrecedence();
boolean isLeftAssociative = op.getAssociativity() == Associativity.LEFT;
StringBuilder exprSb = new StringBuilder();
// Iterate through the operato... | java |
private static StaticAnalysisResult isListExpressionEmpty(ForNode node) {
Optional<RangeArgs> rangeArgs = RangeArgs.createFromNode(node);
if (rangeArgs.isPresent()) {
return isRangeExpressionEmpty(rangeArgs.get());
}
ExprNode expr = node.getExpr().getRoot();
if (expr instanceof ListLiteralNode... | java |
public SoyMsgBundle createFromFile(File inputFile) throws IOException {
// TODO: This is for backwards-compatibility. Figure out how to get rid of this.
// We special-case English locales because they often don't have translated files and falling
// back to the Soy source should be fine.
if (!inputFile... | java |
public SoyMsgBundle createFromResource(URL inputResource) throws IOException {
try {
String inputFileContent = Resources.asCharSource(inputResource, UTF_8).read();
return msgPlugin.parseTranslatedMsgsFile(inputFileContent);
} catch (SoyMsgException sme) {
sme.setFileOrResourceName(inputResou... | java |
@Nullable
public HtmlCloseTagNode getCloseTagNode() {
if (numChildren() > 1) {
return (HtmlCloseTagNode)
getNodeAsHtmlTagNode(getChild(numChildren() - 1), /*openTag=*/ false);
}
return null;
} | java |
public static Locale parseLocale(String localeString) {
if (localeString == null) {
return Locale.US;
}
String[] groups = localeString.split("[-_]");
switch (groups.length) {
case 1:
return new Locale(groups[0]);
case 2:
return new Locale(groups[0], Ascii.toUpperCase(gr... | java |
public <T> void updateRefs(T oldObject, T newObject) {
checkNotNull(oldObject);
checkNotNull(newObject);
checkArgument(!(newObject instanceof Listener));
Object previousMapping = mappings.put(oldObject, newObject);
if (previousMapping != null) {
if (previousMapping instanceof Listener) {
... | java |
public void checkAllListenersFired() {
for (Map.Entry<Object, Object> entry : mappings.entrySet()) {
if (entry.getValue() instanceof Listener) {
throw new IllegalStateException(
"Listener for " + entry.getKey() + " never fired: " + entry.getValue());
}
}
} | java |
public static String unescapeHtml(String s) {
int amp = s.indexOf('&');
if (amp < 0) { // Fast path.
return s;
}
int n = s.length();
StringBuilder sb = new StringBuilder(n);
int pos = 0;
do {
// All numeric entities and all named entities can be represented in less than 12 chars,... | java |
private List<String> genPySrc(
SoyFileSetNode soyTree,
SoyPySrcOptions pySrcOptions,
ImmutableMap<String, String> currentManifest,
ErrorReporter errorReporter) {
BidiGlobalDir bidiGlobalDir =
SoyBidiUtils.decodeBidiGlobalDirFromPyOptions(pySrcOptions.getBidiIsRtlFn());
try (SoyS... | java |
public void genPyFiles(
SoyFileSetNode soyTree,
SoyPySrcOptions pySrcOptions,
String outputPathFormat,
ErrorReporter errorReporter)
throws IOException {
ImmutableList<SoyFileNode> srcsToCompile = ImmutableList.copyOf(soyTree.getChildren());
// Determine the output paths.
List... | java |
private static ImmutableMap<String, String> generateManifest(
List<String> soyNamespaces, Multimap<String, Integer> outputs) {
ImmutableMap.Builder<String, String> manifest = new ImmutableMap.Builder<>();
for (String outputFilePath : outputs.keySet()) {
for (int inputFileIndex : outputs.get(outputFi... | java |
public void check(SoyFileNode file, final ErrorReporter errorReporter) {
// first filter to only the rules that need to be checked for this file.
final List<Rule<?>> rulesForFile = new ArrayList<>(rules.size());
String filePath = file.getFilePath();
for (RuleWithWhitelists rule : rules) {
if (rule... | java |
public static SoyType getTypeForContentKind(SanitizedContentKind contentKind) {
switch (contentKind) {
case ATTRIBUTES:
return AttributesType.getInstance();
case CSS:
return StyleType.getInstance();
case HTML:
return HtmlType.getInstance();
case JS:
return ... | java |
private static <T> T instantiateObject(
String flagName,
String objectType,
Class<T> clazz,
PluginLoader loader,
String instanceClassName) {
try {
return loader.loadPlugin(instanceClassName).asSubclass(clazz).getConstructor().newInstance();
} catch (ClassCastException cce) {
... | java |
public JsCodeBuilder addChunksToOutputVar(List<? extends Expression> codeChunks) {
if (currOutputVarIsInited) {
Expression rhs = CodeChunkUtils.concatChunks(codeChunks);
rhs.collectRequires(requireCollector);
appendLine(currOutputVar.plusEquals(rhs).getCode());
} else {
Expression rhs = ... | java |
private JsCodeBuilder changeIndentHelper(int chg) {
int newIndentDepth = indent.length() + chg * INDENT_SIZE;
Preconditions.checkState(newIndentDepth >= 0);
indent = Strings.repeat(" ", newIndentDepth);
return this;
} | java |
static SanitizedContent create(String content, ContentKind kind) {
checkArgument(
kind != ContentKind.TEXT, "Use UnsanitizedString for SanitizedContent with a kind of TEXT");
if (Flags.stringIsNotSanitizedContent()) {
return new SanitizedContent(content, kind, kind.getDefaultDir());
}
retu... | java |
public static StreamingEscaper create(
LoggingAdvisingAppendable delegate, CrossLanguageStringXform transform) {
if (delegate instanceof StreamingEscaper) {
StreamingEscaper delegateAsStreamingEscaper = (StreamingEscaper) delegate;
if (delegateAsStreamingEscaper.transform == transform) {
r... | java |
public void onResolve(ResolutionCallback callback) {
checkState(this.resolveCallback == null, "callback has already been set.");
checkState(this.value == null, "value is resolved.");
this.resolveCallback = checkNotNull(callback);
} | java |
public static Statement assign(Expression lhs, Expression rhs) {
return Assignment.create(lhs, rhs, null);
} | java |
public static Statement assign(Expression lhs, Expression rhs, JsDoc jsDoc) {
return Assignment.create(lhs, rhs, jsDoc);
} | java |
public static Statement forLoop(String localVar, Expression limit, Statement body) {
return For.create(localVar, Expression.number(0), limit, Expression.number(1), body);
} | java |
public static Optional<CompiledTemplates> compile(
final TemplateRegistry registry,
final SoyFileSetNode fileSet,
boolean developmentMode,
ErrorReporter reporter,
ImmutableMap<String, SoyFileSupplier> filePathsToSuppliers,
SoyTypeRegistry typeRegistry) {
final Stopwatch stopwatch... | java |
public void invokeUnchecked(CodeBuilder cb) {
cb.visitMethodInsn(
opcode(),
owner().internalName(),
method().getName(),
method().getDescriptor(),
// This is for whether the methods owner is an interface. This is mostly to handle java8
// default methods on interfaces... | java |
@Deprecated
protected static SoyData createFromExistingData(Object obj) {
if (obj instanceof SoyData) {
return (SoyData) obj;
} else if (obj instanceof Map<?, ?>) {
@SuppressWarnings("unchecked")
Map<String, ?> objCast = (Map<String, ?>) obj;
return new SoyMapData(objCast);
} else ... | java |
public static boolean hasPlrselPart(List<SoyMsgPart> msgParts) {
for (SoyMsgPart origMsgPart : msgParts) {
if (origMsgPart instanceof SoyMsgPluralPart || origMsgPart instanceof SoyMsgSelectPart) {
return true;
}
}
return false;
} | java |
public void set(int index, SoyData value) {
if (index == list.size()) {
list.add(ensureValidValue(value));
} else {
list.set(index, ensureValidValue(value));
}
} | java |
@Override
public SoyData get(int index) {
try {
return list.get(index);
} catch (IndexOutOfBoundsException ioobe) {
return null;
}
} | java |
public static String getDidYouMeanMessage(Iterable<String> allNames, String wrongName) {
String closestName = getClosest(allNames, wrongName);
if (closestName != null) {
return String.format(" Did you mean '%s'?", closestName);
}
return "";
} | java |
private static int distance(String s, String t, int maxDistance) {
// create two work vectors of integer distances
// it is possible to reduce this to only one array, but performance isn't that important here.
// We could also avoid calculating a lot of the entries by taking maxDistance into account in
... | java |
public static String formatErrors(Iterable<SoyError> errors) {
int numErrors = 0;
int numWarnings = 0;
for (SoyError error : errors) {
if (error.isWarning()) {
numWarnings++;
} else {
numErrors++;
}
}
if (numErrors + numWarnings == 0) {
throw new IllegalArgume... | java |
public void prependKeyToDataPath(String key) {
if (dataPath == null) {
dataPath = key;
} else {
dataPath = key + ((dataPath.charAt(0) == '[') ? "" : ".") + dataPath;
}
} | java |
@Memoized
public Type type() {
int dotIndex = identifier().indexOf('.');
if (dotIndex == 0) {
checkArgument(BaseUtils.isIdentifierWithLeadingDot(identifier()));
return Type.DOT_IDENT;
} else {
checkArgument(BaseUtils.isDottedIdentifier(identifier()));
return dotIndex == -1 ? Type.S... | java |
public Identifier extractPartAfterLastDot() {
String part = BaseUtils.extractPartAfterLastDot(identifier());
return Identifier.create(
part, location().offsetStartCol(identifier().length() - part.length()));
} | java |
@Nullable
public static PrimitiveNode convertPrimitiveDataToExpr(
PrimitiveData primitiveData, SourceLocation location) {
if (primitiveData instanceof StringData) {
return new StringNode(primitiveData.stringValue(), QuoteStyle.SINGLE, location);
} else if (primitiveData instanceof BooleanData) {
... | java |
public static PrimitiveData convertPrimitiveExprToData(PrimitiveNode primitiveNode) {
if (primitiveNode instanceof StringNode) {
return StringData.forValue(((StringNode) primitiveNode).getValue());
} else if (primitiveNode instanceof BooleanNode) {
return BooleanData.forValue(((BooleanNode) primiti... | java |
public static ImmutableMap<String, PrimitiveData> convertCompileTimeGlobalsMap(
Map<String, ?> compileTimeGlobalsMap) {
ImmutableMap.Builder<String, PrimitiveData> resultMapBuilder = ImmutableMap.builder();
for (Map.Entry<String, ?> entry : compileTimeGlobalsMap.entrySet()) {
Object valueObj = en... | java |
boolean shouldCheckConformanceFor(String filePath) {
for (String whitelistedPath : getWhitelistedPaths()) {
if (filePath.contains(whitelistedPath)) {
return false;
}
}
ImmutableList<String> onlyApplyToPaths = getOnlyApplyToPaths();
if (onlyApplyToPaths.isEmpty()) {
return true;... | java |
private static boolean isEmpty(MsgNode msg) {
for (SoyNode child : msg.getChildren()) {
if (child instanceof RawTextNode && ((RawTextNode) child).getRawText().isEmpty()) {
continue;
}
return false;
}
return true;
} | java |
public void setEscapingDirectives(
SoyNode node, Context context, List<EscapingMode> escapingModes) {
Preconditions.checkArgument(
(node instanceof PrintNode)
|| (node instanceof CallNode)
|| (node instanceof MsgFallbackGroupNode),
"Escaping directives may only be set f... | java |
public ImmutableList<EscapingMode> getEscapingModesForNode(SoyNode node) {
ImmutableList<EscapingMode> modes = nodeToEscapingModes.get(node);
if (modes == null) {
modes = ImmutableList.of();
}
return modes;
} | java |
static SoyMsgBundle parseXliffTargetMsgs(String xliffContent) throws SAXException {
// Get a SAX parser.
SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
SAXParser saxParser;
try {
saxParser = saxParserFactory.newSAXParser();
} catch (ParserConfigurationException pce) {
... | java |
static SoyNodeCompiler create(
CompiledTemplateRegistry registry,
InnerClasses innerClasses,
FieldRef stateField,
Expression thisVar,
AppendableExpression appendableVar,
TemplateVariableManager variables,
TemplateParameterLookup parameterLookup,
ErrorReporter reporter,
... | java |
private Expression computeRangeValue(
SyntheticVarName varName,
Optional<ExprNode> expression,
int defaultValue,
Scope scope,
final ImmutableList.Builder<Statement> initStatements) {
if (!expression.isPresent()) {
return constant(defaultValue);
} else if (expression.get() ins... | java |
private static boolean shouldCheckBuffer(PrintNode node) {
if (!(node.getExpr().getRoot() instanceof FunctionNode)) {
return true;
}
FunctionNode fn = (FunctionNode) node.getExpr().getRoot();
if (!(fn.getSoyFunction() instanceof BuiltinFunction)) {
return true;
}
BuiltinFunction bf... | java |
private void validateVeLogNode(VeLogNode node) {
if (node.getVeDataExpression().getRoot().getType().getKind() != Kind.VE_DATA) {
reporter.report(
node.getVeDataExpression().getSourceLocation(),
INVALID_VE,
node.getVeDataExpression().getRoot().getType());
}
if (node.getLog... | java |
public static UniqueNameGenerator forLocalVariables() {
UniqueNameGenerator generator = new UniqueNameGenerator(DANGEROUS_CHARACTERS, "$$");
generator.reserve(JsSrcUtils.JS_LITERALS);
generator.reserve(JsSrcUtils.JS_RESERVED_WORDS);
return generator;
} | java |
public synchronized void put(String fileName, VersionedFile versionedFile) {
cache.put(fileName, versionedFile.copy());
} | java |
public synchronized VersionedFile get(String fileName, Version version) {
VersionedFile entry = cache.get(fileName);
if (entry != null) {
if (entry.version().equals(version)) {
// Make a defensive copy since the caller might run further passes on it.
return entry.copy();
} else {
... | java |
public static boolean isSanitizedContentField(FieldDescriptor fieldDescriptor) {
return fieldDescriptor.getType() == Type.MESSAGE
&& SAFE_PROTO_TYPES.contains(fieldDescriptor.getMessageType().getFullName());
} | java |
public static boolean isSanitizedContentMap(FieldDescriptor fieldDescriptor) {
if (!fieldDescriptor.isMapField()) {
return false;
}
Descriptor valueDesc = getMapValueMessageType(fieldDescriptor);
if (valueDesc == null) {
return false;
}
return SAFE_PROTO_TYPES.contains(valueDesc.getF... | java |
@Nullable
public static Descriptor getMapValueMessageType(FieldDescriptor mapField) {
FieldDescriptor valueDesc = mapField.getMessageType().findFieldByName("value");
if (valueDesc.getType() == FieldDescriptor.Type.MESSAGE) {
return valueDesc.getMessageType();
} else {
return null;
}
} | java |
public static String getJsExtensionImport(FieldDescriptor desc) {
Descriptor scope = desc.getExtensionScope();
if (scope != null) {
while (scope.getContainingType() != null) {
scope = scope.getContainingType();
}
return calculateQualifiedJsName(scope);
}
return getJsPackage(des... | java |
private static String computeJsExtensionName(FieldDescriptor field) {
String name = CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, field.getName());
return field.isRepeated() ? name + "List" : name;
} | java |
private static String getJsPackage(FileDescriptor file) {
String protoPackage = file.getPackage();
if (!protoPackage.isEmpty()) {
return "proto." + protoPackage;
}
return "proto";
} | java |
public static boolean hasJsType(FieldDescriptor fieldDescriptor) {
if (!JS_TYPEABLE_FIELDS.contains(fieldDescriptor.getType())) {
return false;
}
if (fieldDescriptor.getOptions().hasJstype()) {
return true;
}
return false;
} | java |
public static boolean isUnsigned(FieldDescriptor descriptor) {
switch (descriptor.getType()) {
case FIXED32:
case FIXED64:
case UINT32:
case UINT64:
return true;
default:
return false;
}
} | java |
static boolean shouldCheckFieldPresenceToEmulateJspbNullability(FieldDescriptor desc) {
boolean hasBrokenSemantics = false;
if (desc.hasDefaultValue() || desc.isRepeated()) {
return false;
} else if (desc.getFile().getSyntax() == Syntax.PROTO3 || !hasBrokenSemantics) {
// in proto3 or proto2 wit... | java |
@Override
public boolean shouldUseSameVarNameAs(MsgSubstUnitNode other) {
return (other instanceof MsgPlaceholderNode)
&& this.initialNodeKind == ((MsgPlaceholderNode) other).initialNodeKind
&& this.samenessKey.equals(((MsgPlaceholderNode) other).samenessKey);
} | java |
@VisibleForTesting
static String icuEscape(String rawText) {
Matcher matcher = ICU_SYNTAX_CHAR_NEEDING_ESCAPE_PATTERN.matcher(rawText);
if (!matcher.find()) {
return rawText;
}
StringBuffer escapedTextSb = new StringBuffer();
do {
String repl = ICU_SYNTAX_CHAR_ESCAPE_MAP.get(matcher.... | java |
@SuppressWarnings("unchecked") // The constructor guarantees the type of ImmutableList.
private SoyMsg resurrectMsg(long id, ImmutableList<SoyMsgPart> parts) {
return SoyMsg.builder()
.setId(id)
.setLocaleString(localeString)
.setIsPlrselMsg(MsgPartUtils.hasPlrselPart(parts))
.setP... | java |
public Boolean isPossibleHeaderVar() {
if (defn == null) {
throw new NullPointerException(getSourceLocation().toString());
}
return defn.kind() == VarDefn.Kind.PARAM
|| defn.kind() == VarDefn.Kind.STATE
|| defn.kind() == VarDefn.Kind.UNDECLARED;
} | java |
@Nullable
public SoyNode firstChildThatMatches(Predicate<SoyNode> condition) {
int firstChildIndex = 0;
while (firstChildIndex < numChildren() && !condition.test(getChild(firstChildIndex))) {
firstChildIndex++;
}
if (firstChildIndex < numChildren()) {
return getChild(firstChildIndex);
... | java |
@Nullable
public SoyNode lastChildThatMatches(Predicate<SoyNode> condition) {
int lastChildIndex = numChildren() - 1;
while (lastChildIndex >= 0 && !condition.test(getChild(lastChildIndex))) {
lastChildIndex--;
}
if (lastChildIndex >= 0) {
return getChild(lastChildIndex);
}
return ... | java |
@SuppressWarnings("unused") // called in SoyFileParser.jj
public static final String calculateFullCalleeName(
Identifier ident, SoyFileHeaderInfo header, ErrorReporter errorReporter) {
String name = ident.identifier();
switch (ident.type()) {
case DOT_IDENT:
// Case 1: Source callee name ... | java |
@SuppressWarnings("unused") // called in SoyFileParser.jj
public static String unescapeString(String s, ErrorReporter errorReporter, SourceLocation loc) {
StringBuilder sb = new StringBuilder(s.length());
for (int i = 0; i < s.length(); ) {
char c = s.charAt(i);
if (c == '\\') {
i = doUnes... | java |
private static int doUnescape(
String s, int i, StringBuilder sb, ErrorReporter errorReporter, SourceLocation loc) {
checkArgument(i < s.length(), "Found escape sequence at the end of a string.");
char c = s.charAt(i++);
switch (c) {
case 'n':
sb.append('\n');
break;
case ... | java |
static String unescapeCommandAttributeValue(String s, QuoteStyle quoteStyle) {
// NOTE: we don't just use String.replace since it internally allocates/compiles a regular
// expression. Instead we have a handrolled loop.
int index = s.indexOf(quoteStyle == QuoteStyle.DOUBLE ? "\\\"" : "\\\'");
if (index... | java |
public void defineField(ClassVisitor cv) {
cv.visitField(
accessFlags(),
name(),
type().getDescriptor(),
null /* no generic signature */,
null /* no initializer */);
} | java |
public Expression accessor(final Expression owner) {
checkState(!isStatic());
checkArgument(owner.resultType().equals(this.owner().type()));
Features features = Features.of();
if (owner.isCheap()) {
features = features.plus(Feature.CHEAP);
}
if (!isNullable()) {
features = features.p... | java |
public Expression accessor() {
checkState(isStatic());
Features features = Features.of(Feature.CHEAP);
if (!isNullable()) {
features = features.plus(Feature.NON_NULLABLE);
}
return new Expression(type(), features) {
@Override
protected void doGen(CodeBuilder mv) {
accessSta... | java |
void accessStaticUnchecked(CodeBuilder mv) {
checkState(isStatic());
mv.getStatic(owner().type(), FieldRef.this.name(), type());
} | java |
public void putUnchecked(CodeBuilder adapter) {
checkState(!isStatic(), "This field is static!");
adapter.putField(owner().type(), name(), type());
} | java |
void compile() {
TypeInfo factoryType = innerClasses.registerInnerClass(FACTORY_CLASS, FACTORY_ACCESS);
SoyClassWriter cw =
SoyClassWriter.builder(factoryType)
.implementing(FACTORY_TYPE)
.setAccess(FACTORY_ACCESS)
.sourceFileName(templateNode.getSourceLocation().getF... | java |
private int processNextToken(RawTextNode node, final int offset, String text) {
// Find the transition whose pattern matches earliest in the raw text (and is applicable)
int numCharsConsumed;
Context next;
int earliestStart = Integer.MAX_VALUE;
int earliestEnd = -1;
Transition earliestTransition... | java |
private static UriPart getNextUriPart(
RawTextNode node, int offset, UriPart uriPart, char matchChar) {
// This switch statement is designed to process a URI in order via a sequence of fall throughs.
switch (uriPart) {
case MAYBE_SCHEME:
case MAYBE_VARIABLE_SCHEME:
// From the RFC: htt... | java |
public static Expression fromExpr(JsExpr expr, Iterable<GoogRequire> requires) {
return Leaf.create(expr, /* isCheap= */ false, requires);
} | java |
public static Expression regexLiteral(String contents) {
int firstSlash = contents.indexOf('/');
int lastSlash = contents.lastIndexOf('/');
checkArgument(
firstSlash < lastSlash && firstSlash != -1,
"expected regex to start with a '/' and have a second '/' near the end, got %s",
cont... | java |
public static Expression number(long value) {
Preconditions.checkArgument(
IntegerNode.isInRange(value), "Number is outside JS safe integer range: %s", value);
return Leaf.create(Long.toString(value), /* isCheap= */ true);
} | java |
public static Expression function(JsDoc parameters, Statement body) {
return FunctionDeclaration.create(parameters, body);
} | java |
public static Expression arrowFunction(JsDoc parameters, Statement body) {
return FunctionDeclaration.createArrowFunction(parameters, body);
} | java |
public static Expression operation(Operator op, List<Expression> operands) {
Preconditions.checkArgument(operands.size() == op.getNumOperands());
Preconditions.checkArgument(
op != Operator.AND && op != Operator.OR && op != Operator.CONDITIONAL);
switch (op.getNumOperands()) {
case 1:
... | java |
public static Expression arrayLiteral(Iterable<? extends Expression> elements) {
return ArrayLiteral.create(ImmutableList.copyOf(elements));
} | java |
public final Expression withInitialStatements(Iterable<? extends Statement> initialStatements) {
// If there are no new initial statements, return the current chunk.
if (Iterables.isEmpty(initialStatements)) {
return this;
}
// Otherwise, return a code chunk that includes all of the dependent code... | java |
public TagKind getTagKind() {
if (htmlTagNode instanceof HtmlOpenTagNode) {
HtmlOpenTagNode openTagNode = (HtmlOpenTagNode) htmlTagNode;
if (openTagNode.isSelfClosing() || openTagNode.getTagName().isDefinitelyVoid()) {
return TagKind.VOID_TAG;
}
return TagKind.OPEN_TAG;
} else {
... | java |
public static SoyType of(Collection<SoyType> members) {
// sort and flatten the set of types
ImmutableSortedSet.Builder<SoyType> builder = ImmutableSortedSet.orderedBy(MEMBER_ORDER);
for (SoyType type : members) {
// simplify unions containing these types
if (type.getKind() == Kind.UNKNOWN
... | java |
public boolean isNullable() {
return members.stream().anyMatch(t -> t.getKind() == SoyType.Kind.NULL);
} | java |
public SoyType removeNullability() {
if (isNullable()) {
return of(
members.stream()
.filter(t -> t.getKind() != SoyType.Kind.NULL)
.collect(Collectors.toList()));
}
return this;
} | java |
public void addChild(N child) {
checkNotNull(child);
tryRemoveFromOldParent(child);
children.add(child);
child.setParent(master);
} | java |
public void removeChild(int index) {
N child = children.remove(index);
child.setParent(null);
} | java |
public void replaceChild(int index, N newChild) {
checkNotNull(newChild);
tryRemoveFromOldParent(newChild);
N oldChild = children.set(index, newChild);
oldChild.setParent(null);
newChild.setParent(master);
} | java |
public void clearChildren() {
for (int i = 0; i < children.size(); i++) {
children.get(i).setParent(null);
}
children.clear();
} | java |
@SuppressWarnings("unchecked")
public void addChildren(List<? extends N> children) {
// NOTE: if the input list comes from another node, this could cause
// ConcurrentModificationExceptions as nodes are moved from one parent to another. To avoid
// this we make a copy of the input list.
for (Node chi... | java |
public void appendSourceStringForChildren(StringBuilder sb) {
for (N child : children) {
sb.append(child.toSourceString());
}
} | java |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.