@Override @Nullable public ScssDefaultFlagTree defaultFlag() { Optional<ScssDefaultFlagTree> defaultFlag = value.firstValueElementOfType(ScssDefaultFlagTree.class); return defaultFlag.isPresent() ? defaultFlag.get() : null; }
private boolean containsScssOrLessElements(ValueTree value) { for (Tree tree : value.sanitizedValueElements()) { if (PropertyDeclarationTreeImpl.isScssOrLessElement(tree)) { return true; } } return false; }
public LessMixinParameterTreeImpl(Tree parameter) { if (parameter instanceof ValueTree) { if (((ValueTree) parameter).valueElements().size() == 1 && (((ValueTree) parameter).valueElements().get(0) instanceof LessVariableTree)) { variable = (LessVariableTree) ((ValueTree) parameter).valueElements().get(0); } else { value = (ValueTree) parameter; } } else if (parameter instanceof LessVariableDeclarationTree) { variableDeclaration = (LessVariableDeclarationTree) parameter; } else { throw new IllegalStateException("Unknown Less parameter type: " + parameter.getClass()); } }
private void addFontFamilyNameToMap(ValueTree value, Map<String, List<Tree>> mapByFontFamilyName) { if (!containsScssOrLessElements(value)) { if (value.sanitizedValueElements().get(0).is(Tree.Kind.STRING)) { StringTree stringTree = (StringTree) value.sanitizedValueElements().get(0); if (mapByFontFamilyName.get(stringTree.actualText()) != null) { mapByFontFamilyName.get(stringTree.actualText()).add(value); } else { mapByFontFamilyName.put(stringTree.actualText(), Lists.newArrayList(value)); } } else { String fontFamilyName = value.valueElementsOfType(IdentifierTree.class).stream().map(IdentifierTree::text).collect(Collectors.joining(" ")); if (mapByFontFamilyName.get(fontFamilyName) != null) { mapByFontFamilyName.get(fontFamilyName).add(value); } else { mapByFontFamilyName.put(fontFamilyName, Lists.newArrayList(value)); } } } }
private List<StringTree> getAllStringsFromCommaSeparatedListElement(ValueTree valueTree) { return valueTree.valueElementsOfType(StringTree.class); }
private List<UriTree> getUris(PropertyDeclarationTree declaration) { List<UriTree> uris = new ArrayList<>(); if (declaration.value().valueElements().get(0).is(Tree.Kind.VALUE_COMMA_SEPARATED_LIST)) { for (ValueTree v : ((ValueCommaSeparatedListTree) declaration.value().valueElements().get(0)).values()) { uris.addAll(v.valueElementsOfType(UriTree.class).stream() .filter(t -> t.uriContent() != null && !t.uriContent().text().isEmpty()) .collect(Collectors.toList())); } } else { uris = declaration.value().valueElementsOfType(UriTree.class).stream() .filter(t -> t.uriContent() != null && !t.uriContent().text().isEmpty()) .collect(Collectors.toList()); } return uris; }
private void checkSecondToLastSrcPropertyDeclaration(PropertyDeclarationTree declaration) { PropertyTree property = declaration.property(); ValueTree value = declaration.value(); if (value.valueElementsOfType(UriTree.class).size() != 1) { addPreciseIssue( property, "Define one single URL, the URL for the \".eot\" font file in this \"src\" property (to support IE9 Compatibility Modes)."); } else { String font = ""; Optional<UriTree> uri = value.firstValueElementOfType(UriTree.class); if (uri.isPresent() && uri.get().uriContent() != null) { font = uri.get().uriContent().text(); } if (!EOT_PATTERN.matcher(font).matches()) { addPreciseIssue( property, "Set the URL for the \".eot\" file in this \"src\" property (to support IE9 Compatibility Modes)."); } else if (!value.valueElementsOfType(FunctionTree.class).isEmpty()) { addPreciseIssue( property, "Remove additional functions from this \"src\" property (to support IE9 Compatibility Modes)."); } } }
@Override public boolean isValid(String language) { List<Validator> validators = property.standardProperty().getValidators(); List<Tree> valueElements = value.sanitizedValueElements(); int numberOfValueElements = valueElements.size(); && doesValueContainScssElements(value.childrenIterator())) { return true; && doesValueContainLessElements(value.childrenIterator())) { return true;
private void createIssues(Map<String, List<ScssConditionTree>> conditions) { for (Map.Entry<String, List<ScssConditionTree>> condition : conditions.entrySet()) { if (condition.getValue().size() > 1) { for (int i = 1; i < condition.getValue().size(); i++) { PreciseIssue issue = addPreciseIssue( condition.getValue().get(i), "This condition duplicates the one at line " + condition.getValue().get(0).condition().firstValueElement().getLine() + "." + " Either remove or update this condition."); issue.secondary(condition.getValue().get(0), "Duplicated condition"); } } } }
private List<IdentifierTree> getAllIdentifiersFromCommaSeparatedListElement(ValueTree valueTree) { return valueTree.valueElementsOfType(IdentifierTree.class); }
private List<UriTree> getUris(PropertyDeclarationTree declaration) { List<UriTree> uris = new ArrayList<>(); if (declaration.value().valueElements().get(0).is(Tree.Kind.VALUE_COMMA_SEPARATED_LIST)) { for (ValueTree v : ((ValueCommaSeparatedListTree) declaration.value().valueElements().get(0)).values()) { uris.addAll(v.valueElementsOfType(UriTree.class).stream() .filter(t -> t.uriContent() != null && !t.uriContent().text().isEmpty()) .collect(Collectors.toList())); } } else { uris = declaration.value().valueElementsOfType(UriTree.class).stream() .filter(t -> t.uriContent() != null && !t.uriContent().text().isEmpty()) .collect(Collectors.toList()); } return uris; }
private void addFontFamilyNameToMap(ValueTree value, Map<String, List<Tree>> mapByFontFamilyName) { if (!containsScssOrLessElements(value)) { if (value.sanitizedValueElements().get(0).is(Tree.Kind.STRING)) { StringTree stringTree = (StringTree) value.sanitizedValueElements().get(0); if (mapByFontFamilyName.get(stringTree.actualText()) != null) { mapByFontFamilyName.get(stringTree.actualText()).add(value); } else { mapByFontFamilyName.put(stringTree.actualText(), Lists.newArrayList(value)); } } else { String fontFamilyName = value.valueElementsOfType(IdentifierTree.class).stream().map(IdentifierTree::text).collect(Collectors.joining(" ")); if (mapByFontFamilyName.get(fontFamilyName) != null) { mapByFontFamilyName.get(fontFamilyName).add(value); } else { mapByFontFamilyName.put(fontFamilyName, Lists.newArrayList(value)); } } } }
private void checkSecondToLastSrcPropertyDeclaration(PropertyDeclarationTree declaration) { PropertyTree property = declaration.property(); ValueTree value = declaration.value(); if (value.valueElementsOfType(UriTree.class).size() != 1) { addPreciseIssue( property, "Define one single URL, the URL for the \".eot\" font file in this \"src\" property (to support IE9 Compatibility Modes)."); } else { String font = ""; Optional<UriTree> uri = value.firstValueElementOfType(UriTree.class); if (uri.isPresent() && uri.get().uriContent() != null) { font = uri.get().uriContent().text(); } if (!EOT_PATTERN.matcher(font).matches()) { addPreciseIssue( property, "Set the URL for the \".eot\" file in this \"src\" property (to support IE9 Compatibility Modes)."); } else if (!value.valueElementsOfType(FunctionTree.class).isEmpty()) { addPreciseIssue( property, "Remove additional functions from this \"src\" property (to support IE9 Compatibility Modes)."); } } }
@Override public boolean isValid(String language) { List<Validator> validators = property.standardProperty().getValidators(); List<Tree> valueElements = value.sanitizedValueElements(); int numberOfValueElements = valueElements.size(); && doesValueContainScssElements(value.childrenIterator())) { return true; && doesValueContainLessElements(value.childrenIterator())) { return true;
private void createIssues(Map<String, List<ScssConditionTree>> conditions) { for (Map.Entry<String, List<ScssConditionTree>> condition : conditions.entrySet()) { if (condition.getValue().size() > 1) { for (int i = 1; i < condition.getValue().size(); i++) { PreciseIssue issue = addPreciseIssue( condition.getValue().get(i), "This condition duplicates the one at line " + condition.getValue().get(0).condition().firstValueElement().getLine() + "." + " Either remove or update this condition."); issue.secondary(condition.getValue().get(0), "Duplicated condition"); } } } }
private boolean containsScssOrLessElements(ValueTree value) { for (Tree tree : value.sanitizedValueElements()) { if (PropertyDeclarationTreeImpl.isScssOrLessElement(tree)) { return true; } } return false; }
private List<StringTree> getAllStringsFromCommaSeparatedListElement(ValueTree valueTree) { return valueTree.valueElementsOfType(StringTree.class); }
public LessMixinParameterTreeImpl(Tree parameter) { if (parameter instanceof ValueTree) { if (((ValueTree) parameter).valueElements().size() == 1 && (((ValueTree) parameter).valueElements().get(0) instanceof LessVariableTree)) { variable = (LessVariableTree) ((ValueTree) parameter).valueElements().get(0); } else { value = (ValueTree) parameter; } } else if (parameter instanceof LessVariableDeclarationTree) { variableDeclaration = (LessVariableDeclarationTree) parameter; } else { throw new IllegalStateException("Unknown Less parameter type: " + parameter.getClass()); } }