2012-08-03 7 views
9

यह एक ठेठ कॉपी-पेस्ट त्रुटि है:क्या कोई उपकरण है जो डुप्लिकेट इंटरफ़ेस GUID का पता लगाता है?

अगर कुछ डेल्फी GUIDs के साथ इंटरफेस घोषणाओं युक्त कोड कॉपी-पेस्ट किया है, डेल्फी शिकायत और कोड जो विभिन्न स्थानों में फिर से उपयोग करता है एक ही GUID संकलन नहीं होंगे।

"समर्थन" फ़ंक्शन इंटरफ़ेस के साथ उनके GUID के आधार पर काम करता है, इसलिए त्रुटियां संभव हैं।

क्या कोई 'गुणवत्ता आश्वासन' उपकरण उपलब्ध है (पेगेंजा या डेल्फी सोनार प्लगइन शायद) जो उन्हें पहचान सकता है?

+3

अधिक सटीक होने के लिए, आपको कुछ ऐसा पता होना चाहिए जो कि विभिन्न इंटरफ़ेस परिभाषा के लिए GUID का उपयोग किया जाता है? GUID एक ही इंटरफ़ेस के लिए स्रोत कोड में कई बार प्रकट हो सकता है। लेकिन IMHO यह Ctrl + Shift + G की बजाय नई परिभाषा के प्रतिलिपि बनाने और पेस्ट करने के लिए कोडिंग त्रुटि है। –

+4

मुझे पता नहीं है कि पीएएल की ऐसी रिपोर्ट है, लेकिन यह एक अच्छा विस्तार होगा। मैंने एक फीचर अनुरोध किया है। –

उत्तर

1

आप पर एक यूनिक्स/मैक कर रहे हैं इस कोशिश - या यदि आप अपने पीसी पर cygwin है

find . -name '*.pas' -exec awk "/\['{.*}'\]/ {print $1}" {} \; | sed 's/ //g' | sort | uniq -d 

तब व्यक्ति डुप्लिकेट

find . -name '*.pas' -exec grep -i -l 'XXXX-XXX-XXX' {} \; 

पर एक मैक परीक्षण किया गया लगता है

+0

हेक्टेयर - यह नहीं पता था कि यह प्रश्न 2 साल पुराना था: - / – daven11

1

केवल डेल्फी के हाल के संस्करण के साथ काम करता है। आप रन-टाइम पर इसका पता लगाने के लिए निम्न कोड का उपयोग कर सकते हैं:

unit uInterfaces.Duplicates; 

interface 

uses 
    System.Rtti, 
    Spring, 
    Spring.Collections; 

type 
    /// <summary> 
    /// Class allows to list the interfaces which are not implemented by any class in your module. 
    /// </summary> 
    InterfacesWithDuplicateGUID = class 
    private class var 
    /// <summary> 
    /// Reference to the RTTI context. 
    /// </summary> 
    FCtx: TRttiContext; 
    public 
    /// <summary> 
    /// Function returns the list of interfaces with duplicate GUID. 
    /// </summary> 
    /// <param name="AFilter"> 
    /// A filter predicate for types to process. 
    /// </param> 
    class function Map(AFilter: TPredicate<TRttiInterfaceType> = nil): IMultiMap<TGUID, TRttiInterfaceType>; 

    class constructor Create; 
    class destructor Destroy; 
    end; 

implementation 

uses 
    System.TypInfo; 

{ InterfacesNotImplemented } 

class constructor InterfacesWithDuplicateGUID.Create; 
begin 
    FCtx := TRttiContext.Create; 
end; 

class destructor InterfacesWithDuplicateGUID.Destroy; 
begin 
    FCtx.Free; 
end; 

class function InterfacesWithDuplicateGUID.Map(AFilter: TPredicate<TRttiInterfaceType> = nil): IMultiMap<TGUID, TRttiInterfaceType>; 
var 
    LType: TRttiType; 
    LIntf: TRttiInterfaceType; 
    LTypes: IList<TRttiInterfaceType>; 
begin 
    { Create the result instance } 
    Result := TCollections.CreateMultiMap<TGUID, TRttiInterfaceType>; 

    { Get all the types } 
    LTypes := TCollections.CreateList<TRttiInterfaceType>; 

    { Build the multimap } 
    for LType in FCtx.GetTypes do 
    { Add only classes and interfaces } 
    if LType.TypeKind = tkInterface then 
     { Skip interfaces which does not have GUID } 
     if TRttiInterfaceType(LType).GUID <> TGUID.Empty then 
     begin 
      { Handle user filter } 
      if Assigned(AFilter) then 
      if not AFilter(TRttiInterfaceType(LType)) then 
       Continue; 

      LTypes.Add(TRttiInterfaceType(LType)); 
     end; 

    { For all interaces } 
    for LIntf in LTypes do 
    if LTypes.Any(
     function (const AType: TRttiInterfaceType): Boolean 
     begin 
     Result := (AType.GUID = LIntf.GUID) and (LIntf.QualifiedName <> AType.QualifiedName); 
     end) then 
     Result.Add(LIntf.GUID, LIntf); 
end; 

end. 

बेशक यह आपकी आवश्यकताओं के अनुरूप है। चूंकि इसे उत्पादन कोड में शामिल करना सबसे अच्छा विचार नहीं है। हालांकि परीक्षण कोड में शामिल किया जा सकता है।

संबंधित मुद्दे