Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <basic/codecompletecache.hxx>
21 : #include <iostream>
22 : #include <rtl/instance.hxx>
23 : #include <officecfg/Office/BasicIDE.hxx>
24 :
25 : namespace
26 : {
27 : class theCodeCompleteOptions: public ::rtl::Static< CodeCompleteOptions, theCodeCompleteOptions >{};
28 : }
29 :
30 0 : CodeCompleteOptions::CodeCompleteOptions()
31 : {
32 0 : bIsAutoCorrectOn = officecfg::Office::BasicIDE::Autocomplete::AutoCorrect::get();
33 0 : bIsAutoCloseParenthesisOn = officecfg::Office::BasicIDE::Autocomplete::AutocloseParenthesis::get();
34 0 : bIsAutoCloseQuotesOn = officecfg::Office::BasicIDE::Autocomplete::AutocloseDoubleQuotes::get();
35 0 : bIsProcedureAutoCompleteOn = officecfg::Office::BasicIDE::Autocomplete::AutocloseProc::get();
36 0 : bIsCodeCompleteOn = officecfg::Office::BasicIDE::Autocomplete::CodeComplete::get();
37 0 : bExtendedTypeDeclarationOn = officecfg::Office::BasicIDE::Autocomplete::UseExtended::get();
38 0 : }
39 :
40 0 : bool CodeCompleteOptions::IsCodeCompleteOn()
41 : {
42 0 : return theCodeCompleteOptions::get().aMiscOptions.IsExperimentalMode() && theCodeCompleteOptions::get().bIsCodeCompleteOn;
43 : }
44 :
45 0 : void CodeCompleteOptions::SetCodeCompleteOn( const bool& b )
46 : {
47 0 : theCodeCompleteOptions::get().bIsCodeCompleteOn = b;
48 0 : }
49 :
50 0 : bool CodeCompleteOptions::IsExtendedTypeDeclaration()
51 : {
52 0 : return theCodeCompleteOptions::get().aMiscOptions.IsExperimentalMode() && theCodeCompleteOptions::get().bExtendedTypeDeclarationOn;
53 : }
54 :
55 0 : void CodeCompleteOptions::SetExtendedTypeDeclaration( const bool& b )
56 : {
57 0 : theCodeCompleteOptions::get().bExtendedTypeDeclarationOn = b;
58 0 : }
59 :
60 0 : bool CodeCompleteOptions::IsProcedureAutoCompleteOn()
61 : {
62 0 : return theCodeCompleteOptions::get().aMiscOptions.IsExperimentalMode() && theCodeCompleteOptions::get().bIsProcedureAutoCompleteOn;
63 : }
64 :
65 0 : void CodeCompleteOptions::SetProcedureAutoCompleteOn( const bool& b )
66 : {
67 0 : theCodeCompleteOptions::get().bIsProcedureAutoCompleteOn = b;
68 0 : }
69 :
70 0 : bool CodeCompleteOptions::IsAutoCloseQuotesOn()
71 : {
72 0 : return theCodeCompleteOptions::get().aMiscOptions.IsExperimentalMode() && theCodeCompleteOptions::get().bIsAutoCloseQuotesOn;
73 : }
74 :
75 0 : void CodeCompleteOptions::SetAutoCloseQuotesOn( const bool& b )
76 : {
77 0 : theCodeCompleteOptions::get().bIsAutoCloseQuotesOn = b;
78 0 : }
79 :
80 0 : bool CodeCompleteOptions::IsAutoCloseParenthesisOn()
81 : {
82 0 : return theCodeCompleteOptions::get().aMiscOptions.IsExperimentalMode() && theCodeCompleteOptions::get().bIsAutoCloseParenthesisOn;
83 : }
84 :
85 0 : void CodeCompleteOptions::SetAutoCloseParenthesisOn( const bool& b )
86 : {
87 0 : theCodeCompleteOptions::get().bIsAutoCloseParenthesisOn = b;
88 0 : }
89 :
90 0 : bool CodeCompleteOptions::IsAutoCorrectOn()
91 : {
92 0 : return theCodeCompleteOptions::get().aMiscOptions.IsExperimentalMode() && theCodeCompleteOptions::get().bIsAutoCorrectOn;
93 : }
94 :
95 0 : void CodeCompleteOptions::SetAutoCorrectOn( const bool& b )
96 : {
97 0 : theCodeCompleteOptions::get().bIsAutoCorrectOn = b;
98 0 : }
99 :
100 0 : std::ostream& operator<< (std::ostream& aStream, const CodeCompleteDataCache& aCache)
101 : {
102 0 : aStream << "Global variables" << std::endl;
103 0 : for(CodeCompleteVarTypes::const_iterator aIt = aCache.aGlobalVars.begin(); aIt != aCache.aGlobalVars.end(); ++aIt )
104 : {
105 0 : aStream << aIt->first << "," << aIt->second << std::endl;
106 : }
107 0 : aStream << "Local variables" << std::endl;
108 0 : for( CodeCompleteVarScopes::const_iterator aIt = aCache.aVarScopes.begin(); aIt != aCache.aVarScopes.end(); ++aIt )
109 : {
110 0 : aStream << aIt->first << std::endl;
111 0 : CodeCompleteVarTypes aVarTypes = aIt->second;
112 0 : for( CodeCompleteVarTypes::const_iterator aOtherIt = aVarTypes.begin(); aOtherIt != aVarTypes.end(); ++aOtherIt )
113 : {
114 0 : aStream << "\t" << aOtherIt->first << "," << aOtherIt->second << std::endl;
115 : }
116 0 : }
117 0 : aStream << "-----------------" << std::endl;
118 0 : return aStream;
119 : }
120 :
121 0 : void CodeCompleteDataCache::Clear()
122 : {
123 0 : aVarScopes.clear();
124 0 : aGlobalVars.clear();
125 0 : }
126 :
127 0 : void CodeCompleteDataCache::InsertGlobalVar( const OUString& sVarName, const OUString& sVarType )
128 : {
129 0 : aGlobalVars.insert( CodeCompleteVarTypes::value_type(sVarName, sVarType) );
130 0 : }
131 :
132 0 : void CodeCompleteDataCache::InsertLocalVar( const OUString& sProcName, const OUString& sVarName, const OUString& sVarType )
133 : {
134 0 : CodeCompleteVarScopes::const_iterator aIt = aVarScopes.find( sProcName );
135 0 : if( aIt == aVarScopes.end() ) //new procedure
136 : {
137 0 : CodeCompleteVarTypes aTypes;
138 0 : aTypes.insert( CodeCompleteVarTypes::value_type(sVarName, sVarType) );
139 0 : aVarScopes.insert( CodeCompleteVarScopes::value_type(sProcName, aTypes) );
140 : }
141 : else
142 : {
143 0 : CodeCompleteVarTypes aTypes = aVarScopes[ sProcName ];
144 0 : aTypes.insert( CodeCompleteVarTypes::value_type(sVarName, sVarType) );
145 0 : aVarScopes[ sProcName ] = aTypes;
146 : }
147 0 : }
148 :
149 0 : OUString CodeCompleteDataCache::GetVarType( const OUString& sVarName ) const
150 : {
151 0 : for( CodeCompleteVarScopes::const_iterator aIt = aVarScopes.begin(); aIt != aVarScopes.end(); ++aIt )
152 : {
153 0 : CodeCompleteVarTypes aTypes = aIt->second;
154 0 : for( CodeCompleteVarTypes::const_iterator aOtherIt = aTypes.begin(); aOtherIt != aTypes.end(); ++aOtherIt )
155 : {
156 0 : if( aOtherIt->first.equalsIgnoreAsciiCase( sVarName ) )
157 : {
158 0 : return aOtherIt->second;
159 : }
160 : }
161 0 : }
162 : //not a local, search global scope
163 0 : for( CodeCompleteVarTypes::const_iterator aIt = aGlobalVars.begin(); aIt != aGlobalVars.end(); ++aIt )
164 : {
165 0 : if( aIt->first.equalsIgnoreAsciiCase( sVarName ) )
166 0 : return aIt->second;
167 : }
168 0 : return OUString(""); //not found
169 : }
170 :
171 0 : OUString CodeCompleteDataCache::GetCorrectCaseVarName( const OUString& sVarName, const OUString& sActProcName ) const
172 : {
173 0 : for( CodeCompleteVarScopes::const_iterator aIt = aVarScopes.begin(); aIt != aVarScopes.end(); ++aIt )
174 : {
175 0 : CodeCompleteVarTypes aTypes = aIt->second;
176 0 : for( CodeCompleteVarTypes::const_iterator aOtherIt = aTypes.begin(); aOtherIt != aTypes.end(); ++aOtherIt )
177 : {
178 0 : if( aOtherIt->first.equalsIgnoreAsciiCase( sVarName ) && aIt->first.equalsIgnoreAsciiCase( sActProcName ) )
179 : {
180 0 : return aOtherIt->first;
181 : }
182 : }
183 0 : }
184 : // search global scope
185 0 : for( CodeCompleteVarTypes::const_iterator aIt = aGlobalVars.begin(); aIt != aGlobalVars.end(); ++aIt )
186 : {
187 0 : if( aIt->first.equalsIgnoreAsciiCase( sVarName ) )
188 0 : return aIt->first;
189 : }
190 0 : return OUString(""); //not found
191 3 : }
192 :
193 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|