protected override Action <ITextControl> ExecutePsiTransaction(ISolution solution, IProgressIndicator progress)
        {
            IXmlTagHeader tagHeader = GetTagHeader();

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

            IXmlTag tag = XmlTagNavigator.GetByTagHeader(tagHeader);

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

            XmlElementFactory factory = XmlElementFactory.GetInstance(tag);

            IXmlAttribute idAttr = factory.CreateAttributeForTag(tag, "id=\"\"");

            tag.AddAttributeBefore(idAttr, null);

            // continuation to do after transaction committed
            return(textControl =>
                   // move cursor inside new created id attribute
                   textControl.Caret.MoveTo(idAttr.Value.GetDocumentRange().TextRange.StartOffset, CaretVisualPlacement.Generic));
        }
Example #2
0
        private IList <IXmlToken> getStringsToCheck()
        {
            IList <IXmlToken> tokens  = new List <IXmlToken>();
            IXmlFile          xmlFile = _file.GetTheOnlyPsiFile(XmlLanguage.Instance) as IXmlFile;

            if (xmlFile != null)
            {
                IXmlTag root = xmlFile.GetTag(delegate(IXmlTag tag) { return(tag.GetTagName() == "root"); });

                if (root != null)
                {
                    IEnumerable <IXmlTag> datas = root.GetTags <IXmlTag>().Where(tag => tag.GetTagName() == "data");
                    foreach (IXmlTag data in datas)
                    {
                        if (data.GetAttribute("type") == null)
                        {
                            IXmlTag val = data.GetTag(delegate(IXmlTag tag) { return(tag.GetTagName() == "value"); });
                            if (val != null)
                            {
                                if (val.FirstChild != null && val.FirstChild.NextSibling != null)
                                {
                                    IXmlToken value = val.FirstChild.NextSibling as IXmlToken;
                                    if (value != null)
                                    {
                                        tokens.Add(value);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(tokens);
        }
Example #3
0
 public SimpleParameterOwner(IXmlTag tag, IParameterDescriptorProvider provider)
 {
     if (tag == null) throw new ArgumentNullException("tag");
     if (provider == null) throw new ArgumentNullException("provider");
     this.tag = tag;
     this.provider = provider;
 }
Example #4
0
 public override IXmlTag CreateTag(IXmlTagHeaderNode header, IXmlTag parentTag)
 {
     IXmlTag tag = CreateTagInternal(parentTag, header);
     IL4NElement element = tag as IL4NElement;
     if (element != null)
         HandleCreateTagElement(element, header, parentTag);
     return tag;
 }
        public override IXmlTag CreateTag(IXmlTagHeaderNode header, IXmlTag parentTag) {
            Logger.LogMessage("CreateTag {0}: {1}", header.Name.XmlName, header.GetText());

            string name = header.Name.XmlName;

            switch (name) {
                case Keyword.HibernateMapping:
                    return new HibernateMappingTag();
                case Keyword.Class:
                    return new ClassTag();
                case Keyword.Id:
                    return new IdTag();
                case Keyword.Property:
                    return new PropertyTag();
                case Keyword.Bag:
                    return new BagTag();
                case Keyword.IdBag:
                    return new IdBagTag();
                case Keyword.Set:
                    return new SetTag();
                case Keyword.Array:
                    return new ArrayTag();
                case Keyword.PrimitiveArray:
                    return new PrimitiveArrayTag();
                case Keyword.List:
                    return new ListTag();
                case Keyword.Any:
                    return new AnyTag();
                case Keyword.Map:
                    return new MapTag();
                case Keyword.Component:
                    return new ComponentTag();
                case Keyword.DynamicComponent:
                    return new DynamicComponentTag();
                case Keyword.Subclass:
                    return new SubclassTag();
                case Keyword.JoinedSubclass:
                    return new JoinedSubclassTag();
                case Keyword.OneToOne:
                    return new OneToOneTag();
                case Keyword.OneToMany:
                    return new OneToManyTag();
                case Keyword.ManyToMany:
                    return new ManyToManyTag();
                case Keyword.ManyToAny:
                    return new ManyToAnyTag();
                case Keyword.ManyToOne:
                    return new ManyToOneTag();
                case Keyword.CompositeElement:
                    return new CompositeElementTag();
                case Keyword.NestedCompositeElement:
                    return new NestedCompositeElementTag();
                case Keyword.Parent:
                    return new ParentTag();
            }

            return base.CreateTag(header, parentTag);
        }
Example #6
0
        public override IXmlTag CreateTag(IXmlTagHeaderNode header, IXmlTag parentTag)
        {
            IXmlTag created = base.CreateTagGenerated(header, parentTag);
            if (created != null)
            {
                HandleCreateTagElement((INHElement)created,header, parentTag);
                return created;
            }

            return base.CreateTag(header, parentTag);
        }
        public static string GetExternalConfigName(this IXmlTag xmlTag)
        {
            var attributes = xmlTag.GetAttributes();

            foreach (var attribute in attributes)
            {
                if (attribute.XmlName.Equals(SettingsConstants.ExternalConfigTagName))
                {
                    return(attribute.UnquotedValue);
                }
            }

            return(null);
        }
Example #8
0
        private IXmlTag CreateTagInternal(IXmlTag parentTag, IXmlTagHeaderNode header)
        {
            string parentTagName = ((IXmlTag)parentTag).TagName;

            string name = header.Name.GetText();

            if (name == L4NConstants.LOG4NET)
            {
                return new L4NSectionImpl();
            }
            else if (parentTag is IL4NSection)
            {
                if (name == L4NConstants.APPENDER)
                {
                    return new AppenderImpl();
                }
                else if (name == L4NConstants.LOGGER || name == L4NConstants.ROOT_LOGGER)
                {
                    return new LoggerImpl();
                }
            }
            else if (parentTag is ILogger)
            {
                if (name == L4NConstants.APPENDER_REF)
                {
                    return new AppenderRefImpl();
                }
                // TODO other properties
                //else
            }
            else if (parentTag is IDeclaredParametersOwner)
            {
                if (name != L4NConstants.PARAM)
                {
                    return new PropertyParamImpl();
                }
            }

            return base.CreateTag(header, parentTag);
        }
        private void HighlightPropertyType(IAccessor accessor, IElement nameAttribute, ITypeOwner field, IElement typeAttribute, IXmlTag xmlTag, string attributeName) {
            ITypeElement propertyClass = HighlightUndefinedType(xmlTag, attributeName);
            if (accessor != null) {
                // TODO: use accessor.ReturnType on getter
                IDeclaredType declaredType = accessor.Parameters[0].Type as IDeclaredType;
                if (declaredType != null) {
                    ITypeElement propertyTypeElement = declaredType.GetTypeElement();
                    if ((propertyTypeElement != null) && (propertyClass != null) && (!propertyClass.IsDescendantOf(propertyTypeElement))) {
                        AddHighlighting(typeAttribute, new TypeHighlighting(string.Format("Class name '{0}' should be '{1}' or a descendant", propertyClass.ShortName, propertyTypeElement.ShortName)));
                    }
                }
            }
            if (field != null) {
                IDeclaredType declaredType = field.Type as IDeclaredType;
                if (declaredType != null) {
                    ITypeElement fieldTypeElement = declaredType.GetTypeElement();
                    if ((fieldTypeElement != null) && (propertyClass != null) && (!propertyClass.IsDescendantOf(fieldTypeElement))) {
                        AddHighlighting(typeAttribute, new TypeHighlighting(string.Format("Class name '{0}' should be '{1}' or a descendant", propertyClass.ShortName, fieldTypeElement.ShortName)));
                    }
                }
            }

            if ((accessor != null) && (field != null)) {
                IDeclaredType declaredAccessorType = accessor.Parameters[0].Type as IDeclaredType;
                IDeclaredType declaredFieldType = field.Type as IDeclaredType;
                if ((declaredAccessorType != null) && (declaredFieldType != null)) {
                    ITypeElement propertyTypeElement = declaredAccessorType.GetTypeElement();
                    ITypeElement fieldTypeElement = declaredFieldType.GetTypeElement();
                    if ((propertyTypeElement != null) && (fieldTypeElement != null) && (!propertyTypeElement.Equals(fieldTypeElement))) {
                        AddHighlighting(nameAttribute, new TypeHighlighting(string.Format("Property and field type differ: '{0}' vs. '{1}'", propertyTypeElement.ShortName, fieldTypeElement.ShortName)));
                    }
                }
            }
        }
        private void HighlightUndefinedMappedProperty(IXmlTag xmlTag, string propertyName, IElement nameAttribute, IElement typeAttribute, ITypeElement typeElement, AccessMethod access, string attributeName) {
            IAccessor propertyGetter = null;
            IAccessor propertySetter = null;
            IField field = null;
            string className = (typeElement == null) ? UndefinedType : typeElement.ShortName;
            if ((access.Method == AccessMethod.AccessMethodProperty) || (access.Method == AccessMethod.AccessMethodNosetter)) {
                propertyGetter = PsiUtils.GetPropertyGetter(typeElement, propertyName);
                HighlightPropertyGetter(propertyName, propertyGetter, nameAttribute, className);
            }
            if (access.Method == AccessMethod.AccessMethodProperty) {
                propertySetter = PsiUtils.GetPropertySetter(typeElement, propertyName);
                HighlightPropertySetter(propertyName, propertySetter, nameAttribute, className);
            }
            if ((access.Method == AccessMethod.AccessMethodField) || (access.Method == AccessMethod.AccessMethodNosetter)) {
                field = PsiUtils.GetField(typeElement, propertyName, access);
                HighlightField(access, propertyName, nameAttribute, className, field);
            }

            ITypeElement propertyClass = HighlightUndefinedType(xmlTag, attributeName);
            if ((typeAttribute != null) && (propertyClass != null)) {
                if (propertyGetter != null) {
                    IDeclaredType getterType = propertyGetter.ReturnType as IDeclaredType;
                    if ((getterType != null) && (!propertyClass.IsDescendantOf(getterType.GetTypeElement()))) {
                        AddHighlighting(typeAttribute, new TypeHighlighting(string.Format("Class name '{0}' should be '{1}' or a descendant for property getter", propertyClass.ShortName, getterType.GetTypeElement().ShortName)));
                    }
                }
                if (propertySetter != null) {
                    IDeclaredType setterType = propertySetter.Parameters[0] as IDeclaredType;
                    if ((setterType != null) && (!propertyClass.IsDescendantOf(setterType.GetTypeElement()))) {
                        AddHighlighting(typeAttribute, new TypeHighlighting(string.Format("Class name '{0}' should be '{1}' or a descendant for property setter", propertyClass.ShortName, setterType.GetTypeElement().ShortName)));
                    }
                }
                if (field != null) {
                    IDeclaredType fieldType = field.Type as IDeclaredType;
                    if ((fieldType != null) && (!propertyClass.IsDescendantOf(fieldType.GetTypeElement()))) {
                        AddHighlighting(typeAttribute, new TypeHighlighting(string.Format("Class name '{0}' should be '{1}' or a descendant for field '{2}'", propertyClass.ShortName, fieldType.GetTypeElement().ShortName, field.ShortName)));
                    }
                }
            }
        }
 private void HighlightUndefinedProperty(IXmlTag xmlTag, ITypeElement typeElement, string typeAttributeName) {
     string propertyName = null;
     IXmlAttribute nameAttribute = null;
     IXmlAttribute typeAttribute = null;
     string accessMethod = null;
     IXmlAttribute accessAttribute = null;
     foreach (IXmlAttribute attribute in xmlTag.Attributes) {
         if ((attribute.XmlName == "name") && (attribute.UnquotedValue != null)) {
             nameAttribute = attribute;
             propertyName = attribute.UnquotedValue;
             Logger.LogMessage("Mapped property is {0}", propertyName);
         }
         if ((attribute.XmlName == typeAttributeName) && (attribute.UnquotedValue != null)) {
             typeAttribute = attribute;
             string propertyType = attribute.UnquotedValue;
             Logger.LogMessage("Property type is {0}", propertyType);
         }
         if ((attribute.XmlName == "access") && (attribute.UnquotedValue != null)) {
             accessAttribute = attribute;
             accessMethod = attribute.UnquotedValue;
             Logger.LogMessage("Access method is {0}", accessMethod);
         }
     }
     if (propertyName != null) {
         AccessMethod access = HighlightUndefinedAccessAttribute(accessAttribute, accessMethod);
         HighlightUndefinedMappedProperty(xmlTag, propertyName, nameAttribute, typeAttribute, typeElement, access, typeAttributeName);
     }
 }
        private ITypeElement HighlightUndefinedType(IXmlTag tag, string attributeName) {
            IXmlAttribute attribute = tag.GetAttribute(attributeName);
            if ((attribute == null) || (attribute.XmlName != attributeName) || (attribute.UnquotedValue == null)) {
                return null;
            }

            string fullQualifiedTypeName = attribute.UnquotedValue;
            Logger.LogMessage("Type is {0}", fullQualifiedTypeName);
            Parser parser = new Parser();
            IParserError error;
            parser.Parse(fullQualifiedTypeName, out error);
            if (error != ParserError.None) {
                AddHighlighting(attribute, new TypeHighlighting(string.Format("Error in type: {0}", error.Message)));
            }
            
            ITypeElement typeElement = PsiUtils.GetTypeElement(tag, m_Process.Solution, fullQualifiedTypeName);
            if ((typeElement == null) || (typeElement.Module == null)) {
                AddHighlighting(attribute, new TypeHighlighting(string.Format("Type '{0}' could not be resolved", fullQualifiedTypeName)));
            }
            else {
                // TODO: put TypeNameParser into Parser and refactor this
                TypeNameParser typeNameParser = new TypeNameParser(fullQualifiedTypeName, m_Assembly, m_Namespace);
                string assemblyName = typeNameParser.AssemblyName;
                if (typeElement.Module.Name != "mscorlib") {
                    BuildSettingsManager buildSettingsManager = BuildSettingsManager.GetInstance(typeElement.GetProjectFiles()[0].GetProject());
                    if (buildSettingsManager != null) {
                        IAssemblyFile outputAssemblyFile = buildSettingsManager.GetOutputAssemblyFile();
                        if ((outputAssemblyFile != null) && (outputAssemblyFile.Name != assemblyName)) {
                            AddHighlighting(attribute, new TypeHighlighting(string.Format("Assembly name '{0}' should be '{1}'", assemblyName, outputAssemblyFile.Name)));
                        }
                    }
                }
            }
            return typeElement;
        }
 private static ITypeElement GetPropertyType(IXmlTag node, ITypeElement typeElement) {
     if (typeElement == null) {
         return null;
     }
     IXmlAttribute attribute = node.GetAttribute("name");
     if ((attribute != null) && (attribute.Value != null)) {
         string propertyName = attribute.UnquotedValue;
         IProperty property = PsiUtils.GetProperty(typeElement, propertyName);
         if (property != null) {
             IDeclaredType declaredType = property.Type as IDeclaredType;
             if (declaredType != null) {
                 return declaredType.GetTypeElement();
             }
         }
     }
     return null;
 }