public Parameter(Declaration declaration, int index, bool isRemoved = false) { Declaration = declaration; Name = declaration.Context.GetText().RemoveExtraSpacesLeavingIndentation(); Index = index; IsRemoved = isRemoved; }
private static string DetermineMemberName(Declaration declaration) { var type = declaration.DeclarationType; switch (type) { case DeclarationType.PropertyGet: return declaration.IdentifierName + " (Get)"; case DeclarationType.PropertyLet: return declaration.IdentifierName + " (Let)"; case DeclarationType.PropertySet: return declaration.IdentifierName + " (Set)"; case DeclarationType.Variable: if (declaration.IsArray()) { return declaration.IdentifierName + "()"; } return declaration.IdentifierName; case DeclarationType.Constant: var valuedDeclaration = (ValuedDeclaration)declaration; return valuedDeclaration.IdentifierName + " = " + valuedDeclaration.Value; default: return declaration.IdentifierName; } }
public ValuedDeclaration(QualifiedMemberName qualifiedName, Declaration parentDeclaration, string parentScope, string asTypeName, Accessibility accessibility, DeclarationType declarationType, string value, ParserRuleContext context, Selection selection, bool isBuiltIn = false) :base(qualifiedName, parentDeclaration, parentScope, asTypeName, true, false, accessibility, declarationType, context, selection, isBuiltIn) { _value = value; }
public static NavigateCodeEventArgs GetNavigateCodeEventArgs(this SyntaxErrorException exception, Declaration declaration) { if (declaration == null) return null; var selection = new Selection(exception.LineNumber, exception.Position, exception.LineNumber, exception.Position); return new NavigateCodeEventArgs(declaration.QualifiedName.QualifiedModuleName, selection); }
public void SetSelectionText(Declaration declaration) { if (declaration == null && _vbe.ActiveCodePane != null) { var selection = _vbe.ActiveCodePane.GetSelection(); SetSelectionText(selection); _selectionButton.TooltipText = _selectionButton.Caption; } else if (declaration != null && !declaration.IsBuiltIn && declaration.DeclarationType != DeclarationType.Class && declaration.DeclarationType != DeclarationType.Module) { _selectionButton.Caption = string.Format("{0} ({1}): {2} ({3})", declaration.QualifiedName.QualifiedModuleName, declaration.QualifiedSelection.Selection, declaration.IdentifierName, RubberduckUI.ResourceManager.GetString("DeclarationType_" + declaration.DeclarationType)); _selectionButton.TooltipText = string.IsNullOrEmpty(declaration.DescriptionString) ? _selectionButton.Caption : declaration.DescriptionString; } else if (declaration != null) { var selection = _vbe.ActiveCodePane.GetSelection(); _selectionButton.Caption = string.Format("{0}: {1} ({2}) {3}", declaration.QualifiedName.QualifiedModuleName, declaration.IdentifierName, RubberduckUI.ResourceManager.GetString("DeclarationType_" + declaration.DeclarationType), selection.Selection); _selectionButton.TooltipText = string.IsNullOrEmpty(declaration.DescriptionString) ? _selectionButton.Caption : declaration.DescriptionString; } }
/// <summary>Common method for adding declaration with some default values</summary> private void AddDeclarationItem(IMock<ParserRuleContext> context, Selection selection, QualifiedMemberName? qualifiedName = null, DeclarationType declarationType = DeclarationType.Project, string identifierName = "identifierName") { Declaration declarationItem = null; var qualName = qualifiedName ?? new QualifiedMemberName(_module, "fakeModule"); declarationItem = new Declaration( qualifiedName: qualName, parentScope: "module.proc", asTypeName: "asTypeName", isSelfAssigned: false, isWithEvents: false, accessibility: Accessibility.Public, declarationType: declarationType, context: context.Object, selection: selection ); _declarations.Add(declarationItem); if (_listDeclarations == null) _listDeclarations = new List<Declaration>(); _listDeclarations.Add(declarationItem); }
/// <summary>Common method for adding a reference to given declaration item</summary> private static void AddReference(Declaration itemToAdd, IdentifierReference reference) { var declaration = _declarations.Items.ToList().FirstOrDefault(x => x.Equals(itemToAdd)); if (declaration == null) return; declaration.AddReference(reference); }
public RenameProjectQuickFix(ParserRuleContext context, QualifiedSelection selection, Declaration target, RubberduckParserState state, ICodePaneWrapperFactory wrapperFactory) : base(context, selection, string.Format(RubberduckUI.Rename_DeclarationType, RubberduckUI.ResourceManager.GetString("DeclarationType_" + DeclarationType.Project, RubberduckUI.Culture))) { _target = target; _state = state; _wrapperFactory = wrapperFactory; }
public MultilineParameterInspectionResult(IInspection inspection, Declaration target) : base(inspection, target) { _quickFixes = new[] { new MakeSingleLineParameterQuickFix(Context, QualifiedSelection), }; }
public AssignedByValParameterInspectionResult(IInspection inspection, Declaration target) : base(inspection, target) { _quickFixes = new[] { new PassParameterByReferenceQuickFix(target.Context, QualifiedSelection), }; }
private void BindTarget(Declaration target) { var listBox = Control.ResultBox; listBox.DataSource = target.References.Select(reference => new IdentifierReferenceListItem(reference)).ToList(); listBox.DisplayMember = "DisplayString"; listBox.ValueMember = "Selection"; Control.Navigate += ControlNavigate; }
public ParameterCanBeByValInspectionResult(IInspection inspection, Declaration target, ParserRuleContext context, QualifiedMemberName qualifiedName) : base(inspection, qualifiedName.QualifiedModuleName, context, target) { _quickFixes = new[] { new PassParameterByValueQuickFix(Context, QualifiedSelection), }; }
public MoveFieldCloserToUsageInspectionResult(IInspection inspection, Declaration target, RubberduckParserState parseResult, ICodePaneWrapperFactory wrapperFactory, IMessageBox messageBox) : base(inspection, target) { _quickFixes = new[] { new MoveFieldCloserToUsageQuickFix(target.Context, target.QualifiedSelection, target, parseResult, wrapperFactory, messageBox), }; }
public MoveFieldCloserToUsageQuickFix(ParserRuleContext context, QualifiedSelection selection, Declaration target, RubberduckParserState parseResult, ICodePaneWrapperFactory wrapperFactory, IMessageBox messageBox) : base(context, selection, string.Format(InspectionsUI.MoveFieldCloserToUsageInspectionResultFormat, target.IdentifierName)) { _target = target; _parseResult = parseResult; _wrapperFactory = wrapperFactory; _messageBox = messageBox; }
public DefaultProjectNameInspectionResult(IInspection inspection, Declaration target, RubberduckParserState parseResult, ICodePaneWrapperFactory wrapperFactory) : base(inspection, target) { _quickFixes = new[] { new RenameProjectQuickFix(target.Context, target.QualifiedSelection, target, parseResult, wrapperFactory), }; }
/// <summary> /// Creates an inspection result. /// </summary> protected InspectionResultBase(IInspection inspection, QualifiedModuleName qualifiedName, ParserRuleContext context, Declaration declaration, CommentNode comment = null) { _inspection = inspection; _qualifiedName = qualifiedName; _context = context; _target = declaration; _comment = comment; }
public BitmapImage this[Declaration declaration] { get { var key = Tuple.Create(declaration.DeclarationType, declaration.Accessibility); return Images[key]; } }
private bool IsInterfaceImplementation(Declaration target) { var interfaceImplementation = State.AllUserDeclarations.FindInterfaceImplementationMembers().SingleOrDefault(m => m.Equals(target)); if (interfaceImplementation == null) { return false; } var interfaceMember = State.AllUserDeclarations.FindInterfaceMember(interfaceImplementation); return interfaceMember != null; }
private void AcquireTarget(out Declaration target, QualifiedSelection selection) { target = _declarations .Where(item => !item.IsBuiltIn && item.DeclarationType != DeclarationType.ModuleOption) .FirstOrDefault(item => item.IsSelected(selection) || item.References.Any(r => r.IsSelected(selection))); PromptIfTargetImplementsInterface(ref target); }
public UseMeaningfulNameInspectionResult(IInspection inspection, Declaration target, RubberduckParserState parserState, ICodePaneWrapperFactory wrapperFactory, IMessageBox messageBox) : base(inspection, target) { _quickFixes = new CodeInspectionQuickFix[] { new RenameDeclarationQuickFix(target.Context, target.QualifiedSelection, target, parserState, wrapperFactory, messageBox), new IgnoreOnceQuickFix(Context, QualifiedSelection, Inspection.AnnotationName), }; }
public VariableTypeNotDeclaredInspectionResult(IInspection inspection, Declaration target) : base(inspection, target) { _quickFixes = new CodeInspectionQuickFix[] { new DeclareAsExplicitVariantQuickFix(Context, QualifiedSelection), new IgnoreOnceQuickFix(Context, QualifiedSelection, Inspection.AnnotationName), }; }
public FunctionReturnValueNotUsedInspectionResult( IInspection inspection, ParserRuleContext context, QualifiedMemberName qualifiedName, IEnumerable<string> returnStatements, Declaration target) : this(inspection, context, qualifiedName, returnStatements, new List<Tuple<ParserRuleContext, QualifiedSelection, IEnumerable<string>>>(), target) { }
public void Refactor(Declaration target) { if (!ReorderParametersModel.ValidDeclarationTypes.Contains(target.DeclarationType)) { throw new ArgumentException("Invalid declaration type"); } _editor.SetSelection(target.QualifiedSelection); Refactor(); }
public ObsoleteTypeHintInspectionResult(IInspection inspection, string result, QualifiedContext qualifiedContext, Declaration declaration) : base(inspection, qualifiedContext.ModuleName, qualifiedContext.Context) { _result = result; _quickFixes = new CodeInspectionQuickFix[] { new RemoveTypeHintsQuickFix(Context, QualifiedSelection, declaration), new IgnoreOnceQuickFix(Context, QualifiedSelection, Inspection.AnnotationName), }; }
public void Refactor(Declaration target) { if (!RemoveParametersModel.ValidDeclarationTypes.Contains(target.DeclarationType) && target.DeclarationType != DeclarationType.Parameter) { throw new ArgumentException("Invalid declaration type"); } target.QualifiedSelection.Select(); Refactor(); }
public void Refactor(Declaration target) { var presenter = _factory.Create(); _model = presenter.Show(target); if (_model != null && _model.Declarations != null) { Rename(); } }
public IdentifierReference(QualifiedModuleName qualifiedName, string identifierName, Selection selection, ParserRuleContext context, Declaration declaration, bool isAssignmentTarget = false, bool hasExplicitLetStatement = false) { _qualifiedName = qualifiedName; _identifierName = identifierName; _selection = selection; _context = context; _declaration = declaration; _hasExplicitLetStatement = hasExplicitLetStatement; _isAssignmentTarget = isAssignmentTarget; }
public IdentifierNotAssignedInspectionResult(IInspection inspection, Declaration target, ParserRuleContext context, QualifiedModuleName qualifiedName) : base(inspection, target, context, qualifiedName) { _target = target; _quickFixes = new CodeInspectionQuickFix[] { new RemoveUnassignedIdentifierQuickFix(Context, QualifiedSelection), new IgnoreOnceQuickFix(context, QualifiedSelection, Inspection.AnnotationName), }; }
public ParameterNotUsedInspectionResult(IInspection inspection, Declaration target, ParserRuleContext context, QualifiedMemberName qualifiedName, bool isInterfaceImplementation, RemoveParametersRefactoring refactoring, RubberduckParserState parseResult) : base(inspection, qualifiedName.QualifiedModuleName, context, target) { _quickFixes = isInterfaceImplementation ? new CodeInspectionQuickFix[] {} : new CodeInspectionQuickFix[] { new RemoveUnusedParameterQuickFix(Context, QualifiedSelection, refactoring, parseResult), new IgnoreOnceQuickFix(Context, QualifiedSelection, Inspection.AnnotationName), }; }
public NavigateCodeEventArgs(Declaration declaration) { if (declaration == null) { return; } _declaration = declaration; _qualifiedName = declaration.QualifiedName.QualifiedModuleName; _selection = declaration.Selection; }
public Declaration FindMemberReferencedProject(Declaration callingProject, Declaration callingModule, Declaration callingParent, Declaration referencedProject, string memberName, DeclarationType memberType) { var memberMatches = FindAllInReferencedProjectByPriority(callingProject, memberName, p => p.DeclarationType.HasFlag(memberType) && referencedProject.Equals(Declaration.GetMemberProject(p))); var accessibleMembers = memberMatches.Where(m => AccessibilityCheck.IsMemberAccessible(callingProject, callingModule, callingParent, m)); var match = accessibleMembers.FirstOrDefault(); return(match); }
private Declaration FindInReferencedProjectByPriority(Declaration enclosingProject, string name, Func <Declaration, bool> predicate) { return(FindAllInReferencedProjectByPriority(enclosingProject, name, predicate).FirstOrDefault()); }
private Declaration CreateMemberDeclaration(out FUNCDESC memberDescriptor, TYPEKIND typeKind, ITypeInfo info, int memberIndex, QualifiedModuleName typeQualifiedModuleName, Declaration moduleDeclaration, out string[] memberNames) { IntPtr memberDescriptorPointer; info.GetFuncDesc(memberIndex, out memberDescriptorPointer); memberDescriptor = (FUNCDESC)Marshal.PtrToStructure(memberDescriptorPointer, typeof(FUNCDESC)); if (memberDescriptor.callconv != CALLCONV.CC_STDCALL) { memberDescriptor = new FUNCDESC(); memberNames = new string[] {}; return(null); } memberNames = new string[255]; int namesArrayLength; info.GetNames(memberDescriptor.memid, memberNames, 255, out namesArrayLength); var memberName = memberNames[0]; var funcValueType = (VarEnum)memberDescriptor.elemdescFunc.tdesc.vt; var memberDeclarationType = GetDeclarationType(memberDescriptor, funcValueType, typeKind); var asTypeName = string.Empty; if (memberDeclarationType != DeclarationType.Procedure && !TypeNames.TryGetValue(funcValueType, out asTypeName)) { if (funcValueType == VarEnum.VT_PTR) { try { var asTypeDesc = (TYPEDESC)Marshal.PtrToStructure(memberDescriptor.elemdescFunc.tdesc.lpValue, typeof(TYPEDESC)); asTypeName = GetTypeName(asTypeDesc, info); } catch { asTypeName = funcValueType.ToString(); //TypeNames[VarEnum.VT_VARIANT]; } } else { asTypeName = funcValueType.ToString(); //TypeNames[VarEnum.VT_VARIANT]; } } var attributes = new Attributes(); if (memberName == "_NewEnum" && ((FUNCFLAGS)memberDescriptor.wFuncFlags).HasFlag(FUNCFLAGS.FUNCFLAG_FNONBROWSABLE)) { attributes.AddEnumeratorMemberAttribute(memberName); } else if (memberDescriptor.memid == 0) { attributes.AddDefaultMemberAttribute(memberName); //Debug.WriteLine("Default member found: {0}.{1} ({2} / {3})", moduleDeclaration.IdentifierName, memberName, memberDeclarationType, (VarEnum)memberDescriptor.elemdescFunc.tdesc.vt); } else if (((FUNCFLAGS)memberDescriptor.wFuncFlags).HasFlag(FUNCFLAGS.FUNCFLAG_FHIDDEN)) { attributes.AddHiddenMemberAttribute(memberName); } return(new Declaration(new QualifiedMemberName(typeQualifiedModuleName, memberName), moduleDeclaration, moduleDeclaration, asTypeName, false, false, Accessibility.Global, memberDeclarationType, null, Selection.Home, true, null, attributes)); }
private Declaration CreateFieldDeclaration(ITypeInfo info, int fieldIndex, DeclarationType typeDeclarationType, QualifiedModuleName typeQualifiedModuleName, Declaration moduleDeclaration) { IntPtr ppVarDesc; info.GetVarDesc(fieldIndex, out ppVarDesc); var varDesc = (VARDESC)Marshal.PtrToStructure(ppVarDesc, typeof(VARDESC)); var names = new string[255]; int namesArrayLength; info.GetNames(varDesc.memid, names, 255, out namesArrayLength); var fieldName = names[0]; var fieldValueType = (VarEnum)varDesc.elemdescVar.tdesc.vt; var memberType = GetDeclarationType(varDesc, typeDeclarationType); string asTypeName; if (!TypeNames.TryGetValue(fieldValueType, out asTypeName)) { asTypeName = TypeNames[VarEnum.VT_VARIANT]; } return(new Declaration(new QualifiedMemberName(typeQualifiedModuleName, fieldName), moduleDeclaration, moduleDeclaration, asTypeName, false, false, Accessibility.Global, memberType, null, Selection.Home)); }
public void SetCurrentScope() { _currentScope = _moduleDeclaration; _currentParent = _moduleDeclaration; }
public override void ExitEnumerationStmt(VBAParser.EnumerationStmtContext context) { _parentDeclaration = _moduleDeclaration; }
public Declaration FindMemberEnclosedProjectWithoutEnclosingModule(Declaration callingProject, Declaration callingModule, Declaration callingParent, string memberName, DeclarationType memberType) { return(FindMemberEnclosedProjectWithoutEnclosingModule(callingProject, callingModule, callingParent, memberName, memberType, DeclarationType.Module)); }
/// <summary> /// Sets current scope to specified module member. /// </summary> /// <param name="procedureDeclaration"></param> /// <param name="name">The name of the member owning the current scope.</param> private void SetCurrentScope(Declaration procedureDeclaration, string name) { _currentScope = _qualifiedName + "." + name; _currentScopeDeclaration = procedureDeclaration; _parentDeclaration = procedureDeclaration; }
private void AddSubtype(Declaration subtype) { InvalidateCachedIsGlobal(); _subtypes.AddOrUpdate(subtype, 1, (key, value) => value); }
public void AddParameter(Declaration parameter) { _parameters.Add(parameter); }
internal void AddMember(Declaration member) { _members.Add(member); }
public DeclarationSymbolsListener( RubberduckParserState state, QualifiedModuleName qualifiedName, ComponentType type, IEnumerable <IAnnotation> annotations, IDictionary <Tuple <string, DeclarationType>, Attributes> attributes, Declaration projectDeclaration, string asTypeName = null) { _qualifiedName = qualifiedName; _annotations = annotations; _attributes = attributes; var declarationType = type == ComponentType.StandardModule ? DeclarationType.ProceduralModule : DeclarationType.ClassModule; var key = Tuple.Create(_qualifiedName.ComponentName, declarationType); var moduleAttributes = attributes.ContainsKey(key) ? attributes[key] : new Attributes(); if (declarationType == DeclarationType.ProceduralModule) { _moduleDeclaration = new ProceduralModuleDeclaration( _qualifiedName.QualifyMemberName(_qualifiedName.ComponentName), projectDeclaration, _qualifiedName.ComponentName, false, FindAnnotations(), moduleAttributes); } else { bool hasDefaultInstanceVariable = type != ComponentType.ClassModule && type != ComponentType.StandardModule; Declaration superType = null; if (type == ComponentType.Document) { if (!string.IsNullOrEmpty(asTypeName)) { superType = state.CoClasses.FirstOrDefault(cls => cls.Value.IdentifierName == asTypeName).Value; } else { foreach (var coclass in state.CoClasses) { try { if (_qualifiedName.Component == null || coclass.Key.Count != _qualifiedName.Component.Properties.Count) { continue; } var allNamesMatch = true; for (var i = 0; i < coclass.Key.Count; i++) { if (coclass.Key[i] != _qualifiedName.Component.Properties[i + 1].Name) { allNamesMatch = false; break; } } if (allNamesMatch) { superType = coclass.Value; break; } } catch (COMException) { } } } } _moduleDeclaration = new ClassModuleDeclaration( _qualifiedName.QualifyMemberName(_qualifiedName.ComponentName), projectDeclaration, _qualifiedName.ComponentName, false, FindAnnotations(), moduleAttributes, hasDefaultInstanceVariable: hasDefaultInstanceVariable); if (superType != null) { ((ClassModuleDeclaration)_moduleDeclaration).AddSupertype(superType); } } SetCurrentScope(); AddDeclaration(_moduleDeclaration); var component = _moduleDeclaration.QualifiedName.QualifiedModuleName.Component; if (component.Type == ComponentType.UserForm || component.HasDesigner) { DeclareControlsAsMembers(component); } }
public DeclarationEventArgs(Declaration declaration) { _declaration = declaration; }
public Declaration FindMemberEnclosedProjectInModule(Declaration callingProject, Declaration callingModule, Declaration callingParent, Declaration memberModule, string memberName, DeclarationType memberType) { var allMatches = MatchName(memberName); var memberMatches = allMatches.Where(m => m.DeclarationType.HasFlag(memberType) && Declaration.GetMemberProject(m).Equals(callingProject) && memberModule.Equals(Declaration.GetMemberModule(m))); var accessibleMembers = memberMatches.Where(m => AccessibilityCheck.IsMemberAccessible(callingProject, callingModule, callingParent, m)); var match = accessibleMembers.FirstOrDefault(); return(match); }
public static bool HasDefaultMember(Declaration type) { var classModule = type as ClassModuleDeclaration; return(classModule?.DefaultMember != null); }
public Declaration FindReferencedProject(Declaration callingProject, string referencedProjectName) { return(FindInReferencedProjectByPriority(callingProject, referencedProjectName, p => p.DeclarationType.HasFlag(DeclarationType.Project))); }
public void AddSupertype(Declaration supertype) { (supertype as ClassModuleDeclaration)?.AddSubtype(this); _supertypes.Add(supertype); }
/// <summary> /// Sets current scope to module-level. /// </summary> private void SetCurrentScope() { _currentScope = _qualifiedName.ToString(); _currentScopeDeclaration = _moduleDeclaration; _parentDeclaration = _moduleDeclaration; }
public Declaration FindModuleReferencedProject(Declaration callingProject, Declaration callingModule, Declaration referencedProject, string calleeModuleName, DeclarationType moduleType) { var moduleMatches = FindAllInReferencedProjectByPriority(callingProject, calleeModuleName, p => referencedProject.Equals(Declaration.GetMemberProject(p)) && p.DeclarationType.HasFlag(moduleType)); var accessibleModules = moduleMatches.Where(calledModule => AccessibilityCheck.IsModuleAccessible(callingProject, callingModule, calledModule)); var match = accessibleModules.FirstOrDefault(); return(match); }
private Declaration CreateDeclaration( string identifierName, string asTypeName, Accessibility accessibility, DeclarationType declarationType, ParserRuleContext context, Selection selection, bool isArray, VBAParser.AsTypeClauseContext asTypeContext, string typeHint, bool selfAssigned = false, bool withEvents = false) { Declaration result; if (declarationType == DeclarationType.Parameter) { var argContext = (VBAParser.ArgContext)context; var isOptional = argContext.OPTIONAL() != null; var isByRef = argContext.BYREF() != null || argContext.BYVAL() == null; var isParamArray = argContext.PARAMARRAY() != null; result = new ParameterDeclaration( new QualifiedMemberName(_qualifiedName, identifierName), _parentDeclaration, context, selection, asTypeName, asTypeContext, typeHint, isOptional, isByRef, isArray, isParamArray); if (_parentDeclaration is IParameterizedDeclaration) { ((IParameterizedDeclaration)_parentDeclaration).AddParameter(result); } } else { var key = Tuple.Create(identifierName, declarationType); Attributes attributes = null; if (_attributes.ContainsKey(key)) { attributes = _attributes[key]; } var annotations = FindAnnotations(selection.StartLine); if (declarationType == DeclarationType.Procedure) { result = new SubroutineDeclaration(new QualifiedMemberName(_qualifiedName, identifierName), _parentDeclaration, _currentScopeDeclaration, asTypeName, accessibility, context, selection, false, annotations, attributes); } else if (declarationType == DeclarationType.Function) { result = new FunctionDeclaration( new QualifiedMemberName(_qualifiedName, identifierName), _parentDeclaration, _currentScopeDeclaration, asTypeName, asTypeContext, typeHint, accessibility, context, selection, isArray, false, annotations, attributes); } else if (declarationType == DeclarationType.Event) { result = new EventDeclaration( new QualifiedMemberName(_qualifiedName, identifierName), _parentDeclaration, _currentScopeDeclaration, asTypeName, asTypeContext, typeHint, accessibility, context, selection, isArray, false, annotations, attributes); } else if (declarationType == DeclarationType.LibraryProcedure || declarationType == DeclarationType.LibraryFunction) { result = new ExternalProcedureDeclaration(new QualifiedMemberName(_qualifiedName, identifierName), _parentDeclaration, _currentScopeDeclaration, declarationType, asTypeName, asTypeContext, accessibility, context, selection, false, annotations); } else if (declarationType == DeclarationType.PropertyGet) { result = new PropertyGetDeclaration( new QualifiedMemberName(_qualifiedName, identifierName), _parentDeclaration, _currentScopeDeclaration, asTypeName, asTypeContext, typeHint, accessibility, context, selection, isArray, false, annotations, attributes); } else if (declarationType == DeclarationType.PropertySet) { result = new PropertySetDeclaration(new QualifiedMemberName(_qualifiedName, identifierName), _parentDeclaration, _currentScopeDeclaration, asTypeName, accessibility, context, selection, false, annotations, attributes); } else if (declarationType == DeclarationType.PropertyLet) { result = new PropertyLetDeclaration(new QualifiedMemberName(_qualifiedName, identifierName), _parentDeclaration, _currentScopeDeclaration, asTypeName, accessibility, context, selection, false, annotations, attributes); } else { result = new Declaration( new QualifiedMemberName(_qualifiedName, identifierName), _parentDeclaration, _currentScopeDeclaration, asTypeName, typeHint, selfAssigned, withEvents, accessibility, declarationType, context, selection, isArray, asTypeContext, false, annotations, attributes); } if (_parentDeclaration.DeclarationType == DeclarationType.ClassModule && result is ICanBeDefaultMember && ((ICanBeDefaultMember)result).IsDefaultMember) { ((ClassModuleDeclaration)_parentDeclaration).DefaultMember = result; } } return(result); }
public Declaration FindModuleEnclosingProjectWithoutEnclosingModule(Declaration callingProject, Declaration callingModule, string calleeModuleName, DeclarationType moduleType) { var nameMatches = MatchName(calleeModuleName); var moduleMatches = nameMatches.Where(m => m.DeclarationType.HasFlag(moduleType) && Declaration.GetMemberProject(m).Equals(callingProject) && !m.Equals(callingModule)); var accessibleModules = moduleMatches.Where(calledModule => AccessibilityCheck.IsModuleAccessible(callingProject, callingModule, calledModule)); var match = accessibleModules.FirstOrDefault(); return(match); }
private static ParameterDeclaration CreateParameterDeclaration(IReadOnlyList <string> memberNames, int paramIndex, FUNCDESC memberDescriptor, QualifiedModuleName typeQualifiedModuleName, Declaration memberDeclaration) { var paramName = memberNames[paramIndex + 1]; var paramPointer = new IntPtr(memberDescriptor.lprgelemdescParam.ToInt64() + Marshal.SizeOf(typeof(ELEMDESC)) * paramIndex); var elementDesc = (ELEMDESC)Marshal.PtrToStructure(paramPointer, typeof(ELEMDESC)); var isOptional = elementDesc.desc.paramdesc.wParamFlags.HasFlag(PARAMFLAG.PARAMFLAG_FOPT); var asParamTypeName = string.Empty; var isByRef = false; var isArray = false; var paramDesc = elementDesc.tdesc; var valueType = (VarEnum)paramDesc.vt; if (valueType == VarEnum.VT_PTR || valueType == VarEnum.VT_BYREF) { //var paramTypeDesc = (TYPEDESC) Marshal.PtrToStructure(paramDesc.lpValue, typeof (TYPEDESC)); isByRef = true; var paramValueType = (VarEnum)paramDesc.vt; if (!TypeNames.TryGetValue(paramValueType, out asParamTypeName)) { asParamTypeName = TypeNames[VarEnum.VT_VARIANT]; } //var href = paramDesc.lpValue.ToInt32(); //ITypeInfo refTypeInfo; //info.GetRefTypeInfo(href, out refTypeInfo); // todo: get type info? } if (valueType == VarEnum.VT_CARRAY || valueType == VarEnum.VT_ARRAY || valueType == VarEnum.VT_SAFEARRAY) { // todo: tell ParamArray arrays from normal arrays isArray = true; } return(new ParameterDeclaration(new QualifiedMemberName(typeQualifiedModuleName, paramName), memberDeclaration, asParamTypeName, isOptional, isByRef, isArray)); }
private void AddDeclaration(Declaration declaration) { _createdDeclarations.Add(declaration); }
public override void ExitPrivateTypeDeclaration(VBAParser.PrivateTypeDeclarationContext context) { _parentDeclaration = _moduleDeclaration; }