Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1470,10 +1470,10 @@ jobs:
timeout-minutes: 60
strategy:
matrix:
java: [ '21', '26' ]
java: [ '21', '27-ea' ]
config: [ 'batch1', 'batch2' ]
exclude:
- java: ${{ github.event_name == 'pull_request' && 'nothing' || '26' }}
- java: ${{ github.event_name == 'pull_request' && 'nothing' || '27-ea' }}
fail-fast: false
steps:

Expand Down
2 changes: 1 addition & 1 deletion java/java.completion/nbproject/project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# specific language governing permissions and limitations
# under the License.
is.autoload=true
javac.release=17
javac.release=21
javac.compilerargs=-Xlint -Xlint:-serial
spec.version.base=2.19.0
#test configs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -717,22 +717,32 @@ private SourcePositionsImpl(Tree root, SourcePositions original, SourcePositions

@Override
public long getStartPosition(CompilationUnitTree compilationUnitTree, Tree tree) {
return getStartPosition(tree);
}

@Override
public long getStartPosition(Tree tree) {
if (tree == root) {
return startOffset;
}
found = false;
scan(root, tree);
return found ? modified.getStartPosition(compilationUnitTree, tree) + startOffset : original.getStartPosition(compilationUnitTree, tree);
return found ? modified.getStartPosition(tree) + startOffset : original.getStartPosition(tree);
}

@Override
public long getEndPosition(CompilationUnitTree compilationUnitTree, Tree tree) {
return getEndPosition(tree);
}

@Override
public long getEndPosition(Tree tree) {
if (tree == root) {
return endOffset;
}
found = false;
scan(root, tree);
return found ? modified.getEndPosition(compilationUnitTree, tree) + startOffset : original.getEndPosition(compilationUnitTree, tree);
return found ? modified.getEndPosition(tree) + startOffset : original.getEndPosition(tree);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2058,7 +2058,7 @@ private void insideLambdaExpression(Env env) throws IOException {
}
case COMMA -> {
if (let.getParameters().isEmpty()
|| !env.getController().getTreeUtilities().isSynthetic(new TreePath(path, let.getParameters().get(0).getType()))) {
|| (let.getParameters().get(0).getType() instanceof Tree type && type.getKind() != Kind.VAR_TYPE)) {
addClassTypes(env, null);
addPrimitiveTypeKeywords(env);
addKeyword(env, FINAL_KEYWORD, SPACE, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -434,12 +434,11 @@ public Void scan(DocTree node, Void p) {
result[0] = trees.getElement(getCurrentPath());
} else {
long startPosition = positions.getStartPosition(javac.getCompilationUnit(), node);
long endPosition = positions.getEndPosition(javac.getCompilationUnit(), node);
if (startPosition == 0 && endPosition == -1) {//vanilla javac returns 0 for start and -1 for end positions
if (startPosition == 0) {//vanilla javac returns 0 for start
if (parentNode != null && parentNode.toString().contains(node.toString())) {
long parentNodeStartPosition = positions.getStartPosition(javac.getCompilationUnit(), docComment, parentNode);
startPosition = parentNode.toString().indexOf(node.toString()) + parentNodeStartPosition;
endPosition = startPosition + node.toString().length();
long endPosition = startPosition + node.toString().length();
if (startPosition <= offset
&& endPosition >= offset) {
result[0] = trees.getElement(getCurrentPath());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ public class AddDefaultCase implements ErrorRule<Void> {

private static final Set<String> CODES = Set.of(
"compiler.err.not.exhaustive",
"compiler.err.not.exhaustive.statement"
"compiler.err.not.exhaustive.details",
"compiler.err.not.exhaustive.statement",
"compiler.err.not.exhaustive.statement.details"
);

private static final String THROW_ISE = "throw new IllegalStateException(\"Unexpected value: \" + %1$s);";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package org.netbeans.modules.java.hints.errors;

import com.sun.source.tree.ArrayTypeTree;
import com.sun.source.tree.ExpressionTree;
import com.sun.source.tree.NewArrayTree;
import com.sun.source.tree.Tree;
Expand All @@ -41,6 +42,7 @@
import org.netbeans.spi.java.hints.JavaFix;
import org.openide.util.NbBundle.Messages;
import javax.lang.model.util.Types;
import org.netbeans.api.java.source.GeneratorUtilities;

/**
*
Expand Down Expand Up @@ -164,14 +166,10 @@ protected void performRewrite(TransformationContext tc) throws Exception {
}

arrayType = Utilities.resolveCapturedType(wc, arrayType);
ArrayTypeTree newType = make.ArrayType(make.Type(arrayType));
VariableTree newVariable = Utilities.setVariableType(wc, oldVariableTree, newType);

VariableTree newVariableTree = make.Variable(
oldVariableTree.getModifiers(),
oldVariableTree.getName(),
make.ArrayType(make.Type(arrayType)),
oldVariableTree.getInitializer()
);
tc.getWorkingCopy().rewrite(oldVariableTree, newVariableTree);
tc.getWorkingCopy().rewrite(oldVariableTree, newVariable);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3407,4 +3407,19 @@ private static Name getLeftTreeName(StatementTree statement) {
return ((IdentifierTree) assignTree.getVariable()).getName();
}

public static VariableTree setVariableType(WorkingCopy copy, VariableTree var, Tree newType) {
TreeMaker make = copy.getTreeMaker();
Tree origType = var.getType();

if (origType != null) {
GeneratorUtilities.get(copy).copyComments(origType, newType, true);
GeneratorUtilities.get(copy).copyComments(origType, newType, false);
}

return make.Variable(var.getModifiers(),
var.getName(),
newType,
var.getInitializer()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public Set<String> getCodes() {
@Override
public List<Fix> run(CompilationInfo info, String diagnosticKey, int offset, TreePath treePath, Data<Void> data) {

Tree.Kind parentKind = treePath.getParentPath().getLeaf().getKind();
Tree.Kind parentKind = treePath.getParentPath().getParentPath().getLeaf().getKind();
if (parentKind != Tree.Kind.BLOCK && parentKind != Tree.Kind.CASE) {
return null;
}
Expand Down Expand Up @@ -102,7 +102,7 @@ public String toDebugString() {

@Override
protected void performRewrite(TransformationContext ctx) throws Exception {
TreePath statementPath = ctx.getPath();
TreePath statementPath = ctx.getPath().getParentPath();
Tree parent = statementPath.getParentPath().getLeaf();
List<? extends StatementTree> statements = null;
switch (parent.getKind()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,17 +118,9 @@ protected void performRewrite(TransformationContext tc) throws Exception {
EnhancedForLoopTree elfTree = (EnhancedForLoopTree) statementPath.getLeaf();
ExpressionTree expTree = elfTree.getExpression();
VariableTree vtt = elfTree.getVariable();
String elfTreeVariable = elfTree.getVariable().getType().toString();
if (expTree == null) {
return;
}
TypeMirror type = wc.getTrees().getTypeMirror(new TreePath(statementPath, vtt));
//VariableTree with null ExpressionTree as no initialization required
VariableTree newVariableTree = make.Variable(
vtt.getModifiers(),
vtt.getName(),
make.Type(elfTreeVariable),
null
);
VariableTree newVariableTree = Utilities.setVariableType(wc, vtt, make.Type(type));
StatementTree statement = ((EnhancedForLoopTree) statementPath.getLeaf()).getStatement();
EnhancedForLoopTree newElfTree = make.EnhancedForLoop(newVariableTree, expTree, statement);
wc.rewrite(elfTree, newElfTree);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
import com.sun.source.tree.UnaryTree;
import com.sun.source.tree.UnionTypeTree;
import com.sun.source.tree.UsesTree;
import com.sun.source.tree.VarTypeTree;
import com.sun.source.tree.VariableTree;
import com.sun.source.tree.WhileLoopTree;
import com.sun.source.tree.WildcardTree;
Expand Down Expand Up @@ -313,6 +314,11 @@ public List<? extends TypeMirror> visitVariable(VariableTree node, Object p) {
return null;
}

@Override
public List<? extends TypeMirror> visitVarType(VarTypeTree node, Object p) {
return null;
}

@Override
public List<? extends TypeMirror> visitDoWhileLoop(DoWhileLoopTree node, Object p) {
if (theExpression == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -651,13 +651,16 @@ protected String getText() {

@Override
protected void performRewrite(TransformationContext ctx) throws Exception {
WorkingCopy wc = ctx.getWorkingCopy();
TreeMaker make = wc.getTreeMaker();
LambdaExpressionTree let = (LambdaExpressionTree) ctx.getPath().getLeaf();

for (VariableTree var : let.getParameters()) {
TreePath typePath = TreePath.getPath(ctx.getPath(), var.getType());
if (ctx.getWorkingCopy().getTreeUtilities().isSynthetic(typePath)) {
Tree imported = ctx.getWorkingCopy().getTreeMaker().Type(ctx.getWorkingCopy().getTrees().getTypeMirror(typePath));
ctx.getWorkingCopy().rewrite(var.getType(), imported);
if (var.getType() == null || var.getType().getKind() == Kind.VAR_TYPE) {
Tree newType = make.Type(wc.getTrees().getTypeMirror(new TreePath(ctx.getPath(), var)));
VariableTree newVariable = Utilities.setVariableType(wc, var, newType);

wc.rewrite(var, newVariable);
}
}
}
Expand All @@ -680,7 +683,10 @@ protected void performRewrite(JavaFix.TransformationContext ctx) throws Exceptio
LambdaExpressionTree let = (LambdaExpressionTree) ctx.getPath().getLeaf();
TreeMaker make = ctx.getWorkingCopy().getTreeMaker();
let.getParameters().forEach((var) -> {
ctx.getWorkingCopy().rewrite(var.getType(), make.Type("var")); // NOI18N
Tree newType = make.Type("var"); //XXX: make.VarType()!
VariableTree newVariable = Utilities.setVariableType(ctx.getWorkingCopy(), var, newType);

ctx.getWorkingCopy().rewrite(var, newVariable); // NOI18N
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ public void testArrayObjectElementsFix() throws Exception {
performFixTest("test/Test.java",
"package test; public class Test {{final/*comment1*/ var/**comment2**/ j/*comment3*/ = /*comment4*/{new java.util.ArrayList(),new java.util.ArrayList()};}}",
-1, FIX_MSG,
"package test; import java.util.ArrayList; public class Test {{final/*comment1*/ ArrayList[]/**comment2**/ j/*comment3*/ = /*comment4*/{new java.util.ArrayList(),new java.util.ArrayList()};}}");
//TODO: the space between ArrayList[] and /**comment2**/
"package test; import java.util.ArrayList; public class Test {{final/*comment1*/ ArrayList[] /**comment2**/ j/*comment3*/ = /*comment4*/{new java.util.ArrayList(),new java.util.ArrayList()};}}");
}

public void testArrayPrimitiveNumericElementsFix() throws Exception {
Expand Down Expand Up @@ -198,7 +199,8 @@ public void testArrayObject7ElementsFix() throws Exception {
"package test; public class Test {{var/*comment1*/ a = {2,3.1f};}}",
-1,
FIX_MSG,
"package test; public class Test {{float[]/*comment1*/ a = {2,3.1f};}}");
//TODO: the space between float[] and /*comment1*/
"package test; public class Test {{float[] /*comment1*/ a = {2,3.1f};}}");
}

public void testArrayObject8ElementsFix() throws Exception {
Expand All @@ -213,7 +215,8 @@ public void testArrayObject9ElementsFix() throws Exception {
performFixTest("test/Test.java",
"package test; public class Test {{var/*comment1*/ k = {1,'c'};}}",
-1, FIX_MSG,
"package test; public class Test {{int[]/*comment1*/ k = {1,'c'};}}");
//TODO: the space between int[] and /*comment1*/
"package test; public class Test {{int[] /*comment1*/ k = {1,'c'};}}");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1621,7 +1621,7 @@ interface I {
}
}
""",
"int ii");
"/*missing*/ ii");
}

public void testCatchParameters() throws Exception {
Expand Down
2 changes: 1 addition & 1 deletion java/java.source.base/nbproject/project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#javac.compilerargs=-Xlint:unchecked
nbroot=../..
is.autoload=true
javac.release=17
javac.release=21
javadoc.name=Java Source Base
javadoc.title=Java Source Base
javadoc.arch=${basedir}/arch.xml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -804,7 +804,7 @@ private static <T extends Tree> T doParse(JavacTaskImpl task, String text, Sourc
try {
CharBuffer buf = CharBuffer.wrap((text+"\u0000").toCharArray(), 0, text.length());
ParserFactory factory = ParserFactory.instance(context);
Parser parser = factory.newParser(buf, false, true, false, false);
Parser parser = factory.newParser(buf, false, true, false);
if (parser instanceof JavacParser javacParser) {
if (sourcePositions != null)
sourcePositions[0] = new ParserSourcePositions(javacParser, offset);
Expand Down Expand Up @@ -844,11 +844,20 @@ private ParserSourcePositions(JavacParser parser, int offset) {

@Override
public long getStartPosition(CompilationUnitTree file, Tree tree) {
return getStartPosition(tree);
}

@Override
public long getStartPosition(Tree tree) {
return parser.getStartPos((JCTree)tree) - offset;
}

@Override
public long getEndPosition(CompilationUnitTree file, Tree tree) {
return getEndPosition(tree);
}
@Override
public long getEndPosition(Tree tree) {
return parser.getEndPos((JCTree)tree) - offset;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -509,22 +509,6 @@ private void addSyntheticTrees(DiffContext diffContext, Tree node) {
}
}
}
if (node.getKind() == Kind.VARIABLE) {
JCVariableDecl var = (JCVariableDecl) node;

if (var.declaredUsingVar()) {
diffContext.syntheticTrees.add(var.vartype);
}
}
if (node.getKind() == Kind.LAMBDA_EXPRESSION) {
JCLambda lambda = (JCLambda) node;

if (lambda.paramKind == JCLambda.ParameterKind.IMPLICIT) {
for (JCVariableDecl param : lambda.params) {
diffContext.syntheticTrees.add(param.vartype);
}
}
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
*/
public class NoJavacHelper {

public static final int REQUIRED_JAVAC_VERSION = 26; // <- TODO: increment on every release
public static final int REQUIRED_JAVAC_VERSION = 27; // <- TODO: increment on every release
private static final boolean HAS_WORKING_JAVAC;

static {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
import com.sun.tools.javac.tree.JCTree;
import com.sun.tools.javac.tree.JCTree.*;
import com.sun.tools.javac.tree.JCTree.JCCaseLabel;
import com.sun.tools.javac.tree.JCTree.JCVariableDecl.DeclKind;
import com.sun.tools.javac.util.DiagnosticSource;
import com.sun.tools.javac.util.ListBuffer;
import com.sun.tools.javac.util.Name;
Expand Down Expand Up @@ -419,7 +420,11 @@ public DoWhileLoopTree DoWhileLoop(ExpressionTree condition, StatementTree state
public EmptyStatementTree EmptyStatement() {
return make.at(NOPOS).Skip();
}


public VarTypeTree VarType() {
return make.at(NOPOS).VarType();
}

public EnhancedForLoopTree EnhancedForLoop(VariableTree variable,
ExpressionTree expression,
StatementTree statement) {
Expand Down Expand Up @@ -941,8 +946,13 @@ public VariableTree Variable(ModifiersTree modifiers,
CharSequence name,
Tree type,
ExpressionTree initializer) {
DeclKind kind = switch (type) {
case null -> DeclKind.IMPLICIT;
case VarTypeTree vtt -> DeclKind.VAR;
default -> DeclKind.EXPLICIT;
};
return make.at(NOPOS).VarDef((JCModifiers)modifiers, names.fromString(name.toString()),
(JCExpression)type, (JCExpression)initializer);
(JCExpression)type, (JCExpression)initializer, kind);
}

public VariableTree RecordComponent(ModifiersTree modifiers,
Expand Down
Loading
Loading