From 7a456e5b935242acaf16619b4ae8e9a12e4e52f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Tue, 25 Aug 2020 15:16:30 +0200 Subject: [PATCH] Remove ruleContext attributes Refs #2676 Was forgotten in #2672 --- .../java/net/sourceforge/pmd/RuleContext.java | 92 +------------------ .../net/sourceforge/pmd/RuleContextTest.java | 54 ----------- 2 files changed, 1 insertion(+), 145 deletions(-) diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/RuleContext.java b/pmd-core/src/main/java/net/sourceforge/pmd/RuleContext.java index 76f30aae84..5690591011 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/RuleContext.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/RuleContext.java @@ -5,8 +5,6 @@ package net.sourceforge.pmd; import java.io.File; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; import java.util.logging.Logger; import net.sourceforge.pmd.lang.LanguageVersion; @@ -34,14 +32,13 @@ public class RuleContext { private Report report = new Report(); private File sourceCodeFile; private LanguageVersion languageVersion; - private final ConcurrentMap attributes; private boolean ignoreExceptions = true; /** * Default constructor. */ public RuleContext() { - attributes = new ConcurrentHashMap<>(); + // nothing to do } /** @@ -52,7 +49,6 @@ public class RuleContext { * the context from which the values are shared */ public RuleContext(RuleContext ruleContext) { - this.attributes = ruleContext.attributes; this.report.addListeners(ruleContext.getReport().getListeners()); } @@ -146,92 +142,6 @@ public class RuleContext { this.languageVersion = languageVersion; } - /** - * Set an attribute value on the RuleContext, if it does not already exist. - *

- * Attributes can be shared between RuleContext instances. This operation is - * thread-safe. - *

- * Attribute values should be modified directly via the reference provided. - * It is not necessary to call setAttribute(String, Object) to - * update an attribute value. Modifications made to the attribute value will - * automatically be seen by other threads. Because of this, you must ensure - * the attribute values are themselves thread safe. - * - * @param name - * The attribute name. - * @param value - * The attribute value. - * @exception IllegalArgumentException - * if name or value are - * null - * @return true if the attribute was set, false - * otherwise. - * - * @deprecated Stateful methods of the rule context will be removed. - * Their interaction with incremental analysis are unspecified. - */ - @Deprecated - public boolean setAttribute(String name, Object value) { - if (name == null) { - throw new IllegalArgumentException("Parameter 'name' cannot be null."); - } - if (value == null) { - throw new IllegalArgumentException("Parameter 'value' cannot be null."); - } - return this.attributes.putIfAbsent(name, value) == null; - } - - /** - * Get an attribute value on the RuleContext. - *

- * Attributes can be shared between RuleContext instances. This operation is - * thread-safe. - *

- * Attribute values should be modified directly via the reference provided. - * It is not necessary to call setAttribute(String, Object) to - * update an attribute value. Modifications made to the attribute value will - * automatically be seen by other threads. Because of this, you must ensure - * the attribute values are themselves thread safe. - * - * @param name - * The attribute name. - * @return The current attribute value, or null if the - * attribute does not exist. - * - * @deprecated Stateful methods of the rule context will be removed. - * Their interaction with incremental analysis are unspecified. - */ - @Deprecated - public Object getAttribute(String name) { - return this.attributes.get(name); - } - - /** - * Remove an attribute value on the RuleContext. - *

- * Attributes can be shared between RuleContext instances. This operation is - * thread-safe. - *

- * Attribute values should be modified directly via the reference provided. - * It is not necessary to call setAttribute(String, Object) to - * update an attribute value. Modifications made to the attribute value will - * automatically be seen by other threads. Because of this, you must ensure - * the attribute values are themselves thread safe. - * - * @param name - * The attribute name. - * @return The current attribute value, or null if the - * attribute does not exist. - * - * @deprecated Stateful methods of the rule context will be removed. - * Their interaction with incremental analysis are unspecified. - */ - @Deprecated - public Object removeAttribute(String name) { - return this.attributes.remove(name); - } - /** * Configure whether exceptions during applying a rule should be ignored or * not. If set to true then such exceptions are logged as diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/RuleContextTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/RuleContextTest.java index 279d60c66b..7ae5aba5eb 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/RuleContextTest.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/RuleContextTest.java @@ -5,11 +5,7 @@ package net.sourceforge.pmd; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; import java.io.File; @@ -45,56 +41,6 @@ public class RuleContextTest { assertEquals("filename mismatch", new File("somefile.java"), ctx.getSourceCodeFile()); } - @Test - public void testAttributes() { - RuleContext ctx1 = new RuleContext(); - Object obj1 = new Object(); - Object obj2 = new Object(); - assertNull("attribute should be null", ctx1.getAttribute("attribute")); - boolean set = ctx1.setAttribute("attribute", obj1); - assertTrue("attribute should have been set", set); - assertNotNull("attribute should not be null", ctx1.getAttribute("attribute")); - assertSame("attribute should be expected instance", ctx1.getAttribute("attribute"), obj1); - set = ctx1.setAttribute("attribute", obj2); - assertFalse("attribute should not have been set", set); - assertSame("attribute should be expected instance", ctx1.getAttribute("attribute"), obj1); - Object value = ctx1.removeAttribute("attribute"); - assertSame("attribute value should be expected instance", value, obj1); - assertNull("attribute should be null", ctx1.getAttribute("attribute")); - } - - @Test - public void testSharedAttributes() { - RuleContext ctx1 = new RuleContext(); - RuleContext ctx2 = new RuleContext(ctx1); - StringBuilder obj1 = new StringBuilder(); - StringBuilder obj2 = new StringBuilder(); - - ctx1.setAttribute("attribute1", obj1); - ctx2.setAttribute("attribute2", obj2); - assertNotNull("attribute should not be null", ctx1.getAttribute("attribute1")); - assertNotNull("attribute should not be null", ctx1.getAttribute("attribute2")); - assertNotNull("attribute should not be null", ctx2.getAttribute("attribute1")); - assertNotNull("attribute should not be null", ctx2.getAttribute("attribute2")); - assertSame("attribute should be expected instance", ctx1.getAttribute("attribute1"), obj1); - assertSame("attribute should be expected instance", ctx1.getAttribute("attribute2"), obj2); - assertSame("attribute should be expected instance", ctx2.getAttribute("attribute1"), obj1); - assertSame("attribute should be expected instance", ctx2.getAttribute("attribute2"), obj2); - - ctx1.removeAttribute("attribute1"); - assertNull("attribute should be null", ctx1.getAttribute("attribute1")); - assertNull("attribute should be null", ctx2.getAttribute("attribute1")); - assertNotNull("attribute should not be null", ctx1.getAttribute("attribute2")); - assertNotNull("attribute should not be null", ctx2.getAttribute("attribute2")); - - StringBuilder value = (StringBuilder) ctx1.getAttribute("attribute2"); - assertEquals("attribute value should be empty", "", value.toString()); - value.append("x"); - StringBuilder value1 = (StringBuilder) ctx1.getAttribute("attribute2"); - assertEquals("attribute value should be 'x'", "x", value1.toString()); - StringBuilder value2 = (StringBuilder) ctx2.getAttribute("attribute2"); - assertEquals("attribute value should be 'x'", "x", value2.toString()); - } public static junit.framework.Test suite() { return new JUnit4TestAdapter(RuleContextTest.class);