This is an automated email from the ASF dual-hosted git repository.
mbien pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/netbeans.git
The following commit(s) were added to refs/heads/master by this push:
new b2b5e95 [jackpot] support for INT_LITERAL variables in conditions.
new 4559136 Merge pull request #3439 from mbien/sourceversion2
b2b5e95 is described below
commit b2b5e95363c4af491d854ccb96c0b8cee1734f21
Author: Michael Bien <[email protected]>
AuthorDate: Mon Jan 10 22:30:25 2022 +0100
[jackpot] support for INT_LITERAL variables in conditions.
---
.../modules/java/hints/declarative/Condition.java | 1 +
.../java/hints/declarative/DeclarativeHintsParser.java | 3 +++
.../java/hints/declarative/MethodInvocationContext.java | 7 ++++++-
.../java/hints/declarative/conditionapi/Variable.java | 5 +++++
.../hints/declarative/DeclarativeHintsParserTest.java | 16 ++++++++++++++--
5 files changed, 29 insertions(+), 3 deletions(-)
diff --git
a/java/java.hints.declarative/src/org/netbeans/modules/java/hints/declarative/Condition.java
b/java/java.hints.declarative/src/org/netbeans/modules/java/hints/declarative/Condition.java
index 044f992..28dc570 100644
---
a/java/java.hints.declarative/src/org/netbeans/modules/java/hints/declarative/Condition.java
+++
b/java/java.hints.declarative/src/org/netbeans/modules/java/hints/declarative/Condition.java
@@ -122,6 +122,7 @@ public abstract class Condition {
public enum ParameterKind {
VARIABLE,
STRING_LITERAL,
+ INT_LITERAL,
ENUM_CONSTANT;
}
}
diff --git
a/java/java.hints.declarative/src/org/netbeans/modules/java/hints/declarative/DeclarativeHintsParser.java
b/java/java.hints.declarative/src/org/netbeans/modules/java/hints/declarative/DeclarativeHintsParser.java
index bf4729c..3947e4f 100644
---
a/java/java.hints.declarative/src/org/netbeans/modules/java/hints/declarative/DeclarativeHintsParser.java
+++
b/java/java.hints.declarative/src/org/netbeans/modules/java/hints/declarative/DeclarativeHintsParser.java
@@ -508,6 +508,9 @@ public class DeclarativeHintsParser {
case STRING_LITERAL:
params.put(((LiteralTree)
t).getValue().toString(), ParameterKind.STRING_LITERAL);
break;
+ case INT_LITERAL:
+ params.put(((LiteralTree)
t).getValue().toString(), ParameterKind.INT_LITERAL);
+ break;
case IDENTIFIER:
String name = ((IdentifierTree)
t).getName().toString();
diff --git
a/java/java.hints.declarative/src/org/netbeans/modules/java/hints/declarative/MethodInvocationContext.java
b/java/java.hints.declarative/src/org/netbeans/modules/java/hints/declarative/MethodInvocationContext.java
index 13f8747..a074654 100644
---
a/java/java.hints.declarative/src/org/netbeans/modules/java/hints/declarative/MethodInvocationContext.java
+++
b/java/java.hints.declarative/src/org/netbeans/modules/java/hints/declarative/MethodInvocationContext.java
@@ -34,7 +34,6 @@ import java.util.Map.Entry;
import java.util.concurrent.atomic.AtomicInteger;
import org.netbeans.api.annotations.common.NonNull;
import org.netbeans.api.java.classpath.ClassPath;
-import org.netbeans.api.java.platform.JavaPlatform;
import
org.netbeans.modules.java.hints.declarative.Condition.MethodInvocation.ParameterKind;
import org.netbeans.modules.java.hints.declarative.conditionapi.Context;
import
org.netbeans.modules.java.hints.declarative.conditionapi.DefaultRuleUtilities;
@@ -68,6 +67,9 @@ public class MethodInvocationContext {
case STRING_LITERAL:
paramTypes.add(String.class);
break;
+ case INT_LITERAL:
+ paramTypes.add(int.class);
+ break;
case ENUM_CONSTANT:
Enum<?> constant = loadEnumConstant(e.getKey());
@@ -140,6 +142,9 @@ public class MethodInvocationContext {
case STRING_LITERAL:
toAdd = e.getKey();
break;
+ case INT_LITERAL:
+ toAdd = Integer.valueOf(e.getKey());
+ break;
case ENUM_CONSTANT:
Enum<?> constant = loadEnumConstant(e.getKey());
diff --git
a/java/java.hints.declarative/src/org/netbeans/modules/java/hints/declarative/conditionapi/Variable.java
b/java/java.hints.declarative/src/org/netbeans/modules/java/hints/declarative/conditionapi/Variable.java
index 53193ec..f9065da 100644
---
a/java/java.hints.declarative/src/org/netbeans/modules/java/hints/declarative/conditionapi/Variable.java
+++
b/java/java.hints.declarative/src/org/netbeans/modules/java/hints/declarative/conditionapi/Variable.java
@@ -38,4 +38,9 @@ public class Variable {
this.index = index;
}
+ @Override
+ public String toString() {
+ return "Variable{" + "variableName=" + variableName + '}';
+ }
+
}
diff --git
a/java/java.hints.declarative/test/unit/src/org/netbeans/modules/java/hints/declarative/DeclarativeHintsParserTest.java
b/java/java.hints.declarative/test/unit/src/org/netbeans/modules/java/hints/declarative/DeclarativeHintsParserTest.java
index 30478df..a60af63 100644
---
a/java/java.hints.declarative/test/unit/src/org/netbeans/modules/java/hints/declarative/DeclarativeHintsParserTest.java
+++
b/java/java.hints.declarative/test/unit/src/org/netbeans/modules/java/hints/declarative/DeclarativeHintsParserTest.java
@@ -20,7 +20,6 @@
package org.netbeans.modules.java.hints.declarative;
import java.io.File;
-import java.io.IOException;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
@@ -39,7 +38,6 @@ import
org.netbeans.modules.java.hints.declarative.Condition.Instanceof;
import org.netbeans.modules.java.hints.declarative.Condition.MethodInvocation;
import
org.netbeans.modules.java.hints.declarative.Condition.MethodInvocation.ParameterKind;
import
org.netbeans.modules.java.hints.declarative.DeclarativeHintsParser.FixTextDescription;
-import static org.junit.Assert.*;
import
org.netbeans.modules.java.hints.declarative.DeclarativeHintsParser.HintTextDescription;
import
org.netbeans.modules.java.hints.declarative.DeclarativeHintsParser.Result;
import org.netbeans.modules.java.hints.declarative.conditionapi.Variable;
@@ -112,6 +110,19 @@ public class DeclarativeHintsParserTest extends NbTestCase
{
.setDisplayName("test"));
}
+ public void testMethodInvocationCondition3() throws Exception {
+ Map<String, ParameterKind> m = new LinkedHashMap<>();
+
+ m.put("$1", ParameterKind.VARIABLE);
+ m.put("42", ParameterKind.INT_LITERAL);
+
+ performTest("'test': $1 + $2 :: test($1, 42) => 1 + 1;;",
+ StringHintDescription.create("$1 + $2 ")
+ .addCondition(new
MethodInvocation(false, "test", m, null))
+ .addTos(" 1 + 1")
+ .setDisplayName("test"));
+ }
+
public void testNegation() throws Exception {
Map<String, ParameterKind> m = new LinkedHashMap<String,
ParameterKind>();
@@ -506,6 +517,7 @@ public class DeclarativeHintsParserTest extends NbTestCase {
public static final class TestConditionClass {
public boolean test(String s, Variable v1, Variable v2) { return
false; }
+ public boolean test(Variable var, int i) { return false; }
public boolean test(Variable var, Modifier mod, SourceVersion sv) {
return false; }
public boolean test(Variable var, String... strings) { return false; }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists