private String renameConstant(String originalName) { String newName; do { newName = originalName + "__RENAMED__" + renamingCounter; renamingCounter++; } while (defMapping.containsValue(newName)); return newName; }
public Set<String> getBooleanConditions() { return ImmutableSet.copyOf(booleanConditions); }
public List<String> getPermutationAxes() { return ImmutableList.copyOf(permutationAxesSet); }
@Override public Map<String, GssFunction> get() { Map<String, GssFunction> gssFunctionMap = super.get(); return ImmutableMap.<String, GssFunction>builder().putAll(gssFunctionMap) // TODO add a namespace for gwt-specific function ? .put(EvalFunction.getName(), new EvalFunction()) .put(ValueFunction.getName(), new ValueFunction()) .put(ResourceUrlFunction.getName(), new ResourceUrlFunction(context)) .build(); } }
/** * In GSS, constant names are defined in upper case but a method name to access a constant in * a CssResource interface can be written in lower camel case. * <p> * This method converts all constant names in a lower camel case identifier. */ private Collection<String> renameDefs(Iterable<String> constantsNames) { return Lists.newArrayList(Iterables.transform(constantsNames, new Function<String, String>() { @Override public String apply(String constantName) { String lowerCase = CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, constantName); // If we cannot revert the method name to the original constant name, use the // original constant name. // This case happens when number are used after an underscore: // CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, "DEF_1") returns def1 // but CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, "def1") returns DEF1 and the // GssResourceGenerator is not able to match the name of the method with the name of the // constant . if (!constantName.equals(CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, lowerCase))) { return constantName; } return lowerCase; } })); }
private Set<String> getTrueConfigurationProperties(ResourceContext context, Set<String> configurationProperties, TreeLogger logger) throws UnableToCompleteException { Builder<String> setBuilder = ImmutableSet.builder(); PropertyOracle oracle = context.getGeneratorContext().getPropertyOracle(); for (String property : configurationProperties) { try { // TODO : only check configuration properties ? ConfigurationProperty confProp = oracle.getConfigurationProperty(property); if (!checkPropertyIsSingleValueAndBoolean(confProp, logger)) { throw new UnableToCompleteException(); } if ("true".equals(confProp.getValues().get(0))) { setBuilder.add(property); } } catch (BadPropertyValueException e1) { logger.log(Type.ERROR, "Unknown configuration property [" + property + "]"); throw new UnableToCompleteException(); } } return setBuilder.build(); }
private RenamingResult doClassRenaming(CssTree cssTree, JMethod method, TreeLogger logger, ResourceContext context) throws UnableToCompleteException { Map<String, Map<String, String>> replacementsWithPrefix = computeReplacements(method, logger, context); RenamingSubstitutionMap substitutionMap = new RenamingSubstitutionMap(replacementsWithPrefix); new CssClassRenaming(cssTree.getMutatingVisitController(), substitutionMap, null).runPass(); Map<String, String> mapping = replacementsWithPrefix.get(""); mapping = Maps.newHashMap(Maps.filterKeys(mapping, Predicates.in(substitutionMap .getStyleClasses()))); return new RenamingResult(mapping, substitutionMap.getExternalClassCandidates()); }
private List<String> getPathElement(String imageResourcePath) { return Lists.newArrayList(imageResourcePath.split("\\.")); }
@Override public List<CssValueNode> getCallResultNodes(List<CssValueNode> args, ErrorManager errorManager) throws GssFunctionException { CssValueNode functionToEval = args.get(0); SourceCodeLocation sourceCodeLocation = extractSourceCodeLocation(functionToEval); CssJavaExpressionNode result = new CssJavaExpressionNode(functionToEval.getValue(), sourceCodeLocation); return ImmutableList.of((CssValueNode) result); }
public DefCollectorVisitor(boolean lenient, TreeLogger treeLogger) { this.lenient = lenient; this.treeLogger = treeLogger; defMapping = HashBiMap.create(); constantNodes = new LinkedList<CssDef>(); }
private Set<String> getCurrentDeferredBindingProperties(ResourceContext context, List<String> permutationAxes, TreeLogger logger) throws UnableToCompleteException { Builder<String> setBuilder = ImmutableSet.builder(); PropertyOracle oracle = context.getGeneratorContext().getPropertyOracle(); for (String permutationAxis : permutationAxes) { String propValue; try { SelectionProperty selProp = oracle.getSelectionProperty(null, permutationAxis); propValue = selProp.getCurrentValue(); } catch (BadPropertyValueException e) { try { ConfigurationProperty confProp = oracle.getConfigurationProperty(permutationAxis); propValue = confProp.getValues().get(0); } catch (BadPropertyValueException e1) { logger.log(Type.ERROR, "Unknown configuration property [" + permutationAxis + "]"); throw new UnableToCompleteException(); } } if (propValue != null) { setBuilder.add(permutationAxis + ":" + propValue); } } return setBuilder.build(); }
@Override public boolean enterConditionalBlock(CssConditionalBlockNode block) { // We have to visit all the CssConditionalRuleNode when we visit the CssConditionalBlockNode // parent node because we are going to replace CssConditionalRuleNode by another node and // unfortunately the visitController doesn't support to replace a CssConditionalRuleNode and // we have to do it manually. That implies that the new nodes won't be visited by the // visitor if we do that during the visit of the CssConditionalRuleNodes and they can contain // other CssConditionalBlockNodes that won't be visited. // Once MutatingVisitController supports replacement of CssConditionalRuleNode, // we will be able to visit CssConditionalRuleNode directly. // Make a copy in order to avoid ConcurrentModificationException List<CssConditionalRuleNode> children = Lists.newArrayList(block.getChildren()); for (CssConditionalRuleNode ruleNode : children) { visitConditionalRule(ruleNode, block); } return true; }
@Override public List<CssValueNode> getCallResultNodes(List<CssValueNode> cssValueNodes, ErrorManager errorManager) throws GssFunctionException { CssValueNode functionToEval = cssValueNodes.get(0); String value = functionToEval.getValue(); SourceCodeLocation location = functionToEval.getSourceCodeLocation(); String javaExpression = buildJavaExpression(value, location, errorManager); CssFunctionNode urlNode = buildUrlNode(javaExpression, location); return ImmutableList.<CssValueNode>of(urlNode); }
private CssDeclarationNode createDeclarationNode(CssPropertyNode propertyNode, CssPropertyValueNode propertyValueNode, SourceCodeLocation location, boolean useAlternate) { CssDeclarationNode replaceNode = new CssDeclarationNode(propertyNode, propertyValueNode); replaceNode.setSourceCodeLocation(location); if (useAlternate) { replaceNode.setComments(ImmutableList.of(new CssCommentNode(ALTERNATE, location))); } return replaceNode; }
private void setRuntimeCondition(CssJavaExpressionNode condition) { Preconditions.checkState(getType() != Type.ELSE); Preconditions.checkState(getParametersCount() <= 1); this.setParameters(ImmutableList.<CssValueNode>of(condition)); }
private CssFunctionNode buildUrlNode(String javaExpression, SourceCodeLocation location) { CssFunctionNode urlNode = GssFunctions.createUrlNode("", location); CssJavaExpressionNode cssJavaExpressionNode = new CssJavaExpressionNode(javaExpression); CssFunctionArgumentsNode arguments = new CssFunctionArgumentsNode(ImmutableList.<CssValueNode>of(cssJavaExpressionNode)); urlNode.setArguments(arguments); return urlNode; } }
private CssDeclarationNode buildOverflowDeclaration(SourceCodeLocation location) { CssPropertyNode propertyNode = new CssPropertyNode("overflow", location); CssValueNode valueNode = new CssLiteralNode("hidden", location); CssPropertyValueNode propertyValueNode = new CssPropertyValueNode(ImmutableList.of(valueNode)); return createDeclarationNode(propertyNode, propertyValueNode, location, true); }
private CssDeclarationNode buildWidthDeclaration(String imageResource, SourceCodeLocation location) { CssPropertyNode propertyNode = new CssPropertyNode("width", location); CssValueNode valueNode = new CssDotPathNode(resourceThisPrefix, imageResource + ".getWidth", null, "px", location); CssPropertyValueNode propertyValueNode = new CssPropertyValueNode(ImmutableList.of(valueNode)); return createDeclarationNode(propertyNode, propertyValueNode, location, true); }
private CssDeclarationNode buildHeightDeclaration(String imageResource, SourceCodeLocation location) { CssPropertyNode propertyNode = new CssPropertyNode("height", location); CssValueNode valueNode = new CssDotPathNode(resourceThisPrefix, imageResource + ".getHeight", null, "px", location); CssPropertyValueNode propertyValueNode = new CssPropertyValueNode(ImmutableList.of(valueNode)); return createDeclarationNode(propertyNode, propertyValueNode, location, true); }