compilationunit

Unable to parse code snippet in roslyn

不打扰是莪最后的温柔 提交于 2019-12-13 19:53:57
问题 I'm trying to dynamically build a c# class from small pieces of code. We have a window where a user can enter c# code (valid or not), and we parse these strings into roslyn. I recently found an issue when i was using this : public override IEnumerable<StatementSyntax> GenerateStatements() { var result = new List<StatementSyntax>(); if (!string.IsNullOrWhiteSpace(this.Tag.Code)) { result.Add(SyntaxFactory.ParseStatement(this.Tag.Code)); } return result; } Turns out when compiling in VB, if the

Eclipse Abstract Syntax Tree Diff

萝らか妹 提交于 2019-12-07 10:23:31
问题 Given the following code in Eclipse: import org.eclipse.jdt.core.dom.AST; import org.eclipse.jdt.core.dom.ASTParser; import org.eclipse.jdt.core.dom.CompilationUnit; public class Question { public static void main(String[] args) { String source = "class Bob {}"; ASTParser parser = ASTParser.newParser(AST.JLS3); parser.setSource(source.toCharArray()); CompilationUnit result = (CompilationUnit) parser.createAST(null); String source2 = "class Bob {public void MyMethod(){}}"; ASTParser parser2 =

Eclipse Abstract Syntax Tree Diff

痴心易碎 提交于 2019-12-05 12:59:13
Given the following code in Eclipse: import org.eclipse.jdt.core.dom.AST; import org.eclipse.jdt.core.dom.ASTParser; import org.eclipse.jdt.core.dom.CompilationUnit; public class Question { public static void main(String[] args) { String source = "class Bob {}"; ASTParser parser = ASTParser.newParser(AST.JLS3); parser.setSource(source.toCharArray()); CompilationUnit result = (CompilationUnit) parser.createAST(null); String source2 = "class Bob {public void MyMethod(){}}"; ASTParser parser2 = ASTParser.newParser(AST.JLS3); parser2.setSource(source2.toCharArray()); CompilationUnit result2 =

Eclipse create CompilationUnit from .java file

怎甘沉沦 提交于 2019-11-27 15:42:14
How can I load a .java file into a CompilationUnit? For example, lets say I have a A.java file in my current project. I would like to load it into a CompilationUnit and then pass it to the ASTParser. It is not an option just to load it as a plain text since it seems that in that case I will not get the binding information in the AST. You can load the projects using jdt and eclipse core libraries. Using the following code you can load all the projects in the workspace. IWorkspace workspace = ResourcesPlugin.getWorkspace(); IWorkspaceRoot root = workspace.getRoot(); // Get all projects in the

Eclipse create CompilationUnit from .java file

我们两清 提交于 2019-11-26 17:16:11
问题 How can I load a .java file into a CompilationUnit? For example, lets say I have a A.java file in my current project. I would like to load it into a CompilationUnit and then pass it to the ASTParser. It is not an option just to load it as a plain text since it seems that in that case I will not get the binding information in the AST. 回答1: You can load the projects using jdt and eclipse core libraries. Using the following code you can load all the projects in the workspace. IWorkspace