Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » Problem with enums when building an AST(Problem with enums when building an AST)
Problem with enums when building an AST [message #1106621] Wed, 11 September 2013 06:34 Go to next message
j vl is currently offline j vl
Messages: 5
Registered: September 2013
Junior Member
Hi

When obtaining a compilation unit from the following basic enum:

public enum Day {
SUNDAY, MONDAY, TUESDAY, WEDNESDAY,
THURSDAY, FRIDAY, SATURDAY;
}

The compilation unit doesn't contain anything and I get the following messages, from within the compilation unit.

Messages:

Syntax error on token "enum", interface expected
Syntax error on token ",", delete this token

I got this problem before and updated all my libraries to the most current being shipped with Eclipse Kepler, but the problem remains.

Any help, would be appreciated.

Thanks
Re: Problem with enums when building an AST [message #1107750 is a reply to message #1106621] Thu, 12 September 2013 18:03 Go to previous messageGo to next message
Stephan Herrmann is currently offline Stephan Herrmann
Messages: 977
Registered: July 2009
Senior Member
How exactly do you obtain the AST?
You must tell JDT which Java source version it should parse.
Apparently, it tried to parse it as Java 1.4 or less.
Re: Problem with enums when building an AST [message #1108175 is a reply to message #1107750] Fri, 13 September 2013 08:55 Go to previous messageGo to next message
j vl is currently offline j vl
Messages: 5
Registered: September 2013
Junior Member
Hi

This is how I obtain the Compilation unit

public static CompilationUnit GetCU(String path) {
	ASTParser parser = ASTParser.newParser(AST.JLS4);

	String f = null;
	f = readFile(path);
	parser.setSource(f.toCharArray());

	parser.setKind(ASTParser.K_COMPILATION_UNIT);
	return (CompilationUnit) parser.createAST(null);
}


Thanks
Re: Problem with enums when building an AST [message #1117754 is a reply to message #1108175] Thu, 26 September 2013 15:35 Go to previous message
j vl is currently offline j vl
Messages: 5
Registered: September 2013
Junior Member
Fixed it with:

public static CompilationUnit GetCU(String path) {
		ASTParser parser = ASTParser.newParser(AST.JLS4);

		String f = readFile(path);
		parser.setSource(f.toCharArray());

		Map options = JavaCore.getOptions();
		JavaCore.setComplianceOptions(JavaCore.VERSION_1_7, options);
		parser.setCompilerOptions(options);
		return (CompilationUnit) parser.createAST(null);
}
Previous Topic:Problems with enums when building AST
Next Topic:Tooltip over expression: Ocurrence of Vs. Javadoc
Goto Forum:
  


Current Time: Tue Jul 22 17:37:44 EDT 2014

Powered by FUDForum. Page generated in 0.02055 seconds