diff --git a/ua/org.eclipse.pde.ua.core/src/org/eclipse/pde/internal/ua/core/cheatsheet/simple/text/SimpleCSDocumentFactory.java b/ua/org.eclipse.pde.ua.core/src/org/eclipse/pde/internal/ua/core/cheatsheet/simple/text/SimpleCSDocumentFactory.java index 2e7c33e5c7..41f53bd528 100644 --- a/ua/org.eclipse.pde.ua.core/src/org/eclipse/pde/internal/ua/core/cheatsheet/simple/text/SimpleCSDocumentFactory.java +++ b/ua/org.eclipse.pde.ua.core/src/org/eclipse/pde/internal/ua/core/cheatsheet/simple/text/SimpleCSDocumentFactory.java @@ -45,8 +45,7 @@ public SimpleCSDocumentFactory(SimpleCSModel model) { @Override public IDocumentTextNode createDocumentTextNode(String content, IDocumentElementNode parent) { - IDocumentTextNode textNode = new SimpleCSDocumentTextNode(); - textNode.setEnclosingElement(parent); + IDocumentTextNode textNode = new SimpleCSDocumentTextNode(parent); parent.addTextNode(textNode); textNode.setText(content); return textNode; diff --git a/ua/org.eclipse.pde.ua.core/src/org/eclipse/pde/internal/ua/core/cheatsheet/simple/text/SimpleCSDocumentTextNode.java b/ua/org.eclipse.pde.ua.core/src/org/eclipse/pde/internal/ua/core/cheatsheet/simple/text/SimpleCSDocumentTextNode.java index 8492531277..2eb9fc25e6 100644 --- a/ua/org.eclipse.pde.ua.core/src/org/eclipse/pde/internal/ua/core/cheatsheet/simple/text/SimpleCSDocumentTextNode.java +++ b/ua/org.eclipse.pde.ua.core/src/org/eclipse/pde/internal/ua/core/cheatsheet/simple/text/SimpleCSDocumentTextNode.java @@ -16,6 +16,7 @@ import java.util.HashSet; import org.eclipse.pde.internal.core.text.DocumentTextNode; +import org.eclipse.pde.internal.core.text.IDocumentElementNode; import org.eclipse.pde.internal.core.util.PDETextHelper; public class SimpleCSDocumentTextNode extends DocumentTextNode { @@ -30,15 +31,14 @@ public class SimpleCSDocumentTextNode extends DocumentTextNode { TAG_EXCEPTIONS.add("br/"); //$NON-NLS-1$ } - public SimpleCSDocumentTextNode() { - super(); + public SimpleCSDocumentTextNode(IDocumentElementNode enclosingElement) { + super(enclosingElement); } @Override public String write() { String content = getText().trim(); - return PDETextHelper.translateWriteText(content, TAG_EXCEPTIONS, - SUBSTITUTE_CHARS); + return PDETextHelper.translateWriteText(content, TAG_EXCEPTIONS, SUBSTITUTE_CHARS); } } diff --git a/ua/org.eclipse.pde.ua.core/src/org/eclipse/pde/internal/ua/core/cheatsheet/simple/text/SimpleCSObject.java b/ua/org.eclipse.pde.ua.core/src/org/eclipse/pde/internal/ua/core/cheatsheet/simple/text/SimpleCSObject.java index d816366f52..ccd53657b1 100644 --- a/ua/org.eclipse.pde.ua.core/src/org/eclipse/pde/internal/ua/core/cheatsheet/simple/text/SimpleCSObject.java +++ b/ua/org.eclipse.pde.ua.core/src/org/eclipse/pde/internal/ua/core/cheatsheet/simple/text/SimpleCSObject.java @@ -82,8 +82,8 @@ public void writeDelimeter(PrintWriter writer) { } @Override - protected IDocumentTextNode createDocumentTextNode() { - return new SimpleCSDocumentTextNode(); + protected IDocumentTextNode createDocumentTextNode(IDocumentElementNode enclosingElement) { + return new SimpleCSDocumentTextNode(enclosingElement); } } diff --git a/ua/org.eclipse.pde.ua.core/src/org/eclipse/pde/internal/ua/core/ctxhelp/text/CtxHelpDescription.java b/ua/org.eclipse.pde.ua.core/src/org/eclipse/pde/internal/ua/core/ctxhelp/text/CtxHelpDescription.java index cf603ceee8..fcb8e6715f 100644 --- a/ua/org.eclipse.pde.ua.core/src/org/eclipse/pde/internal/ua/core/ctxhelp/text/CtxHelpDescription.java +++ b/ua/org.eclipse.pde.ua.core/src/org/eclipse/pde/internal/ua/core/ctxhelp/text/CtxHelpDescription.java @@ -13,6 +13,7 @@ *******************************************************************************/ package org.eclipse.pde.internal.ua.core.ctxhelp.text; +import org.eclipse.pde.internal.core.text.IDocumentElementNode; import org.eclipse.pde.internal.core.text.IDocumentTextNode; /** @@ -35,8 +36,8 @@ public CtxHelpDescription(CtxHelpModel model) { } @Override - protected IDocumentTextNode createDocumentTextNode() { - return new CtxHelpDescriptionTextNode(); + protected IDocumentTextNode createDocumentTextNode(IDocumentElementNode enclosingElement) { + return new CtxHelpDescriptionTextNode(enclosingElement); } @Override diff --git a/ua/org.eclipse.pde.ua.core/src/org/eclipse/pde/internal/ua/core/ctxhelp/text/CtxHelpDescriptionTextNode.java b/ua/org.eclipse.pde.ua.core/src/org/eclipse/pde/internal/ua/core/ctxhelp/text/CtxHelpDescriptionTextNode.java index 28ebcf2a89..a6530c39f1 100644 --- a/ua/org.eclipse.pde.ua.core/src/org/eclipse/pde/internal/ua/core/ctxhelp/text/CtxHelpDescriptionTextNode.java +++ b/ua/org.eclipse.pde.ua.core/src/org/eclipse/pde/internal/ua/core/ctxhelp/text/CtxHelpDescriptionTextNode.java @@ -17,6 +17,7 @@ import java.util.HashSet; import org.eclipse.pde.internal.core.text.DocumentTextNode; +import org.eclipse.pde.internal.core.text.IDocumentElementNode; import org.eclipse.pde.internal.core.util.PDETextHelper; public class CtxHelpDescriptionTextNode extends DocumentTextNode { @@ -30,15 +31,14 @@ public class CtxHelpDescriptionTextNode extends DocumentTextNode { TAG_EXCEPTIONS.add("/b"); //$NON-NLS-1$ } - public CtxHelpDescriptionTextNode() { - super(); + public CtxHelpDescriptionTextNode(IDocumentElementNode enclosingElement) { + super(enclosingElement); } @Override public String write() { String content = getText().trim(); - return PDETextHelper.translateWriteText(content, TAG_EXCEPTIONS, - SUBSTITUTE_CHARS); + return PDETextHelper.translateWriteText(content, TAG_EXCEPTIONS, SUBSTITUTE_CHARS); } } diff --git a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/util/PDETextHelper.java b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/util/PDETextHelper.java index f8976e36cc..6fe0b3a07b 100644 --- a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/util/PDETextHelper.java +++ b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/util/PDETextHelper.java @@ -13,8 +13,6 @@ *******************************************************************************/ package org.eclipse.pde.internal.core.util; -import java.util.HashMap; -import java.util.HashSet; import java.util.Map; import java.util.Set; import java.util.regex.Matcher; @@ -42,10 +40,7 @@ public static String truncateAndTrailOffText(String text, int limit) { } public static boolean isDefined(String text) { - if ((text == null) || (text.isEmpty())) { - return false; - } - return true; + return text != null && !text.isEmpty(); } public static boolean isDefinedAfterTrim(String text) { @@ -101,11 +96,12 @@ public static String translateReadText(String text) { return result; } - public static String translateWriteText(String text, HashMap substituteChars) { + public static String translateWriteText(String text, Map substituteChars) { return translateWriteText(text, null, substituteChars); } - public static String translateWriteText(String text, HashSet tagExceptions, HashMap substituteChars) { + public static String translateWriteText(String text, Set tagExceptions, + Map substituteChars) { // Ensure not null if (text == null) { return ""; //$NON-NLS-1$ diff --git a/ui/org.eclipse.pde.core/text/org/eclipse/pde/internal/core/text/DocumentElementNode.java b/ui/org.eclipse.pde.core/text/org/eclipse/pde/internal/core/text/DocumentElementNode.java index dd39ba95d9..cc86d64bbd 100644 --- a/ui/org.eclipse.pde.core/text/org/eclipse/pde/internal/core/text/DocumentElementNode.java +++ b/ui/org.eclipse.pde.core/text/org/eclipse/pde/internal/core/text/DocumentElementNode.java @@ -693,8 +693,7 @@ public boolean setXMLContent(String text) { IDocumentTextNode node = getTextNode(); if (node == null) { // Text does not exist, create it - node = createDocumentTextNode(); - node.setEnclosingElement(this); + node = createDocumentTextNode(this); addTextNode(node); } // Update text on node @@ -732,8 +731,8 @@ protected IDocumentAttributeNode createDocumentAttributeNode() { return new DocumentAttributeNode(); } - protected IDocumentTextNode createDocumentTextNode() { - return new DocumentTextNode(); + protected IDocumentTextNode createDocumentTextNode(IDocumentElementNode enclosingElement) { + return new DocumentTextNode(enclosingElement); } @Override diff --git a/ui/org.eclipse.pde.core/text/org/eclipse/pde/internal/core/text/DocumentNodeFactory.java b/ui/org.eclipse.pde.core/text/org/eclipse/pde/internal/core/text/DocumentNodeFactory.java index 795d95fe73..8d53dae29d 100644 --- a/ui/org.eclipse.pde.core/text/org/eclipse/pde/internal/core/text/DocumentNodeFactory.java +++ b/ui/org.eclipse.pde.core/text/org/eclipse/pde/internal/core/text/DocumentNodeFactory.java @@ -42,8 +42,7 @@ public IDocumentAttributeNode createAttribute(String name, String value, IDocume @Override public IDocumentTextNode createDocumentTextNode(String content, IDocumentElementNode parent) { - IDocumentTextNode textNode = new DocumentTextNode(); - textNode.setEnclosingElement(parent); + IDocumentTextNode textNode = new DocumentTextNode(parent); parent.addTextNode(textNode); textNode.setText(content); return textNode; diff --git a/ui/org.eclipse.pde.core/text/org/eclipse/pde/internal/core/text/DocumentTextNode.java b/ui/org.eclipse.pde.core/text/org/eclipse/pde/internal/core/text/DocumentTextNode.java index 54849f1383..47a874f7ec 100644 --- a/ui/org.eclipse.pde.core/text/org/eclipse/pde/internal/core/text/DocumentTextNode.java +++ b/ui/org.eclipse.pde.core/text/org/eclipse/pde/internal/core/text/DocumentTextNode.java @@ -13,7 +13,7 @@ *******************************************************************************/ package org.eclipse.pde.internal.core.text; -import java.util.HashMap; +import java.util.Map; import org.eclipse.pde.internal.core.util.PDETextHelper; @@ -21,15 +21,13 @@ public class DocumentTextNode extends DocumentXMLNode implements IDocumentTextNo private static final long serialVersionUID = 1L; - protected static final HashMap SUBSTITUTE_CHARS = new HashMap<>(5); - - static { - SUBSTITUTE_CHARS.put(Character.valueOf('&'), "&"); //$NON-NLS-1$ - SUBSTITUTE_CHARS.put(Character.valueOf('<'), "<"); //$NON-NLS-1$ - SUBSTITUTE_CHARS.put(Character.valueOf('>'), ">"); //$NON-NLS-1$ - SUBSTITUTE_CHARS.put(Character.valueOf('\''), "'"); //$NON-NLS-1$ - SUBSTITUTE_CHARS.put(Character.valueOf('\"'), """); //$NON-NLS-1$ - } + protected static final Map SUBSTITUTE_CHARS = Map.of( // + Character.valueOf('&'), "&", //$NON-NLS-1$ + Character.valueOf('<'), "<", //$NON-NLS-1$ + Character.valueOf('>'), ">", //$NON-NLS-1$ + Character.valueOf('\''), "'", //$NON-NLS-1$ + Character.valueOf('\"'), """ //$NON-NLS-1$ + ); private transient int fOffset; private transient int fLength; @@ -37,15 +35,10 @@ public class DocumentTextNode extends DocumentXMLNode implements IDocumentTextNo private String fText; - public DocumentTextNode() { + public DocumentTextNode(IDocumentElementNode enclosingElement) { fOffset = -1; fLength = 0; - fEnclosingElement = null; - } - - @Override - public void setEnclosingElement(IDocumentElementNode node) { - fEnclosingElement = node; + fEnclosingElement = enclosingElement; } @Override diff --git a/ui/org.eclipse.pde.core/text/org/eclipse/pde/internal/core/text/IDocumentTextNode.java b/ui/org.eclipse.pde.core/text/org/eclipse/pde/internal/core/text/IDocumentTextNode.java index 26574e6104..55b1515ec9 100644 --- a/ui/org.eclipse.pde.core/text/org/eclipse/pde/internal/core/text/IDocumentTextNode.java +++ b/ui/org.eclipse.pde.core/text/org/eclipse/pde/internal/core/text/IDocumentTextNode.java @@ -17,10 +17,7 @@ public interface IDocumentTextNode extends IDocumentRange, Serializable, IDocumentXMLNode { - public static final String F_PROPERTY_CHANGE_TYPE_PCDATA = "type_pcdata"; //$NON-NLS-1$ - - // Used by text edit operations - void setEnclosingElement(IDocumentElementNode node); + String F_PROPERTY_CHANGE_TYPE_PCDATA = "type_pcdata"; //$NON-NLS-1$ IDocumentElementNode getEnclosingElement(); @@ -33,9 +30,9 @@ public interface IDocumentTextNode extends IDocumentRange, Serializable, IDocume void setLength(int length); // Not used by text edit operations - public void reconnect(IDocumentElementNode parent); + void reconnect(IDocumentElementNode parent); // Not used by text edit operations - public String write(); + String write(); } diff --git a/ui/org.eclipse.pde.core/text/org/eclipse/pde/internal/core/text/plugin/PluginDocumentNodeFactory.java b/ui/org.eclipse.pde.core/text/org/eclipse/pde/internal/core/text/plugin/PluginDocumentNodeFactory.java index ce7908b810..6bfe4ac28a 100644 --- a/ui/org.eclipse.pde.core/text/org/eclipse/pde/internal/core/text/plugin/PluginDocumentNodeFactory.java +++ b/ui/org.eclipse.pde.core/text/org/eclipse/pde/internal/core/text/plugin/PluginDocumentNodeFactory.java @@ -143,8 +143,7 @@ public IPluginExtensionPoint createExtensionPoint() { @Override public IDocumentTextNode createDocumentTextNode(String content, IDocumentElementNode parent) { - DocumentTextNode textNode = new DocumentTextNode(); - textNode.setEnclosingElement(parent); + DocumentTextNode textNode = new DocumentTextNode(parent); parent.addTextNode(textNode); textNode.setText(content.trim()); return textNode; diff --git a/ui/org.eclipse.pde.core/text/org/eclipse/pde/internal/core/text/plugin/PluginElementNode.java b/ui/org.eclipse.pde.core/text/org/eclipse/pde/internal/core/text/plugin/PluginElementNode.java index 070e19f07e..27362699fa 100644 --- a/ui/org.eclipse.pde.core/text/org/eclipse/pde/internal/core/text/plugin/PluginElementNode.java +++ b/ui/org.eclipse.pde.core/text/org/eclipse/pde/internal/core/text/plugin/PluginElementNode.java @@ -69,8 +69,7 @@ public void setText(String text) throws CoreException { IDocumentTextNode node = getTextNode(); String oldText = node == null ? null : node.getText(); if (node == null) { - node = new DocumentTextNode(); - node.setEnclosingElement(this); + node = new DocumentTextNode(this); addTextNode(node); } node.setText(text.trim());