private void AppendTypeElement([NotNull] ITypeElement typeElement, [NotNull] ISubstitution substitution, QualifierDisplays expectedQualifierDisplay, Context context) { if (!(typeElement is ITypeParameter) && (context.Options.ShowQualifiers & expectedQualifierDisplay) != QualifierDisplays.None) { INamespace containingNamespace = typeElement.GetContainingNamespace(); AppendNamespace(containingNamespace); if (!containingNamespace.IsRootNamespace) { AppendText(".", _highlighterIdProvider.Operator); } ITypeElement containingType = typeElement.GetContainingType(); if (containingType != null && !(typeElement is IDelegate && context.Options.FormatDelegatesAsLambdas)) { AppendDeclaredType(TypeFactory.CreateType(containingType, substitution), QualifierDisplays.None, context); AppendText(".", _highlighterIdProvider.Operator); } } var deleg = typeElement as IDelegate; if (deleg != null && context.Options.FormatDelegatesAsLambdas && expectedQualifierDisplay == QualifierDisplays.Parameters) { AppendParameters(deleg.InvokeMethod, substitution, false, context); AppendText(" => ", _highlighterIdProvider.Operator); AppendTypeWithoutModule(substitution.Apply(deleg.InvokeMethod.ReturnType), expectedQualifierDisplay, context); return; } string highlighterId = _highlighterIdProvider.GetForTypeElement(typeElement); AppendText(FormatShortName(typeElement.ShortName), highlighterId); AppendTypeParameters(typeElement, substitution, context); }
/// <summary> /// Applies backwards the relevant operator effects and operator preconditions to the given target conditions. /// </summary> /// <param name="conditions">Target conditions to be modified.</param> /// <param name="operatorSubstitution">Variables substitution.</param> /// <returns>Preceding conditions.</returns> public IConditions ApplyBackwards(IConditions conditions, ISubstitution operatorSubstitution) { ConditionsCNF expression = (ConditionsCNF)conditions?.GetCNF(); if (expression == null) { return(null); } OperatorSubstitution = operatorSubstitution; Effects.GroundEffectsByCurrentOperatorSubstitution(GroundingManager, operatorSubstitution); if (expression.Parameters != null) { EffectsRelevanceConditionsEvaluator evaluator = new EffectsRelevanceConditionsEvaluator(Effects, GroundingManager); List <ConditionsCNF> subResults = new List <ConditionsCNF>(); IEnumerable <ISubstitution> expressionSubstitutions = GroundingManager.GenerateAllLocalSubstitutions(expression.Parameters); expression.Parameters = null; foreach (var expressionSubstitution in expressionSubstitutions) { // do backward apply only when the effects are relevant to the current grounding of the expression if (evaluator.Evaluate(expression, operatorSubstitution, expressionSubstitution)) { subResults.Add(ApplyBackwardsImpl(expression, expressionSubstitution)); } } return(ConstructCNFFromDisjunction(subResults)); } return(ApplyBackwardsImpl(expression, new Substitution())); }
/// <summary> /// Returns a string containing declared element text presentation made according to this presenter settings. /// This method is usefull when additional processing is required for the returned string, /// e.g. as is done in the following method: /// /// <code> /// RichText Foo(IMethod method) /// { /// DeclaredElementPresenterMarking marking; /// RichTextParameters rtp = new RichTextParameters(ourFont); /// // make rich text with declared element presentation /// RichText result = new RichText(ourInvocableFormatter.Format(method, out marking),rtp); /// // highlight name of declared element in rich text /// result.SetColors(SystemColors.HighlightText,SystemColors.Info,marking.NameRange.StartOffset,marking.NameRange.EndOffset); /// return result; /// } /// </code> /// </summary> /// <param name="style">The style.</param> /// <param name="element">Contains <see cref="T:JetBrains.ReSharper.Psi.IDeclaredElement" /> to provide string presentation of.</param> /// <param name="substitution">The substitution.</param> /// <param name="marking">Returns the markup of the string with a <see cref="T:JetBrains.ReSharper.Psi.IDeclaredElement" /> presentation.</param> /// <returns>System.String.</returns> public string Format(DeclaredElementPresenterStyle style, IDeclaredElement element, ISubstitution substitution, out DeclaredElementPresenterMarking marking) { marking = new DeclaredElementPresenterMarking(); var itemDeclaredElement = (IItemDeclaredElement)element; var sb = new StringBuilder(); if (style.ShowEntityKind != EntityKindForm.NONE) { marking.EntityKindRange = AppendString(sb, style.ShowEntityKind == EntityKindForm.NORMAL_IN_BRACKETS ? "[Item] " : "Item "); } if (style.ShowName != NameStyle.NONE) { if (style.ShowNameInQuotes) { sb.Append('"'); } marking.NameRange = style.ShowName == NameStyle.SHORT || style.ShowName == NameStyle.SHORT_RAW ? AppendString(sb, itemDeclaredElement.ShortName) : AppendString(sb, itemDeclaredElement.ItemName); if (style.ShowNameInQuotes) { sb.Append('"'); } } return sb.ToString(); }
private static StringBuilder AppendType(this StringBuilder identifier, ITypeElement type, ISubstitution substitution, IDictionary <DeclaredElementInstance, IName> seenElements) { return(identifier.Append('[').Append(type.GetName(substitution, seenElements).Identifier).Append(']')); }
public MethodInvocation(IReference reference, IType type, IMethod method, ISubstitution substitution) { Reference = reference; Type = type; Method = method; Substitution = substitution; }
public override bool Accepts(IDeclaredElement declaredElement, ISubstitution substitution) { if (myMode == EventHandlerArgumentMode.Unknown) { return(false); } if (myMode != EventHandlerArgumentMode.None && myType == null) { return(false); } if (!(declaredElement is IMethod method)) { return(false); } var parameters = method.Parameters; if (parameters.Count == 0 && myType == null) { return(true); } if (parameters.Count == 1) { var param = parameters[0]; return(param.Type.Equals(myType)); } return(false); }
private static TN IfElementIs <TN, TE>(IDeclaredElement element, DeclaredElementToName <TN, TE> map, ISubstitution substitution, TN unknownName, IDictionary <DeclaredElementInstance, IName> seenElements) where TE : class, IDeclaredElement where TN : class, IName { var specificElement = element as TE; if (specificElement == null) { return(null); } var dei = new DeclaredElementInstance(element, substitution); // exit if we encounter a recursive type, e.g., delegate IList<D> D(); if (seenElements.ContainsKey(dei)) { return((TN)seenElements[dei]); } // this makes us default to the unknownName, if we reencounter an element while resolving it seenElements[dei] = unknownName; // after this call we have resolved the element and cached the result seenElements[dei] = IsMissingDeclaration(specificElement) ? unknownName : map(specificElement, substitution, seenElements); return((TN)seenElements[dei]); }
public static DeclaredElementInstance <IMethod> ResolveMethod( [NotNull] this ICSharpInvocationReference invocationRef) { var resolvedRef = invocationRef.Resolve().Result; IMethod declaration = null; ISubstitution substitution = null; if (resolvedRef.DeclaredElement != null) { declaration = resolvedRef.DeclaredElement as IMethod; substitution = resolvedRef.Substitution; if (declaration == null) { var prop = resolvedRef.DeclaredElement as IProperty; } } else if (!resolvedRef.Candidates.IsEmpty()) { // TODO reconsider this, maybe switch to "invocations" as analysis result, where an invocation can have zero, one, or more methods as its target declaration = (IMethod)resolvedRef.Candidates.First(); substitution = resolvedRef.CandidateSubstitutions.First(); } if (declaration != null) { return(new DeclaredElementInstance <IMethod>(declaration, substitution)); } return(null); }
public DistributionTable(ISubstitution substitution) { _substitution = substitution; Table = new Dictionary <byte, Dictionary <byte, byte> >(); CreateTable(); }
public override bool Accepts(IDeclaredElement declaredElement, ISubstitution substitution) { var typeElement = declaredElement as ITypeElement; if (typeElement == null) { return(!myMustBeClass); } if (myKind == ExpectedObjectTypeReferenceKind.Component) { // User components must derive from MonoBehaviour, but built in components only have to derive from // Component. A built in component will be something that isn't an asset, which means it's come from // one of the UnityEngine assemblies, or UnityEditor.dll. Another check might be that the referenced // module lives in Assets, but packages makes a mess of that (referenced packages are compiled and // referenced from Library or local packages can include a dll as an asset, external to the project) myIsBuiltin = typeElement.IsBuiltInUnityClass(); if (myIsBuiltin) { return(typeElement.DerivesFrom(KnownTypes.Component)); } return(typeElement.DerivesFrom(KnownTypes.MonoBehaviour)); } return(typeElement.DerivesFrom(KnownTypes.ScriptableObject)); }
/// <summary> /// Evaluates whether the operator effects are relevant for the specified relative state. /// </summary> /// <param name="relativeState">Relative state.</param> /// <param name="operatorSubstitution">Variables substitution of the operator.</param> /// <param name="relevantConditionalEffects">Output indices of relevant conditional effects (can be null).</param> /// <returns>Effect relevance (relevant, irrelevant, or anti-relevant).</returns> private EffectRelevance EvaluateInternal(IRelativeState relativeState, ISubstitution operatorSubstitution, IList <int> relevantConditionalEffects = null) { Effects.GroundEffectsByCurrentOperatorSubstitution(GroundingManager, operatorSubstitution); OperatorSubstitution = operatorSubstitution; var primitivesResult = ProcessPrimitiveEffects(relativeState); if (primitivesResult == EffectRelevance.ANTI_RELEVANT) { return(EffectRelevance.ANTI_RELEVANT); } var forallResult = ProcessForallEffects(relativeState); if (forallResult == EffectRelevance.ANTI_RELEVANT) { return(EffectRelevance.ANTI_RELEVANT); } var whenResult = ProcessWhenEffects(relativeState, relevantConditionalEffects); if (whenResult == EffectRelevance.ANTI_RELEVANT) { return(EffectRelevance.ANTI_RELEVANT); } if (primitivesResult == EffectRelevance.RELEVANT || forallResult == EffectRelevance.RELEVANT || whenResult == EffectRelevance.RELEVANT) { return(EffectRelevance.RELEVANT); } return(EffectRelevance.IRRELEVANT); }
private void AppendTypeElement([NotNull] ITypeElement typeElement, [NotNull] ISubstitution substitution, NamespaceDisplays expectedNamespaceDisplay) { if (!(typeElement is ITypeParameter)) { if ((_options.ShowNamespaces & expectedNamespaceDisplay) != NamespaceDisplays.None) { AppendNamespace(typeElement.GetContainingNamespace()); AppendText(".", VsHighlightingAttributeIds.Operator); } ITypeElement containingType = typeElement.GetContainingType(); if (containingType != null && !(typeElement is IDelegate && _options.FormatDelegatesAsLambdas)) { AppendDeclaredType(TypeFactory.CreateType(containingType, substitution), NamespaceDisplays.None); AppendText(".", VsHighlightingAttributeIds.Operator); } } var deleg = typeElement as IDelegate; if (deleg != null && _options.FormatDelegatesAsLambdas && expectedNamespaceDisplay == NamespaceDisplays.Parameters) { AppendParameters(deleg.InvokeMethod, substitution, false); AppendText(" => ", VsHighlightingAttributeIds.Operator); AppendType(substitution.Apply(deleg.InvokeMethod.ReturnType), expectedNamespaceDisplay); return; } string attributeId = _options.UseReSharperColors ? HighlightingAttributeIds.GetHighlightAttributeForTypeElement(typeElement) : VsHighlightingAttributeIds.GetForTypeElement(typeElement); AppendText(FormatShortName(typeElement.ShortName), attributeId); AppendTypeParameters(typeElement, substitution); }
/// <summary> /// Grounds the conditions by the specified substitution. /// </summary> /// <param name="conditions">Conditions.</param> /// <param name="substitution">Variable substitution.</param> /// <returns>Grounded conditions.</returns> public Conditions Ground(Conditions conditions, ISubstitution substitution) { // (partially) ground the whole conditions by the specified substitution Conditions newConditions = conditions.CloneEmpty(); foreach (var expression in conditions) { newConditions.Add(ExpressionsGrounder.Value.Ground(expression, substitution)); } // for partially lifted conditions - remove parameters that were grounded by the substitution if (conditions.Parameters != null) { newConditions.Parameters.Clear(); foreach (var parameter in conditions.Parameters) { if (!substitution.Contains(parameter.ParameterNameId)) { newConditions.Parameters.Add(parameter.Clone()); } } // if the conditions are fully grounded, set the parameters as null if (newConditions.Parameters.Count == 0) { newConditions.Parameters = null; } } return(newConditions); }
public override bool Accepts(IDeclaredElement declaredElement, ISubstitution substitution) { var method = declaredElement as IMethod; if (method == null) { return(false); } if (!Equals(myMethodSignature.ReturnType, method.ReturnType)) { return(false); } if (myMethodSignature.Parameters.Length != method.Parameters.Count) { return(false); } for (var i = 0; i < method.Parameters.Count; i++) { if (!Equals(myMethodSignature.Parameters[i].Type, method.Parameters[i].Type)) { ITypeConversionRule rule = method.Module.GetTypeConversionRule(); if (!rule.IsImplicitlyConvertibleTo(method.Parameters[i].Type, myMethodSignature.Parameters[i].Type)) { return(false); } } } return(true); }
private void AppendNameWithContainer([NotNull] IDeclaredElement element, [NotNull] ISubstitution substitution, [CanBeNull] string highlightingAttributeId) { var typeElement = element as ITypeElement; if (typeElement != null) { AppendTypeElement(typeElement, substitution, NamespaceDisplays.Member); return; } var ns = element as INamespace; if (ns != null) { AppendNamespace(ns); return; } var typeMember = element as ITypeMember; if (typeMember != null) { ITypeElement containingTypeElement = typeMember.GetContainingType(); if (containingTypeElement != null) { AppendTypeElement(containingTypeElement, substitution, NamespaceDisplays.Member); AppendText(".", VsHighlightingAttributeIds.Operator); } } AppendName(element, highlightingAttributeId); }
public override bool Accepts(IDeclaredElement declaredElement, ISubstitution substitution) { if (myMode != EventHandlerArgumentMode.Void && myMode != EventHandlerArgumentMode.EventDefined && myTypes.Count == 0) { return(false); } if (!(declaredElement is IMethod method)) { return(false); } // Since Unity 2018.4+ we don't know the type of the event if (myMode == EventHandlerArgumentMode.EventDefined && myTypes.Count == 0) { return(true); } var parameters = method.Parameters; if (parameters.Count == myTypes.Count) { for (var i = 0; i < myTypes.Count; i++) { if (!parameters[i].Type.Equals(myTypes[i])) { return(false); } } return(true); } return(false); }
public PresentedInfo AppendDeclaredElement(IDeclaredElement element, ISubstitution substitution, PresenterOptions options) { var context = new Context(options, new PresentedInfo()); if (!IsClrPresentableElement(element)) { return(context.PresentedInfo); } if (options.ShowElementKind != ElementKindDisplay.None) { AppendElementKind(element, context, options.ShowElementKind == ElementKindDisplay.Stylized); } if (options.ShowAccessRights) { AppendAccessRights(element, true); } if (options.ShowModifiers) { AppendModifiers(element); } var attributesSet = element as IAttributesSet; if (attributesSet != null) { AppendAnnotations(attributesSet, options.ShowElementAnnotations); } if (options.ShowElementType == ElementTypeDisplay.Before) { AppendElementType(element, substitution, QualifierDisplays.ElementType, null, " ", context); } if (options.ShowName) { AppendNameWithContainer(element, substitution, context); } if (options.ShowParametersType || options.ShowParametersName) { AppendParameters(element, substitution, true, context); } if (options.ShowElementType == ElementTypeDisplay.After) { AppendElementType(element, substitution, QualifierDisplays.ElementType, ":", null, context); } if (options.ShowConstantValue) { var constantValueOwner = element as IConstantValueOwner; if (constantValueOwner != null) { AppendConstantValue(constantValueOwner, true); } } return(context.PresentedInfo); }
/// <summary> /// Grounds the atom. /// </summary> /// <param name="atom">Function or predicate atom.</param> /// <param name="substitution">Variables substitution.</param> /// <returns>Grounded atom.</returns> public IAtom GroundAtom(IAtom atom, ISubstitution substitution) { List <ITerm> groundedTerms = new List <ITerm>(); atom.GetTerms().ForEach(term => groundedTerms.Add(GroundTerm(term, substitution))); return(new Atom(atom.GetNameId(), groundedTerms)); }
/// <summary> /// Grounds the atom. The "deep" version of terms grounding is used. /// </summary> /// <param name="atom">Function or predicate atom.</param> /// <param name="substitution">Variables substitution.</param> /// <param name="referenceState">Reference state.</param> /// <returns>Grounded atom.</returns> public IAtom GroundAtomDeep(IAtom atom, ISubstitution substitution, IState referenceState) { List <ITerm> groundedTerms = new List <ITerm>(); atom.GetTerms().ForEach(term => groundedTerms.Add(GroundTermDeep(term, substitution, referenceState))); return(new Atom(atom.GetNameId(), groundedTerms)); }
private void AppendElementType([NotNull] IDeclaredElement element, [NotNull] ISubstitution substitution, NamespaceDisplays namespaceDisplays, [CanBeNull] string before, [CanBeNull] string after) { // Use the special type first if available (eg Razor helper), colorize it as a keyword string specialTypeString = CSharpModificationUtil.GetSpecialElementType(_specialTypeStyle, element, substitution); if (!specialTypeString.IsEmpty()) { AppendText(before, null); AppendText(specialTypeString, VsHighlightingAttributeIds.Keyword); AppendText(after, null); return; } IType elementType = GetElementType(element, substitution); if (elementType == null) { return; } AppendText(before, null); AppendType(elementType, namespaceDisplays); AppendText(after, null); }
/// <summary> /// Applies backwards the relevant operator effects and operator preconditions to the given target relative state. /// </summary> /// <param name="relativeState">Target relative state to be modified.</param> /// <param name="operatorSubstitution">Variables substitution.</param> /// <returns>Preceding relative states.</returns> public IEnumerable <Planner.IRelativeState> ApplyBackwards(IRelativeState relativeState, ISubstitution operatorSubstitution) { OperatorSubstitution = operatorSubstitution; Effects.GroundEffectsByCurrentOperatorSubstitution(GroundingManager, operatorSubstitution); relativeState = (IRelativeState)relativeState.Clone(); // prepare operator preconditions var operatorPreconditions = (OperatorPreconditions != null) ? GroundingManager.GroundConditions(ClearRigidRelations(OperatorPreconditions), OperatorSubstitution) : null; // remove positively contributing effects from the relative state and insert the operator preconditions ProcessPrimitiveEffects(relativeState); relativeState = ProcessForallEffects(relativeState); foreach (var resultState in ProcessWhenEffects(relativeState)) { if (operatorPreconditions != null) { foreach (var modifiedResultState in ProcessOperatorPreconditions(operatorPreconditions, resultState)) { yield return(modifiedResultState); } } else { yield return(resultState); } } }
/// <summary> /// Constructs the numeric assignment backwards replacer. /// </summary> /// <param name="numericFunctionAssignments">Numeric function assignments.</param> /// <param name="groundingManager">Grounding manager.</param> /// <param name="operatorSubstitution">Operator substitution.</param> /// <param name="expressionSubstitution">Expression substitution.</param> public NumericAssignmentsBackwardsReplacer(Dictionary <IAtom, INumericExpression> numericFunctionAssignments, GroundingManager groundingManager, ISubstitution operatorSubstitution, ISubstitution expressionSubstitution) { NumericFunctionAssignments = numericFunctionAssignments; GroundingManager = groundingManager; OperatorSubstitution = operatorSubstitution; ExpressionSubstitution = expressionSubstitution; }
private void AppendElementType([NotNull] IDeclaredElement element, [NotNull] ISubstitution substitution, QualifierDisplays expectedQualifierDisplay, [CanBeNull] string before, [CanBeNull] string after, Context context) { // Use the special type first if available (eg Razor helper), colorize it as a keyword string specialTypeString = CSharpModificationUtil.GetSpecialElementType(_specialTypeStyle, element, substitution); if (!specialTypeString.IsEmpty()) { AppendText(before, null); AppendText(specialTypeString, _highlighterIdProvider.Keyword); AppendText(after, null); return; } IType elementType = GetElementType(element, substitution); if (elementType == null) { return; } AppendText(before, null); AppendTypeWithoutModule(elementType, expectedQualifierDisplay, context); AppendText(after, null); }
private static IType GetElementType([NotNull] IDeclaredElement element, [NotNull] ISubstitution substitution) { if (element is IConstructor || CSharpDeclaredElementUtil.IsDestructor(element)) { return(null); } var typeOwner = element as ITypeOwner; if (typeOwner != null) { return(substitution.Apply(typeOwner.Type)); } var parametersOwner = element as IParametersOwner; if (parametersOwner != null) { return(substitution.Apply(parametersOwner.ReturnType)); } var deleg = element as IDelegate; if (deleg != null) { return(substitution.Apply(deleg.InvokeMethod.ReturnType)); } return(null); }
public override bool Accepts(IDeclaredElement declaredElement, ISubstitution substitution) { IModifiersOwner modifiersOwner = declaredElement as IModifiersOwner; if (modifiersOwner == null) return false; return modifiersOwner.GetAccessRights() == AccessRights.PUBLIC || modifiersOwner.GetAccessRights() == AccessRights.PROTECTED; }
public override bool Accepts(IDeclaredElement declaredElement, ISubstitution substitution) { if (!(declaredElement is ITypeElement typeElement)) { return(true); } return(typeElement.TypeParameters.Count == 0); }
/// <summary> /// Evaluates the label of the operator with the specified preconditions and substitution. /// </summary> /// <param name="conditions">Operator conditions.</param> /// <param name="substitution">Variable substitution.</param> /// <param name="stateLabels">Atom labels in the predecessor layer.</param> /// <param name="evaluationStrategy">Evaluation strategy.</param> /// <returns>Operator label value in the relaxed planning graph.</returns> public double Evaluate(ConditionsCNF conditions, ISubstitution substitution, StateLabels stateLabels, ForwardCostEvaluationStrategy evaluationStrategy) { Substitution = substitution; StateLabels = stateLabels; EvaluationStrategy = evaluationStrategy; return(conditions.Accept(this).Item1); }
/// <summary> /// Checks whether the operator is relevant to the given target relative state. /// </summary> /// <param name="relativeState">Target relative state.</param> /// <param name="substitution">Variables substitution.</param> /// <param name="relevantConditionalEffects">Output indices of relevant conditional effects (can be null).</param> /// <returns>True if the operator is relevant to the given relative state, false otherwise.</returns> public bool IsRelevant(IRelativeState relativeState, ISubstitution substitution, IList <int> relevantConditionalEffects = null) { if (!Preconditions.EvaluateRigidRelationsCompliance(substitution)) { return(false); } return(Effects.IsRelevant(relativeState, substitution, relevantConditionalEffects)); }
public override bool Accepts(IDeclaredElement declaredElement, ISubstitution substitution) { if (declaredElement is ITypeElement) { return(declaredElement is IClass); } return(true); }
private static ITypeName GetName(this IStruct structElement, ISubstitution substitution, IDictionary <DeclaredElementInstance, IName> seenElements) { var structName = structElement.GetAssemblyQualifiedName(substitution, seenElements); return(Names.Type("s:{0}", structName)); }
public DeclaredElementInfo([NotNull] IDeclaredElement declaredElement, [NotNull] ISubstitution substitution, [NotNull] IFile file, TextRange sourceRange, [CanBeNull] IReference reference) { DeclaredElement = declaredElement; Substitution = substitution; File = file; SourceRange = sourceRange; Reference = reference; }
private static IName FallbackHandler(IDeclaredElement element, ISubstitution substitution) { var typeName = element.GetType().FullName; var elementName = element.ShortName; var id = string.Format("UnknownDeclaredElement: {0}, '{1}', {2}", typeName, elementName, substitution); return(Names.General(id)); }
private static ILocalVariableName GetName(this ITypeOwner variable, ISubstitution substitution, IDictionary <DeclaredElementInstance, IName> seenElements) { var identifier = new StringBuilder(); identifier.AppendType(variable.Type, seenElements).Append(' ').Append(variable.ShortName); return(Names.LocalVariable(identifier.ToString())); }
protected override string Format(IDeclaredElement declaredElement, ISubstitution substitution, PsiLanguageType languageType, DeclaredElementPresenterStyle presenter, IReference reference) { if (declaredElement == null) return "null"; // Output the element like it is in the QuickDoc - element name + type return DeclaredElementPresenter.Format(JavaScriptLanguage.Instance, XmlDocPresenterUtil.MemberPresentationStyle, declaredElement, EmptySubstitution.INSTANCE); }
public string Format(DeclaredElementPresenterStyle style, IDeclaredElement element, ISubstitution substitution, out DeclaredElementPresenterMarking marking) { marking = new DeclaredElementPresenterMarking(); var ruleDeclaration = element as IRuleDeclaration; if (ruleDeclaration != null) { return ruleDeclaration.RuleName.GetText(); } return element.ShortName; }
///<param name="element">Contains <see cref="T:JetBrains.ReSharper.Psi.IDeclaredElement" /> to provide string presentation of.</param> ///<param name="marking">Returns the markup of the string with a <see cref="T:JetBrains.ReSharper.Psi.IDeclaredElement" /> presentation.</param> ///<summary> /// /// Returns a string containing declared element text presentation made according to this presenter settings. /// This method is usefull when additional processing is required for the returned string, /// e.g. as is done in the following method: /// ///<code> /// /// RichText Foo(IMethod method) /// { /// DeclaredElementPresenterMarking marking; /// RichTextParameters rtp = new RichTextParameters(ourFont); /// // make rich text with declared element presentation /// RichText result = new RichText(ourInvocableFormatter.Format(method, out marking),rtp); /// // highlight name of declared element in rich text /// result.SetColors(SystemColors.HighlightText,SystemColors.Info,marking.NameRange.StartOffset,marking.NameRange.EndOffset); /// return result; /// } /// ///</code> /// ///</summary> /// public string Format(DeclaredElementPresenterStyle style, IDeclaredElement element, ISubstitution substitution, out DeclaredElementPresenterMarking marking) { DeclaredElementPresenterMarking m = new DeclaredElementPresenterMarking(); if (style.ShowName != NameStyle.NONE) { m.NameRange = new TextRange(0, element.ShortName.Length); } marking = m; return element.ShortName; }
public string Format(DeclaredElementPresenterStyle style, IDeclaredElement declaredElement, ISubstitution substitution, out DeclaredElementPresenterMarking marking) { if (!declaredElement.IsValid()) throw new ArgumentException("declaredElement should be valid", "declaredElement"); var nitraDeclaredElement = declaredElement as NitraDeclaredElement; if (nitraDeclaredElement == null) throw new ArgumentException("declaredElement should have language supported by Nitra", "declaredElement"); var result = new StringBuilder(); marking = new DeclaredElementPresenterMarking(); if (style.ShowEntityKind != EntityKindForm.NONE) { string entityKind = GetEntityKindStr(nitraDeclaredElement); if (entityKind != "") { if (style.ShowEntityKind == EntityKindForm.NORMAL_IN_BRACKETS) entityKind = "(" + entityKind + ")"; marking.EntityKindRange = AppendString(result, entityKind); result.Append(" "); } } if (style.ShowNameInQuotes) result.Append("\'"); if (style.ShowName != NameStyle.NONE) { var elementName = nitraDeclaredElement.ShortName; if (elementName == SharedImplUtil.MISSING_DECLARATION_NAME) elementName = "<unknown name>"; marking.NameRange = AppendString(result, elementName); } if (style.ShowNameInQuotes) { if (result[result.Length - 1] == '\'') result.Remove(result.Length - 1, 1); else { TrimString(result); result.Append("\' "); } } TrimString(result); return result.ToString(); }
public string Format( DeclaredElementPresenterStyle style, IDeclaredElement element, ISubstitution substitution, out DeclaredElementPresenterMarking marking) { marking = new DeclaredElementPresenterMarking(); var uriIdentifier = element as IUriIdentifierDeclaredElement; if (uriIdentifier != null) { return uriIdentifier.GetUri(); } return element.ShortName; }
public PresentedInfo AppendDeclaredElement(IDeclaredElement element, ISubstitution substitution, PresenterOptions options) { var context = new Context(options, new PresentedInfo()); if (!IsClrPresentableElement(element)) return context.PresentedInfo; if (options.ShowElementKind) AppendElementKindStylized(element); if (options.ShowAccessRights) AppendAccessRights(element, true); if (options.ShowModifiers) AppendModifiers(element); var attributesSet = element as IAttributesSet; if (attributesSet != null) AppendAnnotations(attributesSet, options.ShowElementAnnotations); if (options.ShowElementType == ElementTypeDisplay.Before) AppendElementType(element, substitution, QualifierDisplays.ElementType, null, " ", context); if (options.ShowName) AppendNameWithContainer(element, substitution, context); if (options.ShowParametersType || options.ShowParametersName) AppendParameters(element, substitution, true, context); if (options.ShowElementType == ElementTypeDisplay.After) AppendElementType(element, substitution, QualifierDisplays.ElementType, ":", null, context); if (options.ShowConstantValue) { var constantValueOwner = element as IConstantValueOwner; if (constantValueOwner != null) AppendConstantValue(constantValueOwner); } return context.PresentedInfo; }
public override bool Accepts(IDeclaredElement declaredElement, ISubstitution substitution) { return ((declaredElement is IProperty) || (declaredElement is IField)); }
protected override string Format(IDeclaredElement declaredElement, ISubstitution substitution, PsiLanguageType languageType, DeclaredElementPresenterStyle presenter, IReference reference) { var format = base.Format(declaredElement, substitution, languageType, presenter, reference); if (declaredElement != null) format += " (" + declaredElement.GetElementType().PresentableName + ")"; return format; }
public override bool Accepts(IDeclaredElement declaredElement, ISubstitution substitution) { return declaredElement.ShortName != PathDeclaredElement.ROOT_NAME; }
///<summary> /// /// Bind this reference to given Declared Element and substitution. May insert using directive. /// ///</summary> /// ///<returns> ///new "this" ///</returns> /// public IReference BindTo(IDeclaredElement element, ISubstitution substitution) { throw new System.NotImplementedException(); }
public string GetSpecialMethodType(DeclaredElementPresenterStyle presenter, IMethod method, ISubstitution substitution) { return null; }
public override IReference BindTo(IDeclaredElement element, ISubstitution substitution) { return this.BindTo(element); }
///<summary> /// /// Bind this reference to given Declared Element and substitution. May insert using directive. /// ///</summary> /// ///<returns> ///new "this" ///</returns> /// public IReference BindTo(IDeclaredElement element, ISubstitution substitution) { return BindTo(element); }
private StaticDeclaredTypeWrapper MakeDeclaredType(ITypeElement typeElementHandle, ISubstitution substitutionHandle) { if (typeElementHandle is ITypeParameter) throw new ArgumentException("This method should never be called with a generic parameter as input.", "typeElementHandle"); ITypeElement declaringTypeElementHandle = typeElementHandle.GetContainingType(); StaticDeclaredTypeWrapper type; if (declaringTypeElementHandle != null) { StaticDeclaredTypeWrapper declaringType = MakeDeclaredType(declaringTypeElementHandle, substitutionHandle); type = new StaticDeclaredTypeWrapper(this, typeElementHandle, declaringType, declaringType.Substitution); } else { type = new StaticDeclaredTypeWrapper(this, typeElementHandle, null, StaticTypeSubstitution.Empty); } #if ! RESHARPER_50_OR_NEWER var typeParameterHandles = new List<ITypeParameter>(typeElementHandle.AllTypeParameters); #else var typeParameterHandles = new List<ITypeParameter>(typeElementHandle.GetAllTypeParameters()); #endif #if RESHARPER_31 || RESHARPER_40 || RESHARPER_41 if (substitutionHandle.IsIdempotent(typeParameterHandles)) #else if (substitutionHandle.IsIdempotentAll(typeParameterHandles)) #endif { return type; } ITypeInfo[] genericArguments = GenericCollectionUtils.ConvertAllToArray<ITypeParameter, ITypeInfo>(typeParameterHandles, delegate(ITypeParameter typeParameterHandle) { IType substitutedType = substitutionHandle.Apply(typeParameterHandle); if (substitutedType.IsUnknown) return MakeGenericParameterType(typeParameterHandle); return MakeType(substitutedType); }); return type.MakeGenericType(genericArguments); }
public string GetSpecialElementType(DeclaredElementPresenterStyle presenter, IDeclaredElement declaredElement, ISubstitution substitution) { return null; }