19
19
import java .util .zip .ZipFile ;
20
20
21
21
import com .github .codeql .Logger ;
22
- import static com .github .codeql .ClassNamesKt .getIrDeclBinaryName ;
22
+ import static com .github .codeql .ClassNamesKt .getIrElementBinaryName ;
23
23
import static com .github .codeql .ClassNamesKt .getIrClassVirtualFile ;
24
24
25
+ import org .jetbrains .kotlin .ir .IrElement ;
25
26
import org .jetbrains .kotlin .ir .declarations .IrClass ;
26
27
27
28
import com .intellij .openapi .vfs .VirtualFile ;
@@ -212,20 +213,19 @@ private File trapFileFor(File file) {
212
213
PathTransformer .std ().fileAsDatabaseString (file ) + ".trap.gz" );
213
214
}
214
215
215
- private File getTrapFileForDecl (IrDeclaration sym , String signature ) {
216
+ private File getTrapFileForDecl (IrElement sym , String signature ) {
216
217
if (currentSpecFileEntry == null )
217
218
return null ;
218
219
return trapFileForDecl (sym , signature );
219
220
}
220
221
221
- private File trapFileForDecl (IrDeclaration sym , String signature ) {
222
+ private File trapFileForDecl (IrElement sym , String signature ) {
222
223
return FileUtil .fileRelativeTo (currentSpecFileEntry .getTrapFolder (),
223
224
trapFilePathForDecl (sym , signature ));
224
225
}
225
226
226
- private String trapFilePathForDecl (IrDeclaration sym , String signature ) {
227
- String binaryName = getIrDeclBinaryName (sym );
228
- String binaryNameWithSignature = binaryName + signature ;
227
+ private String trapFilePathForDecl (IrElement sym , String signature ) {
228
+ String binaryName = getIrElementBinaryName (sym );
229
229
// TODO: Reinstate this?
230
230
//if (getTrackClassOrigins())
231
231
// classId += "-" + StringDigestor.digest(sym.getSourceFileId());
@@ -241,7 +241,7 @@ private String trapFilePathForDecl(IrDeclaration sym, String signature) {
241
241
* Deletion of existing trap files.
242
242
*/
243
243
244
- private void deleteTrapFileAndDependencies (IrDeclaration sym , String signature ) {
244
+ private void deleteTrapFileAndDependencies (IrElement sym , String signature ) {
245
245
File trap = trapFileForDecl (sym , signature );
246
246
if (trap .exists ()) {
247
247
trap .delete ();
@@ -269,7 +269,7 @@ private void deleteTrapFileAndDependencies(IrDeclaration sym, String signature)
269
269
* Any unique suffix needed to distinguish `sym` from other declarations with the same name.
270
270
* For functions for example, this means its parameter signature.
271
271
*/
272
- private TrapFileManager getMembersWriterForDecl (File trap , File trapFileBase , TrapClassVersion trapFileVersion , IrDeclaration sym , String signature ) {
272
+ private TrapFileManager getMembersWriterForDecl (File trap , File trapFileBase , TrapClassVersion trapFileVersion , IrElement sym , String signature ) {
273
273
if (use_trap_locking ) {
274
274
TrapClassVersion currVersion = TrapClassVersion .fromSymbol (sym , log );
275
275
String shortName = sym instanceof IrDeclarationWithName ? ((IrDeclarationWithName )sym ).getName ().asString () : "(name unknown)" ;
@@ -326,7 +326,7 @@ private TrapFileManager getMembersWriterForDecl(File trap, File trapFileBase, Tr
326
326
return trapWriter (trap , sym , signature );
327
327
}
328
328
329
- private TrapFileManager trapWriter (File trapFile , IrDeclaration sym , String signature ) {
329
+ private TrapFileManager trapWriter (File trapFile , IrElement sym , String signature ) {
330
330
if (!trapFile .getName ().endsWith (".trap.gz" ))
331
331
throw new CatastrophicError ("OdasaOutput only supports writing to compressed trap files" );
332
332
String relative = FileUtil .relativePath (trapFile , currentSpecFileEntry .getTrapFolder ());
@@ -335,7 +335,7 @@ private TrapFileManager trapWriter(File trapFile, IrDeclaration sym, String sign
335
335
return concurrentWriter (trapFile , relative , log , sym , signature );
336
336
}
337
337
338
- private TrapFileManager concurrentWriter (File trapFile , String relative , Logger log , IrDeclaration sym , String signature ) {
338
+ private TrapFileManager concurrentWriter (File trapFile , String relative , Logger log , IrElement sym , String signature ) {
339
339
if (trapFile .exists ())
340
340
return null ;
341
341
return new TrapFileManager (trapFile , relative , true , log , sym , signature );
@@ -345,11 +345,11 @@ public class TrapFileManager implements AutoCloseable {
345
345
346
346
private TrapDependencies trapDependenciesForClass ;
347
347
private File trapFile ;
348
- private IrDeclaration sym ;
348
+ private IrElement sym ;
349
349
private String signature ;
350
350
private boolean hasError = false ;
351
351
352
- private TrapFileManager (File trapFile , String relative , boolean concurrentCreation , Logger log , IrDeclaration sym , String signature ) {
352
+ private TrapFileManager (File trapFile , String relative , boolean concurrentCreation , Logger log , IrElement sym , String signature ) {
353
353
trapDependenciesForClass = new TrapDependencies (relative );
354
354
this .trapFile = trapFile ;
355
355
this .sym = sym ;
@@ -360,7 +360,7 @@ public File getFile() {
360
360
return trapFile ;
361
361
}
362
362
363
- public void addDependency (IrDeclaration dep , String signature ) {
363
+ public void addDependency (IrElement dep , String signature ) {
364
364
trapDependenciesForClass .addDependency (trapFilePathForDecl (dep , signature ));
365
365
}
366
366
@@ -460,19 +460,19 @@ public TrapLocker getTrapLockerForModule(String moduleName) {
460
460
*
461
461
* @return a {@link TrapLocker} for the trap file corresponding to the given class symbol.
462
462
*/
463
- public TrapLocker getTrapLockerForDecl (IrDeclaration sym , String signature , boolean fromSource ) {
463
+ public TrapLocker getTrapLockerForDecl (IrElement sym , String signature , boolean fromSource ) {
464
464
return new TrapLocker (sym , signature , fromSource );
465
465
}
466
466
467
467
public class TrapLocker implements AutoCloseable {
468
- private final IrDeclaration sym ;
468
+ private final IrElement sym ;
469
469
private final File trapFile ;
470
470
// trapFileBase is used when doing lockless TRAP file writing.
471
471
// It is trapFile without the #metadata.trap.gz suffix.
472
472
private File trapFileBase = null ;
473
473
private TrapClassVersion trapFileVersion = null ;
474
474
private final String signature ;
475
- private TrapLocker (IrDeclaration decl , String signature , boolean fromSource ) {
475
+ private TrapLocker (IrElement decl , String signature , boolean fromSource ) {
476
476
this .sym = decl ;
477
477
this .signature = signature ;
478
478
if (sym ==null ) {
@@ -720,11 +720,18 @@ private static long getVirtualFileTimeStamp(VirtualFile vf, Logger log) {
720
720
return vf .getTimeStamp ();
721
721
}
722
722
723
- private static TrapClassVersion fromSymbol (IrDeclaration sym , Logger log ) {
724
- VirtualFile vf = sym instanceof IrClass ? getIrClassVirtualFile ((IrClass )sym ) :
725
- sym .getParent () instanceof IrClass ? getIrClassVirtualFile ((IrClass )sym .getParent ()) :
726
- null ;
727
- if (vf == null )
723
+ private static VirtualFile getVirtualFileIfClass (IrElement e ) {
724
+ if (e instanceof IrClass )
725
+ return getIrClassVirtualFile ((IrClass )e );
726
+ else
727
+ return null ;
728
+ }
729
+
730
+ private static TrapClassVersion fromSymbol (IrElement sym , Logger log ) {
731
+ VirtualFile vf = getVirtualFileIfClass (sym );
732
+ if (vf == null && sym instanceof IrDeclaration )
733
+ vf = getVirtualFileIfClass (((IrDeclaration )sym ).getParent ());
734
+ if (vf == null )
728
735
return new TrapClassVersion (-1 , 0 , 0 , null );
729
736
730
737
final int [] versionStore = new int [1 ];
0 commit comments