Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » Problems with enums when building AST
Problems with enums when building AST [message #1117726] Thu, 26 September 2013 15:00 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.

This is how I obtain the ompilation 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);
}


Any help, would be appreciated.

Thanks
Re: Problems with enums when building AST [message #1117753 is a reply to message #1117726] Thu, 26 September 2013 15:34 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:JSF Support
Next Topic:Problem with enums when building an AST
Goto Forum:
  


Current Time: Thu Jul 31 05:36:53 EDT 2014

Powered by FUDForum. Page generated in 0.01525 seconds