public override bool IsAvailable(IUserDataHolder cache) { myMethodDeclaration = myProvider.GetSelectedElement<IMethodDeclaration>(true, true); if (myMethodDeclaration == null) return false; // only on non-generic methods var method = myMethodDeclaration.DeclaredElement; if (method == null || method.TypeParameters.Any()) return false; if (!method.IsStatic) { // only on non-generic types myClassDeclaration = method.GetContainingType() as IClass; if (myClassDeclaration == null || myClassDeclaration.HasTypeParameters()) return false; // with default constructor if (!myClassDeclaration.IsStatic || (!myClassDeclaration.Constructors.IsEmpty() && !myClassDeclaration.Constructors.Any(c => c.Parameters.IsEmpty()))) return false; } return !method.Parameters.Any(); }
protected internal BinaryFormula(NodeType nodeType, Formula left, IMethodDeclaration method, Formula right) : base(nodeType, left.Type) { Left = left; Method = method; Right = right; }
protected internal MethodCallFormula(Formula instance, IMethodDeclaration method, ReadOnlyCollection<Formula> arguments) : base(NodeType.Call, method.ReturnType) { Instance = instance; Method = method; Arguments = arguments; }
protected internal BinaryFormula(NodeType nodeType, IFormula left, IFormula right, ITypeDeclaration type, IMethodDeclaration method, IFormula parent) : base(nodeType, type, parent) { Left = left; Method = method; Right = right; }
public static bool IsAsyncSuffixMissing(IMethodDeclaration methodDeclaration) { if (methodDeclaration.IsOverride) return false; var declaredElement = methodDeclaration.DeclaredElement; if (declaredElement != null) { var settings = methodDeclaration.GetSettingsStore(); var excludeTestMethods = settings.GetValue(AsyncSuffixSettingsAccessor.ExcludeTestMethodsFromAnalysis); if (excludeTestMethods) { if (IsAnnotatedWithKnownTestAttribute(methodDeclaration)) { return false; } } if (declaredElement.ShortName.EndsWith("Async", StringComparison.Ordinal)) { return false; } var returnType = declaredElement.ReturnType as IDeclaredType; if (returnType != null) { if (returnType.IsTaskType()) { return true; } } } return false; }
protected internal EqualFormulaRef(IFormulaRef left, IFormulaRef right, ITypeDeclaration type, IMethodDeclaration method, IFormulaRef parent) : base(left, right, type, method, parent) { this.parent = parent; this.left = left; this.right = right; }
public MethodDefinition GetMethodDefinition(IMethodDeclaration item) { return TryGetOrAdd(_methodcache, item, mdef => { var tdef = GetTypeDefinition(item.DeclaringType as ITypeDeclaration); return tdef == null ? null : ReflectorHelper.FindMatchingMethod(tdef, mdef); }); }
private IncorrectMethodSignatureQuickFix(IMethodDeclaration methodDeclaration, MethodSignature[] expectedMethodSignatures) { myMethodDeclaration = methodDeclaration; myExpectedMethodSignatures = new FrugalLocalList <MethodSignature>(expectedMethodSignatures); myMatches = new FrugalLocalList <MethodSignatureMatch>(); for (var i = 0; i < myExpectedMethodSignatures.Count; i++) { myMatches.Add(MethodSignatureMatch.NoMatch); } }
/// <summary>Gets the annotation.</summary> /// <param name="method">The method.</param> /// <returns>Returns the annotation.</returns> public CodeAnnotationAttribute GetAnnotation([NotNull] IMethodDeclaration method) { if (method == null) { throw new ArgumentNullException("method"); } var attributesOwner = method.DeclaredElement as IAttributesOwner; return(attributesOwner != null?this.GetAnnotation(attributesOwner) : CodeAnnotationAttribute.Undefined); }
protected override bool IsAvailable(IUserDataHolder cache, IMethodDeclaration containingMethod) { var isHotIconsEnabled = mySettingStore.GetValue((UnitySettings key) => key.EnableIconsForPerformanceCriticalCode); if (isHotIconsEnabled) { return(false); } return(base.IsAvailable(cache, containingMethod)); }
protected override IExpression ConvertMethodInvoke(IMethodInvokeExpression imie) { if (imie.Method.Target is IThisReferenceExpression) { IMethodDeclaration imd = context.FindAncestor <IMethodDeclaration>(); int sourceMethod = GetMethodIndex(imd); int targetMethod = GetMethodIndex(imie.Method.Method); MethodGraph.AddEdge(sourceMethod, targetMethod); //Trace.WriteLine($"{sourceMethod} {methods[sourceMethod].Name} called {targetMethod} {methods[targetMethod].Name}"); } return(base.ConvertMethodInvoke(imie)); }
protected internal MethodCallFormula( IFormula instance, IMethodDeclaration method, ReadOnlyCollection<IFormula> arguments, ITypeDeclaration type, IFormula parent) : base(NodeType.Call, type, parent) { Instance = instance; Method = method; Arguments = arguments; }
protected override void DoConvertMethodBody(IList <IStatement> outputs, IList <IStatement> inputs) { // get the dead flags for this method IMethodDeclaration imd = context.FindAncestor <IMethodDeclaration>(); int methodIndex = analysis.analysis.IndexOfMethod[imd]; this.liveness = analysis.LivenessInMethod[methodIndex]; // as we convert assignments, increment a counter // if isDead array says dead, return null assignmentIndex = 0; base.DoConvertMethodBody(outputs, inputs); }
protected override IMethodDeclaration DoConvertMethod(IMethodDeclaration md, IMethodDeclaration imd) { loopMergingInfo = context.InputAttributes.Get <LoopMergingInfo>(imd); if (debug && loopMergingInfo != null && !hasDebugInfo) { var itdOut = context.FindOutputForAncestor <ITypeDeclaration, ITypeDeclaration>(); context.OutputAttributes.Add(itdOut, loopMergingInfo.GetDebugInfo(this)); hasDebugInfo = true; } isTopLevel = true; return(base.DoConvertMethod(md, imd)); }
protected override IMethodDeclaration ConvertMethod(IMethodDeclaration imd) { if (MethodToTransform != null) { MethodBase mb = Builder.ToMethod(imd); if (mb != MethodToTransform) { return(null); } } return(base.ConvertMethod(imd)); }
public static bool IsAvailable([CanBeNull] IMethodDeclaration methodDeclaration) { if (methodDeclaration == null) { return(false); } var declaredElement = methodDeclaration.DeclaredElement; return(declaredElement != null && methodDeclaration.IsValid() && !BurstCodeAnalysisUtil.IsBurstProhibitedFunction(declaredElement)); }
private static ArgumentList buildArguments(IMethodDeclaration method, String cmdLineArgs) { ArgumentList arguments = new ArgumentList(); if (method.getParameters().Count == 1) { String name = method.getParameters()[0].GetName(); IExpression value = parseCmdLineArgs(cmdLineArgs); arguments.Add(new Argument(new UnresolvedParameter(name), value)); } return(arguments); }
private void SynthesizeBody(IMethodDeclaration methodDecl, MethodDeclarationSyntax methodSyntax) { pdCache.Clear(); vdCache.Clear(); foreach (var paramDecl in methodDecl.Parameters) { pdCache[paramDecl.Name] = paramDecl; } methodDecl.Body = ConvertBlock(methodSyntax.Body); pdCache.Clear(); vdCache.Clear(); }
public static bool IsAsyncSuffixMissing(this IMethodDeclaration methodDeclaration) { if (methodDeclaration.IsOverride) { return(false); } var declaredElement = methodDeclaration.DeclaredElement; if (declaredElement != null) { var memberInstances = declaredElement.GetAllSuperMembers(); if (memberInstances.Count > 0) { return(false); } var settings = methodDeclaration.GetSettingsStore(); var excludeTestMethods = settings.GetValue(AsyncSuffixSettingsAccessor.ExcludeTestMethodsFromAnalysis); if (excludeTestMethods) { if (declaredElement.IsTestMethod() || methodDeclaration.IsAnnotatedWithKnownTestAttribute()) { return(false); } } if (declaredElement.ShortName.EndsWith("Async", StringComparison.Ordinal)) { return(false); } var returnType = declaredElement.ReturnType as IDeclaredType; if (returnType == null) { return(false); } var customAsyncTypeNames = settings.EnumEntryIndices(AsyncSuffixSettingsAccessor.CustomAsyncTypes) .ToArray(); var customAsyncTypes = new List <IDeclaredType>(); customAsyncTypeNames .ForEach(type => customAsyncTypes.Add(TypeFactory.CreateTypeByCLRName(type, declaredElement.Module))); var returnTypeElement = returnType.GetTypeElement(); var isCustomAsyncType = returnTypeElement != null && customAsyncTypes.Any(type => returnTypeElement.IsDescendantOf(type.GetTypeElement())); if (returnType.IsTaskType() || isCustomAsyncType) { return(true); } } return(false); }
public IMethodDeclaration Anonymize(IMethodDeclaration d) { var defaultName = Names.UnknownMethod; var isDefaultName = defaultName.Equals(d.Name); return(new MethodDeclaration { Name = isDefaultName ? defaultName : d.Name.ToAnonymousName(), IsEntryPoint = d.IsEntryPoint, Body = _statementAnon.Anonymize(d.Body) }); }
public static ICollection GetMethods(ITypeDeclaration value, IVisibilityConfiguration visibility) { IMethodDeclarationCollection methods = value.Methods; ICollection result; if (methods.Count > 0) { ArrayList arrayList = new ArrayList(0); foreach (object obj in methods) { IMethodDeclaration value2 = (IMethodDeclaration)obj; if (visibility == null || IsVisible(value2, visibility)) { arrayList.Add(value2); } } foreach (object obj2 in value.Properties) { IPropertyDeclaration propertyDeclaration = (IPropertyDeclaration)obj2; if (propertyDeclaration.SetMethod != null) { arrayList.Remove(propertyDeclaration.SetMethod.Resolve()); } if (propertyDeclaration.GetMethod != null) { arrayList.Remove(propertyDeclaration.GetMethod.Resolve()); } } foreach (object obj3 in value.Events) { IEventDeclaration eventDeclaration = (IEventDeclaration)obj3; if (eventDeclaration.AddMethod != null) { arrayList.Remove(eventDeclaration.AddMethod.Resolve()); } if (eventDeclaration.RemoveMethod != null) { arrayList.Remove(eventDeclaration.RemoveMethod.Resolve()); } if (eventDeclaration.InvokeMethod != null) { arrayList.Remove(eventDeclaration.InvokeMethod.Resolve()); } } arrayList.Sort(); result = arrayList; } else { result = new IMethodDeclaration[0]; } return(result); }
protected override void ProcessMethodBody(IMethodDeclaration methodDecl, UsageContext context) { base.ProcessMethodBody(methodDecl, context); if (context.TargetType != null) { _matchingQuery = context.AllQueries.First(q => context.TargetType.Equals(q.type)); // prevent traversion of the complete SST throw new CompletionPointFoundException(); } }
public static MethodRef CreateLocalReference(IMethodName methodName, IMethod method, IMethodDeclaration methodDecl) { return(new MethodRef { Name = methodName, Declaration = methodDecl, Method = method, IsAssemblyReference = false }); }
public static bool IsBaseMethod(IMethodReference value, IMethodReference baseMethod) { bool result; if (value.Name != baseMethod.Name) { result = false; } else { if (value.GenericMethod != null) { value = value.GenericMethod; } if (baseMethod.GenericMethod != null) { baseMethod = baseMethod.GenericMethod; } if (!value.ReturnType.Type.Equals(baseMethod.ReturnType.Type)) { result = false; } else if (value.HasThis != baseMethod.HasThis && value.ExplicitThis != baseMethod.ExplicitThis && value.CallingConvention != baseMethod.CallingConvention) { result = false; } else if (value.Parameters.Count != baseMethod.Parameters.Count) { result = false; } else { for (int i = 0; i < value.Parameters.Count; i++) { if (!value.Parameters[i].ParameterType.Equals(baseMethod.Parameters[i].ParameterType)) { return(false); } } if (value.GenericArguments.Count != baseMethod.GenericArguments.Count) { result = false; } else { IMethodDeclaration methodDeclaration = value.Resolve(); IMethodDeclaration methodDeclaration2 = baseMethod.Resolve(); result = (methodDeclaration != null && methodDeclaration2 != null && methodDeclaration.Virtual && methodDeclaration2.Virtual && IsBaseType(methodDeclaration.DeclaringType, methodDeclaration2.DeclaringType)); } } } return(result); }
protected void AssertBody(IMethodDeclaration method, IKaVEList <IStatement> body) { if (!body.Equals(method.Body)) { Console.WriteLine("AssertBody failed!"); Console.WriteLine("\n-- expected body --\n"); Console.WriteLine(body.ToString()); Console.WriteLine("\n-- actual body --\n"); Console.WriteLine(method.Body.ToString()); Assert.Fail(); } }
public InvalidSignatureFix(InvalidSignatureWarning warning) { myEventFunction = warning.Function; myMethodDeclaration = warning.MethodDeclaration; var parameters = string.Join(", ", myEventFunction.Parameters.Select(p => string.Format("{0} {1}", CreateParameterType(p).GetPresentableName(myMethodDeclaration.Language), p.Name))); Text = $"Change parameters to '({parameters})'"; }
/// <summary> /// Analyses the method specified in MethodToTransform, if any. Otherwise analyses all methods. /// </summary> /// <param name="imd"></param> /// <returns></returns> protected override IMethodDeclaration ConvertMethod(IMethodDeclaration imd) { IMethodDeclaration imd2 = base.ConvertMethod(imd); ITypeDeclaration td = context.FindOutputForAncestor <ITypeDeclaration, ITypeDeclaration>(); //td.Documentation = "model '"+imd.Name+"'"; if (inferCount == 0) { Error("No variables were marked for inference, please mark some variables with InferNet.Infer(var)."); } return(imd2); }
public static IEnumerable <ShowBurstCallsBulbAction> GetBurstCallsActions(IMethodDeclaration methodDeclaration) { var incoming = new ShowBurstCallsBulbAction(methodDeclaration, ShowCallsType.INCOMING); // var outgoing = new ShowBurstCallsBulbAction(methodDeclaration, ShowCallsType.OUTGOING); return(new[] { incoming // , outgoing }); }
/// <summary> /// Find a matching method in the Cecil object model for a given Reflector method /// </summary> /// <param name="typedef">Cecil type definition</param> /// <param name="type">Reflector method declaration</param> /// <returns>Cecil method definition (null if not found)</returns> internal static MethodDefinition FindMatchingMethod(TypeDefinition typedef, IMethodDeclaration type) { foreach (MethodDefinition retMethod in typedef.Methods) { if (MethodMatches(retMethod, type)) { return(retMethod); } } return(null); }
public InvalidReturnTypeFix(InvalidReturnTypeWarning warning) { var eventFunction = warning.Function; myMethodDeclaration = warning.MethodDeclaration; myReturnType = TypeFactory.CreateTypeByCLRName(eventFunction.ReturnType, myMethodDeclaration.GetPsiModule()); if (eventFunction.ReturnTypeIsArray) { myReturnType = TypeFactory.CreateArrayType(myReturnType, 1); } }
protected override IExpression ConvertArgumentRef(IArgumentReferenceExpression iare) { IParameterDeclaration ipd = iare.Parameter.Resolve(); IMethodDeclaration imd = context.FindAncestor <IMethodDeclaration>(); int index = imd.Parameters.IndexOf(ipd); if (index == -1) { Error("Parameter value not found for '" + iare.Parameter.Name + "'."); return(iare); } return(Builder.LiteralExpr(args[index])); }
protected override IMethodDeclaration ConvertMethod(IMethodDeclaration imd) { MethodBase mb = Builder.ToMethod(imd); if (mb != MethodToTransform) { return(null); } IMethodDeclaration md = (IMethodDeclaration)base.ConvertMethod(imd); md.Parameters.Clear(); return(md); }
private static void ChangeAnnotationAttribute(IMethodDeclaration methodDeclaration, string toReplace, ITypeElement replacement) { var toReplaceAttribute = methodDeclaration.Attributes .FirstOrDefault(a => string.Compare(a.Name.QualifiedName, toReplace, StringComparison.InvariantCultureIgnoreCase) == 0); if (toReplaceAttribute != null && replacement != null) { var annotation = CSharpAnnotationsUtil.Annotate(methodDeclaration, replacement); if (annotation.Status == CSharpAnnotationsUtil.Status.AnnotationInserted) { methodDeclaration.RemoveAttribute(toReplaceAttribute); } } }
public Snapshot EatUnitTest(IMethodDeclaration unitTest) { var snapshot = new Snapshot(unitTest); foreach (var parameterDeclaration in unitTest.ParameterDeclarations) { _eater.Eat(snapshot, parameterDeclaration); } _eater.Eat(snapshot, unitTest.Body); return snapshot; }
protected override bool CheckCallGraph(IMethodDeclaration methodDeclaration, IReadOnlyCallGraphContext context) { var callGraphReady = UnityCallGraphUtil.IsCallGraphReady(myConfiguration); if (!callGraphReady) { return(false); } var declaredElement = methodDeclaration.DeclaredElement; return(myExpensiveContextProvider.IsMarkedStage(declaredElement, context)); }
public override IType check(Context context) { IMethodDeclaration declaration = getDeclaration(context); if (declaration != null) { return(new MethodType(declaration)); } else { throw new SyntaxError("Not a method:" + expression.ToString()); } }
public Snapshot EatUnitTest(IMethodDeclaration unitTest) { var snapshot = new Snapshot(unitTest); foreach (var parameterDeclaration in unitTest.ParameterDeclarations) { _eater.Eat(snapshot, parameterDeclaration); } _eater.Eat(snapshot, unitTest.Body); return(snapshot); }
public IEnumerable <BulbMenuItem> GetMenuItems(IMethodDeclaration methodDeclaration, ITextControl textControl, IReadOnlyCallGraphContext context) { methodDeclaration.GetPsiServices().Locks.AssertReadAccessAllowed(); if (!CheckCallGraph(methodDeclaration, context)) { return(EmptyList <BulbMenuItem> .Enumerable); } var result = GetActions(methodDeclaration, textControl); return(result); }
public static DocumentRange GetTypeParametersOrMethodNameHighlightingRange(IMethodDeclaration methodDeclaration) { var typeParameterList = methodDeclaration.TypeParameterList; if (typeParameterList == null) { return(methodDeclaration.GetNameDocumentRange()); } var documentRange = typeParameterList.GetDocumentRange(); return(documentRange.IsValid() ? documentRange : methodDeclaration.GetNameDocumentRange()); }
protected internal MethodCallFormulaRef( IFormulaRef instance, IMethodDeclaration method, Collection<IFormulaRef> arguments, ITypeDeclaration type, IFormulaRef parent) : base(instance, method, arguments.ToReadOnlyWithCast<IFormula>(), type, parent) { this.parent = parent; this.instance = instance; this.arguments = arguments; }
/// <summary> /// Creates the normalize method definition. /// </summary> /// <param name="methodDefinition">The method definition.</param> /// <returns>A new NormalizeMethodDefinition instance, based on the input.</returns> internal static NormalizeMethodDefinition CreateNormalizeMethodDefinition(IMethodDeclaration methodDefinition) { if (methodDefinition == null) { throw new ArgumentNullException("methodDefinition"); } ITypeReference typeReference = methodDefinition.DeclaringType as ITypeReference; return new NormalizeMethodDefinition( typeReference.Name, typeReference.Namespace, methodDefinition.Name, BuildParameterList(methodDefinition.Parameters), methodDefinition.ReturnType.Type.ToString(), string.Empty); }
/// <summary> /// Determines whether the specified action is available for execution. /// </summary> /// <param name="cache">Ignored.</param> public override bool IsAvailable(IUserDataHolder cache) { // Check that the caret is within method declaration var methodDeclaration = _provider.GetSelectedElement<IMethodDeclaration>(true, true); if (null == methodDeclaration) return false; // Check that the caret is exactly on the method name ITreeNode selectedElement = _provider.SelectedElement; if (null == selectedElement) return false; if (!methodDeclaration.GetNameDocumentRange().Contains(selectedElement.GetDocumentRange())) return false; // Cache method declaration for reuse in the execute method _methodDeclaration = methodDeclaration; return true; }
private static bool IsAnnotatedWithKnownTestAttribute(IMethodDeclaration methodDeclaration) { if (methodDeclaration.AttributeSectionList != null) { foreach (var attribute in methodDeclaration.AttributeSectionList.AttributesEnumerable) { var attributeClass = attribute.Name.Reference.Resolve().DeclaredElement as IClass; if (attributeClass == null) { return false; } var clrTypeName = attributeClass.GetClrName(); if (TestMethodClrAttributes.Contains(clrTypeName)) { return true; } } } return false; }
/// <summary> /// Adds the new call. /// </summary> /// <param name="typeName">Name of the type.</param> /// <param name="methodDefinition">The method definition.</param> /// <param name="callDefinition">The call definition.</param> /// <param name="startMethod">The start method.</param> /// <returns>The IMethodDeclaration based on the given call definition. This provides a means of working through the method's call stack.</returns> internal IMethodDeclaration AddNewCall(string typeName, IMethodDeclaration methodDefinition, object callDefinition, string startMethod) { Logger.Current.Info(typeName); Logger.Current.Info(methodDefinition.Name); Logger.Current.Info(startMethod); if (!Rules.IsValidCall(callDefinition, new CallRules())) { return null; } MethodCallInfo methodInfo = new MethodCallInfo(); methodInfo.StartMethod = startMethod; methodInfo.TypeName = typeName; methodInfo.MethodName = ReflectorHelper.CreateNormalizeMethodDefinition(methodDefinition).ToString(); methodDefinition = callDefinition as IMethodDeclaration; IMethodReference methodReference = callDefinition as IMethodReference; if (methodDefinition != null || methodReference != null) { NormalizeMethodDefinition norm = null; if (methodDefinition == null) { norm = ReflectorHelper.CreateNormalizeMethodDefinition(methodReference); } else { norm = ReflectorHelper.CreateNormalizeMethodDefinition(methodDefinition); } methodInfo.MethodCallType = norm.DeclaringTypeFullName; methodInfo.MethodCallNamespace = norm.DeclaringTypeNamespace; methodInfo.MethodCallName = norm.ToString(); this.MethodCallList.Add(methodInfo); } return methodDefinition; }
public MethodInfo Method(IMethodDeclaration method, TypeInfo type) { if (_methodCorrespondence.ContainsKey(method)) { return _methodCorrespondence[method]; } var methodInfo = new MethodInfo { Text = method.ToString(), Name = method.Name, FullName = method.Name, IsInternal = method.Visibility == MethodVisibility.Assembly, IsPrivate = method.Visibility == MethodVisibility.Private, IsPublic = method.Visibility == MethodVisibility.Public, IsProtected = method.Visibility == MethodVisibility.Family, IsProtectedAndInternal = method.Visibility == MethodVisibility.FamilyAndAssembly, IsProtectedOrInternal = method.Visibility == MethodVisibility.FamilyOrAssembly, IsVirtual = method.Virtual, IsOverride = method.Virtual && !method.NewSlot, IsSpecialName = method.SpecialName, IsStatic = method.Static, IsFinal = method.Final, MemberReference = method, DeclaringType = type }; _methodCorrespondence.Add(method, methodInfo); if (method.Overrides.Count > 0) { var overridden = method.Overrides[0]; var declaringType = overridden.DeclaringType as ITypeReference; if (declaringType.Resolve().Interface) { methodInfo.IsOverride = false; } } int correction = methodInfo.Text.Contains(".ctor") || methodInfo.Text.Contains(".cctor") ? 0 : 1; methodInfo.Text = methodInfo.Text.Substring(methodInfo.Text.LastIndexOf('.') + correction); methodInfo.Name = methodInfo.Name.Substring(methodInfo.Name.LastIndexOf('.') + correction); methodInfo.Icon = Images.Images.GetMethodIcon(methodInfo); return methodInfo; }
/// <summary> /// Visits the method declaration. /// </summary> /// <param name="methodDeclaration">The method declaration.</param> /// <param name="consumer">The consumer.</param> /// <returns></returns> public override object VisitMethodDeclaration(IMethodDeclaration methodDeclaration, IHighlightingConsumer consumer) { this.VisitTypeMember(methodDeclaration, consumer); return base.VisitMethodDeclaration(methodDeclaration, consumer); }
public static ITypeAsFormulaRef TypeAs(ITypeDeclaration type, IFormulaRef operand, IMethodDeclaration method, IFormulaRef parent) { return new TypeAsFormulaRef(type, operand, method, parent); }
private static bool MethodMatches(MethodDefinition mdef, IMethodDeclaration itype) { if (mdef == null || itype == null) return false; if (!IsSameName(mdef.Name, itype.Name) || mdef.Parameters.Count != itype.Parameters.Count || !TypeMatches(mdef.ReturnType, itype.ReturnType.Type)) return false; // Compatible with code alteration feature !!! // Called only the first time then in cache, so even if code is altered, this will work if ((itype.Body is IMethodBody) && (mdef.Body != null)) { if ((itype.Body as IMethodBody).Instructions.Count != mdef.Body.Instructions.Count) return false; } else if ((itype.Body != null) ^ (mdef.Body != null)) { // abstract vs default method return false; } // Same than above for parameter alteration for (var i = 0; i <= mdef.Parameters.Count - 1; i++) { if (!TypeMatches(mdef.Parameters[i].ParameterType, itype.Parameters[i].ParameterType)) return false; } return true; }
protected internal AndAlsoFormula(IFormula left, IFormula right, ITypeDeclaration type, IMethodDeclaration method, IFormula parent) : base(NodeType.AndAlso, left, right, type, method, parent) { }
private static bool CorrectReturnType(IMethodDeclaration method) { try { IMethod declaredElement = method.DeclaredElement; IDeclaredType declaredType = declaredElement?.ReturnType as IDeclaredType; if (declaredType == null || declaredType.IsVoid()) return false; ISubstitution sub = declaredType.GetSubstitution(); if (sub.IsEmpty()) return false; IType parameterType = sub.Apply(sub.Domain[0]); IType realType = declaredElement.Type(); PredefinedType predefinedType = declaredElement.Module.GetPredefinedType(); ITypeElement generic = predefinedType.GenericList.GetTypeElement(); IType sampleType = EmptySubstitution.INSTANCE .Extend(generic.TypeParameters, new IType[] { parameterType }) .Apply(predefinedType.GenericList); bool good = realType.IsImplicitlyConvertibleTo(sampleType, new CSharpTypeConversionRule(declaredElement.Module)); return good; } catch (Exception e) { Debug.WriteLine(e.ToString()); throw; } }
/// <summary> /// Swap return type to built in type. /// </summary> /// <param name="methodDeclaration"> /// The method declaration. /// </param> private static void SwapReturnTypeToBuiltInType(IMethodDeclaration methodDeclaration) { using (WriteLockCookie.Create(true)) { methodDeclaration.SetType(methodDeclaration.GetReturnType()); } }
public ConsiderUsingAsyncSuffixHighlighting(IMethodDeclaration methodDeclaration) { MethodDeclaration = methodDeclaration; }
/// <summary> /// Checks method comment blocks. /// </summary> /// <param name="methodDeclaration"> /// The method <see cref="IDeclaration"/> to check. /// </param> /// <param name="options"> /// <see cref="OrderingOptions"/>Current options that we can reference. /// </param> private void CheckMethodDeclarationDocumentation(IMethodDeclaration methodDeclaration, DocumentationOptions options) { Param.RequireNotNull(options, "options"); if (methodDeclaration == null) { return; } bool insertMissingParamTagOption = options.SA1611ElementParametersMustBeDocumented; bool insertMissingReturnTagOption = options.SA1615ElementReturnValueMustBeDocumented; bool removeReturnTagOnVoidElementsOption = options.SA1617VoidReturnValueMustNotBeDocumented; if (insertMissingParamTagOption && !Utils.IsRuleSuppressed(methodDeclaration, StyleCopRules.SA1611)) { if (methodDeclaration.ParameterDeclarations.Count > 0) { this.InsertMissingParamElement(methodDeclaration); } } DeclaredTypeFromCLRName declaredTypeFromCLRName = methodDeclaration.GetReturnType() as DeclaredTypeFromCLRName; if (removeReturnTagOnVoidElementsOption && !Utils.IsRuleSuppressed(methodDeclaration, StyleCopRules.SA1617)) { // Remove the <returns> if the return type is void if (declaredTypeFromCLRName != null && declaredTypeFromCLRName.GetClrName().FullName == "System.Void") { this.RemoveReturnsElement(methodDeclaration); } } if (insertMissingReturnTagOption && !Utils.IsRuleSuppressed(methodDeclaration, StyleCopRules.SA1615)) { // Insert the <returns> if the return type is not void and it was missing if (declaredTypeFromCLRName != null && declaredTypeFromCLRName.GetClrName().FullName != "System.Void") { this.InsertReturnsElement(methodDeclaration); } } }
public static IConvertFormulaRef Convert(ITypeDeclaration type, IFormulaRef operand, IMethodDeclaration method, IFormulaRef parent) { return new ConvertFormulaRef(type, operand, method, parent); }
private void AddStatementAfter(IMethodDeclaration method, ICSharpStatement statement, ICSharpStatement addAfter) { method.Body.AddStatementAfter(statement, addAfter); }
private static bool ParametersMatch(IMethodDeclaration method1, IMethodDeclaration method2) { if (method1.Parameters.Count != method2.Parameters.Count) { return false; } for (int i = 0; i < method1.Parameters.Count; i++) { if (method1.Parameters[i].ParameterType != method2.Parameters[i].ParameterType) { return false; } } return true; }
internal static MethodDefinition FindMatchingMethod(TypeDefinition typedef, IMethodDeclaration type) { return typedef.Methods.FirstOrDefault(retMethod => MethodMatches(retMethod, type)); }
private void AddContractInvariantAttribute(IMethodDeclaration method) { ITypeElement type = TypeFactory.CreateTypeByCLRName( typeof(ContractInvariantMethodAttribute).FullName, _provider.PsiModule, _currentFile.GetResolveContext()).GetTypeElement(); var attribute = _factory.CreateAttribute(type); method.AddAttributeBefore(attribute, null); }
MethodContractInfo([NotNull] IMethodDeclaration declaration, [NotNull] IType type) : base(ContractKind.Ensures, type) { this.declaration = declaration; }
public static IMethodCallFormulaRef Call(IFormulaRef instance, IMethodDeclaration method, Collection<IFormulaRef> arguments, ITypeDeclaration type, IFormulaRef parent) { return new MethodCallFormulaRef(instance, method, arguments, type, parent); }