/// <summary> /// /// </summary> /// <param name="c"></param> public void Remove(IClass c) { classDictionary.Remove(c.DotNetName); foreach (IClass innerClass in c.InnerClasses) { classDictionary.Remove(innerClass.DotNetName); } }
void AddClassMemberBookmarks(IClass c, TextDocument document) { if (c.IsSynthetic) return; if (!c.Region.IsEmpty) { bookmarks.Add(new ClassBookmark(c, document)); } foreach (IClass innerClass in c.InnerClasses) { AddClassMemberBookmarks(innerClass, document); } foreach (IMethod m in c.Methods) { if (m.Region.IsEmpty || m.IsSynthetic) continue; bookmarks.Add(new ClassMemberBookmark(m, document)); } foreach (IProperty p in c.Properties) { if (p.Region.IsEmpty || p.IsSynthetic) continue; bookmarks.Add(new ClassMemberBookmark(p, document)); } foreach (IField f in c.Fields) { if (f.Region.IsEmpty || f.IsSynthetic) continue; bookmarks.Add(new ClassMemberBookmark(f, document)); } foreach (IEvent e in c.Events) { if (e.Region.IsEmpty || e.IsSynthetic) continue; bookmarks.Add(new ClassMemberBookmark(e, document)); } }
global::EnvDTE.vsCMInfoLocation GetInfoLocation(IProjectContent projectContent, IClass c) { if (projectContent.Project == c.ProjectContent.Project) { return global::EnvDTE.vsCMInfoLocation.vsCMInfoLocationProject; } return global::EnvDTE.vsCMInfoLocation.vsCMInfoLocationExternal; }
public ResolveResult Resolve(ExpressionResult expressionResult, ParseInformation parseInfo, string fileContent) { if (parseInfo == null || (string.IsNullOrEmpty(fileContent) && !(expressionResult.Context is XamlContext))) return null; this.resolveExpression = expressionResult.Expression; this.caretLine = expressionResult.Region.BeginLine; this.caretColumn = expressionResult.Region.BeginColumn; this.callingClass = parseInfo.CompilationUnit.GetInnermostClass(caretLine, caretColumn); this.context = expressionResult.Context as XamlContext ?? CompletionDataHelper.ResolveContext(fileContent, parseInfo.CompilationUnit.FileName, Utils.GetOffsetFromFilePos(fileContent, caretLine, caretColumn)); switch (this.context.Description) { case XamlContextDescription.AtTag: case XamlContextDescription.None: return ResolveElementName(resolveExpression); case XamlContextDescription.InTag: return ResolveAttribute(resolveExpression) ?? ResolveElementName(resolveExpression); case XamlContextDescription.InAttributeValue: MemberResolveResult mrr = ResolveAttribute(context.Attribute.Name); if (mrr != null) { var rr = ResolveAttributeValue(mrr.ResolvedMember, resolveExpression) ?? mrr; return rr; } break; case XamlContextDescription.InMarkupExtension: return ResolveMarkupExtension(resolveExpression); } return null; }
private IClass GetRectangleClass() { var variables = new string[] { "x", "y", "width", "height" }; var methods = new string[] { "x ^x", "y ^y", "x: newX x := newX", "y: newY y := newY", "area ^x*y", "width ^width", "height ^height", "width: newWidth width := newWidth", "height: newHeight height := newHeight", "side: newSide x := newSide. y := newSide" }; if (this.rectangleClass == null) { this.rectangleClass = ParserTests.CompileClass( "Rectangle", variables, methods); } return this.rectangleClass; }
void InitMemberNode(IMember member) { this.member = member; this.ContextmenuAddinTreePath = "/SharpDevelop/Pads/ClassBrowser/MemberContextMenu"; declaringType = member.DeclaringType; modifiers = member.Modifiers; }
/// <summary> /// Note that projectContent may be different to the IClass.ProjectContent since the class /// is retrieved from the namespace contents and could belong to a separate project or /// referenced assembly. /// </summary> public CodeType(IProjectContent projectContent, IClass c) : base(c) { this.Class = c; this.ProjectContent = projectContent; InfoLocation = GetInfoLocation(projectContent, c); }
public PythonMethod CreateMethod(IClass c) { if (IsConstructor) { return new PythonConstructor(c, methodDefinition); } return new PythonMethod(c, methodDefinition); }
// create public static TypeDeclaration add_Type(this NamespaceDeclaration namespaceDeclaration, IClass iClass) { // move to method IClass.typeDeclaration(); var typeName = iClass.Name; var newType = namespaceDeclaration.type(typeName); // check if already exists and if it does return it if (newType != null) return newType; const Modifiers modifiers = Modifiers.None | Modifiers.Public; newType = new TypeDeclaration(modifiers, new List<AttributeSection>()); newType.Name = typeName; foreach (var baseType in iClass.BaseTypes) { if (baseType.FullyQualifiedName != "System.Object") // no need to include this one newType.BaseTypes.Add(new TypeReference(baseType.FullyQualifiedName)); } namespaceDeclaration.AddChild(newType); return newType; //return namespaceDeclaration.add_Type(iClass.Name); }
IProject GetProject(IClass c) { if (c != null) { return c.ProjectContent.Project as IProject; } return null; }
public DefaultField(IReturnType type, string name, ModifierEnum m, DomRegion region, IClass declaringType) : base(declaringType, name) { this.ReturnType = type; this.Region = region; this.Modifiers = m; }
public IEnumerable<OpenedFile> GetSourceFiles(out OpenedFile designerCodeFile) { // get new initialize components ParseInformation info = ParserService.ParseFile(this.viewContent.PrimaryFileName, this.viewContent.PrimaryFileContent); ICompilationUnit cu = info.CompilationUnit; foreach (IClass c in cu.Classes) { if (FormsDesignerSecondaryDisplayBinding.BaseClassIsFormOrControl(c)) { this.currentClassPart = c; this.initializeComponents = FormsDesignerSecondaryDisplayBinding.GetInitializeComponents(c); if (this.initializeComponents != null) { string designerFileName = this.initializeComponents.DeclaringType.CompilationUnit.FileName; if (designerFileName != null) { designerCodeFile = FileService.GetOrCreateOpenedFile(designerFileName); CompoundClass compound = c.GetCompoundClass() as CompoundClass; if (compound == null) { return new [] {designerCodeFile}; } else { return compound.Parts .Select(cl => FileService.GetOrCreateOpenedFile(cl.CompilationUnit.FileName)) .Distinct(); } } } } } throw new FormsDesignerLoadException("Could not find InitializeComponent method in any part of the open class."); }
FileCodeModelCodeNamespace CreateFileCodeModelNamespace(IClass c) { var codeNamespace = new FileCodeModelCodeNamespace(compilationUnit.ProjectContent, c.Namespace); AddCodeElement(codeNamespace); fileCodeModelNamespaces.Add(codeNamespace); return codeNamespace; }
public DefaultTypeParameter(IMethod method, string name, int index) { this.method = method; this.targetClass = method.DeclaringType; this.name = name; this.index = index; }
public DefaultTypeParameter(IMethod method, Type type) { this.method = method; this.targetClass = method.DeclaringType; this.name = type.Name; this.index = type.GenericParameterPosition; }
public override void VisitAttribute(AXmlAttribute attribute) { Debug.Assert(document != null); if (attribute.ParentElement != null) { if (attribute.ParentElement.Parent == document && attribute.LocalName == "Class" && attribute.Namespace == CompletionDataHelper.XamlNamespace) { this.generatedClass = AddClass(attribute.Value, attribute.ParentElement); } else if (generatedClass != null && attribute.LocalName == "Name") { string name = attribute.Value; if (!string.IsNullOrEmpty(name)) { IReturnType type = TypeFromXmlNode(CompilationUnit, attribute.ParentElement); DomRegion position = CreateRegion(attribute.ParentElement.StartOffset, attribute.ParentElement.StartOffset + attribute.ParentElement.Name.Length); ModifierEnum fieldModifier = ModifierEnum.Internal; string modifierValue = (attribute.ParentElement.GetAttributeValue(CompletionDataHelper.XamlNamespace, "FieldModifier") ?? string.Empty).Trim(); string publicString = currentAmbience.ConvertAccessibility(ModifierEnum.Public).Trim(); if (projectContent.Language.NameComparer.Compare(modifierValue, publicString) == 0) fieldModifier = ModifierEnum.Public; generatedClass.Fields.Add(new DefaultField(type, name, fieldModifier, position, generatedClass)); } } } base.VisitAttribute(attribute); }
internal AllorsPredicateRoleInstanceofSql(AllorsExtentFilteredSql extent, IRoleType role, IObjectType instanceType, IClass[] instanceClasses) { extent.CheckRole(role); PredicateAssertions.ValidateRoleInstanceOf(role, instanceType); this.role = role; this.instanceClasses = instanceClasses; }
public static IDeclaredElement GetPrimaryDeclaredElementForClass(IClass @class) { string className = @class.ShortName; var cache = @class.GetPsiServices().Solution.GetComponent<PsiCache>(); List<IPsiSymbol> symbols = cache.GetSymbols(PsiRenamesFactory.NameFromCamelCase(className)).ToList(); if (symbols.Count > 0) { IPsiSymbol symbol = symbols.ToArray()[0]; ITreeNode element = symbol.SourceFile.GetPsiFile<PsiLanguage>(new DocumentRange(symbol.SourceFile.Document, 0)).FindNodeAt(new TreeTextRange(new TreeOffset(symbol.Offset), 1)); while (element != null) { if (element is IDeclaredElement) { { return (IDeclaredElement)element; } } element = element.Parent; } { return null; } } return null; }
public Insertion(IClass @class, Guid id) { if (@class == null) throw new ArgumentNullException ("class"); Class = @class; Id = id; }
internal AllorsPredicateAssociationInstanceofSql(AllorsExtentFilteredSql extent, IAssociationType association, IObjectType instanceType, IClass[] instanceClasses) { extent.CheckAssociation(association); PredicateAssertions.ValidateAssociationInstanceof(association, instanceType); this.association = association; this.instanceClasses = instanceClasses; }
public ReflectionField(FieldInfo fieldInfo, IClass declaringType) : base(declaringType, fieldInfo.Name) { this.ReturnType = ReflectionReturnType.Create(this, fieldInfo.FieldType, false); ModifierEnum modifiers = ModifierEnum.None; if (fieldInfo.IsInitOnly) { modifiers |= ModifierEnum.Readonly; } if (fieldInfo.IsStatic) { modifiers |= ModifierEnum.Static; } if (fieldInfo.IsAssembly) { modifiers |= ModifierEnum.Internal; } if (fieldInfo.IsPrivate) { // I assume that private is used most and public last (at least should be) modifiers |= ModifierEnum.Private; } else if (fieldInfo.IsFamily || fieldInfo.IsFamilyOrAssembly) { modifiers |= ModifierEnum.Protected; } else if (fieldInfo.IsPublic) { modifiers |= ModifierEnum.Public; } else { modifiers |= ModifierEnum.Internal; } if (fieldInfo.IsLiteral) { modifiers |= ModifierEnum.Const; } this.Modifiers = modifiers; }
public void ValidateClassNames(ValidationContext context, IClass cls) { // Property and Role names must be unique within a class hierarchy. List<string> foundNames = new List<string>(); List<IProperty> allPropertiesInHierarchy = new List<IProperty>(); List<IProperty> superRoles = new List<IProperty>(); FindAllAssocsInSuperClasses(superRoles, cls.SuperClasses); foreach (IProperty p in cls.GetOutgoingAssociationEnds()) { superRoles.Add(p); } foreach (IProperty p in superRoles) { allPropertiesInHierarchy.Add(p); } foreach (IProperty p in cls.Members) { allPropertiesInHierarchy.Add(p); } foreach (IProperty attribute in allPropertiesInHierarchy) { string name = attribute.Name; if (!string.IsNullOrEmpty(name) && foundNames.Contains(name)) { context.LogError( string.Format("Duplicate property or role name '{0}' in class '{1}'", name, cls.Name), "001", cls); } foundNames.Add(name); } }
// Indexer declaration public PrefetchPolicy this[IClass @class] { get { PrefetchPolicy prefetchPolicy; if (!this.prefetchPolicyByClass.TryGetValue(@class, out prefetchPolicy)) { var prefetchPolicyBuilder = new PrefetchPolicyBuilder(); foreach (var roleType in @class.RoleTypes) { prefetchPolicyBuilder.WithRule(roleType); } foreach (var associationType in @class.AssociationTypes) { prefetchPolicyBuilder.WithRule(associationType); } prefetchPolicy = prefetchPolicyBuilder.Build(); this.prefetchPolicyByClass[@class] = prefetchPolicy; } return prefetchPolicy; } }
public ResolveVisitor(BooResolver resolver) { this.resolver = resolver; this.callingClass = resolver.CallingClass; this.projectContent = resolver.ProjectContent; this.cu = resolver.CompilationUnit; }
void MakeTypeResult(IClass c) { if (c != null) resolveResult = new TypeResolveResult(callingClass, resolver.CallingMember, c); else ClearResult(); }
public bool IsValidTestMethod(IProject project, IClass testClass, IMethod testMethod) { if (project == null || testClass == null || testMethod == null) return false; return IsValidTestMethod(project, testClass.GetClrName().FullName, testMethod.ShortName); }
public void SetUpFixture() { string ruby = "class Test\r\n" + "\tdef initialize\r\n" + "\t\tputs 'test'\r\n" + "\tend\r\n" + "end"; DefaultProjectContent projectContent = new DefaultProjectContent(); RubyParser parser = new RubyParser(); compilationUnit = parser.Parse(projectContent, @"C:\test.rb", ruby); if (compilationUnit.Classes.Count > 0) { c = compilationUnit.Classes[0]; if (c.Methods.Count > 0) { method = c.Methods[0]; } TextArea textArea = new TextArea(); document = new TextDocument(); textArea.Document = document; textArea.Document.Text = ruby; // Get folds. ParserFoldingStrategy foldingStrategy = new ParserFoldingStrategy(textArea); ParseInformation parseInfo = new ParseInformation(compilationUnit); foldingStrategy.UpdateFoldings(parseInfo); List<FoldingSection> folds = new List<FoldingSection>(foldingStrategy.FoldingManager.AllFoldings); if (folds.Count > 1) { classFold = folds[0]; methodFold = folds[1]; } } }
void AddClassMemberBookmarks(IClass c) { if (c.IsSynthetic) return; if (!c.Region.IsEmpty) { bookmarks.Add(new ClassBookmark(c)); } foreach (IClass innerClass in c.InnerClasses) { AddClassMemberBookmarks(innerClass); } foreach (IMethod m in c.Methods) { if (m.Region.IsEmpty || m.IsSynthetic) continue; bookmarks.Add(new ClassMemberBookmark(m)); } foreach (IProperty m in c.Properties) { if (m.Region.IsEmpty || m.IsSynthetic) continue; bookmarks.Add(new ClassMemberBookmark(m)); } foreach (IField f in c.Fields) { if (f.Region.IsEmpty || f.IsSynthetic) continue; bookmarks.Add(new ClassMemberBookmark(f)); } foreach (IEvent e in c.Events) { if (e.Region.IsEmpty || e.IsSynthetic) continue; bookmarks.Add(new ClassMemberBookmark(e)); } }
public bool IsValidTestClass(IProject project, IClass testClass) { if (project == null || testClass == null) return false; return IsValidTestClass(project, testClass.GetClrName().FullName); }
public ClassProxy(IClass c) { this.FullyQualifiedName = c.FullyQualifiedName; this.Documentation = c.Documentation; this.modifiers = c.Modifiers; this.classType = c.ClassType; }
public virtual string ConstructorParameters(IClass @class) { return(null); }
public abstract string Convert(IClass c);
public virtual string ClassAnnotations(IClass @class) { return(null); }
public virtual IEnumerable <string> GetInterfaces(IClass @class) { return(new List <string>()); }
public virtual string GetBaseClass(IClass @class) { return(null); }
public virtual string ClassOtherConstructors(IClass @class) { return(null); }
public virtual string ConstructorBody(IClass @class) { return(null); }
TypeResolveResult CreateTypeResolveResult(IClass c) { return(new TypeResolveResult(null, null, c)); }
internal static ITypeInfo AsTypeInfo(this IClass type) { return(new PsiClassWrapper(type)); }
public Ticket(IClass clas, bool vikno, bool ret) { Return = ret; Vikno = vikno; this.clas = clas; }
public static void AddImportedNamespaceContents(ArrayList result, ICompilationUnit cu, IClass callingClass) { IProjectContent projectContent = cu.ProjectContent; projectContent.AddNamespaceContents(result, "", projectContent.Language, true); foreach (IUsing u in cu.Usings) { AddUsing(result, u, projectContent); } AddUsing(result, projectContent.DefaultImports, projectContent); if (callingClass != null) { string[] namespaceParts = callingClass.Namespace.Split('.'); for (int i = 1; i <= namespaceParts.Length; i++) { foreach (object member in projectContent.GetNamespaceContents(string.Join(".", namespaceParts, 0, i))) { if (!result.Contains(member)) { result.Add(member); } } } IClass currentClass = callingClass; do { foreach (IClass innerClass in currentClass.GetAccessibleTypes(currentClass)) { if (!result.Contains(innerClass)) { result.Add(innerClass); } } currentClass = currentClass.DeclaringType; } while (currentClass != null); } }
public PsiClassWrapper(IClass psiType) { this.psiType = psiType; }
/// <summary> /// Finds the matching nodes of a <see cref="IEqualityExpression"/>. /// </summary> /// <param name="node">The agent expression to check.</param> /// <param name="errorList">The list of errors found.</param> /// <param name="resolvedResult">The expression result types upon return.</param> /// <param name="resolvedException">Exceptions the expression can throw upon return.</param> /// <param name="constantSourceList">Sources of the constant expression upon return, if any.</param> /// <param name="expressionConstant">The constant value upon return, if any.</param> public static bool ResolveCompilerReferences(IEqualityExpression node, IErrorList errorList, out IResultType resolvedResult, out IResultException resolvedException, out ISealableList <IExpression> constantSourceList, out ILanguageConstant expressionConstant) { resolvedResult = null; resolvedException = null; constantSourceList = new SealableList <IExpression>(); expressionConstant = NeutralLanguageConstant.NotConstant; IExpression LeftExpression = (IExpression)node.LeftExpression; IExpression RightExpression = (IExpression)node.RightExpression; IClass EmbeddingClass = node.EmbeddingClass; IResultType LeftResult = LeftExpression.ResolvedResult.Item; IResultType RightResult = RightExpression.ResolvedResult.Item; if (LeftResult.Count != RightResult.Count) { errorList.AddError(new ErrorExpressionResultMismatch(node)); return(false); } if (!Expression.IsLanguageTypeAvailable(LanguageClasses.Boolean.Guid, node, out ITypeName ResultTypeName, out ICompiledType ResultType)) { errorList.AddError(new ErrorBooleanTypeMissing(node)); return(false); } if (LeftResult.Count > 1) { int MismatchingResultCount = 0; foreach (IExpressionType LeftItem in LeftResult) { ICompiledType LeftExpressionType = LeftItem.ValueType; bool MatchingNameFound = false; foreach (IExpressionType RightItem in RightResult) { if (LeftItem.Name == RightItem.Name) { MatchingNameFound = true; ICompiledType RightExpressionType = RightItem.ValueType; if (!ObjectType.TypeConformToBase(LeftExpressionType, RightExpressionType, isConversionAllowed: true) && !ObjectType.TypeConformToBase(RightExpressionType, LeftExpressionType, isConversionAllowed: true)) { MismatchingResultCount++; } break; } } if (!MatchingNameFound) { MismatchingResultCount++; } } if (MismatchingResultCount > 0) { errorList.AddError(new ErrorExpressionResultMismatch(node)); return(false); } } resolvedResult = new ResultType(ResultTypeName, ResultType, string.Empty); constantSourceList.Add(LeftExpression); constantSourceList.Add(RightExpression); resolvedException = new ResultException(); ResultException.Merge(resolvedException, LeftExpression.ResolvedException); ResultException.Merge(resolvedException, RightExpression.ResolvedException); #if COVERAGE Debug.Assert(node.IsComplex); #endif return(true); }
public ReflectionClass(ICompilationUnit compilationUnit, Type type, string fullName, IClass declaringType) : base(compilationUnit, declaringType) { FullyQualifiedName = SplitTypeParameterCountFromReflectionName(fullName); try { AddAttributes(compilationUnit.ProjectContent, this.Attributes, CustomAttributeData.GetCustomAttributes(type)); } catch (Exception ex) { HostCallback.ShowError("Error reading custom attributes", ex); } // set classtype if (type.IsInterface) { this.ClassType = ClassType.Interface; } else if (type.IsEnum) { this.ClassType = ClassType.Enum; } else if (type.IsValueType) { this.ClassType = ClassType.Struct; } else if (IsDelegate(type)) { this.ClassType = ClassType.Delegate; } else { this.ClassType = ClassType.Class; ApplySpecialsFromAttributes(this); } if (type.IsGenericTypeDefinition) { foreach (Type g in type.GetGenericArguments()) { this.TypeParameters.Add(new DefaultTypeParameter(this, g)); } int i = 0; foreach (Type g in type.GetGenericArguments()) { AddConstraintsFromType(this.TypeParameters[i++], g); } } ModifierEnum modifiers = ModifierEnum.None; if (type.IsNestedAssembly) { modifiers |= ModifierEnum.Internal; } if (type.IsSealed) { modifiers |= ModifierEnum.Sealed; } if (type.IsAbstract) { modifiers |= ModifierEnum.Abstract; } if (type.IsSealed && type.IsAbstract) { modifiers |= ModifierEnum.Static; } if (type.IsNestedPrivate) // I assume that private is used most and public last (at least should be) { modifiers |= ModifierEnum.Private; } else if (type.IsNestedFamily) { modifiers |= ModifierEnum.Protected; } else if (type.IsNestedPublic || type.IsPublic) { modifiers |= ModifierEnum.Public; } else if (type.IsNotPublic) { modifiers |= ModifierEnum.Internal; } else if (type.IsNestedFamORAssem || type.IsNestedFamANDAssem) { modifiers |= ModifierEnum.Protected; modifiers |= ModifierEnum.Internal; } this.Modifiers = modifiers; // set base classes if (type.BaseType != null) // it's null for System.Object ONLY !!! { BaseTypes.Add(ReflectionReturnType.Create(this, type.BaseType, false)); } foreach (Type iface in type.GetInterfaces()) { BaseTypes.Add(ReflectionReturnType.Create(this, iface, false)); } InitMembers(type); }
internal static void AddParameters(AST.ParameterDeclarationCollection parameters, IList <IParameter> output, IMethodOrProperty method, IClass c) { if (c == null) { throw new ArgumentNullException("c"); } DefaultParameter p = null; foreach (AST.ParameterDeclaration par in parameters) { p = new DefaultParameter(par.Name, CreateReturnType(par.Type, c, method as IMethod, c.Region.BeginLine + 1, 1, c.ProjectContent), new DomRegion(par.LexicalInfo.Line, par.LexicalInfo.Column)); if (par.IsByRef) { p.Modifiers |= ParameterModifiers.Ref; } output.Add(p); } if (parameters.HasParamArray) { p.Modifiers |= ParameterModifiers.Params; } }
public ReflectionProperty(PropertyInfo propertyInfo, IClass declaringType) : base(declaringType, propertyInfo.Name) { this.ReturnType = ReflectionReturnType.Create(this, propertyInfo.PropertyType, false); CanGet = propertyInfo.CanRead; CanSet = propertyInfo.CanWrite; ParameterInfo[] parameterInfo = propertyInfo.GetIndexParameters(); if (parameterInfo != null && parameterInfo.Length > 0) { // check if this property is an indexer (=default member of parent class) foreach (MemberInfo memberInfo in propertyInfo.DeclaringType.GetDefaultMembers()) { if (memberInfo == propertyInfo) { this.IsIndexer = true; break; } } // there are only few properties with parameters, so we can load them immediately foreach (ParameterInfo info in parameterInfo) { this.Parameters.Add(new ReflectionParameter(info, this)); } } MethodInfo getterMethod = null; try { getterMethod = propertyInfo.GetGetMethod(true); } catch (Exception) {} MethodInfo setterMethod = null; try { setterMethod = propertyInfo.GetSetMethod(true); } catch (Exception) {} MethodInfo methodBase = getterMethod ?? setterMethod; ModifierEnum modifiers = ModifierEnum.None; if (methodBase != null) { if (methodBase.IsStatic) { modifiers |= ModifierEnum.Static; } if (methodBase.IsAssembly) { modifiers |= ModifierEnum.Internal; } if (methodBase.IsPrivate) // I assume that private is used most and public last (at least should be) { modifiers |= ModifierEnum.Private; } else if (methodBase.IsFamily || methodBase.IsFamilyOrAssembly) { modifiers |= ModifierEnum.Protected; } else if (methodBase.IsPublic) { modifiers |= ModifierEnum.Public; } else { modifiers |= ModifierEnum.Internal; } if (methodBase.IsFinal) { modifiers |= ModifierEnum.Sealed; } else if (methodBase.IsAbstract) { modifiers |= ModifierEnum.Abstract; } else if (methodBase.IsVirtual) { modifiers |= ModifierEnum.Virtual; } } else // assume public property, if no methodBase could be get. { modifiers = ModifierEnum.Public; } this.Modifiers = modifiers; if (getterMethod != null) { ModifierEnum getterModifier = GetAccessorModifier(getterMethod); if (getterModifier == ModifierEnum.Private) { this.CanGet = false; } else { if (getterModifier != (modifiers & ModifierEnum.VisibilityMask)) { this.GetterModifiers = getterModifier; } } } if (setterMethod != null) { ModifierEnum setterModifier = GetAccessorModifier(setterMethod); if (setterModifier == ModifierEnum.Private) { this.CanSet = false; } else { if (setterModifier != (modifiers & ModifierEnum.VisibilityMask)) { this.SetterModifiers = setterModifier; } } } }
void ReadClass(DefaultClass c) { this.currentClass = c; int count; count = reader.ReadByte(); for (int i = 0; i < count; i++) { c.TypeParameters.Add(new DefaultTypeParameter(c, ReadString(), i)); } if (count > 0) { foreach (ITypeParameter typeParameter in c.TypeParameters) { count = reader.ReadInt32(); for (int i = 0; i < count; i++) { typeParameter.Constraints.Add(ReadType()); } } } else { c.TypeParameters = DefaultTypeParameter.EmptyTypeParameterList; } count = reader.ReadInt32(); for (int i = 0; i < count; i++) { c.BaseTypes.Add(ReadType()); } c.Modifiers = (ModifierEnum)reader.ReadInt32(); c.CalculatedFlags = reader.ReadByte(); c.ClassType = (ClassType)reader.ReadByte(); ReadAttributes(c); count = reader.ReadInt32(); for (int i = 0; i < count; i++) { DefaultClass innerClass = new DefaultClass(c.CompilationUnit, c); innerClass.FullyQualifiedName = reader.ReadString(); c.InnerClasses.Add(innerClass); ReadClass(innerClass); } this.currentClass = c; count = reader.ReadInt32(); for (int i = 0; i < count; i++) { c.Methods.Add(ReadMethod()); } count = reader.ReadInt32(); for (int i = 0; i < count; i++) { c.Properties.Add(ReadProperty()); } count = reader.ReadInt32(); for (int i = 0; i < count; i++) { c.Events.Add(ReadEvent()); } count = reader.ReadInt32(); for (int i = 0; i < count; i++) { c.Fields.Add(ReadField()); } this.currentClass = null; }
public static IReturnType CreateReturnType(AST.TypeReference reference, IClass callingClass, IMethodOrProperty callingMember, int caretLine, int caretColumn, IProjectContent projectContent) { System.Diagnostics.Debug.Assert(projectContent != null); if (reference == null) { return(GetDefaultReturnType(projectContent)); } if (reference is AST.ArrayTypeReference) { AST.ArrayTypeReference arr = (AST.ArrayTypeReference)reference; return(new ArrayReturnType(projectContent, CreateReturnType(arr.ElementType, callingClass, callingMember, caretLine, caretColumn, projectContent), (arr.Rank != null) ? (int)arr.Rank.Value : 1)); } else if (reference is AST.SimpleTypeReference) { string name = ((AST.SimpleTypeReference)reference).Name; IReturnType rt; int typeParameterCount = (reference is AST.GenericTypeReference) ? ((AST.GenericTypeReference)reference).GenericArguments.Count : 0; if (name == "duck") { rt = new BooResolver.DuckClass(new DefaultCompilationUnit(projectContent)).DefaultReturnType; } else if (BooAmbience.ReverseTypeConversionTable.ContainsKey(name)) { rt = new GetClassReturnType(projectContent, BooAmbience.ReverseTypeConversionTable[name], typeParameterCount); } else if (callingClass == null) { rt = new GetClassReturnType(projectContent, name, typeParameterCount); } else { rt = new SearchClassReturnType(projectContent, callingClass, caretLine, caretColumn, name, typeParameterCount); } if (typeParameterCount > 0) { AST.TypeReferenceCollection arguments = ((AST.GenericTypeReference)reference).GenericArguments; // GenericTypeReference derives from SimpleTypeReference IReturnType[] typeArguments = new IReturnType[arguments.Count]; for (int i = 0; i < typeArguments.Length; i++) { typeArguments[i] = CreateReturnType(arguments[i], callingClass, callingMember, caretLine, caretColumn, projectContent); } rt = new ConstructedReturnType(rt, typeArguments); } return(rt); } else if (reference is AST.CallableTypeReference) { AST.CallableTypeReference ctr = (AST.CallableTypeReference)reference; AnonymousMethodReturnType amrt = new AnonymousMethodReturnType(new DefaultCompilationUnit(projectContent)); if (ctr.ReturnType != null) { amrt.MethodReturnType = CreateReturnType(ctr.ReturnType, callingClass, callingMember, caretLine, caretColumn, projectContent); } amrt.MethodParameters = new List <IParameter>(); AddParameters(ctr.Parameters, amrt.MethodParameters, callingMember, callingClass ?? new DefaultClass(new DefaultCompilationUnit(projectContent), "__Dummy")); return(amrt); } else { throw new NotSupportedException("unknown reference type: " + reference.ToString()); } }
public bool MustBeShown(IClass callingClass, bool showStatic, bool isClassInInheritanceTree) { throw new NotImplementedException(); }
public override bool HandleKeyPress(CodeEditorControl editor, char ch) { CSharpExpressionFinder ef = new CSharpExpressionFinder(editor.ActiveViewControl.FileName); int cursor = editor.ActiveViewControl.Caret.Offset; ExpressionContext context = null; if (ch == '(') { if (CodeCompletionOptions.KeywordCompletionEnabled) { switch (editor.ActiveViewControl.Caret.CurrentWord.Text.Trim()) { case "for": case "lock": context = ExpressionContext.Default; break; case "using": context = ExpressionContext.TypeDerivingFrom(ScriptControl.Parser.ProjectParser.CurrentProjectContent.GetClass("System.IDisposable"), false); break; case "catch": context = ExpressionContext.TypeDerivingFrom(ScriptControl.Parser.ProjectParser.CurrentProjectContent.GetClass("System.Exception"), false); break; case "foreach": case "typeof": case "sizeof": case "default": context = ExpressionContext.Type; break; } } if (context != null) { if (IsInComment(editor)) { return(false); } editor.ActiveViewControl.ShowCompletionWindow(new CtrlSpaceCompletionDataProvider(context), ch); return(true); } else if (EnableMethodInsight) { editor.ActiveViewControl.ShowInsightWindow(new MethodInsightDataProvider()); return(true); } return(false); } else if (ch == '[') { Word curWord = editor.ActiveViewControl.Caret.CurrentWord; //Word preWord = curWord.Row.FormattedWords[curWord.Index-1]; //int lineOffset = editor.ActiveViewControl.Document.Text.Substring(0, editor.ActiveViewControl.Caret.Offset - editor.ActiveViewControl.Caret.Position.X).Length; //TextPoint tp = editor.ActiveViewControl.Document.IntPosToPoint(lineOffset); if (curWord.Text.Length == 0) { // [ is first character on the line // -> Attribute completion editor.ActiveViewControl.ShowCompletionWindow(new AttributesDataProvider(ScriptControl.Parser.ProjectParser.CurrentProjectContent), ch); return(true); } } else if (ch == ',' && CodeCompletionOptions.InsightRefreshOnComma && CodeCompletionOptions.InsightEnabled) { if (InsightRefreshOnComma(editor, ch)) { return(true); } } else if (ch == '=') { string curLine = editor.ActiveViewControl.Caret.CurrentRow.Text; string documentText = ScriptControl.Parser.ProjectParser.GetFileContents(editor.FileName); int position = editor.ActiveViewControl.Caret.Offset - 2; if (position > 0 && (documentText[position + 1] == '+')) { ExpressionResult result = ef.FindFullExpression(documentText, position); if (result.Expression != null) { ResolveResult resolveResult = ScriptControl.Parser.ProjectParser.GetResolver().Resolve(result, editor.ActiveViewControl.Caret.Position.Y + 1, editor.ActiveViewControl.Caret.Position.X + 1, editor.ActiveViewControl.FileName, documentText); if (resolveResult != null && resolveResult.ResolvedType != null) { IClass underlyingClass = resolveResult.ResolvedType.GetUnderlyingClass(); if (underlyingClass == null && resolveResult.ResolvedType.FullyQualifiedName.Length > 0) { underlyingClass = ScriptControl.Parser.ProjectParser.CurrentProjectContent.GetClass(resolveResult.ResolvedType.FullyQualifiedName); } //if (underlyingClass != null && underlyingClass.IsTypeInInheritanceTree(ScriptControl.Parser.ProjectParser.CurrentProjectContent.GetClass("System.MulticastDelegate"))) { if (underlyingClass != null && underlyingClass.IsTypeInInheritanceTree(ScriptControl.Parser.ProjectParser.CurrentProjectContent.GetClass("System.Delegate"))) { EventHandlerCompletitionDataProvider eventHandlerProvider = new EventHandlerCompletitionDataProvider(result.Expression, resolveResult); eventHandlerProvider.InsertSpace = true; editor.ActiveViewControl.ShowCompletionWindow(eventHandlerProvider, ch); } } } } else if (position > 0) { ExpressionResult result = ef.FindFullExpression(documentText, position); if (result.Expression != null) { ResolveResult resolveResult = ScriptControl.Parser.ProjectParser.GetResolver().Resolve(result, editor.ActiveViewControl.Caret.Position.Y + 1, editor.ActiveViewControl.Caret.Position.X + 1, editor.ActiveViewControl.FileName, documentText); if (resolveResult != null && resolveResult.ResolvedType != null) { if (ProvideContextCompletion(editor, resolveResult.ResolvedType, ch)) { return(true); } } } } } else if (ch == ';') { string curLine = editor.ActiveViewControl.Caret.CurrentRow.Text; // don't return true when inference succeeds, otherwise the ';' won't be added to the document. TryDeclarationTypeInference(editor, curLine); } return(base.HandleKeyPress(editor, ch)); }
/// <summary> /// Checks if an implicit conversion exists from <paramref name="from"/> to <paramref name="to"/>. /// </summary> public static bool ConversionExists(IReturnType from, IReturnType to) { // ECMA-334, § 13.1 Implicit conversions // Identity conversion: if (from == to) { return(true); } if (from == null || to == null) { return(false); } if (from.Equals(to)) { return(true); } bool fromIsDefault = from.IsDefaultReturnType; bool toIsDefault = to.IsDefaultReturnType; if (fromIsDefault && toIsDefault) { // Implicit numeric conversions: int f = GetPrimitiveType(from); int t = GetPrimitiveType(to); if (f == SByte && (t == Short || t == Int || t == Long || t == Float || t == Double || t == Decimal)) { return(true); } if (f == Byte && (t == Short || t == UShort || t == Int || t == UInt || t == Long || t == ULong || t == Float || t == Double || t == Decimal)) { return(true); } if (f == Short && (t == Int || t == Long || t == Float || t == Double || t == Decimal)) { return(true); } if (f == UShort && (t == Int || t == UInt || t == Long || t == ULong || t == Float || t == Double || t == Decimal)) { return(true); } if (f == Int && (t == Long || t == Float || t == Double || t == Decimal)) { return(true); } if (f == UInt && (t == Long || t == ULong || t == Float || t == Double || t == Decimal)) { return(true); } if ((f == Long || f == ULong) && (t == Float || t == Double || t == Decimal)) { return(true); } if (f == Char && (t == UShort || t == Int || t == UInt || t == Long || t == ULong || t == Float || t == Double || t == Decimal)) { return(true); } if (f == Float && t == Double) { return(true); } } // Implicit reference conversions: if (toIsDefault && to.FullyQualifiedName == "System.Object") { return(true); // from any type to object } if (toIsDefault && (fromIsDefault || from.IsArrayReturnType)) { IClass c1 = from.GetUnderlyingClass(); IClass c2 = to.GetUnderlyingClass(); if (c1 != null && c1.IsTypeInInheritanceTree(c2)) { return(true); } } if (from.IsArrayReturnType && to.IsArrayReturnType) { ArrayReturnType fromArt = from.CastToArrayReturnType(); ArrayReturnType toArt = to.CastToArrayReturnType(); // from array to other array type if (fromArt.ArrayDimensions == toArt.ArrayDimensions) { return(ConversionExists(fromArt.ArrayElementType, toArt.ArrayElementType)); } } if (from.IsConstructedReturnType && to.IsConstructedReturnType) { if (from.FullyQualifiedName == to.FullyQualifiedName) { IList <IReturnType> fromTypeArguments = from.CastToConstructedReturnType().TypeArguments; IList <IReturnType> toTypeArguments = to.CastToConstructedReturnType().TypeArguments; if (fromTypeArguments.Count == toTypeArguments.Count) { for (int i = 0; i < fromTypeArguments.Count; i++) { if (fromTypeArguments[i] == toTypeArguments[i]) { continue; } if (object.Equals(fromTypeArguments[i], toTypeArguments[i])) { continue; } if (!(toTypeArguments[i].IsGenericReturnType)) { return(false); } } return(true); } } } return(false); }
public ClassNameTypeCountPair(IClass c) { this.ClassName = c.FullyQualifiedName; this.TypeParameterCount = (byte)c.TypeParameters.Count; }
public FeatureLayer(string name, string filename) : this(name) { _class = new FeatureClass(filename); TryInitByFeatureClass(); }
public bool IsAccessible(IClass callingClass, bool isClassInInheritanceTree) { throw new NotImplementedException(); }
public CodeClass(IProjectContent projectContent, IClass c) : base(projectContent, c) { }
/// <summary> /// Gets the type parameter that was passed to a certain base class. /// For example, when <paramref name="returnType"/> is Dictionary(of string, int) /// this method will return KeyValuePair(of string, int) /// </summary> public static IReturnType GetTypeParameterPassedToBaseClass(IReturnType parentType, IClass baseClass, int baseClassTypeParameterIndex) { if (!parentType.IsConstructedReturnType) { return(null); } ConstructedReturnType returnType = parentType.CastToConstructedReturnType(); IClass c = returnType.GetUnderlyingClass(); if (c == null) { return(null); } if (baseClass.CompareTo(c) == 0) { if (baseClassTypeParameterIndex >= returnType.TypeArguments.Count) { return(null); } return(returnType.TypeArguments[baseClassTypeParameterIndex]); } foreach (IReturnType baseType in c.BaseTypes) { if (baseClass.CompareTo(baseType.GetUnderlyingClass()) == 0) { if (!baseType.IsConstructedReturnType) { return(null); } ConstructedReturnType baseTypeCRT = baseType.CastToConstructedReturnType(); if (baseClassTypeParameterIndex >= baseTypeCRT.TypeArguments.Count) { return(null); } IReturnType result = baseTypeCRT.TypeArguments[baseClassTypeParameterIndex]; if (returnType.TypeArguments != null) { result = ConstructedReturnType.TranslateType(result, returnType.TypeArguments, false); } return(result); } } return(null); }
static bool CreateEventHandlerCode(CompletionContext context, NewEventCompletionItem completionItem, out int discriminator) { ParseInformation p = ParserService.GetParseInformation(context.Editor.FileName); var unit = p.CompilationUnit; var loc = context.Editor.Document.OffsetToPosition(context.StartOffset); IClass c = unit.GetInnermostClass(loc.Line, loc.Column); discriminator = 1; if (c == null) { return(false); } IMethod initializeComponent = c.Methods[0]; CompoundClass compound = c.GetCompoundClass() as CompoundClass; IMethod invokeMethod = completionItem.EventType.ReturnType.GetMethods().FirstOrDefault(m => m.Name == "Invoke"); string handlerName = completionItem.HandlerName; if (invokeMethod == null) { throw new ArgumentException("delegateType is not a valid delegate!"); } if (compound != null) { foreach (IClass part in compound.Parts) { IMember lastMember = part.Methods.LastOrDefault(); if (lastMember != null && lastMember.ToString() == initializeComponent.ToString()) { continue; } if (completionItem.EventType.ReturnType == null) { return(false); } while (part.Methods.Any(m => m.Name == handlerName && m.Parameters.Count == invokeMethod.Parameters.Count && m.Parameters.SequenceEqual(invokeMethod.Parameters, new ParameterComparer()) )) { handlerName = completionItem.HandlerName + discriminator; discriminator++; } discriminator--; ParametrizedNode node = (ParametrizedNode)CodeGenerator.ConvertMember(invokeMethod, new ClassFinder(part, context.Editor.Caret.Line, context.Editor.Caret.Column)); node.Name = handlerName; node.Modifier = Modifiers.None; IViewContent viewContent = FileService.OpenFile(part.CompilationUnit.FileName, XamlBindingOptions.SwitchToCodeViewAfterInsertion); IFileDocumentProvider document = viewContent as IFileDocumentProvider; if (viewContent != null && document != null) { DomRegion domRegion; if (lastMember != null) { unit.ProjectContent.Language.CodeGenerator.InsertCodeAfter(lastMember, new RefactoringDocumentAdapter(document.GetDocumentForFile(viewContent.PrimaryFile)), node); domRegion = lastMember.BodyRegion; } else { unit.ProjectContent.Language.CodeGenerator.InsertCodeAtEnd(part.Region, new RefactoringDocumentAdapter(document.GetDocumentForFile(viewContent.PrimaryFile)), node); domRegion = part.Region; } // move caret to generated code ITextEditorProvider provider = viewContent as ITextEditorProvider; if (provider != null) { provider.TextEditor.JumpTo(domRegion.EndLine + 2, domRegion.EndColumn - 1); } } return(true); } } return(false); }
/// <summary> /// Creates a new instance of the BaseTestMethod. /// </summary> /// <param name="derivedClass">The derived class and not /// the class where the method is actually defined.</param> /// <param name="method">The base class's test method.</param> public BaseTestMethod(IClass derivedClass, IMethod method) : base(method.Name, method.ReturnType, method.Modifiers, method.Region, method.BodyRegion, derivedClass) { this.method = method; }
internal ProjectItem(IProjectContent projectContent, IClass c) : this((MSBuildBasedProject)projectContent.Project, c) { }
ICollection GetCompatibleMethods(ParseInformation parseInfo) { IClass c = GetClass(parseInfo.CompilationUnit); return(GetCompatibleMethods(c)); }