Comments (14)
Your test case can be reduced to the following.
There seem to be 2 problems:
The label parsing which does not tolerate the '.' character;
The parsing of the expression which does not tolerate a negative integer;
@Test
void issue4400() {
String code =
"enum LEVEL {\r\n"
+ " LOW, MEDIUM, HIGH;\r\n"
+ " }\r\n"
+ " \r\n"
+ " public class Foo {\r\n"
+ " public static int match(LEVEL level) {\n"
+ " return switch (level) {\n"
+ " default -> throw new UnsupportedOperationException();\n"
+ " case LEVEL.LOW -> -1;\n"
+ " };\n"
+ " }\n"
+ " }";
JavaParser javaParser = new JavaParser();
javaParser.getParserConfiguration().setLanguageLevel(ParserConfiguration.LanguageLevel.RAW);
ParseResult<CompilationUnit> result = javaParser.parse(code);
if (!result.isSuccessful()) {
for (Problem problem : result.getProblems()) {
System.out.println(problem.getMessage());
}
}
}
from javaparser.
Code formatting doesn't do it justice, here's a picture with an I-beam indicating the exact place:
from javaparser.
Can you provide us with a unit test?
from javaparser.
Can you provide us with a unit test?
Would the code being parsed suffice? I don't really know how to setup a unit test for this
from javaparser.
Can you provide us with a unit test?
Would the code being parsed suffice? I don't really know how to setup a unit test for this
from javaparser.
The program is using the latest version of JavaParser available on maven-central (3.25.10)
from javaparser.
Thank you. Can you show us how you configure the parser.
from javaparser.
Thank you. Can you show us how you configure the parser.
from javaparser.
I get no exceptions when I parse your class with this code snippet.
JavaParser javaParser = new JavaParser();
javaParser.getParserConfiguration().setLanguageLevel(ParserConfiguration.LanguageLevel.RAW);
ParseResult<CompilationUnit> result = javaParser.parse(code);
from javaparser.
Very weird, it seems to work standalone for me too....
from javaparser.
Very weird, it seems to work standalone for me too....
nevermind, result.isSuccessful() is not true
from javaparser.
Very weird, it seems to work standalone for me too....
nevermind, result.isSuccessful() is not true
JavaParser javaParser = new JavaParser();
javaParser.getParserConfiguration().setLanguageLevel(ParserConfiguration.LanguageLevel.RAW);
ParseResult<CompilationUnit> result = javaParser.parse(code);
if (!result.isSuccessful()) {
for (Problem problem : result.getProblems()) {
System.out.println(problem.getMessage());
}
}
Parse error. Found ".", expected one of "," ";" "=" "@" "["
Parse error. Found ".", expected one of "," ";" "=" "@" "["
Parse error. Found ".", expected one of "," ";" "=" "@" "["
Parse error. Found ".", expected one of "," ";" "=" "@" "["
from javaparser.
This problem seems to have been solved in the current version javaparser-parent-3.26.0-snapshot
from javaparser.
I'm closing this issue as it seems to have been resolved.
from javaparser.
Related Issues (20)
- ParseProblemException when parsing record pattern with primitive types HOT 7
- `com.github.javaparser.ast.Node#setParentNode` maybe lost parentNode,There may be forced modifications to the original AST Node HOT 5
- FindAll does not retrieve all the MethodCallExpr within a Statement HOT 2
- javaparser-core.jar is not reproducible due to JavaParserBuild
- Out of Memory Error with `sourceZip` API while trying to parse java's Core Library by javaparser HOT 2
- JavaParser cannot resolve objectCreationExpression when type argument is a record type HOT 2
- Question: Getting the index of token in parsed text HOT 1
- ResolvedMethodDeclaration.toDescription fails in the presence of type variables HOT 1
- VariableDeclarator character range does not match range of children HOT 1
- How to find implementation by MethodCallExpr HOT 2
- Pattern variables not always introduced into the correct scope HOT 7
- Node.PostOrderIterator broken for root without children
- Parsing issue in switch with yield HOT 2
- parseVariableDeclarationExpr with `var` HOT 1
- LexicalPreservingPrinter performance HOT 7
- ParseProblemException Switch expressions with constants throw error HOT 4
- After toAst(),error: Symbol resolution not configured: to configure consider setting a SymbolResolver in the ParserConfiguration HOT 6
- Import added through CompilationUnit.addImport should not have a range HOT 3
- Unable to compile under Java 21 HOT 1
- Node::getData : Possibility to check if a key is pointing at null is missing HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from javaparser.