Exemplo n.º 1
0
        public override Boolean IsAvailable(IUserDataHolder cache)
        {
            ResolveResultWithInfo resolve_result_with_info = this.error.Reference.Resolve();
            Boolean is_available = resolve_result_with_info.DeclaredElement is IMethod || resolve_result_with_info.DeclaredElement is IConstructor;

            return(is_available);
        }
        private static FileSystemPath GetBasePathBeforeMapping(IQualifiableReference pathReference)
        {
            IQualifier qualifier = pathReference.GetQualifier();

            if (qualifier == null)
            {
                IProjectFile file = pathReference.GetTreeNode().GetSourceFile().ToProjectFile();
                Assertion.AssertNotNull(file, "file == null");
                return(file.Location.Directory);
            }

            var reference = qualifier as IReference;

            if (reference != null)
            {
                ResolveResultWithInfo resolveResultWithInfo = (reference).Resolve();
                var pathDeclaredElement = resolveResultWithInfo.DeclaredElement as IPathDeclaredElement;
                if (pathDeclaredElement == null)
                {
                    return(FileSystemPath.Empty);
                }

                return(pathDeclaredElement.Path);
            }

            var pathQualifier = qualifier as IPathQualifier;

            if (pathQualifier != null)
            {
                return(pathQualifier.Path);
            }

            return(FileSystemPath.Empty);
        }
Exemplo n.º 3
0
        public override ResolveResultWithInfo GetResolveResult(ISymbolTable symbolTable, string referenceName)
        {
            ResolveResultWithInfo resolveResult = LocalResolveWithoutCache();

            resolveResult = new ResolveResultWithInfo(resolveResult.Result, GetResolveInfo(resolveResult.Info));

            return(resolveResult);
        }
        public override MethodInvocation ProcessUsage(IReference reference)
        {
            var referenceExpression = reference.GetTreeNode() as IReferenceExpression;

            if (referenceExpression == null)
            {
                Driver.AddConflict(ReferenceConflict.CreateError(reference, "{0} can not be updated correctly.", "Usage"));
                return(null);
            }

            bool isExtensionMethod           = referenceExpression.IsExtensionMethod();
            IInvocationExpression invocation = InvocationExpressionNavigator.GetByInvokedExpression(referenceExpression);

            if (invocation == null)
            {
                Driver.AddConflict(ReferenceConflict.CreateError(reference, "{0} can not be updated correctly.", "Usage"));
                return(null);
            }

            ITreeNode element = GetArgument(invocation, isExtensionMethod);

            var   argument = element as ICSharpArgument;
            IType type     = argument != null?GetTypeOfValue(argument.Value) : GetTypeOfValue(element);

            if (type == null || !type.CanUseExplicitly(invocation))
            {
                Driver.AddConflict(ReferenceConflict.CreateError(
                                       reference, "Argument of {0} is not valid 'typeof' expression.", "usage"));
                return(null);
            }

            // we can rely on resolve result since method declaration is not yet changed.
            ResolveResultWithInfo resolveResult = reference.Resolve();
            ISubstitution         substitution  = resolveResult.Result.Substitution;
            var method = resolveResult.DeclaredElement as IMethod;

            if (method == null)
            {
                return(null);
            }

            if (argument != null)
            {
                invocation.RemoveArgument(argument);
                return(new MethodInvocation(reference, type, method, substitution));
            }

            CSharpElementFactory factory = CSharpElementFactory.GetInstance(invocation.GetPsiModule());
            IReferenceExpression newInvokedExpression =
                invocation.InvokedExpression.ReplaceBy(factory.CreateReferenceExpression("$0", Executer.Method));

            return(new MethodInvocation(newInvokedExpression.Reference, type, method, substitution));
        }
        protected override void AppendTooltip(AttributeNameExpectedError highlighting, CSharpColorizer colorizer)
        {
            ResolveResultWithInfo resolveResult   = highlighting.Reference.Resolve();
            IDeclaredElement      declaredElement = resolveResult.DeclaredElement;

            if (declaredElement == null)
            {
                return;
            }

            colorizer.AppendPlainText("'");
            colorizer.AppendDeclaredElement(declaredElement, resolveResult.Substitution, PresenterOptions.NameOnly, highlighting.Reference.GetTreeNode());
            colorizer.AppendPlainText("' is not an attribute");
        }
        public override void VisitStateName(IStateName stateNameParam, IHighlightingConsumer consumer)
        {
            DocumentRange         colorConstantRange = stateNameParam.GetDocumentRange();
            ResolveResultWithInfo resolve            = stateNameParam.StateNameReference.Resolve();

            if ((resolve == null) || ((resolve.Result.DeclaredElement == null) && (resolve.Result.Candidates.Count == 0)))
            {
                AddHighLighting(colorConstantRange, stateNameParam, consumer, new LexUnresolvedStateHighlighting(stateNameParam));
            }
            else
            {
                AddHighLighting(colorConstantRange, stateNameParam, consumer, new LexStateHighlighting(stateNameParam));
            }
            base.VisitStateName(stateNameParam, consumer);
        }
Exemplo n.º 7
0
        protected override void AppendTooltip(AccessRightsInTextWarning highlighting, CSharpColorizer colorizer)
        {
            ResolveResultWithInfo resolveResult = highlighting.Reference.Resolve();

            if (resolveResult.DeclaredElement is not {
            } declaredElement)
            {
                return;
            }

            colorizer.AppendPlainText("Cannot access ");
            colorizer.AppendElementKind(declaredElement);
            colorizer.AppendPlainText(" '");
            colorizer.AppendDeclaredElement(declaredElement, resolveResult.Substitution, PresenterOptions.NameOnly, highlighting.Reference.GetTreeNode());
            colorizer.AppendPlainText("' here");
        }
        protected override void AppendTooltip(CannotCreateInstanceOfInterfaceError highlighting, CSharpColorizer colorizer)
        {
            ResolveResultWithInfo resolveResult   = highlighting.ReferenceName.Reference.Resolve();
            IDeclaredElement      declaredElement = resolveResult.DeclaredElement;

            colorizer.AppendPlainText("Cannot create an instance of the interface '");
            if (declaredElement != null)
            {
                colorizer.AppendDeclaredElement(declaredElement, resolveResult.Substitution, PresenterOptions.QualifiedName, highlighting.ReferenceName);
            }
            else
            {
                colorizer.AppendInterfaceName(highlighting.ReferenceName.GetText());
            }
            colorizer.AppendPlainText("'");
        }
Exemplo n.º 9
0
        public override void VisitVariableName(IVariableName variableNameParam, IHighlightingConsumer consumer)
        {
            DocumentRange colorConstantRange = variableNameParam.GetDocumentRange();
            var           variableName       = variableNameParam as VariableName;

            if (variableName != null)
            {
                ResolveResultWithInfo resolve = variableName.Resolve();
                if ((resolve != null) && ((resolve.Result.DeclaredElement != null) || (resolve.Result.Candidates.Count > 0)))
                {
                    AddHighLighting(colorConstantRange, variableNameParam, consumer, new PsiVariableHighlighting(variableNameParam));
                }
                else
                {
                    AddHighLighting(colorConstantRange, variableNameParam, consumer, new PsiUnresolvedVariableReferenceHighlighting(variableName));
                }
            }
        }
Exemplo n.º 10
0
        public override void VisitPathName(IPathName pathNameParam, IHighlightingConsumer consumer)
        {
            DocumentRange colorConstantRange = pathNameParam.GetDocumentRange();
            var           pathName           = pathNameParam as PathName;

            if (pathName != null)
            {
                ResolveResultWithInfo resolve = pathName.Resolve();
                if ((resolve != null) && ((resolve.Result.DeclaredElement != null) || (resolve.Result.Candidates.Count > 0)))
                {
                    AddHighLighting(colorConstantRange, pathNameParam, consumer, new PsiRuleHighlighting(pathNameParam));
                }
                else
                {
                    AddHighLighting(colorConstantRange, pathNameParam, consumer, new PsiUnresolvedPathReferenceHighlighting(pathName));
                }
            }
        }
Exemplo n.º 11
0
        public override void VisitRuleName(IRuleName ruleName, IHighlightingConsumer consumer)
        {
            DocumentRange colorConstantRange = ruleName.GetDocumentRange();

            ResolveResultWithInfo resolve = ruleName.RuleNameReference.Resolve();

            bool isRuleResolved = resolve.Result.DeclaredElement != null || (resolve.Result.Candidates.Count > 0);

            if (isRuleResolved)
            {
                AddHighLighting(colorConstantRange, ruleName, consumer, new PsiRuleHighlighting(ruleName));
            }
            else
            {
                AddHighLighting(colorConstantRange, ruleName, consumer, new PsiUnresolvedRuleReferenceHighlighting(ruleName));
            }

            base.VisitRuleName(ruleName, consumer);
        }
Exemplo n.º 12
0
        public override void VisitPrefix(IPrefix prefixParam, IHighlightingConsumer consumer)
        {
            DocumentRange range  = prefixParam.GetDocumentRange();
            var           prefix = prefixParam as Prefix;

            if (prefix != null)
            {
                ResolveResultWithInfo resolve = prefix.Resolve();
                if (resolve == null ||
                    resolve.Result.DeclaredElement is UnresolvedNamespacePrefixDeclaredElement ||
                    ((resolve.Result.DeclaredElement == null) && (resolve.Result.Candidates.Count == 0)))
                {
                    this.AddHighLighting(
                        range,
                        prefixParam,
                        consumer,
                        new NTriplesUnresolvedReferenceHighlighting <NTriplesPrefixReference>(
                            prefix, prefix.PrefixReference, string.Format("Unresolved prefix '{0}'", prefix.GetText())));
                }
            }
        }
Exemplo n.º 13
0
        public override void VisitNode(ITreeNode element, IHighlightingConsumer consumer)
        {
            DocumentRange colorConstantRange = element.GetDocumentRange();

            if ((element is ITokenNode) && ((ITokenNode)element).GetTokenType().IsWhitespace)
            {
                return;
            }

            var variableName = element as VariableName;

            if (variableName != null)
            {
                ResolveResultWithInfo resolve = variableName.Resolve();
                if ((resolve != null) && ((resolve.Result.DeclaredElement != null) || (resolve.Result.Candidates.Count > 0)))
                {
                    AddHighLighting(colorConstantRange, element, consumer, new PsiVariableHighlighting(element));
                }
                else
                {
                    AddHighLighting(colorConstantRange, element, consumer, new PsiUnresolvedVariableReferenceHighlighting(variableName));
                    return;
                }
            }
            var pathName = element as PathName;

            if (pathName != null)
            {
                ResolveResultWithInfo resolve = pathName.Resolve();
                if ((resolve != null) && ((resolve.Result.DeclaredElement != null) || (resolve.Result.Candidates.Count > 0)))
                {
                    AddHighLighting(colorConstantRange, element, consumer, new PsiRuleHighlighting(element));
                }
                else
                {
                    AddHighLighting(colorConstantRange, element, consumer, new PsiUnresolvedPathReferenceHighlighting(pathName));
                }
            }
        }
        private static bool AttributeMatchedReflectionType([NotNull] IAttribute x, [NotNull] Type reflectionType)
        {
            if (x.Name.QualifiedName != reflectionType.Name.RemoveEnd(AttributePostfix))
            {
                return(false);
            }

            ResolveResultWithInfo resolveResultWithInfo = x.Name.Reference.Resolve();

            if (!resolveResultWithInfo.IsValid())
            {
                return(false);
            }

            INamespace attributeNamespace =
                (resolveResultWithInfo.DeclaredElement as IClass)?.GetContainingNamespace();

            if (attributeNamespace == null)
            {
                return(false);
            }

            return(attributeNamespace.QualifiedName == reflectionType.Namespace);
        }
Exemplo n.º 15
0
            public override Expression VisitReferenceExpression(IReferenceExpression referenceExpressionParam, IMetadataResolver context)
            {
                if (referenceExpressionParam.QualifierExpression != null)
                {
                    Expression qualifierExpression = referenceExpressionParam.QualifierExpression.Accept(this, context);

                    var invocationExpression = referenceExpressionParam.Parent as IInvocationExpression;
                    if (invocationExpression != null)
                    {
                        IEnumerable <Expression> arguments = invocationExpression.ArgumentList.Arguments.Select(
                            argument => argument.Accept(this, context));

                        return(new MethodCallExpressionBuilder(referenceExpressionParam, qualifierExpression, arguments, context).Build());
                    }

                    return(new MemberReferenceExpressionBuilder(referenceExpressionParam, qualifierExpression, context).Build());
                }

                ResolveResultWithInfo resolve  = referenceExpressionParam.Reference.Resolve();
                var lambdaParameterDeclaration = resolve.DeclaredElement as ILambdaParameterDeclaration;

                if (lambdaParameterDeclaration != null)
                {
                    return(lambdaParameters.First(
                               parameter => parameter.Name.Equals(lambdaParameterDeclaration.NameIdentifier.GetText())));
                }

                var parameterDeclaration = resolve.DeclaredElement as IParameterDeclaration;

                if (parameterDeclaration != null)
                {
                    return(new ParameterExpressionBuilder(parameterDeclaration, context).Build());
                }

                return(base.VisitReferenceExpression(referenceExpressionParam, context));
            }
Exemplo n.º 16
0
        private static IType GetClosedType(ResolveResultWithInfo resolveResultWithInfo, IType returnType)
        {
            var closedType = resolveResultWithInfo.Result.Substitution.Apply(returnType);

            return(closedType);
        }
 public ReflectedMemberReference([NotNull] IExpression owner, ResolveResultWithInfo resolveResult, ITypeElement typeElement)
     : base(owner)
 {
     _resolveResult = resolveResult;
     _typeElement   = typeElement;
 }