From ddb230583dc958188a4baf7303026bf0ecf227cf Mon Sep 17 00:00:00 2001 From: Stephan Herrmann Date: Tue, 25 Jun 2024 00:41:13 +0200 Subject: [PATCH] Remove guava in wikitext + org.eclipse.mylyn.wikitext https://github.com/eclipse-mylyn/org.eclipse.mylyn/issues/521 --- .../internal/GfmIdGenerationStrategy.java | 37 +++++++++- .../tests/MarkupLanguageProviderTest.java | 2 +- .../parser/tests/MockMarkupLanguage.java | 5 ++ .../META-INF/MANIFEST.MF | 6 +- .../html/RemoveEmptySpansProcessor.java | 3 +- .../html/WhitespaceCleanupProcessor.java | 10 +-- .../wikitext/internal/util/Preconditions.java | 62 ++++++++++++++++ .../mylyn/wikitext/internal/util/Strings.java | 25 +++++++ .../mylyn/wikitext/internal/util/XmlUtil.java | 74 +++++++++++++++++++ .../parser/builder/HtmlDocumentBuilder.java | 23 +++--- .../wikitext/parser/builder/HtmlEntities.java | 48 ++++++------ .../parser/markup/MarkupLanguage.java | 23 +++++- .../parser/markup/MarkupLanguageProvider.java | 2 +- .../parser/util/MarkupToEclipseToc.java | 2 +- .../SplittingHtmlDocumentBuilder.java | 2 +- .../wikitext/util/DefaultXmlStreamWriter.java | 14 ++-- .../mylyn/wikitext/util/ServiceLocator.java | 21 +----- 17 files changed, 272 insertions(+), 87 deletions(-) create mode 100644 mylyn.docs/wikitext/core/org.eclipse.mylyn.wikitext/src/main/java/org/eclipse/mylyn/wikitext/internal/util/Preconditions.java create mode 100644 mylyn.docs/wikitext/core/org.eclipse.mylyn.wikitext/src/main/java/org/eclipse/mylyn/wikitext/internal/util/Strings.java create mode 100644 mylyn.docs/wikitext/core/org.eclipse.mylyn.wikitext/src/main/java/org/eclipse/mylyn/wikitext/internal/util/XmlUtil.java diff --git a/mylyn.docs/wikitext/core/org.eclipse.mylyn.wikitext.markdown/src/main/java/org/eclipse/mylyn/wikitext/markdown/internal/GfmIdGenerationStrategy.java b/mylyn.docs/wikitext/core/org.eclipse.mylyn.wikitext.markdown/src/main/java/org/eclipse/mylyn/wikitext/markdown/internal/GfmIdGenerationStrategy.java index 8c234178aa..ef744d93b3 100644 --- a/mylyn.docs/wikitext/core/org.eclipse.mylyn.wikitext.markdown/src/main/java/org/eclipse/mylyn/wikitext/markdown/internal/GfmIdGenerationStrategy.java +++ b/mylyn.docs/wikitext/core/org.eclipse.mylyn.wikitext.markdown/src/main/java/org/eclipse/mylyn/wikitext/markdown/internal/GfmIdGenerationStrategy.java @@ -13,20 +13,49 @@ package org.eclipse.mylyn.wikitext.markdown.internal; +import java.util.Arrays; import java.util.Locale; import org.eclipse.mylyn.wikitext.parser.markup.IdGenerationStrategy; -import com.google.common.base.CharMatcher; - public class GfmIdGenerationStrategy extends IdGenerationStrategy { + enum ScanState { + HEAD, WORD, HYPHEN + } @Override public String generateId(String headingText) { String id = headingText.toLowerCase(Locale.getDefault()); id = id.replaceAll("[^a-z0-9_-]", "-"); //$NON-NLS-1$//$NON-NLS-2$ - CharMatcher hyphenMatcher = CharMatcher.is('-'); - id = hyphenMatcher.trimFrom(hyphenMatcher.collapseFrom(id, '-')); + ScanState state = ScanState.HEAD; + char[] collected = new char[id.length()]; + int j = 0; + for (int i = 0; i < id.length(); i++) { + char c = id.charAt(i); + switch (state) { + case HEAD: // skip as many hyphens as we can find + if (c == '-') { + continue; + } + state = ScanState.WORD; + break; + case WORD: // commit chars until the next hyphen + if (c == '-') { + state = ScanState.HYPHEN; + continue; // don't yet commit the hyphen in case it is trailing + } + break; + case HYPHEN: + if (c != '-') { + collected[j++] = '-'; // deferred commit of the hyphen + state = ScanState.WORD; + } else { + continue; // skip additional hyphen + } + } + collected[j++] = c; + } + id = String.valueOf(Arrays.copyOfRange(collected, 0, j)); return id; } diff --git a/mylyn.docs/wikitext/core/org.eclipse.mylyn.wikitext.tests/src/test/java/org/eclipse/mylyn/wikitext/parser/markup/tests/MarkupLanguageProviderTest.java b/mylyn.docs/wikitext/core/org.eclipse.mylyn.wikitext.tests/src/test/java/org/eclipse/mylyn/wikitext/parser/markup/tests/MarkupLanguageProviderTest.java index 60dfe013de..3614a23c7e 100644 --- a/mylyn.docs/wikitext/core/org.eclipse.mylyn.wikitext.tests/src/test/java/org/eclipse/mylyn/wikitext/parser/markup/tests/MarkupLanguageProviderTest.java +++ b/mylyn.docs/wikitext/core/org.eclipse.mylyn.wikitext.tests/src/test/java/org/eclipse/mylyn/wikitext/parser/markup/tests/MarkupLanguageProviderTest.java @@ -63,7 +63,7 @@ public void getMarkupLanguagesDuplicatedNames() { @Override protected Set loadMarkupLanguages() { - return Set.of(new MockMarkupLanguage("Test"), new MockMarkupLanguage("Test")); + return Set.of(new MockMarkupLanguage("Test"), new MockMarkupLanguage.MockMarkupLanguage2("Test")); } }; IllegalStateException ise = assertThrows(IllegalStateException.class, () -> provider.getMarkupLanguages()); diff --git a/mylyn.docs/wikitext/core/org.eclipse.mylyn.wikitext.tests/src/test/java/org/eclipse/mylyn/wikitext/parser/tests/MockMarkupLanguage.java b/mylyn.docs/wikitext/core/org.eclipse.mylyn.wikitext.tests/src/test/java/org/eclipse/mylyn/wikitext/parser/tests/MockMarkupLanguage.java index ede75afdca..910fdd43be 100644 --- a/mylyn.docs/wikitext/core/org.eclipse.mylyn.wikitext.tests/src/test/java/org/eclipse/mylyn/wikitext/parser/tests/MockMarkupLanguage.java +++ b/mylyn.docs/wikitext/core/org.eclipse.mylyn.wikitext.tests/src/test/java/org/eclipse/mylyn/wikitext/parser/tests/MockMarkupLanguage.java @@ -35,4 +35,9 @@ public void processContent(MarkupParser parser, String markupContent, boolean as throw new UnsupportedOperationException(); } + public static class MockMarkupLanguage2 extends MockMarkupLanguage { + public MockMarkupLanguage2(String name) { + super(name); + } + } } diff --git a/mylyn.docs/wikitext/core/org.eclipse.mylyn.wikitext/META-INF/MANIFEST.MF b/mylyn.docs/wikitext/core/org.eclipse.mylyn.wikitext/META-INF/MANIFEST.MF index 082ab2cbd6..1ce8342a12 100644 --- a/mylyn.docs/wikitext/core/org.eclipse.mylyn.wikitext/META-INF/MANIFEST.MF +++ b/mylyn.docs/wikitext/core/org.eclipse.mylyn.wikitext/META-INF/MANIFEST.MF @@ -7,11 +7,7 @@ Bundle-Name: Mylyn WikiText Bundle-Vendor: Eclipse Mylyn Bundle-RequiredExecutionEnvironment: JavaSE-17 Require-Capability: osgi.ee;filter:="(&(osgi.ee=JavaSE)(version=17))" -Import-Package: com.google.common.base;version="[33.0,34.0)", - com.google.common.collect;version="[33.0,34.0)", - com.google.common.escape;version="[33.0,34.0)", - com.google.common.xml;version="[33.0,34.0)", - javax.lang.model, +Import-Package: javax.lang.model, javax.xml.namespace, javax.xml.parsers, javax.xml.stream, diff --git a/mylyn.docs/wikitext/core/org.eclipse.mylyn.wikitext/src/main/java/org/eclipse/mylyn/wikitext/internal/parser/html/RemoveEmptySpansProcessor.java b/mylyn.docs/wikitext/core/org.eclipse.mylyn.wikitext/src/main/java/org/eclipse/mylyn/wikitext/internal/parser/html/RemoveEmptySpansProcessor.java index 326619cbb2..7e66b45b56 100644 --- a/mylyn.docs/wikitext/core/org.eclipse.mylyn.wikitext/src/main/java/org/eclipse/mylyn/wikitext/internal/parser/html/RemoveEmptySpansProcessor.java +++ b/mylyn.docs/wikitext/core/org.eclipse.mylyn.wikitext/src/main/java/org/eclipse/mylyn/wikitext/internal/parser/html/RemoveEmptySpansProcessor.java @@ -16,13 +16,12 @@ import java.util.List; +import org.eclipse.mylyn.wikitext.internal.util.Strings; import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; import org.jsoup.nodes.Node; import org.jsoup.nodes.TextNode; -import com.google.common.base.Strings; - /** * @author David Green */ diff --git a/mylyn.docs/wikitext/core/org.eclipse.mylyn.wikitext/src/main/java/org/eclipse/mylyn/wikitext/internal/parser/html/WhitespaceCleanupProcessor.java b/mylyn.docs/wikitext/core/org.eclipse.mylyn.wikitext/src/main/java/org/eclipse/mylyn/wikitext/internal/parser/html/WhitespaceCleanupProcessor.java index 04737c2b09..46cb731cf7 100644 --- a/mylyn.docs/wikitext/core/org.eclipse.mylyn.wikitext/src/main/java/org/eclipse/mylyn/wikitext/internal/parser/html/WhitespaceCleanupProcessor.java +++ b/mylyn.docs/wikitext/core/org.eclipse.mylyn.wikitext/src/main/java/org/eclipse/mylyn/wikitext/internal/parser/html/WhitespaceCleanupProcessor.java @@ -24,8 +24,6 @@ import org.jsoup.nodes.Node; import org.jsoup.nodes.TextNode; -import com.google.common.base.CharMatcher; - /** * @author David Green */ @@ -119,9 +117,7 @@ private void normalizeEmptySpaceBetweenNodes(Element parent) { for (Node child : children) { Node previousSibling = child.previousSibling(); Node nextSibling = child.nextSibling(); - if (child instanceof TextNode textNode && previousSibling instanceof Element && nextSibling instanceof Element) { - Element prevElement = (Element) previousSibling; - Element nextElement = (Element) nextSibling; + if (child instanceof TextNode textNode && previousSibling instanceof Element prevElement && nextSibling instanceof Element nextElement) { normalizeTextBetweenNodes(textNode, prevElement, nextElement); } } @@ -183,7 +179,7 @@ private Element computeBeforeTarget(Element element) { private static int lastIndexOfNonWhitespace(String text) { int i = text.length() - 1; while (i > -1) { - if (!CharMatcher.whitespace().matches(text.charAt(i))) { + if (!Character.isWhitespace(text.charAt(i))) { return i; } --i; @@ -194,7 +190,7 @@ private static int lastIndexOfNonWhitespace(String text) { private static int firstIndexOfNonWhitespace(String text) { int i = 0; while (i < text.length()) { - if (!CharMatcher.whitespace().matches(text.charAt(i))) { + if (!Character.isWhitespace(text.charAt(i))) { return i; } ++i; diff --git a/mylyn.docs/wikitext/core/org.eclipse.mylyn.wikitext/src/main/java/org/eclipse/mylyn/wikitext/internal/util/Preconditions.java b/mylyn.docs/wikitext/core/org.eclipse.mylyn.wikitext/src/main/java/org/eclipse/mylyn/wikitext/internal/util/Preconditions.java new file mode 100644 index 0000000000..69eb50dc74 --- /dev/null +++ b/mylyn.docs/wikitext/core/org.eclipse.mylyn.wikitext/src/main/java/org/eclipse/mylyn/wikitext/internal/util/Preconditions.java @@ -0,0 +1,62 @@ +/******************************************************************************* + * Copyright (c) 2024 GK Software SE, and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * See git history + *******************************************************************************/ +package org.eclipse.mylyn.wikitext.internal.util; + +public class Preconditions { + + /** + * @param expression + * this should be {@code true} otherwise an {@link IllegalArgumentException} is thrown. + * @param errorMessage + * optional error message + * @throws IllegalArgumentException + */ + public static void checkArgument(boolean expression, String... errorMessage) { + if (!expression) { + if (errorMessage == null || errorMessage.length == 0) { + throw new IllegalArgumentException(); + } + throw new IllegalArgumentException(errorMessage[0]); + } + } + + /** + * @param expression + * this should be {@code true} otherwise an {@link IllegalStateException} is thrown. + * @throws IllegalStateException + */ + public static void checkState(boolean expression) { + if (!expression) { + throw new IllegalStateException(); + } + } + + /** + * @param expression + * this should be {@code true} otherwise an {@link IllegalStateException} is thrown. + * @param errorMessage + * error message which may contain placeholders + * @param messageArguments + * optional message arguments to be interpolated into the message + * @throws IllegalStateException + */ + public static void checkState(boolean expression, String errorMessage, Object... messageArguments) { + if (!expression) { + if (messageArguments == null || messageArguments.length == 0) { + throw new IllegalStateException(errorMessage); + } + throw new IllegalStateException(String.format(errorMessage, messageArguments)); + } + } +} diff --git a/mylyn.docs/wikitext/core/org.eclipse.mylyn.wikitext/src/main/java/org/eclipse/mylyn/wikitext/internal/util/Strings.java b/mylyn.docs/wikitext/core/org.eclipse.mylyn.wikitext/src/main/java/org/eclipse/mylyn/wikitext/internal/util/Strings.java new file mode 100644 index 0000000000..dccdc4ac9b --- /dev/null +++ b/mylyn.docs/wikitext/core/org.eclipse.mylyn.wikitext/src/main/java/org/eclipse/mylyn/wikitext/internal/util/Strings.java @@ -0,0 +1,25 @@ +/******************************************************************************* + * Copyright (c) 2024 GK Software SE, and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * See git history + *******************************************************************************/ +package org.eclipse.mylyn.wikitext.internal.util; + +public class Strings { + + public static boolean isNullOrEmpty(String str) { + if (str == null) { + return true; + } + return str.isEmpty(); + } + +} diff --git a/mylyn.docs/wikitext/core/org.eclipse.mylyn.wikitext/src/main/java/org/eclipse/mylyn/wikitext/internal/util/XmlUtil.java b/mylyn.docs/wikitext/core/org.eclipse.mylyn.wikitext/src/main/java/org/eclipse/mylyn/wikitext/internal/util/XmlUtil.java new file mode 100644 index 0000000000..d12fe7b26f --- /dev/null +++ b/mylyn.docs/wikitext/core/org.eclipse.mylyn.wikitext/src/main/java/org/eclipse/mylyn/wikitext/internal/util/XmlUtil.java @@ -0,0 +1,74 @@ +/******************************************************************************* + * Copyright (c) 2024 GK Software SE, and others. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * See git history + *******************************************************************************/ +package org.eclipse.mylyn.wikitext.internal.util; + +public class XmlUtil { + + public static String getEscapedAttribute(String s) { + StringBuilder result = new StringBuilder(s.length() + 10); + for (int i = 0; i < s.length(); ++i) { + appendEscapedChar(result, s.charAt(i), true); + } + return result.toString(); + } + + public static String getEscapedContent(String s) { + StringBuilder result = new StringBuilder(s.length() + 10); + for (int i = 0; i < s.length(); ++i) { + appendEscapedChar(result, s.charAt(i), false); + } + return result.toString(); + } + + private static void appendEscapedChar(StringBuilder buffer, char c, boolean forAttribute) { + String replacement = getReplacement(c, forAttribute); + if (replacement != null) { + buffer.append('&'); + buffer.append(replacement); + buffer.append(';'); + } else if (c >= 0x00 && c <= 0x1F && c != '\t' && c != '\n' && c != '\r') { + buffer.append("\uFFFD"); //$NON-NLS-1$ + } else { + buffer.append(c); + } + } + + private static String getReplacement(char c, boolean forAttribute) { + // Encode special XML characters into the equivalent character references. + // These five are defined by default for all XML documents. + switch (c) { + case '<': + return "lt"; //$NON-NLS-1$ + case '>': + return "gt"; //$NON-NLS-1$ + case '&': + return "amp"; //$NON-NLS-1$ + } + if (forAttribute) { + switch (c) { + case '"': + return "quot"; //$NON-NLS-1$ + case '\'': + return "apos"; //$NON-NLS-1$ + case '\t': + return "#x9"; //$NON-NLS-1$ + case '\n': + return "#xA"; //$NON-NLS-1$ + case '\r': + return "#xD"; //$NON-NLS-1$ + } + } + return null; + } +} diff --git a/mylyn.docs/wikitext/core/org.eclipse.mylyn.wikitext/src/main/java/org/eclipse/mylyn/wikitext/parser/builder/HtmlDocumentBuilder.java b/mylyn.docs/wikitext/core/org.eclipse.mylyn.wikitext/src/main/java/org/eclipse/mylyn/wikitext/parser/builder/HtmlDocumentBuilder.java index 228e64d8e8..85db622cf7 100644 --- a/mylyn.docs/wikitext/core/org.eclipse.mylyn.wikitext/src/main/java/org/eclipse/mylyn/wikitext/parser/builder/HtmlDocumentBuilder.java +++ b/mylyn.docs/wikitext/core/org.eclipse.mylyn.wikitext/src/main/java/org/eclipse/mylyn/wikitext/parser/builder/HtmlDocumentBuilder.java @@ -15,8 +15,8 @@ *******************************************************************************/ package org.eclipse.mylyn.wikitext.parser.builder; -import static com.google.common.base.Preconditions.checkArgument; import static java.util.Map.entry; +import static org.eclipse.mylyn.wikitext.internal.util.Preconditions.checkArgument; import java.io.BufferedReader; import java.io.File; @@ -48,10 +48,6 @@ import org.eclipse.mylyn.wikitext.util.FormattingXMLStreamWriter; import org.eclipse.mylyn.wikitext.util.XmlStreamWriter; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableList.Builder; -import com.google.common.collect.ImmutableMap; - /** * A builder that produces XHTML output. The nature of the output is affected by various settings on the builder. * @@ -224,7 +220,9 @@ public void copyConfiguration(HtmlDocumentBuilder other) { */ public void addLinkUriProcessor(UriProcessor processor) { Objects.requireNonNull(processor, "Must provide processor"); //$NON-NLS-1$ - linkUriProcessors = ImmutableList. builder().addAll(linkUriProcessors).add(processor).build(); + List processors = new ArrayList<>(linkUriProcessors); + processors.add(processor); + linkUriProcessors = List.copyOf(processors); } protected static XmlStreamWriter createFormattingXmlStreamWriter(Writer out) { @@ -249,15 +247,15 @@ public void setElementNameOfSpanType(SpanType spanType, String elementName) { Objects.requireNonNull(spanType, "Must provide spanType"); //$NON-NLS-1$ Objects.requireNonNull(elementName, "Must provide elementName"); //$NON-NLS-1$ - ImmutableMap.Builder builder = ImmutableMap.builder(); + Map builder = new HashMap<>(); for (Entry entry : spanTypeToElementName.entrySet()) { if (!entry.getKey().equals(spanType)) { - builder.put(entry); + builder.put(entry.getKey(), entry.getValue()); } } builder.put(spanType, elementName); - spanTypeToElementName = builder.build(); + spanTypeToElementName = Map.copyOf(builder); } /** @@ -1433,12 +1431,11 @@ public void setCopyrightNotice(String copyrightNotice) { } private void copyLinkProcessors(HtmlDocumentBuilder other) { - List defaultProcessors = other.defaultLinkUriProcessors(); - Builder newProcessors = ImmutableList. builder().addAll(defaultProcessors); + List defaultProcessors = new ArrayList<>(other.defaultLinkUriProcessors()); if (defaultProcessors.size() < linkUriProcessors.size()) { - newProcessors.addAll(linkUriProcessors.subList(defaultProcessors.size(), linkUriProcessors.size())); + defaultProcessors.addAll(linkUriProcessors.subList(defaultProcessors.size(), linkUriProcessors.size())); } - other.linkUriProcessors = newProcessors.build(); + other.linkUriProcessors = List.copyOf(defaultProcessors); } private List defaultLinkUriProcessors() { diff --git a/mylyn.docs/wikitext/core/org.eclipse.mylyn.wikitext/src/main/java/org/eclipse/mylyn/wikitext/parser/builder/HtmlEntities.java b/mylyn.docs/wikitext/core/org.eclipse.mylyn.wikitext/src/main/java/org/eclipse/mylyn/wikitext/parser/builder/HtmlEntities.java index ea31e011e8..829e0b10c7 100644 --- a/mylyn.docs/wikitext/core/org.eclipse.mylyn.wikitext/src/main/java/org/eclipse/mylyn/wikitext/parser/builder/HtmlEntities.java +++ b/mylyn.docs/wikitext/core/org.eclipse.mylyn.wikitext/src/main/java/org/eclipse/mylyn/wikitext/parser/builder/HtmlEntities.java @@ -13,55 +13,56 @@ package org.eclipse.mylyn.wikitext.parser.builder; -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkState; +import static org.eclipse.mylyn.wikitext.internal.util.Preconditions.checkArgument; +import static org.eclipse.mylyn.wikitext.internal.util.Preconditions.checkState; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.nio.charset.StandardCharsets; import java.text.Normalizer; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import java.util.stream.Collectors; -import com.google.common.base.CharMatcher; -import com.google.common.base.Splitter; -import com.google.common.collect.ImmutableListMultimap; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ListMultimap; - class HtmlEntities { private static HtmlEntities instance = new HtmlEntities(); - private static ListMultimap readHtmlEntities() { - ImmutableListMultimap.Builder builder = ImmutableListMultimap.builder(); + private static Map> readHtmlEntities() { + Map> builder = new HashMap<>(); try (BufferedReader reader = new BufferedReader( new InputStreamReader(HtmlDocumentBuilder.class.getResourceAsStream("html-entity-references.txt"), //$NON-NLS-1$ StandardCharsets.UTF_8))) { - Splitter splitter = Splitter.on(CharMatcher.whitespace()).trimResults().omitEmptyStrings(); String line; while ((line = reader.readLine()) != null) { - List lineItems = splitter.splitToList(line); - checkState(lineItems.size() > 1); - for (int x = 1; x < lineItems.size(); ++x) { - builder.put(lineItems.get(0), lineItems.get(x)); + String[] lineItems = line.split("\s"); //$NON-NLS-1$ + checkState(lineItems.length > 1); + for (int x = 1; x < lineItems.length; ++x) { + List list = builder.computeIfAbsent(lineItems[0], i -> new ArrayList<>()); + list.add(lineItems[x]); } } } catch (IOException e) { throw new RuntimeException(e); } - return builder.build(); + return builder.entrySet() + .stream() + .collect(Collectors.toUnmodifiableMap(Entry::getKey, + entry -> List.copyOf(entry.getValue()))); } public static HtmlEntities instance() { return instance; } - private final ListMultimap nameToNumericEntityReferences; + private final Map> nameToNumericEntityReferences; private final Map nameToStringEquivalent; @@ -71,7 +72,8 @@ private HtmlEntities() { } public List nameToEntityReferences(String name) { - return nameToNumericEntityReferences.get(name); + List list = nameToNumericEntityReferences.get(name); + return list != null ? list : Collections.emptyList(); } public String nameToStringEquivalent(String name) { @@ -79,12 +81,10 @@ public String nameToStringEquivalent(String name) { } private Map createNameToStringEquivalent( - ListMultimap nameToNumericEntityReferences) { - ImmutableMap.Builder mapBuilder = ImmutableMap.builder(); - for (String name : nameToNumericEntityReferences.keySet()) { - mapBuilder.put(name, stringEquivalent(nameToNumericEntityReferences.get(name))); - } - return mapBuilder.build(); + Map> nameToNumericEntityReferences) { + return nameToNumericEntityReferences.entrySet() + .stream() + .collect(Collectors.toUnmodifiableMap(Entry::getKey, entry -> stringEquivalent(entry.getValue()))); } private String stringEquivalent(List values) { diff --git a/mylyn.docs/wikitext/core/org.eclipse.mylyn.wikitext/src/main/java/org/eclipse/mylyn/wikitext/parser/markup/MarkupLanguage.java b/mylyn.docs/wikitext/core/org.eclipse.mylyn.wikitext/src/main/java/org/eclipse/mylyn/wikitext/parser/markup/MarkupLanguage.java index 5126cf13e6..35259d794a 100644 --- a/mylyn.docs/wikitext/core/org.eclipse.mylyn.wikitext/src/main/java/org/eclipse/mylyn/wikitext/parser/markup/MarkupLanguage.java +++ b/mylyn.docs/wikitext/core/org.eclipse.mylyn.wikitext/src/main/java/org/eclipse/mylyn/wikitext/parser/markup/MarkupLanguage.java @@ -12,7 +12,7 @@ *******************************************************************************/ package org.eclipse.mylyn.wikitext.parser.markup; -import static com.google.common.base.Preconditions.checkArgument; +import static org.eclipse.mylyn.wikitext.internal.util.Preconditions.checkArgument; import java.io.Writer; import java.util.Collections; @@ -180,4 +180,25 @@ public DocumentBuilder createDocumentBuilder(Writer out) { public DocumentBuilder createDocumentBuilder(Writer out, boolean formatting) { throw new UnsupportedOperationException(); } + + @Override + public int hashCode() { + return Objects.hash(name); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + MarkupLanguage other = (MarkupLanguage) obj; + return Objects.equals(name, other.name); + } + } diff --git a/mylyn.docs/wikitext/core/org.eclipse.mylyn.wikitext/src/main/java/org/eclipse/mylyn/wikitext/parser/markup/MarkupLanguageProvider.java b/mylyn.docs/wikitext/core/org.eclipse.mylyn.wikitext/src/main/java/org/eclipse/mylyn/wikitext/parser/markup/MarkupLanguageProvider.java index f4b63dbe58..d518880f73 100644 --- a/mylyn.docs/wikitext/core/org.eclipse.mylyn.wikitext/src/main/java/org/eclipse/mylyn/wikitext/parser/markup/MarkupLanguageProvider.java +++ b/mylyn.docs/wikitext/core/org.eclipse.mylyn.wikitext/src/main/java/org/eclipse/mylyn/wikitext/parser/markup/MarkupLanguageProvider.java @@ -13,7 +13,7 @@ package org.eclipse.mylyn.wikitext.parser.markup; -import static com.google.common.base.Preconditions.checkState; +import static org.eclipse.mylyn.wikitext.internal.util.Preconditions.checkState; import java.util.HashSet; import java.util.Objects; diff --git a/mylyn.docs/wikitext/core/org.eclipse.mylyn.wikitext/src/main/java/org/eclipse/mylyn/wikitext/parser/util/MarkupToEclipseToc.java b/mylyn.docs/wikitext/core/org.eclipse.mylyn.wikitext/src/main/java/org/eclipse/mylyn/wikitext/parser/util/MarkupToEclipseToc.java index 52cade46e0..dec47a5237 100644 --- a/mylyn.docs/wikitext/core/org.eclipse.mylyn.wikitext/src/main/java/org/eclipse/mylyn/wikitext/parser/util/MarkupToEclipseToc.java +++ b/mylyn.docs/wikitext/core/org.eclipse.mylyn.wikitext/src/main/java/org/eclipse/mylyn/wikitext/parser/util/MarkupToEclipseToc.java @@ -12,7 +12,7 @@ *******************************************************************************/ package org.eclipse.mylyn.wikitext.parser.util; -import static com.google.common.base.Preconditions.checkArgument; +import static org.eclipse.mylyn.wikitext.internal.util.Preconditions.checkArgument; import java.io.StringWriter; import java.io.Writer; diff --git a/mylyn.docs/wikitext/core/org.eclipse.mylyn.wikitext/src/main/java/org/eclipse/mylyn/wikitext/splitter/SplittingHtmlDocumentBuilder.java b/mylyn.docs/wikitext/core/org.eclipse.mylyn.wikitext/src/main/java/org/eclipse/mylyn/wikitext/splitter/SplittingHtmlDocumentBuilder.java index 805bb06d52..092717a0a6 100644 --- a/mylyn.docs/wikitext/core/org.eclipse.mylyn.wikitext/src/main/java/org/eclipse/mylyn/wikitext/splitter/SplittingHtmlDocumentBuilder.java +++ b/mylyn.docs/wikitext/core/org.eclipse.mylyn.wikitext/src/main/java/org/eclipse/mylyn/wikitext/splitter/SplittingHtmlDocumentBuilder.java @@ -12,7 +12,7 @@ *******************************************************************************/ package org.eclipse.mylyn.wikitext.splitter; -import static com.google.common.base.Preconditions.checkState; +import static org.eclipse.mylyn.wikitext.internal.util.Preconditions.checkState; import java.io.File; import java.io.FileOutputStream; diff --git a/mylyn.docs/wikitext/core/org.eclipse.mylyn.wikitext/src/main/java/org/eclipse/mylyn/wikitext/util/DefaultXmlStreamWriter.java b/mylyn.docs/wikitext/core/org.eclipse.mylyn.wikitext/src/main/java/org/eclipse/mylyn/wikitext/util/DefaultXmlStreamWriter.java index c342195f68..447ea4f6b7 100644 --- a/mylyn.docs/wikitext/core/org.eclipse.mylyn.wikitext/src/main/java/org/eclipse/mylyn/wikitext/util/DefaultXmlStreamWriter.java +++ b/mylyn.docs/wikitext/core/org.eclipse.mylyn.wikitext/src/main/java/org/eclipse/mylyn/wikitext/util/DefaultXmlStreamWriter.java @@ -12,6 +12,9 @@ *******************************************************************************/ package org.eclipse.mylyn.wikitext.util; +import static org.eclipse.mylyn.wikitext.internal.util.XmlUtil.getEscapedAttribute; +import static org.eclipse.mylyn.wikitext.internal.util.XmlUtil.getEscapedContent; + import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.PrintWriter; @@ -21,9 +24,6 @@ import java.util.Map; import java.util.Stack; -import com.google.common.escape.Escaper; -import com.google.common.xml.XmlEscapers; - /** * A default implementation of {@link XmlStreamWriter} that creates XML character output. * @@ -32,10 +32,6 @@ */ public class DefaultXmlStreamWriter extends XmlStreamWriter { - private final Escaper attributeEscaper = XmlEscapers.xmlAttributeEscaper(); - - private final Escaper contentEscaper = XmlEscapers.xmlContentEscaper(); - private PrintWriter out; private final Map prefixToUri = new HashMap<>(); @@ -373,8 +369,8 @@ private String processXmlHeader(String header) { } private void printEscaped(PrintWriter writer, CharSequence s, boolean attribute) { - Escaper escaper = attribute ? attributeEscaper : contentEscaper; - writer.write(escaper.escape(s.toString())); + String escaped = attribute ? getEscapedAttribute(s.toString()) : getEscapedContent(s.toString()); + writer.write(escaped); } /** diff --git a/mylyn.docs/wikitext/core/org.eclipse.mylyn.wikitext/src/main/java/org/eclipse/mylyn/wikitext/util/ServiceLocator.java b/mylyn.docs/wikitext/core/org.eclipse.mylyn.wikitext/src/main/java/org/eclipse/mylyn/wikitext/util/ServiceLocator.java index 6576778a75..ac2faa7ed4 100644 --- a/mylyn.docs/wikitext/core/org.eclipse.mylyn.wikitext/src/main/java/org/eclipse/mylyn/wikitext/util/ServiceLocator.java +++ b/mylyn.docs/wikitext/core/org.eclipse.mylyn.wikitext/src/main/java/org/eclipse/mylyn/wikitext/util/ServiceLocator.java @@ -12,7 +12,7 @@ *******************************************************************************/ package org.eclipse.mylyn.wikitext.util; -import static com.google.common.base.Preconditions.checkArgument; +import static org.eclipse.mylyn.wikitext.internal.util.Preconditions.checkArgument; import java.io.BufferedReader; import java.io.IOException; @@ -34,14 +34,10 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.eclipse.mylyn.wikitext.internal.util.Strings; import org.eclipse.mylyn.wikitext.parser.markup.MarkupLanguage; import org.eclipse.mylyn.wikitext.parser.markup.MarkupLanguageProvider; -import com.google.common.base.Strings; -import com.google.common.collect.HashMultimap; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Multimap; - /** * A service locator for use both inside and outside of an Eclipse environment. Provides access to markup languages by name. *

@@ -190,18 +186,7 @@ public Set getAllMarkupLanguages() { markupLanguages.add(language); return true; }); - return filterDuplicates(markupLanguages); - } - - private Set filterDuplicates(Set markupLanguages) { - Multimap> markupLanguageClassesByName = HashMultimap.create(); - ImmutableSet.Builder builder = ImmutableSet.builder(); - for (MarkupLanguage language : markupLanguages) { - if (markupLanguageClassesByName.put(language.getName(), language.getClass())) { - builder.add(language); - } - } - return builder.build(); + return markupLanguages; } public static void setImplementation(Class implementationClass) {