Giter VIP home page Giter VIP logo

Comments (14)

jlerbsc avatar jlerbsc commented on September 27, 2024 1

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.

Decencies avatar Decencies commented on September 27, 2024

Code formatting doesn't do it justice, here's a picture with an I-beam indicating the exact place:
image

from javaparser.

jlerbsc avatar jlerbsc commented on September 27, 2024

Can you provide us with a unit test?

from javaparser.

Decencies avatar Decencies commented on September 27, 2024

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.

Decencies avatar Decencies commented on September 27, 2024

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

https://pastebin.com/TjCbBvWS

from javaparser.

Decencies avatar Decencies commented on September 27, 2024

The program is using the latest version of JavaParser available on maven-central (3.25.10)

from javaparser.

jlerbsc avatar jlerbsc commented on September 27, 2024

Thank you. Can you show us how you configure the parser.

from javaparser.

Decencies avatar Decencies commented on September 27, 2024

Thank you. Can you show us how you configure the parser.

https://github.com/sfPlayer1/Matcher/blob/2cb3bbd8a4652c33ce907c1bb1d5356835ec11d5/src/main/java/matcher/srcprocess/SrcDecorator.java#L72

from javaparser.

jlerbsc avatar jlerbsc commented on September 27, 2024

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.

Decencies avatar Decencies commented on September 27, 2024

Very weird, it seems to work standalone for me too....

from javaparser.

Decencies avatar Decencies commented on September 27, 2024

Very weird, it seems to work standalone for me too....

nevermind, result.isSuccessful() is not true

from javaparser.

Decencies avatar Decencies commented on September 27, 2024

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.

jlerbsc avatar jlerbsc commented on September 27, 2024

This problem seems to have been solved in the current version javaparser-parent-3.26.0-snapshot

from javaparser.

jlerbsc avatar jlerbsc commented on September 27, 2024

I'm closing this issue as it seems to have been resolved.

from javaparser.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.