本文整理汇总了C#中ICSharpCode.NRefactory.Ast类的典型用法代码示例。如果您正苦于以下问题:C# Ast类的具体用法?C# Ast怎么用?C# Ast使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Ast类属于ICSharpCode.NRefactory命名空间,在下文中一共展示了Ast类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConvertModifier
ModifierEnum ConvertModifier(AST.Modifiers m, ModifierEnum defaultVisibility)
{
ModifierEnum r = (ModifierEnum)m;
if ((r & ModifierEnum.VisibilityMask) == ModifierEnum.None)
return r | defaultVisibility;
else
return r;
}
示例2: ConvertTypeModifier
ModifierEnum ConvertTypeModifier(AST.Modifiers m)
{
if (this.IsVisualBasic)
return ConvertModifier(m, ModifierEnum.Public);
if (currentClass.Count > 0)
return ConvertModifier(m, ModifierEnum.Private);
else
return ConvertModifier(m, ModifierEnum.Internal);
}
示例3: CreateReturnType
IReturnType CreateReturnType(NRefactoryAST.TypeReference reference)
{
return CreateReturnType(reference, null, TypeVisitor.ReturnTypeOptions.None);
}
示例4: VisitEventDeclaration
public override object VisitEventDeclaration(NRefactoryAST.EventDeclaration eventDeclaration, object data)
{
DomRegion region = GetRegion(eventDeclaration.StartLocation, eventDeclaration.EndLocation);
DomRegion bodyRegion = GetRegion(eventDeclaration.BodyStart, eventDeclaration.BodyEnd);
DefaultClass c = GetCurrentClass();
IReturnType type;
if (eventDeclaration.TypeReference.IsNull) {
DefaultClass del = new DefaultClass(cu, ClassType.Delegate,
ConvertModifier(eventDeclaration.Modifier),
region, c);
del.Modifiers |= ModifierEnum.Synthetic;
CreateDelegate(del, eventDeclaration.Name + "EventHandler",
new NRefactoryAST.TypeReference("System.Void", true),
new NRefactoryAST.TemplateDefinition[0],
eventDeclaration.Parameters);
type = del.DefaultReturnType;
} else {
type = CreateReturnType(eventDeclaration.TypeReference);
}
DefaultEvent e = new DefaultEvent(eventDeclaration.Name, type, ConvertModifier(eventDeclaration.Modifier), region, bodyRegion, c);
ConvertAttributes(eventDeclaration, e);
c.Events.Add(e);
e.Documentation = GetDocumentation(region.BeginLine, eventDeclaration.Attributes);
if (eventDeclaration.HasAddRegion) {
e.AddMethod = new DefaultMethod(e.DeclaringType, "add_" + e.Name) {
Parameters = { new DefaultParameter("value", e.ReturnType, DomRegion.Empty) },
Region = GetRegion(eventDeclaration.AddRegion.StartLocation, eventDeclaration.AddRegion.EndLocation),
BodyRegion = GetRegion(eventDeclaration.AddRegion.Block.StartLocation, eventDeclaration.AddRegion.Block.EndLocation)
};
}
if (eventDeclaration.HasRemoveRegion) {
e.RemoveMethod = new DefaultMethod(e.DeclaringType, "remove_" + e.Name) {
Parameters = { new DefaultParameter("value", e.ReturnType, DomRegion.Empty) },
Region = GetRegion(eventDeclaration.RemoveRegion.StartLocation, eventDeclaration.RemoveRegion.EndLocation),
BodyRegion = GetRegion(eventDeclaration.RemoveRegion.Block.StartLocation, eventDeclaration.RemoveRegion.Block.EndLocation)
};
}
return null;
}
示例5: VisitPropertyDeclaration
public override object VisitPropertyDeclaration(NRefactoryAST.PropertyDeclaration propertyDeclaration, object data)
{
DomRegion region = GetRegion(propertyDeclaration.StartLocation, propertyDeclaration.EndLocation);
DomRegion bodyRegion = GetRegion(propertyDeclaration.BodyStart, propertyDeclaration.BodyEnd);
IReturnType type = CreateReturnType(propertyDeclaration.TypeReference);
DefaultClass c = GetCurrentClass();
DefaultProperty property = new DefaultProperty(propertyDeclaration.Name, type, ConvertModifier(propertyDeclaration.Modifier), region, bodyRegion, GetCurrentClass());
if (propertyDeclaration.HasGetRegion) {
property.GetterRegion = GetRegion(propertyDeclaration.GetRegion.StartLocation, propertyDeclaration.GetRegion.EndLocation);
property.CanGet = true;
property.GetterModifiers = ConvertModifier(propertyDeclaration.GetRegion.Modifier, ModifierEnum.None);
}
if (propertyDeclaration.HasSetRegion) {
property.SetterRegion = GetRegion(propertyDeclaration.SetRegion.StartLocation, propertyDeclaration.SetRegion.EndLocation);
property.CanSet = true;
property.SetterModifiers = ConvertModifier(propertyDeclaration.SetRegion.Modifier, ModifierEnum.None);
}
property.Documentation = GetDocumentation(region.BeginLine, propertyDeclaration.Attributes);
ConvertAttributes(propertyDeclaration, property);
c.Properties.Add(property);
mapProperty(propertyDeclaration, property);
return null;
}
示例6: VisitDestructorDeclaration
public override object VisitDestructorDeclaration(NRefactoryAST.DestructorDeclaration destructorDeclaration, object data)
{
DomRegion region = GetRegion(destructorDeclaration.StartLocation, destructorDeclaration.EndLocation);
DomRegion bodyRegion = GetRegion(destructorDeclaration.EndLocation, destructorDeclaration.Body != null ? destructorDeclaration.Body.EndLocation : RefParser.Location.Empty);
DefaultClass c = GetCurrentClass();
Destructor destructor = new Destructor(region, bodyRegion, c);
ConvertAttributes(destructorDeclaration, destructor);
c.Methods.Add(destructor);
return null;
}
示例7: VisitOperatorDeclaration
public override object VisitOperatorDeclaration(NRefactoryAST.OperatorDeclaration operatorDeclaration, object data)
{
DefaultClass c = GetCurrentClass();
DomRegion region = GetRegion(operatorDeclaration.StartLocation, operatorDeclaration.EndLocation);
DomRegion bodyRegion = GetRegion(operatorDeclaration.EndLocation, operatorDeclaration.Body != null ? operatorDeclaration.Body.EndLocation : RefParser.Location.Empty);
DefaultMethod method = new DefaultMethod(operatorDeclaration.Name, CreateReturnType(operatorDeclaration.TypeReference), ConvertModifier(operatorDeclaration.Modifier), region, bodyRegion, c);
ConvertAttributes(operatorDeclaration, method);
if(operatorDeclaration.Parameters != null)
{
foreach (NRefactoryAST.ParameterDeclarationExpression par in operatorDeclaration.Parameters) {
method.Parameters.Add(CreateParameter(par, method));
}
}
c.Methods.Add(method);
return null;
}
示例8: TranslateClassType
ClassType TranslateClassType(NRefactoryAST.ClassType type)
{
switch (type) {
case NRefactoryAST.ClassType.Enum:
return ClassType.Enum;
case NRefactoryAST.ClassType.Interface:
return ClassType.Interface;
case NRefactoryAST.ClassType.Struct:
return ClassType.Struct;
case NRefactoryAST.ClassType.Module:
return ClassType.Module;
default:
return ClassType.Class;
}
}
示例9: VisitNamespaceDeclaration
public override object VisitNamespaceDeclaration(NRefactoryAST.NamespaceDeclaration namespaceDeclaration, object data)
{
DefaultUsingScope oldNamespace = currentNamespace;
foreach (string name in namespaceDeclaration.Name.Split('.')) {
currentNamespace = new DefaultUsingScope {
Parent = currentNamespace,
NamespaceName = PrependCurrentNamespace(name),
};
currentNamespace.Parent.ChildScopes.Add(currentNamespace);
}
object ret = namespaceDeclaration.AcceptChildren(this, data);
currentNamespace = oldNamespace;
return ret;
}
示例10: VisitAttributeSection
public override object VisitAttributeSection(NRefactoryAST.AttributeSection attributeSection, object data)
{
if (GetCurrentClass() == null) {
ClassFinder cf = new ClassFinder(new DefaultClass(cu, "DummyClass"), attributeSection.StartLocation.Line, attributeSection.StartLocation.Column);
cu.Attributes.AddRange(VisitAttributes(new[] { attributeSection }, cf));
}
return null;
}
示例11: ConvertAttributeArgument
static object ConvertAttributeArgument(NRefactoryAST.Expression expression)
{
NRefactoryAST.PrimitiveExpression pe = expression as NRefactoryAST.PrimitiveExpression;
if (pe != null)
return pe.Value;
else
return null;
}
示例12: ConvertAttributes
void ConvertAttributes(NRefactoryAST.AttributedNode from, AbstractEntity to)
{
if (from.Attributes.Count == 0) {
to.Attributes = DefaultAttribute.EmptyAttributeList;
} else {
ICSharpCode.NRefactory.Location location = from.Attributes[0].StartLocation;
ClassFinder context;
if (to is IClass) {
context = new ClassFinder((IClass)to, location.Line, location.Column);
} else {
context = new ClassFinder(to.DeclaringType, location.Line, location.Column);
}
to.Attributes = VisitAttributes(from.Attributes, context);
}
}
示例13: VisitUsing
public override object VisitUsing(NRefactoryAST.Using u, object data)
{
Debug.Assert(data is DefaultUsing);
DefaultUsing us = (DefaultUsing)data;
if (u.IsAlias) {
IReturnType rt = CreateReturnType(u.Alias);
if (rt != null) {
us.AddAlias(u.Name, rt);
}
} else {
us.Usings.Add(u.Name);
}
return data;
}
示例14: VisitMethodDeclaration
public override object VisitMethodDeclaration(NRefactoryAST.MethodDeclaration methodDeclaration, object data)
{
DomRegion region = GetRegion(methodDeclaration.StartLocation, methodDeclaration.EndLocation);
DomRegion bodyRegion = GetRegion(methodDeclaration.EndLocation, methodDeclaration.Body != null ? methodDeclaration.Body.EndLocation : RefParser.Location.Empty);
DefaultClass currentClass = GetCurrentClass();
DefaultMethod method = new DefaultMethod(methodDeclaration.Name, null, ConvertModifier(methodDeclaration.Modifier), region, bodyRegion, currentClass);
method.IsExtensionMethod = methodDeclaration.IsExtensionMethod;
method.Documentation = GetDocumentation(region.BeginLine, methodDeclaration.Attributes);
ConvertTemplates(methodDeclaration.Templates, method);
method.ReturnType = CreateReturnType(methodDeclaration.TypeReference, method, TypeVisitor.ReturnTypeOptions.None);
ConvertAttributes(methodDeclaration, method);
if (methodDeclaration.Parameters.Count > 0) {
foreach (NRefactoryAST.ParameterDeclarationExpression par in methodDeclaration.Parameters) {
method.Parameters.Add(CreateParameter(par, method));
}
} else {
method.Parameters = DefaultParameter.EmptyParameterList;
}
if (methodDeclaration.HandlesClause.Count > 0) {
foreach (string handlesClause in methodDeclaration.HandlesClause) {
if (handlesClause.ToLowerInvariant().StartsWith("me."))
method.HandlesClauses.Add(handlesClause.Substring(3));
else if (handlesClause.ToLowerInvariant().StartsWith("mybase."))
method.HandlesClauses.Add(handlesClause.Substring(7));
else
method.HandlesClauses.Add(handlesClause);
}
} else {
method.HandlesClauses = EmptyList<string>.Instance;
}
currentClass.Methods.Add(method);
mapMethod(methodDeclaration, method);
return null;
}
示例15: VisitDeclareDeclaration
public override object VisitDeclareDeclaration(NRefactoryAST.DeclareDeclaration declareDeclaration, object data)
{
DefaultClass currentClass = GetCurrentClass();
DomRegion region = GetRegion(declareDeclaration.StartLocation, declareDeclaration.EndLocation);
DefaultMethod method = new DefaultMethod(declareDeclaration.Name, null, ConvertModifier(declareDeclaration.Modifier), region, DomRegion.Empty, currentClass);
method.Documentation = GetDocumentation(region.BeginLine, declareDeclaration.Attributes);
method.Modifiers |= ModifierEnum.Extern | ModifierEnum.Static;
method.ReturnType = CreateReturnType(declareDeclaration.TypeReference, method, TypeVisitor.ReturnTypeOptions.None);
ConvertAttributes(declareDeclaration, method);
foreach (NRefactoryAST.ParameterDeclarationExpression par in declareDeclaration.Parameters) {
method.Parameters.Add(CreateParameter(par, method));
}
currentClass.Methods.Add(method);
return null;
}