本文整理汇总了C#中ICSharpCode.NRefactory.Ast.CompilationUnit.AcceptVisitor方法的典型用法代码示例。如果您正苦于以下问题:C# CompilationUnit.AcceptVisitor方法的具体用法?C# CompilationUnit.AcceptVisitor怎么用?C# CompilationUnit.AcceptVisitor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICSharpCode.NRefactory.Ast.CompilationUnit
的用法示例。
在下文中一共展示了CompilationUnit.AcceptVisitor方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: VisitCompilationUnit
public override object VisitCompilationUnit(CompilationUnit compilationUnit, object data)
{
base.VisitCompilationUnit(compilationUnit, data);
if (!string.IsNullOrEmpty(NamespacePrefixToAdd)) {
for (int i = 0; i < compilationUnit.Children.Count; i++) {
NamespaceDeclaration ns = compilationUnit.Children[i] as NamespaceDeclaration;
if (ns != null) {
ns.Name = NamespacePrefixToAdd + "." + ns.Name;
}
if (compilationUnit.Children[i] is TypeDeclaration || compilationUnit.Children[i] is DelegateDeclaration) {
ns = new NamespaceDeclaration(NamespacePrefixToAdd);
ns.AddChild(compilationUnit.Children[i]);
compilationUnit.Children[i] = ns;
}
}
}
ToCSharpConvertVisitor v = new ToCSharpConvertVisitor();
compilationUnit.AcceptVisitor(v, data);
if (projectContent != null && projectContent.DefaultImports != null) {
int index = 0;
foreach (string u in projectContent.DefaultImports.Usings) {
compilationUnit.Children.Insert(index++, new UsingDeclaration(u));
}
}
return null;
}
示例2: VisitCompilationUnit
public override object VisitCompilationUnit(CompilationUnit compilationUnit, object data)
{
base.VisitCompilationUnit(compilationUnit, data);
ToVBNetConvertVisitor v = new ToVBNetConvertVisitor();
compilationUnit.AcceptVisitor(v, data);
return null;
}
示例3: GenerateText
public static string GenerateText(TypeDeclaration type, OrderedPartCollection<AbstractDynamicCompilationExtension> extensions)
{
var unit = new CompilationUnit();
var namespaces = new HashSet<string>
{
typeof (SystemTime).Namespace,
typeof (AbstractViewGenerator).Namespace,
typeof (Enumerable).Namespace,
typeof (IEnumerable<>).Namespace,
typeof (IEnumerable).Namespace,
typeof (int).Namespace,
typeof (LinqOnDynamic).Namespace,
typeof(Field).Namespace,
};
foreach (var extension in extensions)
{
foreach (var ns in extension.Value.GetNamespacesToImport())
{
namespaces.Add(ns);
}
}
foreach (var ns in namespaces)
{
unit.AddChild(new Using(ns));
}
unit.AddChild(type);
var output = new CSharpOutputVisitor();
unit.AcceptVisitor(output, null);
return output.Text;
}
示例4: rewriteCode_CSharp
public void rewriteCode_CSharp(CompilationUnit unit, IList<ISpecial> specials)
{
var outputVisitor = new CSharpOutputVisitor();
using (SpecialNodesInserter.Install(specials, outputVisitor)) {
unit.AcceptVisitor(outputVisitor, null);
}
//codeTextBox.Text = outputVisitor.Text.Replace("\t", " ");
CSharpCode = outputVisitor.Text;
}
示例5: ConvertAst
protected override void ConvertAst(CompilationUnit compilationUnit, List<ISpecial> specials, FileProjectItem sourceItem)
{
PreprocessingDirective.CSharpToVB(specials);
IProjectContent pc = ParserService.GetProjectContent(sourceItem.Project) ?? ParserService.CurrentProjectContent;
CSharpToVBNetConvertVisitor visitor = new CSharpToVBNetConvertVisitor(pc, ParserService.GetParseInformation(sourceItem.FileName));
visitor.RootNamespaceToRemove = sourceItem.Project.RootNamespace;
visitor.DefaultImportsToRemove = defaultImports;
visitor.StartupObjectToMakePublic = startupObject;
compilationUnit.AcceptVisitor(visitor, null);
}
示例6: ConvertAst
protected override void ConvertAst(CompilationUnit compilationUnit, List<ISpecial> specials, FileProjectItem sourceItem)
{
PreprocessingDirective.VBToCSharp(specials);
CompilableProject project = (CompilableProject)sourceItem.Project;
RemoveWindowsFormsSpecificCode(compilationUnit, specials, project.OutputType == OutputType.WinExe);
IProjectContent pc = ParserService.GetProjectContent(sourceItem.Project) ?? ParserService.CurrentProjectContent;
VBNetToCSharpConvertVisitor visitor = new VBNetToCSharpConvertVisitorWithMyFormsSupport(pc, ParserService.GetParseInformation(sourceItem.FileName), sourceItem.Project.RootNamespace);
compilationUnit.AcceptVisitor(visitor, null);
}
示例7: setCurrentCompilationUnit
public ICompilationUnit setCurrentCompilationUnit(CompilationUnit compilationUnit)
{
if (compilationUnit == null)
return null;
NRefactoryASTConvertVisitor converter;
converter = new NRefactoryASTConvertVisitor(myProjectContent);
compilationUnit.AcceptVisitor(converter, null);
var newCompilationUnit = converter.Cu;
parseInformation.SetCompilationUnit(newCompilationUnit);
return newCompilationUnit;
}
示例8: rewriteCode_VBNet
public void rewriteCode_VBNet(CompilationUnit unit, IList<ISpecial> specials)
{
var outputVisitor = new VBNetOutputVisitor();
using (SpecialNodesInserter.Install(specials, outputVisitor)) {
unit.AcceptVisitor(outputVisitor, null);
}
//codeTextBox.Text = outputVisitor.Text.Replace("\t", " ");
VBNetCode = outputVisitor.Text;
// PublicDI.log.debug(recreatedCode);
}
示例9: loadCompilationUnit
//DC
/* public void loadCode(string code)
{
code = (code.fileExists()) ? code.fileContents() : code;
var parser = code.csharpAst();
loadCompilationUnit(parser.CompilationUnit);
}*/
//DC
public void loadCompilationUnit(CompilationUnit compilationUnit)
{
try
{
compilationUnit.AcceptVisitor(this, null);
}
catch (Exception ex)
{
ex.log("in MapAstToDom loadCompilationUnit");
}
}
示例10: GenerateText
public static string GenerateText(TypeDeclaration type)
{
var unit = new CompilationUnit();
unit.AddChild(new Using(typeof (AbstractViewGenerator).Namespace));
unit.AddChild(new Using(typeof (Enumerable).Namespace));
unit.AddChild(new Using(typeof (int).Namespace));
unit.AddChild(new Using(typeof (LinqOnDynamic).Namespace));
unit.AddChild(type);
var output = new CSharpOutputVisitor();
unit.AcceptVisitor(output, null);
return output.Text;
}
示例11: ConvertAst
protected override void ConvertAst(CompilationUnit compilationUnit, List<ISpecial> specials, FileProjectItem sourceItem)
{
PreprocessingDirective.VBToCSharp(specials);
CompilableProject project = (CompilableProject)sourceItem.Project;
RemoveWindowsFormsSpecificCode(compilationUnit, specials, project.OutputType == OutputType.WinExe);
IProjectContent pc = ParserService.GetProjectContent(sourceItem.Project) ?? ParserService.CurrentProjectContent;
VBNetToCSharpConvertVisitor visitor = new VBNetToCSharpConvertVisitorWithMyFormsSupport(pc, ParserService.GetParseInformation(sourceItem.FileName), sourceItem.Project.RootNamespace);
// set project options
visitor.OptionInfer = (project.GetEvaluatedProperty("OptionInfer") ?? "Off")
.Equals("On", StringComparison.OrdinalIgnoreCase);
visitor.OptionStrict = (project.GetEvaluatedProperty("OptionStrict") ?? "Off")
.Equals("On", StringComparison.OrdinalIgnoreCase);
compilationUnit.AcceptVisitor(visitor, null);
}
示例12: ConvertCompilationUnit
private ICompilationUnit ConvertCompilationUnit(CompilationUnit cu)
{
NRefactoryASTConvertVisitor converter;
converter = new NRefactoryASTConvertVisitor(myProjectContent);
cu.AcceptVisitor(converter, null);
return converter.Cu;
}
示例13: ConvertCompilationUnit
private ICompilationUnit ConvertCompilationUnit(CompilationUnit cu)
{
var supportedLanguage = SupportedLanguage == SupportedLanguage.CSharp
? ICSharpCode.NRefactory.SupportedLanguage.CSharp
: ICSharpCode.NRefactory.SupportedLanguage.VBNet;
var converter = new NRefactoryASTConvertVisitor(ProjectContent, supportedLanguage);
cu.AcceptVisitor(converter, null);
return converter.Cu;
}
示例14: ResolveLowLevel
public static ResolveResult ResolveLowLevel(string fileName, string fileContent, int caretLine, int caretColumn, CompilationUnit compilationUnit, string expressionString, Expression expression, ExpressionContext context)
{
if (fileName == null) {
throw new ArgumentNullException("fileName");
}
if (fileContent == null) {
throw new ArgumentNullException("fileName");
}
if (expression == null) {
throw new ArgumentNullException("expression");
}
IProject p = ProjectFileDictionaryService.GetProjectForFile(fileName);
if (p == null) {
LoggingService.Info("ResourceToolkit: NRefactoryAstCacheService: ResolveLowLevel failed. Project is null for file '"+fileName+"'");
return null;
}
IProjectContent pc = ResourceResolverService.GetProjectContent(p);
if (pc == null) {
LoggingService.Info("ResourceToolkit: NRefactoryAstCacheService: ResolveLowLevel failed. ProjectContent is null for project '"+p.ToString()+"'");
return null;
}
NRefactoryResolver resolver = ResourceResolverService.CreateResolver(fileName) as NRefactoryResolver;
if (resolver == null) {
resolver = new NRefactoryResolver(LanguageProperties.CSharp);
}
if (compilationUnit == null) {
compilationUnit = GetFullAst(resolver.Language, fileName, fileContent);
}
if (compilationUnit == null) {
LoggingService.Info("ResourceToolkit: NRefactoryAstCacheService: ResolveLowLevel failed due to the compilation unit being unavailable.");
return null;
}
if (!resolver.Initialize(ParserService.GetParseInformation(fileName), caretLine, caretColumn)) {
LoggingService.Info("ResourceToolkit: NRefactoryAstCacheService: ResolveLowLevel failed. NRefactoryResolver.Initialize returned false.");
return null;
}
if (resolver.CallingClass != null) {
ResolveResult rr;
if (expressionString == null) {
// HACK: Re-generate the code for the expression from the expression object by using the code generator.
// This is necessary when invoking from inside an AST visitor where the
// code belonging to this expression is unavailable.
expressionString = resolver.LanguageProperties.CodeGenerator.GenerateCode(expression, String.Empty);
}
if ((rr = CtrlSpaceResolveHelper.GetResultFromDeclarationLine(resolver.CallingClass, resolver.CallingMember as IMethodOrProperty, caretLine, caretColumn, new ExpressionResult(expressionString))) != null) {
return rr;
}
}
if (resolver.CallingMember != null) {
// Cache member->node mappings to improve performance
// (if cache is enabled)
INode memberNode;
if (!CacheEnabled || !cachedMemberMappings.TryGetValue(resolver.CallingMember, out memberNode)) {
MemberFindAstVisitor visitor = new MemberFindAstVisitor(resolver.CallingMember);
compilationUnit.AcceptVisitor(visitor, null);
memberNode = visitor.MemberNode;
if (CacheEnabled && memberNode != null) {
cachedMemberMappings.Add(resolver.CallingMember, memberNode);
}
}
if (memberNode == null) {
LoggingService.Info("ResourceToolkit: NRefactoryAstCacheService: Could not find member in AST: "+resolver.CallingMember.ToString());
} else {
resolver.RunLookupTableVisitor(memberNode);
}
}
return resolver.ResolveInternal(expression, context);
}
示例15: RemoveWindowsFormsSpecificCode
void RemoveWindowsFormsSpecificCode(CompilationUnit compilationUnit, List<ISpecial> specials, bool keepCode)
{
for (int i = 0; i < specials.Count; i++) {
PreprocessingDirective ppd = specials[i] as PreprocessingDirective;
if (ppd != null && ppd.Cmd == "#if") {
if (ppd.Arg == "_MyType = \"WindowsForms\"") {
int depth = 1;
for (int j = i + 1; j < specials.Count; j++) {
ppd = specials[j] as PreprocessingDirective;
if (ppd != null) {
if (ppd.Cmd == "#if") {
depth++;
} else if (ppd.Cmd == "#endif") {
depth--;
if (depth == 0) {
if (keepCode) {
// keep code, remove only the ifdef
specials.RemoveAt(j);
specials.RemoveAt(i);
} else {
// remove ifdef including the code
compilationUnit.AcceptVisitor(new RemoveMembersInRangeVisitor(
DomRegion.FromLocation(specials[i].StartPosition, specials[j].EndPosition)), null);
specials.RemoveRange(i, j - i + 1);
}
i--;
break;
}
}
}
}
}
}
}
}