本文整理汇总了Java中com.google.common.css.compiler.ast.CssNode类的典型用法代码示例。如果您正苦于以下问题:Java CssNode类的具体用法?Java CssNode怎么用?Java CssNode使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CssNode类属于com.google.common.css.compiler.ast包,在下文中一共展示了CssNode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: enter
import com.google.common.css.compiler.ast.CssNode; //导入依赖的package包/类
@Override
public void enter(CssNode n) {
SourceCodeLocation loc = n.getSourceCodeLocation();
if (loc == null || loc.isUnknown()) {
return;
}
if (result == null || result.isUnknown()) {
result = loc;
} else {
Ordering<SourceCodePoint> o = Ordering.natural();
SourceCodePoint lowerBound = o.min(result.getBegin(), loc.getBegin());
SourceCodePoint upperBound = o.max(result.getEnd(), loc.getEnd());
result = new SourceCodeLocationBuilder()
.setSourceCode(result.getSourceCode())
.setBeginLocation(lowerBound)
.setEndLocation(upperBound)
.getSourceCodeLocation();
}
}
示例2: enterRuleset
import com.google.common.css.compiler.ast.CssNode; //导入依赖的package包/类
@Override
public boolean enterRuleset(CssRulesetNode node) {
for (CssNode child : node.getDeclarations().childIterable()) {
// CssPropertyNodes don't get their location set, so just use the
// location of the containing parent.
SourceCodeLocation location = node.getSourceCodeLocation();
if (location == null && !node.getSelectors().isEmpty()) {
// If the ruleset doesn't have a location set, then use location in the selector within.
location = node.getSelectors().getChildAt(0).getSourceCodeLocation();
}
processDeclaration((CssDeclarationNode) child, location);
}
// Clear the map for future re-use
propertyNames.clear();
return true;
}
示例3: enter
import com.google.common.css.compiler.ast.CssNode; //导入依赖的package包/类
@Override
public void enter(CssNode node) {
if (includeHashCodes) {
buffer.append(String.format("(%[email protected]%d ", node.getClass().getName(), node.hashCode()));
} else {
buffer.append(String.format("(%s ", node.getClass().getName()));
}
if (withLocationAnnotation) {
SourceCodeLocation loc = node.getSourceCodeLocation();
if (loc == null) {
loc = SourceCodeLocation.getUnknownLocation();
}
buffer.append(String.format(":scl-unknown %s ", loc.isUnknown()));
}
}
示例4: enterDeclaration
import com.google.common.css.compiler.ast.CssNode; //导入依赖的package包/类
@Override
public boolean enterDeclaration(CssDeclarationNode declaration) {
Property property = declaration.getPropertyName().getProperty();
if (property.hasPositionalParameters()) {
CssPropertyValueNode valueNode = declaration.getPropertyValue();
List<CssValueNode> newValues = abbreviateValues(valueNode.getChildren());
if (newValues != null) {
CssDeclarationNode newDeclaration = new CssDeclarationNode(declaration);
CssPropertyValueNode newValuesNode = new CssPropertyValueNode(newValues);
newDeclaration.setSourceCodeLocation(declaration.getSourceCodeLocation());
newValuesNode.setSourceCodeLocation(valueNode.getSourceCodeLocation());
newDeclaration.setPropertyValue(newValuesNode);
List<CssNode> replacementList = Lists.newArrayList();
replacementList.add(newDeclaration);
visitController.replaceCurrentBlockChildWith(replacementList, false);
}
}
return true;
}
示例5: enterForLoop
import com.google.common.css.compiler.ast.CssNode; //导入依赖的package包/类
@Override
public boolean enterForLoop(CssForLoopRuleNode node) {
GatherLoopDefinitions definitionsGatherer = new GatherLoopDefinitions();
node.getVisitController().startVisit(definitionsGatherer);
Set<String> definitions = definitionsGatherer.getLoopDefinitions();
Integer from = getNumberValue(node.getFrom());
Integer to = getNumberValue(node.getTo());
Integer step = getNumberValue(node.getStep());
if (from == null || to == null || step == null) {
// If any of the loop parameters are illegal, stop processing the node.
// NOTE(user): getNumberValue already reported an error in this case.
visitController.removeCurrentNode();
return false;
}
List<CssNode> blocks = Lists.newArrayListWithCapacity((to - from + step) / step);
for (int i = from; i <= to; i += step) {
blocks.addAll(
makeBlock(node, i, definitions, node.getLoopId()).getChildren());
}
visitController.replaceCurrentBlockChildWith(blocks, true /* visitTheReplacementNodes */);
return true;
}
示例6: asVisitor
import com.google.common.css.compiler.ast.CssNode; //导入依赖的package包/类
/** Transforms the given {@code UniformVisitor} into a {@code CssTreeVisitor}. */
public static CssTreeVisitor asVisitor(final UniformVisitor visitor) {
return Reflection.newProxy(
CssTreeVisitor.class,
new InvocationHandler() {
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
// Allow methods from Object, like toString().
if (Object.class.equals(method.getDeclaringClass())) {
return method.invoke(visitor, args);
}
CssNode node = (CssNode) args[0];
if (method.getName().startsWith("enter")) {
visitor.enter(node);
return true; // Always visit children
} else if (method.getName().startsWith("leave")) {
visitor.leave(node);
return null; // All leave* methods are void
}
throw new IllegalStateException("Unexpected method '" + method + "' called");
}
});
}
示例7: asCombinedVisitor
import com.google.common.css.compiler.ast.CssNode; //导入依赖的package包/类
/**
* Transforms the given visitor into a {@code CssTreeVisitor} that calls the {@code
* UniformVisitor}'s {@code enter} method before each {@code enter*} method and its {@code
* leave} method after each {@code leave*} method.
*/
public static <T extends UniformVisitor & CssTreeVisitor> CssTreeVisitor asCombinedVisitor(
final T visitor) {
return Reflection.newProxy(
CssTreeVisitor.class,
new InvocationHandler() {
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
// Allow methods from Object, like toString().
if (Object.class.equals(method.getDeclaringClass())) {
return method.invoke(visitor, args);
}
CssNode node = (CssNode) args[0];
if (method.getName().startsWith("enter")) {
visitor.enter(node);
return method.invoke(visitor, args);
} else if (method.getName().startsWith("leave")) {
Object result = method.invoke(visitor, args);
visitor.leave(node);
return result;
}
throw new IllegalStateException("Unexpected method '" + method + "' called");
}
});
}
示例8: extractArgument
import com.google.common.css.compiler.ast.CssNode; //导入依赖的package包/类
private CssLiteralNode extractArgument(CssUnknownAtRuleNode node) {
String atRuleName = node.getName().getValue();
if (node.getType().hasBlock()) {
reportError("@" + atRuleName + " with block", node);
return null;
}
List<CssValueNode> params = node.getParameters();
if (params.isEmpty()) {
reportError("@" + atRuleName + " without name", node);
return null;
}
CssNode nameNode = params.get(0);
if (!(nameNode instanceof CssStringNode)) {
reportError("@" + atRuleName + " without a quoted string as name", node);
return null;
}
CssStringNode nameStringNode = (CssStringNode) nameNode;
return new CssLiteralNode(nameStringNode.getValue());
}
示例9: enterRuleset
import com.google.common.css.compiler.ast.CssNode; //导入依赖的package包/类
@Override
public boolean enterRuleset(CssRulesetNode node) {
boolean canModifyRuleset = canModifyRuleset(node);
if (canModifyRuleset) {
List<CssNode> replacementNodes = Lists.newArrayList();
CssSelectorListNode selectors = node.getSelectors();
CssDeclarationBlockNode declarations = node.getDeclarations();
for (CssSelectorNode sel : selectors.childIterable()) {
for (CssNode child : declarations.childIterable()) {
CssRulesetNode ruleset = new CssRulesetNode();
ruleset.setSourceCodeLocation(node.getSourceCodeLocation());
ruleset.addDeclaration(child.deepCopy());
ruleset.addSelector(sel.deepCopy());
replacementNodes.add(ruleset);
}
}
visitController.replaceCurrentBlockChildWith(
replacementNodes,
false);
}
return canModifyRuleset;
}
示例10: isValidInMediaRule
import com.google.common.css.compiler.ast.CssNode; //导入依赖的package包/类
private boolean isValidInMediaRule(CssNode node) {
if (node instanceof CssRulesetNode) {
// rulesets like .CLASS { ... }
return true;
}
if (node instanceof CssAtRuleNode && ALLOWED_AT_RULES_IN_MEDIA.contains(
((CssAtRuleNode) node).getName().getValue())) {
// like @page or @if, but not @def
return true;
}
if (node instanceof CssConditionalBlockNode) {
// @if, @elseif, @else after processing because then they are not @-rules
// anymore
return true;
}
return false;
}
示例11: enterFunctionNode
import com.google.common.css.compiler.ast.CssNode; //导入依赖的package包/类
@Override
public boolean enterFunctionNode(CssFunctionNode function) {
if (function.getFunction() == RGB) {
try {
String hexValue = parseRgbArguments(function);
if (canShortenHexString(hexValue)) {
hexValue = shortenHexString(hexValue);
}
CssValueNode optimizedColor = new CssHexColorNode(
hexValue,
function.getSourceCodeLocation());
List<CssNode> temp = Lists.newArrayList();
temp.add(optimizedColor);
visitController.replaceCurrentBlockChildWith(temp, true);
} catch (NumberFormatException nfe) {
logger.info("Error parsing rgb() function: " + nfe.toString());
}
}
return true;
}
示例12: enterValueNode
import com.google.common.css.compiler.ast.CssNode; //导入依赖的package包/类
@Override
public boolean enterValueNode(CssValueNode node) {
if (node instanceof CssHexColorNode) {
CssHexColorNode color = (CssHexColorNode) node;
if (canShortenHexString(color.getValue())) {
String hexValue = shortenHexString(color.getValue());
CssValueNode optimizedColor = new CssHexColorNode(
hexValue,
node.getSourceCodeLocation());
List<CssNode> temp = Lists.newArrayList();
temp.add(optimizedColor);
visitController.replaceCurrentBlockChildWith(temp, true);
}
}
return true;
}
示例13: leaveUnknownAtRule
import com.google.common.css.compiler.ast.CssNode; //导入依赖的package包/类
@Override
public void leaveUnknownAtRule(CssUnknownAtRuleNode node) {
String name = node.getName().getValue();
if (name.equals(ifName)
|| name.equals(elseifName)
|| name.equals(elseName)) {
activeBlockNode = stack.pop();
CssConditionalRuleNode conditionalNode = createConditionalRuleNode(node, name);
activeBlockNode.addChildToBack(conditionalNode);
updateLocation(activeBlockNode);
if (name.equals(ifName)) {
visitController.replaceCurrentBlockChildWith(
Lists.newArrayList((CssNode) activeBlockNode), false);
} else {
visitController.removeCurrentNode();
if (name.equals(elseName)) {
activeBlockNode = null;
}
}
}
}
示例14: findFirstNodeOf
import com.google.common.css.compiler.ast.CssNode; //导入依赖的package包/类
protected <T> T findFirstNodeOf(final Class<T> clazz) {
final Object[] holder = new Object[1];
final VisitController vc = tree.getVisitController();
vc.startVisit(
UniformVisitor.Adapters.asVisitor(
new UniformVisitor() {
@Override
public void enter(CssNode n) {
if (clazz.isAssignableFrom(n.getClass())) {
holder[0] = n;
vc.stopVisit();
}
}
@Override
public void leave(CssNode node) {}
}));
return clazz.cast(holder[0]);
}
示例15: deepEquals
import com.google.common.css.compiler.ast.CssNode; //导入依赖的package包/类
/**
* Utility method for deep equals comparison between two css nodes.
*/
public void deepEquals(CssNode node1, CssNode node2)
throws IllegalArgumentException, IllegalAccessException {
Class<? extends CssNode> class1 = node1.getClass();
Class<? extends CssNode> class2 = node2.getClass();
Truth.assertThat(class1).isEqualTo(class2);
Class<?> currentClass = class1;
assertFieldsEqual(node1, node2, currentClass);
while (!CssNode.class.equals(currentClass)) {
currentClass = currentClass.getSuperclass();
assertFieldsEqual(node1, node2, currentClass);
}
}