예제 #1
0
        private static AccessRights GetAccessRights(IClrDeclaredElement element)
        {
            ITypeElement parentTypeElement = element.GetContainingType();

            IAccessRightsOwner accessRightsOwner = element as IAccessRightsOwner;
            if (accessRightsOwner == null) return AccessRights.PRIVATE;

            IAccessRightsOwner parentAccessRightsOwner = parentTypeElement as IAccessRightsOwner;
            if (parentAccessRightsOwner == null) return accessRightsOwner.GetAccessRights();

            return parentAccessRightsOwner.GetAccessRights();
        }
예제 #2
0
        public UnityComponentRelatedReferenceExpressionFinder([NotNull] IReferenceExpression referenceExpression, bool ignoreNotComponentInvocations = false)
        {
            ReferenceExpression             = referenceExpression;
            myIgnoreNotComponentInvocations = ignoreNotComponentInvocations;

            DeclaredElement = ReferenceExpression.Reference.Resolve().DeclaredElement as IClrDeclaredElement;
            Assertion.Assert(DeclaredElement != null, "DeclaredElement != null");

            ContainingType = DeclaredElement.GetContainingType();
            Assertion.Assert(ContainingType != null, "ContainingType != null");

            ComponentReferenceExpression = referenceExpression.QualifierExpression as IReferenceExpression;
        }
        private static void AppendMemberBase(this StringBuilder identifier,
                                             IClrDeclaredElement member,
                                             ISubstitution substitution,
                                             IType valueType,
                                             IDictionary <DeclaredElementInstance, IName> seenElements)
        {
            identifier.AppendType(valueType, seenElements);
            identifier.Append(' ');
            var containingType = member.GetContainingType();

            identifier.AppendType(containingType, substitution, seenElements);
            identifier.Append('.');
            identifier.Append(member.ShortName);
        }
        public static void SetRequiredQualifiers([NotNull] FSharpSymbolReference reference,
                                                 [NotNull] IClrDeclaredElement declaredElement)
        {
            var containingType = declaredElement.GetContainingType();

            if (containingType == null)
            {
                return;
            }

            if (containingType.IsModule() && !containingType.RequiresQualifiedAccess())
            {
                return;
            }

            reference.SetQualifier(containingType);
        }
예제 #5
0
        private static TypeAndNamespace GetAccessableTypeElementAndNamespace(ICSharpTypeMemberDeclaration declaration, ISolution solution, ICSharpFile file, IClrDeclaredElement element, IdentifierLookupScopes scope)
        {
            //IPsiModule module = element.Module;

            IXmlDocIdOwner idOwner = element as IXmlDocIdOwner;
            string docId = idOwner == null ? element.ShortName : idOwner.XMLDocId;

            // Get the defining type.
            ITypeElement typeElement = element as ITypeElement ?? element.GetContainingType();
            if (typeElement == null) return null;

            // Create the result
            TypeAndNamespace result = new TypeAndNamespace
                                          {
                                              XmlDocId = docId,
                                              TypeElement = element
                                          };

            // Get the namespace it belongs to.
            INamespace namespaceElement = typeElement.GetContainingNamespace();
            string namespaceName = namespaceElement.QualifiedName;

            // Check if we're ignoring this namespace
            foreach (string namespacePrefix in NamespacePrefixesToIgnore)
            {
                if (namespaceName.StartsWith(namespacePrefix)) return null;
            }

            // Check if it would be possible to access the type
            AccessRights elementAccessRights = GetAccessRights(element);
            if (elementAccessRights == AccessRights.PRIVATE)
            {
                return null;
            }

            // Check if the type is defined in this solution
            IList<IDeclaration> declarations = element.GetDeclarations();
            if (declarations.Count == 0)
            {
                // Assembly is an import so no internal things allowed
                if (elementAccessRights == AccessRights.INTERNAL) return null;
            }

            // Check if the given namespace is already imported in this file.
            if (UsingUtil.CheckAlreadyImported(file, new DeclaredElementInstance(namespaceElement)) || declaration.GetContainingNamespaceDeclaration().QualifiedName.StartsWith(namespaceName))
            {
                string newDocId = docId[1] == ':' ? docId.Substring(2) : docId;
                if (newDocId.StartsWith(namespaceName + ".")) newDocId = newDocId.Substring(namespaceName.Length + 1);
                result.XmlDocId = newDocId;
                return result;
            }

            // If we require it to be in project or using scope then this is not a match
            if (scope == IdentifierLookupScopes.ProjectAndUsings || scope == IdentifierLookupScopes.ProjectOnly)
            {
                return null;
            }

            // No - so add in the namespace.
            result.RequiredNamespaceImport = namespaceElement;

            return result;
        }
예제 #6
0
 private Guid?FindGuidOf([NotNull] IClrDeclaredElement declaredElement)
 {
     return(AssetUtils.GetGuidFor(myMetaFileGuidCache, declaredElement.GetContainingType()));
 }