• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

moosetechnology / Famix-Value / 11854370139

15 Nov 2024 10:13AM UTC coverage: 22.591% (-1.4%) from 24.038%
11854370139

push

github

Gabriel-Darbord
Merge 99bc4b8f0

19 of 253 new or added lines in 12 files covered. (7.51%)

103 existing lines in 11 files now uncovered.

762 of 3373 relevant lines covered (22.59%)

0.23 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/Famix-Value-Importer/FamixJavaEntityFinder.class.st
1
"
2
An importer helper for finding Java types represented by `FamixJavaType` and its subclasses in a FamixJava model.
3
"
4
Class {
5
        #name : 'FamixJavaEntityFinder',
6
        #superclass : 'FamixEntityFinder',
7
        #classVars : [
8
                'FieldDescriptors'
9
        ],
10
        #category : 'Famix-Value-Importer',
11
        #package : 'Famix-Value-Importer'
12
}
13

14
{ #category : 'class initialization' }
15
FamixJavaEntityFinder class >> initialize [
×
16
        "See https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.3.2"
×
17

×
18
        FieldDescriptors := IdentityDictionary new.
×
19
        FieldDescriptors
×
20
                at: $B put: 'byte';
×
21
                at: $C put: 'char';
×
22
                at: $D put: 'double';
×
23
                at: $F put: 'float';
×
24
                at: $I put: 'int';
×
25
                at: $J put: 'long';
×
26
                at: $S put: 'short';
×
27
                at: $Z put: 'boolean'
×
28
]
×
29

30
{ #category : 'enumerating' }
31
FamixJavaEntityFinder >> methodNameFromSignature: signature [
×
32

×
33
        ^ signature copyUpTo: $(
×
34
]
×
35

36
{ #category : 'enumerating' }
37
FamixJavaEntityFinder >> parseTypeName: name [
×
38
        "The name may not be fully qualified.
×
39
        Even if we want to find a name in java.lang or java.util packages, we want to search using the mooseName if it is parameterized.
×
40
        Famix does not represent arrays, but we need the information, so we use a wrapper around the type."
×
41

×
42
        | typeName dimensions type |
×
43
        typeName := self translateFieldDescriptor: name.
×
44
        dimensions := name occurrencesOf: $[.
×
45
        type := (typeName includes: $.)
×
46
                        ifFalse: [ self findTypeWithName: typeName ]
×
47
                        ifTrue: [ "Search by translating the type name to a mooseName."
×
48
                                self findTypeWithMooseName:
×
49
                                        ((typeName allButLast: dimensions * 2)
×
50
                                                 copyReplaceAll: '.'
×
51
                                                 with: '::') ].
×
52
        ^ dimensions > 0
×
53
                  ifFalse: [ type ]
×
54
                  ifTrue: [
×
55
                  (FamixValueJavaArray wrapping: type) dimensions: dimensions ]
×
56
]
×
57

58
{ #category : 'matching' }
59
FamixJavaEntityFinder >> signatureOf: method matches: signature [
×
60
        "Assume the signature includes the method name and the field descriptors of the parameters, e.g. `main([Ljava.lang.String;)`.
×
61
        Because Famix doesn't represent arrays, use the method's signature string which contains array information.
×
62
        However, its format is the one used in source code, e.g. `main(String[])`, so there needs to be a translation."
×
63

×
64
        | parameters |
×
65
        parameters := (signature
×
66
                               copyFrom: method name size + 2
×
67
                               to: signature size - 1)
×
68
                              ifEmpty: [ #(  ) ]
×
69
                              ifNotEmpty: [ :params | params splitOn: $, ].
×
70
        method parameters size = parameters size ifFalse: [ ^ false ].
×
71
        ^ method signatureWithoutParameterTypes
×
72
          = (String streamContents: [ :stream |
×
73
                           stream nextPutAll: method name.
×
74
                           stream nextPut: $(.
×
75
                           self translateFieldDescriptors: parameters on: stream.
×
76
                           stream nextPut: $) ])
×
77
]
×
78

79
{ #category : 'translating' }
80
FamixJavaEntityFinder >> translateFieldDescriptor: fieldDescriptor [
×
81
        "Translate Java field descriptors to a type name used by Moose, e.g. '[I' -> 'int[]'
×
82
        See https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.3.2"
×
83

×
84
        | dimensions typeName |
×
85
        dimensions := 0.
×
86
        [ (fieldDescriptor at: dimensions + 1) == $[ ] whileTrue: [
×
87
                dimensions := dimensions + 1 ].
×
88
        dimensions = 0 ifTrue: [ ^ fieldDescriptor ].
×
89
        typeName := fieldDescriptor allButFirst: dimensions.
×
90
        typeName := FieldDescriptors
×
91
                            at: (typeName at: 1)
×
92
                            ifAbsent: [ "an instance of class, e.g. Ljava.lang.String;"
×
93
                                    (typeName at: 1) == $L
×
94
                                            ifTrue: [ typeName copyFrom: 2 to: typeName size - 1 ]
×
95
                                            ifFalse: [
×
96
                                            self error: 'incoherent Java field descriptor' ] ].
×
97
        [
×
98
        typeName := typeName , '[]'.
×
99
        (dimensions := dimensions - 1) > 0 ] whileTrue.
×
100
        ^ typeName
×
101
]
×
102

103
{ #category : 'matching' }
104
FamixJavaEntityFinder >> translateFieldDescriptors: parameters on: stream [
×
105
        "Only keep the type's simple name, discard the qualifying prefix."
×
106

×
107
        parameters
×
108
                do: [ :parameter |
×
109
                        | translation index |
×
110
                        translation := self translateFieldDescriptor: parameter.
×
NEW
111
                        index := translation
×
NEW
112
                                         lastIndexOfAnyOf: '.$'
×
NEW
113
                                         startingAt: translation size
×
NEW
114
                                         ifAbsent: 0.
×
115
                        stream nextPutAll: (index = 0
×
116
                                         ifTrue: [ translation ]
×
117
                                         ifFalse: [ translation allButFirst: index ]) ]
×
118
                separatedBy: [ stream nextPut: $, ]
×
119
]
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc