Skip to content

Commit

Permalink
Merge pull request #3522 from jlerbsc/issue1743
Browse files Browse the repository at this point in the history
Improve Conditional Operator resolution [JLS 15.25]
  • Loading branch information
jlerbsc committed Mar 20, 2022
2 parents c9987c9 + 333177b commit 79e4b51
Show file tree
Hide file tree
Showing 15 changed files with 417 additions and 355 deletions.
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
class X {
}
class X {
}
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
module M.N {
}
module M.N {
}
Original file line number Diff line number Diff line change
@@ -1,46 +1,46 @@
package demo;

import com.github.javaparser.ParseResult;
import com.github.javaparser.ast.CompilationUnit;
import com.github.javaparser.utils.ParserCollectionStrategy;
import com.github.javaparser.utils.ProjectRoot;
import com.github.javaparser.utils.SourceRoot;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;

/* If there is a module declaration in the root directory, JavaParser doesn't find any .java files. */
public class Main {

public static void main(String[] args) {
if (args.length < 1) {
System.err.println("Usage: provide one or more directory names to process");
System.exit(1);
}
for (String dir : args) {
process(dir);
}
}

private static void process(String dir) {
Path root = Paths.get(dir);
Callback cb = new Callback();
ProjectRoot projectRoot = new ParserCollectionStrategy().collect(root);
projectRoot.getSourceRoots().forEach(sourceRoot -> {
try {
sourceRoot.parse("", cb);
} catch (IOException e) {
System.err.println("IOException: " + e);
}
});
}

private static class Callback implements SourceRoot.Callback {

@Override
public Result process(Path localPath, Path absolutePath, ParseResult<CompilationUnit> result) {
System.out.printf("Found %s%n", absolutePath);
return Result.SAVE;
}
}
}
package demo;

import com.github.javaparser.ParseResult;
import com.github.javaparser.ast.CompilationUnit;
import com.github.javaparser.utils.ParserCollectionStrategy;
import com.github.javaparser.utils.ProjectRoot;
import com.github.javaparser.utils.SourceRoot;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;

/* If there is a module declaration in the root directory, JavaParser doesn't find any .java files. */
public class Main {

public static void main(String[] args) {
if (args.length < 1) {
System.err.println("Usage: provide one or more directory names to process");
System.exit(1);
}
for (String dir : args) {
process(dir);
}
}

private static void process(String dir) {
Path root = Paths.get(dir);
Callback cb = new Callback();
ProjectRoot projectRoot = new ParserCollectionStrategy().collect(root);
projectRoot.getSourceRoots().forEach(sourceRoot -> {
try {
sourceRoot.parse("", cb);
} catch (IOException e) {
System.err.println("IOException: " + e);
}
});
}

private static class Callback implements SourceRoot.Callback {

@Override
public Result process(Path localPath, Path absolutePath, ParseResult<CompilationUnit> result) {
System.out.printf("Found %s%n", absolutePath);
return Result.SAVE;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
module demo {
}
module demo {
}
Original file line number Diff line number Diff line change
@@ -1,46 +1,46 @@
package demo;

import com.github.javaparser.ParseResult;
import com.github.javaparser.ast.CompilationUnit;
import com.github.javaparser.utils.ParserCollectionStrategy;
import com.github.javaparser.utils.ProjectRoot;
import com.github.javaparser.utils.SourceRoot;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;

/* If there is a module declaration in the root directory, JavaParser doesn't find any .java files. */
public class Main {

public static void main(String[] args) {
if (args.length < 1) {
System.err.println("Usage: provide one or more directory names to process");
System.exit(1);
}
for (String dir : args) {
process(dir);
}
}

private static void process(String dir) {
Path root = Paths.get(dir);
Callback cb = new Callback();
ProjectRoot projectRoot = new ParserCollectionStrategy().collect(root);
projectRoot.getSourceRoots().forEach(sourceRoot -> {
try {
sourceRoot.parse("", cb);
} catch (IOException e) {
System.err.println("IOException: " + e);
}
});
}

private static class Callback implements SourceRoot.Callback {

@Override
public Result process(Path localPath, Path absolutePath, ParseResult<CompilationUnit> result) {
System.out.printf("Found %s%n", absolutePath);
return Result.SAVE;
}
}
}
package demo;

import com.github.javaparser.ParseResult;
import com.github.javaparser.ast.CompilationUnit;
import com.github.javaparser.utils.ParserCollectionStrategy;
import com.github.javaparser.utils.ProjectRoot;
import com.github.javaparser.utils.SourceRoot;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;

/* If there is a module declaration in the root directory, JavaParser doesn't find any .java files. */
public class Main {

public static void main(String[] args) {
if (args.length < 1) {
System.err.println("Usage: provide one or more directory names to process");
System.exit(1);
}
for (String dir : args) {
process(dir);
}
}

private static void process(String dir) {
Path root = Paths.get(dir);
Callback cb = new Callback();
ProjectRoot projectRoot = new ParserCollectionStrategy().collect(root);
projectRoot.getSourceRoots().forEach(sourceRoot -> {
try {
sourceRoot.parse("", cb);
} catch (IOException e) {
System.err.println("IOException: " + e);
}
});
}

private static class Callback implements SourceRoot.Callback {

@Override
public Result process(Path localPath, Path absolutePath, ParseResult<CompilationUnit> result) {
System.out.printf("Found %s%n", absolutePath);
return Result.SAVE;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
module demo {
}
module demo {
}
Original file line number Diff line number Diff line change
@@ -1,46 +1,46 @@
package demo;

import com.github.javaparser.ParseResult;
import com.github.javaparser.ast.CompilationUnit;
import com.github.javaparser.utils.ParserCollectionStrategy;
import com.github.javaparser.utils.ProjectRoot;
import com.github.javaparser.utils.SourceRoot;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;

/* If there is a module declaration in the root directory, JavaParser doesn't find any .java files. */
public class Main {

public static void main(String[] args) {
if (args.length < 1) {
System.err.println("Usage: provide one or more directory names to process");
System.exit(1);
}
for (String dir : args) {
process(dir);
}
}

private static void process(String dir) {
Path root = Paths.get(dir);
Callback cb = new Callback();
ProjectRoot projectRoot = new ParserCollectionStrategy().collect(root);
projectRoot.getSourceRoots().forEach(sourceRoot -> {
try {
sourceRoot.parse("", cb);
} catch (IOException e) {
System.err.println("IOException: " + e);
}
});
}

private static class Callback implements SourceRoot.Callback {

@Override
public Result process(Path localPath, Path absolutePath, ParseResult<CompilationUnit> result) {
System.out.printf("Found %s%n", absolutePath);
return Result.SAVE;
}
}
}
package demo;

import com.github.javaparser.ParseResult;
import com.github.javaparser.ast.CompilationUnit;
import com.github.javaparser.utils.ParserCollectionStrategy;
import com.github.javaparser.utils.ProjectRoot;
import com.github.javaparser.utils.SourceRoot;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;

/* If there is a module declaration in the root directory, JavaParser doesn't find any .java files. */
public class Main {

public static void main(String[] args) {
if (args.length < 1) {
System.err.println("Usage: provide one or more directory names to process");
System.exit(1);
}
for (String dir : args) {
process(dir);
}
}

private static void process(String dir) {
Path root = Paths.get(dir);
Callback cb = new Callback();
ProjectRoot projectRoot = new ParserCollectionStrategy().collect(root);
projectRoot.getSourceRoots().forEach(sourceRoot -> {
try {
sourceRoot.parse("", cb);
} catch (IOException e) {
System.err.println("IOException: " + e);
}
});
}

private static class Callback implements SourceRoot.Callback {

@Override
public Result process(Path localPath, Path absolutePath, ParseResult<CompilationUnit> result) {
System.out.printf("Found %s%n", absolutePath);
return Result.SAVE;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public static ResolvedType unp(ResolvedType type) {
/*
* Verify if the ResolvedPrimitiveType is in the list of ResolvedPrimitiveType
*/
public boolean in(ResolvedPrimitiveType[] types) {
public boolean in(ResolvedPrimitiveType... types) {
return Arrays.stream(types).anyMatch(type -> this == type);
}

Expand Down

0 comments on commit 79e4b51

Please sign in to comment.