Remove duplicated include
[LibreOffice.git] / bin / find-unused-using.sh
blob3521f64f49fdb880e86b8867cc3cda22aa9c1751
1 # This file is part of the LibreOffice project.
3 # This Source Code Form is subject to the terms of the Mozilla Public
4 # License, v. 2.0. If a copy of the MPL was not distributed with this
5 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 #!/bin/bash
8 # TODO search also for 'using namespace com/::com/css' - this is likely the fattest target and clang-tidy can't do it
9 for ns in accessibility basegfx chart com css cppu comphelper connectivity formula dbtools editeng rtl sfx2 svt osl oox sax_fastparser sal sd ucbhelper utl vcl xmloff; do
10 echo "Searching for namespace: $ns";
11 # search in cxx files, excluding URE headers, plus some files with false positives
12 for file in $(git grep -l "^\s*using :*$ns::" *hxx *cxx \
13 ':!include/com/' \
14 ':!include/cppu/' \
15 ':!include/cppuhelper/' \
16 ':!include/osl/' \
17 ':!include/rtl/' \
18 ':!include/sal/' \
19 ':!include/salhelper/' \
20 ':!include/systools/' \
21 ':!include/typelib/' \
22 ':!include/uno/' \
23 ':!include/sfx2/stbitem.hxx' \
24 ':!sw/source/uibase/inc/maildispatcher.hxx'
25 ) ; do
26 for class in $(git grep -h "using :*$ns::" "$file" | rev | cut -d : -f -1 | rev | cut -d " " -f 1 | tr -d ";") ; do
27 if [ "$ns" == "com" ] ; then # com namespace may be mentioned in relevant header name too
28 if [[ $(grep -c "$class" "$file") -eq 1 || $(grep -c "$class" "$file") -le 2 && $(grep -c -e "$class".hpp -e "$class".hxx -e "$class".h "$file") -eq 1 ]]; then
29 echo "$file";
30 echo "Class name in above file is mentioned once or twice: $class";
32 else
33 if [ $(grep -c -F "$class" "$file") -eq 1 ]; then
34 echo "$file";
35 echo "Class name in above file is mentioned once: $class";
38 done
39 done
40 done
42 # vim: set noet sw=4 ts=4: