Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin' into limit-modules
Browse files Browse the repository at this point in the history
  • Loading branch information
Achal1607 committed Jan 25, 2024
2 parents 8c1423d + 731f20b commit 3f164e7
Show file tree
Hide file tree
Showing 11 changed files with 6,834 additions and 4,286 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
<!-- This file has been modified for Oracle Java Platform extension -->

# Oracle Java Platform Extension for Visual Studio Code
[![Visual Studio Marketplace](https://img.shields.io/visual-studio-marketplace/v/Oracle.oracle-java?style=for-the-badge&label=VS%20Marketplace&logo=visual-studio-code)](https://marketplace.visualstudio.com/items?itemName=Oracle.oracle-java)
[![Installs](https://img.shields.io/visual-studio-marketplace/i/Oracle.oracle-java?style=for-the-badge)](https://marketplace.visualstudio.com/items?itemName=Oracle.oracle-java)
[![Build Status](https://img.shields.io/github/actions/workflow/status/oracle/javavscode/main.yml?branch=main&style=for-the-badge&logo=github)](https://github.com/oracle/javavscode/actions?query=workflow:Java%20Platform%20Support%20for%20Visual%20Studio%20Code)
[![License](https://img.shields.io/github/license/oracle/javavscode?style=for-the-badge&logo=apache)](https://github.com/oracle/javavscode/blob/main/LICENSE.txt)

The Oracle Java Platform extension brings full featured Java development (edit-compile-debug & test cycle) for Maven and Gradle projects to VS Code, and is available on the [Visual Studio Marketplace](https://marketplace.visualstudio.com/items?itemName=Oracle.oracle-java).

Expand All @@ -38,14 +42,15 @@ In the VS Code command palette :
* __Java: New Project...__ allows creation of new Maven or Gradle project
* __Java: New from Template...__ add various files to currently selected open project. Files are:
* Java - broad selection of various predefined Java classes
* Unit tests - JUnit and TestNB templates for test suites and test cases
* Unit tests - JUnit and TestNG templates for test suites and test cases
* Other - various templates for Javascript, JSON, YAML, properties, ... files
* __Java: Compile Workspace__ - invoke Maven or Gradle build
* __Java: Clean Workspace__ - clean Maven or Gradle build
* __Download, install and Use JDK__ - allows download and installation of JDK binaries
* Debugger __Java+...__ - start main class or test on selected JDK. More in [Debugger section](#debugger-and-launch-configurations)
* __Test Explorer__ for Java tests results visualization and execution including editor code Lenses.
* Maven and Gradle support including multi-project projects, subprojects opening and Gradle priming builds.
* __Java: Go To Test/Tested Class__ - Navigates to the corresponding test or source class file

## Project Explorer
Project Explorer provides an overview of logical project structure, groups sources together and greatly simplifies Java package structure exploration. Project Explorer is an addition to the classical workspace explorer. Use it to build, test, execute and operate your Maven and Gradle Java projects.
Expand Down
8,761 changes: 4,499 additions & 4,262 deletions THIRD_PARTY_LICENSES.txt

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@
<property name="nbplatform.default.harness.dir" location="${nbplatform.default.netbeans.dest.dir}/harness" />
<property name="nbantext.jar" location="netbeans/nbbuild/build/nbantext.jar" />
<property name="nb_all" location="netbeans" />
<property name="patches" value="patches/6330.diff patches/6481.diff patches/6615.diff patches/6631.diff patches/6637.diff patches/6642.diff patches/6649.diff patches/6690.diff patches/6771.diff patches/6329.diff patches/6742.diff patches/mvn-sh.diff patches/rename-debugger.diff" />

<property name="patches" value="patches/6133.diff patches/6330.diff patches/6481.diff patches/6615.diff patches/6631.diff patches/6637.diff patches/6642.diff patches/6649.diff patches/6690.diff patches/6771.diff patches/6329.diff patches/6742.diff patches/6780.diff patches/6834.diff patches/mvn-sh.diff patches/rename-debugger.diff" />
<condition property="cmd.suffix" value=".cmd" else="">
<os family="windows"/>
</condition>
Expand Down Expand Up @@ -224,4 +223,4 @@
<property name="run.args.extra" value="--compute-disabled-modules=${basedir}/nbcode/nbproject/platform.properties --nosplash --nogui" />
</ant>
</target>
</project>
</project>
1,018 changes: 1,018 additions & 0 deletions patches/6133.diff

Large diffs are not rendered by default.

223 changes: 223 additions & 0 deletions patches/6780.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,223 @@
diff --git a/java/java.hints/src/org/netbeans/modules/java/hints/bugs/Bundle.properties b/java/java.hints/src/org/netbeans/modules/java/hints/bugs/Bundle.properties
index aa59c260fd14..eb396dcc3aca 100644
--- a/java/java.hints/src/org/netbeans/modules/java/hints/bugs/Bundle.properties
+++ b/java/java.hints/src/org/netbeans/modules/java/hints/bugs/Bundle.properties
@@ -49,6 +49,10 @@ DESC_org.netbeans.modules.java.hints.bugs.Tiny.equalsNull=Finds invocations of t
ERR_equalsNull=Object equals "null" is never true
FIX_equalsNull=Use == instead of equals method

+DN_org.netbeans.modules.java.hints.bugs.Tiny.varTypeDiamondOperator= var used with diamond operator
+DESC_org.netbeans.modules.java.hints.bugs.Tiny.varTypeDiamondOperator=Finds variables initialzed using var and diamond operator
+ERR_varTypeDiamondOperator=<> would be inferred as <Object>
+
DN_org.netbeans.modules.java.hints.bugs.Tiny.resultSet=Incorrect column index in ResultSet
DESC_org.netbeans.modules.java.hints.bugs.Tiny.resultSet=Reports Iincorrect column indices passed to various methods of java.sql.ResultSet
ERR_ResultSetZero=Column index is zero, but ResultSet columns are counted from 1
diff --git a/java/java.hints/src/org/netbeans/modules/java/hints/bugs/Tiny.java b/java/java.hints/src/org/netbeans/modules/java/hints/bugs/Tiny.java
index c3544a5a9f90..4ad1f50f2677 100644
--- a/java/java.hints/src/org/netbeans/modules/java/hints/bugs/Tiny.java
+++ b/java/java.hints/src/org/netbeans/modules/java/hints/bugs/Tiny.java
@@ -32,9 +32,11 @@
import com.sun.source.tree.LiteralTree;
import com.sun.source.tree.MemberSelectTree;
import com.sun.source.tree.MethodInvocationTree;
+import com.sun.source.tree.NewClassTree;
import com.sun.source.tree.SwitchTree;
import com.sun.source.tree.Tree;
import com.sun.source.tree.Tree.Kind;
+import com.sun.source.tree.VariableTree;
import com.sun.source.tree.WhileLoopTree;
import com.sun.source.util.SourcePositions;
import com.sun.source.util.TreePath;
@@ -51,6 +53,8 @@
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.Name;
import javax.lang.model.element.TypeElement;
+import javax.lang.model.element.TypeParameterElement;
+import javax.lang.model.element.VariableElement;
import javax.lang.model.type.DeclaredType;
import javax.lang.model.type.TypeKind;
import javax.lang.model.type.TypeMirror;
@@ -195,6 +199,42 @@ public static ErrorDescription equalsNull(HintContext ctx) {
return ErrorDescriptionFactory.forTree(ctx, ctx.getPath(), displayName, fix);
}

+ @Hint(displayName = "#DN_org.netbeans.modules.java.hints.bugs.Tiny.varTypeDiamondOperator", description = "#DESC_org.netbeans.modules.java.hints.bugs.Tiny.varTypeDiamondOperator", category="bugs", suppressWarnings="AllowVarTypeDiamondOperator")
+ @TriggerPatterns({
+ @TriggerPattern(value="$mods$ $varType $name = new $type<>($args$)", constraints=@ConstraintVariableType(variable="$type", type="java.util.Collection")),
+ @TriggerPattern(value="$mods$ $varType $name = new $type<>($args$)", constraints=@ConstraintVariableType(variable="$type", type="java.util.Map"))
+ })
+ public static ErrorDescription varTypeDiamondOperator(HintContext ctx) {
+ TreePath path = ctx.getPath();
+ Boolean isVarUsed = ctx.getInfo().getTreeUtilities().isVarType(path);
+ if(!isVarUsed){
+ return null;
+ }
+
+ VariableTree vt = (VariableTree) ctx.getPath().getLeaf();
+ NewClassTree nct = (NewClassTree) vt.getInitializer();
+ Element constructorCand = ctx.getInfo().getTrees().getElement(new TreePath(ctx.getPath(), nct));
+
+ if (constructorCand.getKind() != ElementKind.CONSTRUCTOR) {
+ return null;
+ }
+
+ ExecutableElement constructor = (ExecutableElement) constructorCand;
+
+ for (VariableElement param : constructor.getParameters()) {
+ if (param.asType().getKind() == TypeKind.DECLARED) {
+ DeclaredType dt = (DeclaredType) param.asType();
+ if (!dt.getTypeArguments().isEmpty()) {
+ return null;
+ }
+ }
+ }
+
+ String displayName = NbBundle.getMessage(Tiny.class, "ERR_varTypeDiamondOperator");
+
+ return ErrorDescriptionFactory.forTree(ctx, path, displayName);
+ }
+
@Hint(displayName = "#DN_org.netbeans.modules.java.hints.bugs.Tiny.resultSet", description = "#DESC_org.netbeans.modules.java.hints.bugs.Tiny.resultSet", category="bugs", suppressWarnings="UseOfIndexZeroInJDBCResultSet", options=Options.QUERY)
@TriggerPattern(value="$set.$method($columnIndex, $other$)",
constraints={
diff --git a/java/java.hints/test/unit/src/org/netbeans/modules/java/hints/bugs/Bundle_test.properties b/java/java.hints/test/unit/src/org/netbeans/modules/java/hints/bugs/Bundle_test.properties
index 6b96fc845f38..e92c7d63fec4 100644
--- a/java/java.hints/test/unit/src/org/netbeans/modules/java/hints/bugs/Bundle_test.properties
+++ b/java/java.hints/test/unit/src/org/netbeans/modules/java/hints/bugs/Bundle_test.properties
@@ -33,6 +33,8 @@ ERR_system_arraycopy_negative={0} is negative
ERR_equalsNull=ERR_equalsNull
FIX_equalsNull=FIX_equalsNull

+ERR_varTypeDiamondOperator=ERR_varTypeDiamondOperator
+
ERR_ResultSetZero=ERR_ResultSetZero
ERR_ResultSetNegative=ERR_ResultSetNegative

diff --git a/java/java.hints/test/unit/src/org/netbeans/modules/java/hints/bugs/TinyTest.java b/java/java.hints/test/unit/src/org/netbeans/modules/java/hints/bugs/TinyTest.java
index 824bfca951c1..4e496beda630 100644
--- a/java/java.hints/test/unit/src/org/netbeans/modules/java/hints/bugs/TinyTest.java
+++ b/java/java.hints/test/unit/src/org/netbeans/modules/java/hints/bugs/TinyTest.java
@@ -356,6 +356,121 @@ public void testInconsistentIndentationLast() throws Exception {
}
}

+ public void testVarUsageWithoutExplicitType() throws Exception {
+ HintTest.create()
+ .input("package test;\n" +
+ "public class Test {\n" +
+ " public void test() {\n" +
+ " var v = new java.util.ArrayList<>();\n" +
+ " }\n" +
+ "}\n")
+ .sourceLevel("11")
+ .run(Tiny.class)
+ .assertWarnings("3:8-3:44:verifier:ERR_varTypeDiamondOperator");
+ }
+
+ public void testVarUsageWithoutExplicitType2() throws Exception {
+ HintTest.create()
+ .input("package test;\n" +
+ "public class Test {\n" +
+ " public void test() {\n" +
+ " var v = new java.util.HashSet<>();\n" +
+ " }\n" +
+ "}\n")
+ .sourceLevel("11")
+ .run(Tiny.class)
+ .assertWarnings("3:8-3:42:verifier:ERR_varTypeDiamondOperator");
+ }
+
+ public void testVarUsageWithoutExplicitType3() throws Exception {
+ HintTest.create()
+ .input("package test;\n" +
+ "public class Test {\n" +
+ " public void test() {\n" +
+ " var v = new java.util.HashMap<>();\n" +
+ " }\n" +
+ "}\n")
+ .sourceLevel("11")
+ .run(Tiny.class)
+ .assertWarnings("3:8-3:42:verifier:ERR_varTypeDiamondOperator");
+ }
+
+ public void testVarUsageWithExplicitType() throws Exception {
+ HintTest.create()
+ .input("package test;\n" +
+ "public class Test {\n" +
+ " public void test() {\n" +
+ " var v = new java.util.ArrayList<Integer>();\n" +
+ " }\n" +
+ "}\n")
+ .sourceLevel("11")
+ .run(Tiny.class)
+ .assertWarnings();
+ }
+
+ public void testVarUsageWithExplicitType2() throws Exception {
+ HintTest.create()
+ .input("package test;\n" +
+ "public class Test {\n" +
+ " public void test() {\n" +
+ " var v = new String[2];\n" +
+ " }\n" +
+ "}\n")
+ .sourceLevel("11")
+ .run(Tiny.class)
+ .assertWarnings();
+ }
+
+ public void testWithoutVarUsageWithExplicitType() throws Exception {
+ HintTest.create()
+ .input("package test;\n" +
+ "public class Test {\n" +
+ " public void test() {\n" +
+ " java.util.List<Integer> v = new java.util.ArrayList<Integer>();\n" +
+ " }\n" +
+ "}\n")
+ .run(Tiny.class)
+ .assertWarnings();
+ }
+
+ public void testWithoutVarUsageWithExplicitType2() throws Exception {
+ HintTest.create()
+ .input("package test;\n" +
+ "public class Test {\n" +
+ " public void test() {\n" +
+ " java.util.List<Integer> v = new java.util.ArrayList<>();\n" +
+ " }\n" +
+ "}\n")
+ .run(Tiny.class)
+ .assertWarnings();
+ }
+
+ public void testVarUsageSensibleTypeInferred1() throws Exception {
+ HintTest.create()
+ .input("package test;\n" +
+ "public class Test {\n" +
+ " public void test(java.util.Set<String> input) {\n" +
+ " var v = new java.util.HashSet<>(input);\n" +
+ " }\n" +
+ "}\n")
+ .sourceLevel("11")
+ .run(Tiny.class)
+ .assertWarnings();
+ }
+
+ public void testVarUsageSensibleTypeInferred2() throws Exception {
+ HintTest.create()
+ .input("package test;\n" +
+ "public class Test {\n" +
+ " public void test(java.util.Map<String, String> input) {\n" +
+ " var v = new java.util.HashMap<>(input);\n" +
+ " }\n" +
+ "}\n")
+ .sourceLevel("11")
+ .run(Tiny.class)
+ .assertWarnings();
+ }
+
private static Map<String, String> alterSettings(String... settings) throws Exception {
//XXX: hack, need to initialize the HintTest's lookup before setting the
//formatting preferences

0 comments on commit 3f164e7

Please sign in to comment.