├── .github └── workflows │ ├── benchmarks.yml │ ├── build-and-test.yml │ ├── github-packages.yml │ ├── nightly-builds.yml │ ├── release.yml │ └── telegram-notifications.yml ├── .gitignore ├── LICENSE ├── NOTICE ├── README.md ├── add-licence.sh ├── add-license.bat ├── build.gradle.kts ├── buildSrc ├── build.gradle.kts ├── settings.gradle.kts └── src │ └── main │ └── kotlin │ ├── Dependencies.kt │ └── Tests.kt ├── docs ├── badges │ ├── branches.svg │ ├── coverage-summary.json │ └── jacoco.svg ├── copyright │ └── COPYRIGHT_HEADER.txt └── svg │ ├── block-graph-IRExamples-concatTest-1.svg │ ├── block-graph-IRExamples-init-0.svg │ ├── block-graph-IRExamples-runBinarySearchIteratively-2.svg │ ├── block-graph-IRExamples-runBinarySearchIterativelyTryCatch-3.svg │ ├── block-graph-IRExamples-sortSequence-4.svg │ ├── block-graph-IRExamples-sortTimes-5.svg │ ├── block-graph-IRExamples-test-6.svg │ ├── block-graph-IRExamples-testField-7.svg │ ├── block-graph-IRExamples-testPrimitives-8.svg │ ├── graph-IRExamples-concatTest-1.svg │ ├── graph-IRExamples-init-0.svg │ ├── graph-IRExamples-runBinarySearchIteratively-2.svg │ ├── graph-IRExamples-runBinarySearchIterativelyTryCatch-3.svg │ ├── graph-IRExamples-sortSequence-4.svg │ ├── graph-IRExamples-sortTimes-5.svg │ ├── graph-IRExamples-test-6.svg │ ├── graph-IRExamples-testField-7.svg │ └── graph-IRExamples-testPrimitives-8.svg ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── jacodb-analysis ├── README.md ├── build.gradle.kts └── src │ ├── main │ └── kotlin │ │ └── org │ │ └── jacodb │ │ └── analysis │ │ ├── config │ │ ├── Condition.kt │ │ ├── Position.kt │ │ └── TaintAction.kt │ │ ├── graph │ │ ├── ApplicationGraphFactory.kt │ │ ├── BackwardGraphs.kt │ │ ├── JcApplicationGraphImpl.kt │ │ ├── JcNoopInst.kt │ │ └── SimplifiedJcApplicationGraph.kt │ │ ├── ifds │ │ ├── AccessPath.kt │ │ ├── Accessors.kt │ │ ├── Analyzer.kt │ │ ├── Edge.kt │ │ ├── FlowFunctions.kt │ │ ├── IfdsResult.kt │ │ ├── Manager.kt │ │ ├── Maybe.kt │ │ ├── Reason.kt │ │ ├── Runner.kt │ │ ├── Summary.kt │ │ ├── TraceGraph.kt │ │ ├── UnitResolver.kt │ │ └── Vertex.kt │ │ ├── impl │ │ └── custom │ │ │ ├── AbstractFlowAnalysis.kt │ │ │ ├── BackwardFlowAnalysis.kt │ │ │ ├── FlowAnalysis.kt │ │ │ ├── FlowAnalysisImpl.kt │ │ │ ├── ForwardFlowAnalysis.kt │ │ │ ├── NullAssumptionAnalysis.kt │ │ │ └── ReachingDefinitionsAnalysis.kt │ │ ├── npe │ │ ├── NpeAnalyzers.kt │ │ ├── NpeFlowFunctions.kt │ │ ├── NpeManager.kt │ │ └── Utils.kt │ │ ├── sarif │ │ ├── Sarif.kt │ │ ├── SourceFileResolver.kt │ │ └── Vulnerability.kt │ │ ├── taint │ │ ├── Sarif.kt │ │ ├── TaintAnalyzers.kt │ │ ├── TaintBidiRunner.kt │ │ ├── TaintEvents.kt │ │ ├── TaintFacts.kt │ │ ├── TaintFlowFunctions.kt │ │ ├── TaintManager.kt │ │ ├── TaintSummaries.kt │ │ └── Types.kt │ │ ├── unused │ │ ├── Sarif.kt │ │ ├── UnusedVariableAnalyzer.kt │ │ ├── UnusedVariableEvents.kt │ │ ├── UnusedVariableFacts.kt │ │ ├── UnusedVariableFlowFunctions.kt │ │ ├── UnusedVariableManager.kt │ │ ├── UnusedVariableSummaries.kt │ │ └── Utils.kt │ │ └── util │ │ └── Utils.kt │ └── test │ ├── java │ └── org │ │ └── jacodb │ │ └── analysis │ │ └── impl │ │ └── JavaAnalysisApiTest.java │ ├── kotlin │ └── org │ │ └── jacodb │ │ └── analysis │ │ └── impl │ │ ├── BaseAnalysisTest.kt │ │ ├── ConditionEvaluatorTest.kt │ │ ├── IfdsNpeTest.kt │ │ ├── IfdsSqlTest.kt │ │ ├── IfdsUnusedTest.kt │ │ ├── JodaDateTimeAnalysisTest.kt │ │ ├── NullabilityAssumptionAnalysisTest.kt │ │ └── TaintFlowFunctionsTest.kt │ └── resources │ ├── additional.json │ ├── config_small.json │ ├── config_test.json │ ├── pointerbench.jar │ └── simplelogger.properties ├── jacodb-api ├── README.md ├── build.gradle.kts └── src │ └── main │ └── kotlin │ └── org │ └── jacodb │ └── api │ ├── Api.kt │ ├── Classes.kt │ ├── Exceptions.kt │ ├── Hook.kt │ ├── Index.kt │ ├── JcClasspath.kt │ ├── JcLookup.kt │ ├── PredefinedPrimitive.kt │ ├── Resolution.kt │ ├── Substitution.kt │ ├── Symbols.kt │ ├── Types.kt │ ├── analysis │ ├── ApplicationGraph.kt │ ├── JcApplicationGraph.kt │ ├── JcPointsToAnalysis.kt │ └── PrimitivePointsAnalysis.kt │ ├── cfg │ ├── FullExprSetCollector.kt │ ├── JcBlockGraph.kt │ ├── JcBytecodeGraph.kt │ ├── JcGraph.kt │ ├── JcGraphs.kt │ ├── JcInst.kt │ ├── JcInstList.kt │ ├── JcInstVisitor.kt │ ├── JcRawInst.kt │ └── JcRawInstVisitor.kt │ └── ext │ ├── HierarchyExtension.kt │ ├── JcClasses.kt │ ├── JcClasspaths.kt │ ├── JcCommons.kt │ ├── JcFields.kt │ ├── JcMethods.kt │ ├── JcTypes.kt │ ├── Nullables.kt │ └── cfg │ └── JcInstructions.kt ├── jacodb-approximations ├── README.md ├── build.gradle.kts └── src │ ├── main │ └── kotlin │ │ └── org │ │ └── jacodb │ │ └── approximation │ │ ├── Approximations.kt │ │ ├── InstSubstitutorForApproximations.kt │ │ ├── TransformerIntoVirtual.kt │ │ ├── Util.kt │ │ ├── VirtualInstances.kt │ │ ├── VirtualInstancesBuilders.kt │ │ └── annotation │ │ └── ApproximationAnnotations.kt │ └── test │ ├── java │ └── org │ │ └── jacodb │ │ └── approximations │ │ └── approx │ │ └── IntegerApprox.java │ └── kotlin │ └── org │ └── jacodb │ └── approximations │ ├── ApproximationsTest.kt │ ├── approx │ └── KotlinClassApprox.kt │ └── target │ └── KotlinClass.kt ├── jacodb-benchmarks ├── build.gradle.kts └── src │ └── test │ └── kotlin │ └── org │ └── jacodb │ └── testing │ └── performance │ ├── JcInstructionsBenchmark.kt │ ├── JcdbAwaitBackgroundBenchmarks.kt │ ├── JcdbBenchmarks.kt │ ├── JcdbLifeCycleBenchmarks.kt │ ├── RestoreJcdbBenchmark.kt │ ├── SootBenchmarks.kt │ ├── SootupBenchmarks.kt │ └── TakeMemoryDump.kt ├── jacodb-cli ├── build.gradle.kts └── src │ ├── main │ └── kotlin │ │ └── org │ │ └── jacodb │ │ └── cli │ │ └── main.kt │ └── test │ ├── kotlin │ └── org │ │ └── jacodb │ │ └── cli │ │ └── CliTest.kt │ └── resources │ └── config.json ├── jacodb-core ├── README.md ├── build.gradle.kts └── src │ ├── main │ ├── jooq │ │ └── org │ │ │ └── jacodb │ │ │ └── impl │ │ │ └── storage │ │ │ └── jooq │ │ │ ├── DefaultCatalog.kt │ │ │ ├── DefaultSchema.kt │ │ │ ├── indexes │ │ │ └── Indexes.kt │ │ │ ├── keys │ │ │ └── Keys.kt │ │ │ └── tables │ │ │ ├── Annotations.kt │ │ │ ├── Annotationvalues.kt │ │ │ ├── Applicationmetadata.kt │ │ │ ├── Builders.kt │ │ │ ├── Bytecodelocations.kt │ │ │ ├── Calls.kt │ │ │ ├── Classes.kt │ │ │ ├── Classhierarchies.kt │ │ │ ├── Classinnerclasses.kt │ │ │ ├── Fields.kt │ │ │ ├── Methodparameters.kt │ │ │ ├── Methods.kt │ │ │ ├── Outerclasses.kt │ │ │ ├── Refactorings.kt │ │ │ ├── Symbols.kt │ │ │ ├── records │ │ │ ├── AnnotationsRecord.kt │ │ │ ├── AnnotationvaluesRecord.kt │ │ │ ├── ApplicationmetadataRecord.kt │ │ │ ├── BuildersRecord.kt │ │ │ ├── BytecodelocationsRecord.kt │ │ │ ├── CallsRecord.kt │ │ │ ├── ClassesRecord.kt │ │ │ ├── ClasshierarchiesRecord.kt │ │ │ ├── ClassinnerclassesRecord.kt │ │ │ ├── FieldsRecord.kt │ │ │ ├── MethodparametersRecord.kt │ │ │ ├── MethodsRecord.kt │ │ │ ├── OuterclassesRecord.kt │ │ │ ├── RefactoringsRecord.kt │ │ │ └── SymbolsRecord.kt │ │ │ └── references │ │ │ └── Tables.kt │ ├── kotlin │ │ └── org │ │ │ └── jacodb │ │ │ └── impl │ │ │ ├── Async.kt │ │ │ ├── FeaturesRegistry.kt │ │ │ ├── JcClasspathImpl.kt │ │ │ ├── JcDatabaseImpl.kt │ │ │ ├── JcSettings.kt │ │ │ ├── LocationsRegistry.kt │ │ │ ├── analysis │ │ │ └── impl │ │ │ │ └── StringConcatSimplifierTransformer.kt │ │ │ ├── bytecode │ │ │ ├── Conversions.kt │ │ │ ├── JcAbstractLookup.kt │ │ │ ├── JcAnnotationImpl.kt │ │ │ ├── JcClassLookupImpl.kt │ │ │ ├── JcClassOrInterfaceImpl.kt │ │ │ ├── JcDatabaseClassWritter.kt │ │ │ ├── JcDeclarationImpl.kt │ │ │ ├── JcFieldImpl.kt │ │ │ ├── JcMethodImpl.kt │ │ │ ├── JcParameterImpl.kt │ │ │ ├── KMetadata.kt │ │ │ └── util.kt │ │ │ ├── cfg │ │ │ ├── GraphExt.kt │ │ │ ├── JcBlockGraphImpl.kt │ │ │ ├── JcGraphImpl.kt │ │ │ ├── JcInstListBuilder.kt │ │ │ ├── JcInstListImpl.kt │ │ │ ├── MethodNodeBuilder.kt │ │ │ ├── RawInstListBuilder.kt │ │ │ ├── Simplifier.kt │ │ │ ├── TypedMethodRefImpl.kt │ │ │ ├── ValueExt.kt │ │ │ ├── graphs │ │ │ │ ├── DominatorsTree.kt │ │ │ │ └── GraphDominators.kt │ │ │ └── util │ │ │ │ ├── ExprMapper.kt │ │ │ │ ├── InstructionFilter.kt │ │ │ │ ├── Loops.kt │ │ │ │ ├── printer.kt │ │ │ │ └── types.kt │ │ │ ├── features │ │ │ ├── BuilderExtension.kt │ │ │ ├── Builders.kt │ │ │ ├── Diagnostics.kt │ │ │ ├── HierarchyExtension.kt │ │ │ ├── InMemoryHierarchy.kt │ │ │ ├── JcFeaturesChain.kt │ │ │ ├── UsageRequest.kt │ │ │ ├── Usages.kt │ │ │ ├── UsagesExtension.kt │ │ │ └── classpaths │ │ │ │ ├── ClasspathCache.kt │ │ │ │ ├── Events.kt │ │ │ │ ├── JcUnknownClass.kt │ │ │ │ ├── JcUnknownType.kt │ │ │ │ ├── KotlinMetadata.kt │ │ │ │ ├── MethodInstructionsFeature.kt │ │ │ │ ├── StringConcatSimplifier.kt │ │ │ │ ├── VirtualClassContent.kt │ │ │ │ ├── VirtualClasses.kt │ │ │ │ └── virtual │ │ │ │ ├── JcVirtualClass.kt │ │ │ │ ├── JcVirtualField.kt │ │ │ │ ├── JcVirtualMethod.kt │ │ │ │ └── VirtualClassesBuilder.kt │ │ │ ├── fs │ │ │ ├── AbstractByteCodeLocation.kt │ │ │ ├── BuildFolderLocation.kt │ │ │ ├── ByteCodeConverter.kt │ │ │ ├── ByteCodeLoaderImpl.kt │ │ │ ├── ByteCodeLocations.kt │ │ │ ├── ClassSource.kt │ │ │ ├── JarLocationImpl.kt │ │ │ ├── Jars.kt │ │ │ ├── JavaRuntime.kt │ │ │ └── JavaVersionImpl.kt │ │ │ ├── jacodb.kt │ │ │ ├── storage │ │ │ ├── AbstractJcDatabasePersistenceImpl.kt │ │ │ ├── Caches.kt │ │ │ ├── DataStorageException.kt │ │ │ ├── Enums.kt │ │ │ ├── JcRefactoring.kt │ │ │ ├── Jooq.kt │ │ │ ├── PersistenceService.kt │ │ │ ├── PersistentLocationRegistry.kt │ │ │ └── SQLitePersistenceImpl.kt │ │ │ ├── types │ │ │ ├── JcArrayTypeImpl.kt │ │ │ ├── JcClassTypeImpl.kt │ │ │ ├── JcClassTypeLookup.kt │ │ │ ├── JcGenericTypes.kt │ │ │ ├── JcTypeBindings.kt │ │ │ ├── JcTypedFieldImpl.kt │ │ │ ├── JcTypedMethodImpl.kt │ │ │ ├── JcTypedMethodParameterImpl.kt │ │ │ ├── Objects.kt │ │ │ ├── TypeParameters.kt │ │ │ ├── signature │ │ │ │ ├── FieldSignature.kt │ │ │ │ ├── JvmTypeAnnotationUpdateVisitor.kt │ │ │ │ ├── JvmTypeCopyWithExt.kt │ │ │ │ ├── JvmTypeKMetadataUpdateVisitor.kt │ │ │ │ ├── JvmTypeParameterDeclaration.kt │ │ │ │ ├── JvmTypes.kt │ │ │ │ ├── MethodSignature.kt │ │ │ │ ├── RecordSignature.kt │ │ │ │ ├── Resolutions.kt │ │ │ │ ├── Signature.kt │ │ │ │ ├── TypeExtractor.kt │ │ │ │ ├── TypeRegistrant.kt │ │ │ │ └── TypeSignature.kt │ │ │ └── substition │ │ │ │ ├── JcSubstitutorImpl.kt │ │ │ │ ├── JcSubstitutors.kt │ │ │ │ └── RecursiveJvmTypeVisitor.kt │ │ │ └── vfs │ │ │ ├── ClassTreeListener.kt │ │ │ ├── ClassVfsItem.kt │ │ │ ├── ClasspathVfs.kt │ │ │ ├── GlobalClassesVfs.kt │ │ │ ├── PackageVfsItem.kt │ │ │ ├── PersistentByteCodeLocation.kt │ │ │ └── Vfs.kt │ └── resources │ │ ├── jacodb.properties │ │ └── sqlite │ │ ├── add-indexes.sql │ │ ├── create-schema.sql │ │ ├── drop-schema.sql │ │ ├── empty.db │ │ └── usages │ │ ├── add-indexes.sql │ │ ├── create-schema.sql │ │ └── drop-schema.sql │ ├── test │ ├── java │ │ └── org │ │ │ └── jacodb │ │ │ └── testing │ │ │ ├── JavaApi.java │ │ │ └── JavaApiTest.java │ ├── kotlin │ │ └── org │ │ │ └── jacodb │ │ │ └── testing │ │ │ ├── AnnotationsTest.kt │ │ │ ├── ApiExtTest.kt │ │ │ ├── Bar.kt │ │ │ ├── ClassesTest.kt │ │ │ ├── DatabaseLifecycleTest.kt │ │ │ ├── DirectUsagesTest.kt │ │ │ ├── HierarchyStabilityTest.kt │ │ │ ├── JarFacadeTest.kt │ │ │ ├── JavaVersionTest.kt │ │ │ ├── ParameterNamesTest.kt │ │ │ ├── SignatureTest.kt │ │ │ ├── SubclassesTest.kt │ │ │ ├── UnknownClassesTest.kt │ │ │ ├── cfg │ │ │ ├── BaseInstructionsTest.kt │ │ │ ├── IRSvgGenerator.kt │ │ │ ├── IRTest.kt │ │ │ ├── IincTest.kt │ │ │ ├── InstructionsTest.kt │ │ │ ├── InvokeDynamicTest.kt │ │ │ ├── KotlinInstructionsTest.kt │ │ │ └── LoopsTest.kt │ │ │ ├── features │ │ │ ├── BaseSearchUsagesTest.kt │ │ │ ├── BuildersTest.kt │ │ │ └── InMemoryHierarchyTest.kt │ │ │ ├── persistence │ │ │ ├── IncompleteDataTest.kt │ │ │ └── RestoredDBTest.kt │ │ │ ├── tree │ │ │ ├── DummyCodeLocation.kt │ │ │ └── GlobalClassVfsTest.kt │ │ │ └── types │ │ │ ├── AssignTypesTest.kt │ │ │ ├── BaseTypesTest.kt │ │ │ ├── IgnoreSubstitutionProblemsTest.kt │ │ │ ├── InnerTypesTest.kt │ │ │ ├── LinkedGenericsTest.kt │ │ │ ├── MultiParametersTest.kt │ │ │ ├── OverridesTest.kt │ │ │ ├── RecursiveTypesTest.kt │ │ │ ├── TypeAnnotationsTest.kt │ │ │ ├── TypesTest.kt │ │ │ ├── WildcardTypesTest.kt │ │ │ └── nullability │ │ │ ├── JavaNullabilityTest.kt │ │ │ ├── KotlinJavaInteropNullabilityTest.kt │ │ │ ├── KotlinNullabilityTest.kt │ │ │ └── TypeNullabilityTree.kt │ └── resources │ │ ├── samples │ │ ├── GenericsApi.class │ │ ├── GenericsApiConsumer.class │ │ ├── PhantomClassSubclass.class │ │ ├── PhantomCodeConsumer.class │ │ ├── PhantomDeclaration.class │ │ ├── PhantomDeclarationConsumer.class │ │ ├── TestLDC.class │ │ └── VirtualInstructions.class │ │ └── src │ │ ├── GenericsApi.java │ │ ├── PhantomClass.java │ │ ├── PhantomClassSubclass.java │ │ ├── PhantomCodeConsumer.java │ │ ├── PhantomDeclaration.java │ │ ├── PhantomDeclarationConsumer.java │ │ ├── PhantomInterface.java │ │ ├── PhantomInterfaceConsumer.java │ │ └── PhantomInterfaceImpl.java │ └── testFixtures │ ├── java │ └── org │ │ └── jacodb │ │ └── testing │ │ ├── Bar.java │ │ ├── Common.java │ │ ├── analysis │ │ ├── NpeExamples.java │ │ └── SqlInjectionExamples.java │ │ ├── builders │ │ ├── Hierarchy.java │ │ ├── Interfaces.java │ │ └── Simple.java │ │ ├── cfg │ │ ├── ArgAssignmentExample.java │ │ ├── BinarySearchTree.java │ │ ├── Close.java │ │ ├── Conditionals.java │ │ ├── IRExamples.java │ │ ├── Incrementation.java │ │ ├── InvokeDynamicExamples.java │ │ ├── JavaArrays.java │ │ ├── JavaTasks.java │ │ ├── Lambdas.java │ │ ├── MultiplyTests.java │ │ ├── NullAssumptionAnalysisExample.java │ │ ├── SimpleAlias1.java │ │ └── StaticInterfaceMethodCall.java │ │ ├── hierarchies │ │ ├── Creature.java │ │ ├── Inheritance.java │ │ └── Overrides.java │ │ ├── primitives │ │ └── Primitives.java │ │ ├── structure │ │ ├── EnumExamples.java │ │ ├── FieldsAndMethods.java │ │ └── HiddenFieldSuperClass.java │ │ ├── types │ │ ├── AAA.java │ │ ├── Comparables.java │ │ ├── Generics.java │ │ ├── InnerClasses.java │ │ ├── MultipleParametrization.java │ │ ├── NullAnnotationExamples.java │ │ ├── PrimitiveAndArrays.java │ │ └── WildcardBounds.java │ │ └── usages │ │ ├── Generics.java │ │ ├── HelloWorldAnonymousClasses.java │ │ ├── WithInner.java │ │ ├── direct │ │ └── DirectA.java │ │ ├── fields │ │ ├── FakeFieldA.java │ │ ├── FieldA.java │ │ └── FieldB.java │ │ └── methods │ │ ├── MethodA.java │ │ ├── MethodB.java │ │ └── MethodC.java │ └── kotlin │ └── org │ └── jacodb │ └── testing │ ├── BaseTest.kt │ ├── Enums.kt │ ├── Foo.kt │ ├── Hierarchy.kt │ ├── KotlinNullabilityExamples.kt │ ├── LibrariesMixin.kt │ ├── cfg │ ├── Arrays.kt │ ├── DefaultArgs.kt │ ├── DifferentReceivers.kt │ ├── DoubleComparison.kt │ ├── Equals.kt │ ├── Iinc.kt │ ├── InvokeMethodWithException.kt │ ├── Overloading.kt │ ├── Ranges.kt │ ├── Sequence.kt │ ├── SimpleTest.kt │ ├── TryCatchFinally.kt │ ├── Varargs.kt │ └── WhenExpr.kt │ └── tests │ └── DatabaseEnvTest.kt ├── jacodb-examples ├── build.gradle.kts └── src │ └── main │ ├── java │ └── org │ │ └── jacodb │ │ └── examples │ │ └── JavaReadMeExamples.java │ └── kotlin │ └── org │ └── jacodb │ └── examples │ ├── KotlinReadMeExamples.kt │ └── analysis │ ├── PerformanceMetrics.kt │ └── SootPerformanceMetrics.kt ├── jacodb-taint-configuration ├── README.md ├── build.gradle.kts └── src │ ├── main │ └── kotlin │ │ └── org │ │ └── jacodb │ │ └── taint │ │ └── configuration │ │ ├── ConfigurationTrie.kt │ │ ├── Position.kt │ │ ├── SerializedTaintConfigurationItem.kt │ │ ├── TaintAction.kt │ │ ├── TaintCondition.kt │ │ ├── TaintConfigurationFeature.kt │ │ ├── TaintConfigurationItem.kt │ │ ├── TaintMark.kt │ │ └── Util.kt │ └── test │ ├── kotlin │ └── org │ │ └── jacodb │ │ └── taint │ │ └── configuration │ │ ├── ConfigurationTest.kt │ │ └── UtilTest.kt │ └── resources │ └── testJsonConfig.json ├── pre-commit └── settings.gradle.kts /.github/workflows/benchmarks.yml: -------------------------------------------------------------------------------- 1 | # This workflow uses actions that are not certified by GitHub. 2 | # They are provided by a third-party and are governed by 3 | # separate terms of service, privacy policy, and support 4 | # documentation. 5 | # This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time 6 | # For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle 7 | 8 | name: Run benchmarks 9 | 10 | on: 11 | schedule: 12 | - cron: '30 23 * * 1,2,3,4,5' 13 | 14 | permissions: 15 | contents: read 16 | 17 | jobs: 18 | jdk11: 19 | 20 | runs-on: ubuntu-latest 21 | 22 | steps: 23 | - uses: actions/checkout@v3 24 | - name: Set up JDK 11 25 | uses: actions/setup-java@v3 26 | with: 27 | java-version: '11' 28 | distribution: 'temurin' 29 | - uses: gradle/gradle-build-action@v2 30 | with: 31 | gradle-version: 7.6.1 32 | - name: Build and run tests 33 | run: | 34 | gradle benchmark --no-daemon --info 35 | 36 | jdk8: 37 | 38 | runs-on: ubuntu-latest 39 | 40 | steps: 41 | - uses: actions/checkout@v3 42 | - name: Set up JDK 8 43 | uses: actions/setup-java@v3 44 | with: 45 | java-version: '8' 46 | distribution: 'zulu' 47 | java-package: jdk+fx 48 | - uses: gradle/gradle-build-action@v2 49 | with: 50 | gradle-version: 7.6.1 51 | - name: Build and run tests 52 | run: | 53 | gradle benchmark --no-daemon --info 54 | -------------------------------------------------------------------------------- /.github/workflows/github-packages.yml: -------------------------------------------------------------------------------- 1 | name: Publish to GitHub packages 2 | 3 | on: 4 | push: 5 | branches: 6 | - develop 7 | 8 | jobs: 9 | publish: 10 | runs-on: ubuntu-latest 11 | permissions: 12 | contents: read 13 | packages: write 14 | steps: 15 | - uses: actions/checkout@v3 16 | - name: Set up JDK 11 17 | uses: actions/setup-java@v3 18 | with: 19 | java-version: '11' 20 | distribution: 'temurin' 21 | - name: Publish package 22 | uses: gradle/gradle-build-action@67421db6bd0bf253fb4bd25b31ebb98943c375e1 23 | with: 24 | gradle-version: 7.6.1 25 | arguments: | 26 | publish 27 | -Pactor=${{ github.actor }} 28 | -Ptoken=${{ secrets.GITHUB_TOKEN }} 29 | -PrepoUrl=https://maven.pkg.github.com/UnitTestBot/jacodb 30 | -------------------------------------------------------------------------------- /.github/workflows/nightly-builds.yml: -------------------------------------------------------------------------------- 1 | name: Nightly builds for Maven Central 2 | 3 | on: 4 | schedule: 5 | - cron: '30 23 * * 1,2,3,4,5' 6 | 7 | jobs: 8 | publish: 9 | runs-on: ubuntu-latest 10 | permissions: 11 | contents: read 12 | packages: write 13 | steps: 14 | - uses: actions/checkout@v3 15 | with: 16 | ref: develop 17 | - name: Set up JDK 11 18 | uses: actions/setup-java@v3 19 | with: 20 | java-version: '11' 21 | distribution: 'temurin' 22 | - name: Publish package 23 | uses: gradle/gradle-build-action@67421db6bd0bf253fb4bd25b31ebb98943c375e1 24 | with: 25 | gradle-version: 7.6.1 26 | arguments: | 27 | publish 28 | -Pactor=${{ secrets.MAVEN_CENTRAL_LOGIN }} 29 | -Ptoken=${{ secrets.MAVEN_CENTRAL_TOKEN }} 30 | -PrepoUrl=https://s01.oss.sonatype.org/content/repositories/snapshots/ 31 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: Release 2 | run-name: Releasing ${{inputs.semVer}} 3 | 4 | on: 5 | workflow_dispatch: 6 | inputs: 7 | semVer: 8 | required: true 9 | type: string 10 | description: "Version number" 11 | 12 | jobs: 13 | publish: 14 | if: ${{ github.actor == 'lehvolk' || github.actor == 'denis-fokin' || github.actor == 'bissquit' || github.actor == 'Vassiliy-Kudryashov' }} 15 | runs-on: ubuntu-latest 16 | permissions: 17 | contents: write 18 | packages: write 19 | steps: 20 | - uses: actions/checkout@v3 21 | - name: Set up JDK 11 22 | uses: actions/setup-java@v3 23 | with: 24 | java-version: '11' 25 | distribution: 'temurin' 26 | - name: Publish package 27 | uses: gradle/gradle-build-action@67421db6bd0bf253fb4bd25b31ebb98943c375e1 28 | with: 29 | gradle-version: 7.6.1 30 | arguments: | 31 | publish 32 | -PincludeDokka=true 33 | -PsemVer=${{inputs.semVer}} 34 | -Pactor=${{ secrets.MAVEN_CENTRAL_LOGIN }} 35 | -Ptoken=${{ secrets.MAVEN_CENTRAL_TOKEN }} 36 | -PgpgKey="${{ secrets.OSSRH_GPG_SECRET_KEY }}" 37 | -PgpgPassphrase=${{ secrets.OSSRH_GPG_SECRET_PASSPHRASE }} 38 | -PrepoUrl=https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/ 39 | - name: Upload release artifacts 40 | uses: softprops/action-gh-release@v1 41 | with: 42 | draft: true 43 | files: | 44 | jacodb-api/build/libs/jacodb-api-${{inputs.semVer}}.jar 45 | jacodb-approximations/build/libs/jacodb-approximations-${{inputs.semVer}}.jar 46 | jacodb-taint-configuration/build/libs/jacodb-taint-configuration-${{inputs.semVer}}.jar 47 | jacodb-analysis/build/libs/jacodb-analysis-${{inputs.semVer}}.jar 48 | jacodb-core/build/libs/jacodb-core-${{inputs.semVer}}.jar 49 | jacodb-cli/build/libs/jacodb-cli-${{inputs.semVer}}.jar 50 | jacodb-examples/build/libs/jacodb-examples-${{inputs.semVer}}.jar 51 | -------------------------------------------------------------------------------- /.github/workflows/telegram-notifications.yml: -------------------------------------------------------------------------------- 1 | name: Telegram Pull Request Notifier 2 | 3 | on: 4 | pull_request: 5 | types: [opened, review_requested] 6 | 7 | jobs: 8 | notification: 9 | runs-on: ubuntu-latest 10 | 11 | steps: 12 | - name: Pull Request Telegram 13 | uses: F2had/pr-telegram-action@v1.0.0 14 | with: 15 | bot_token: '${{ secrets.TELEGRAM_TOKEN }}' 16 | chat_id: '${{ secrets.TELEGRAM_CHAT_ID }}' -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | .gradle/ 3 | build/ 4 | idea-community 5 | *.db 6 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | UnitTestBot 2 | Copyright 2022 UnitTestBot contributors (utbot.org) -------------------------------------------------------------------------------- /add-licence.sh: -------------------------------------------------------------------------------- 1 | ./gradlew licenseFormat -------------------------------------------------------------------------------- /add-license.bat: -------------------------------------------------------------------------------- 1 | ./gradlew licenseFormat -------------------------------------------------------------------------------- /buildSrc/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | `kotlin-dsl` 3 | } 4 | 5 | repositories { 6 | mavenCentral() 7 | } 8 | -------------------------------------------------------------------------------- /buildSrc/settings.gradle.kts: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UnitTestBot/jacodb/5068453f689cfd789cad149c12c7fa03d36df353/buildSrc/settings.gradle.kts -------------------------------------------------------------------------------- /buildSrc/src/main/kotlin/Tests.kt: -------------------------------------------------------------------------------- 1 | import org.gradle.api.tasks.TaskProvider 2 | import org.gradle.api.tasks.testing.Test 3 | 4 | object Tests { 5 | val lifecycleTag = "lifecycle" 6 | 7 | } 8 | 9 | fun Test.setup(jacocoTestReport: TaskProvider<*>) { 10 | testLogging { 11 | events("passed", "skipped", "failed") 12 | } 13 | finalizedBy(jacocoTestReport) // report is always generated after tests run 14 | jvmArgs = listOf("-Xmx2g", "-XX:+HeapDumpOnOutOfMemoryError", "-XX:HeapDumpPath=heapdump.hprof") 15 | } 16 | -------------------------------------------------------------------------------- /docs/badges/branches.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /docs/badges/coverage-summary.json: -------------------------------------------------------------------------------- 1 | {"branches": 68.83633809412315, "coverage": 70.64358620296952} -------------------------------------------------------------------------------- /docs/badges/jacoco.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /docs/copyright/COPYRIGHT_HEADER.txt: -------------------------------------------------------------------------------- 1 | Copyright 2022 UnitTestBot contributors (utbot.org) 2 |
3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 |
7 | http://www.apache.org/licenses/LICENSE-2.0 8 |
9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. -------------------------------------------------------------------------------- /docs/svg/block-graph-IRExamples-concatTest-1.svg: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 24 | -------------------------------------------------------------------------------- /docs/svg/block-graph-IRExamples-init-0.svg: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 20 | -------------------------------------------------------------------------------- /docs/svg/block-graph-IRExamples-testField-7.svg: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 20 | -------------------------------------------------------------------------------- /docs/svg/graph-IRExamples-init-0.svg: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 31 | -------------------------------------------------------------------------------- /docs/svg/graph-IRExamples-testField-7.svg: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 31 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | kotlin.code.style=official 2 | 3 | intellij_community_url=https://download-cdn.jetbrains.com/idea/ideaIC-2022.2.3.win.zip 4 | #database_location=d:\\work\\jacodb\\jcdb-http.db 5 | 6 | org.gradle.jvmargs=-XX:MaxMetaspaceSize=512m 7 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/UnitTestBot/jacodb/5068453f689cfd789cad149c12c7fa03d36df353/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-all.zip 4 | networkTimeout=10000 5 | zipStoreBase=GRADLE_USER_HOME 6 | zipStorePath=wrapper/dists 7 | -------------------------------------------------------------------------------- /jacodb-analysis/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | kotlin("plugin.serialization") 3 | `java-test-fixtures` 4 | } 5 | 6 | dependencies { 7 | api(project(":jacodb-core")) 8 | api(project(":jacodb-api")) 9 | api(project(":jacodb-taint-configuration")) 10 | 11 | implementation(Libs.kotlin_logging) 12 | implementation(Libs.slf4j_simple) 13 | implementation(Libs.kotlinx_coroutines_core) 14 | implementation(Libs.kotlinx_serialization_json) 15 | api(Libs.sarif4k) 16 | 17 | testImplementation(testFixtures(project(":jacodb-core"))) 18 | testImplementation(project(":jacodb-api")) 19 | testImplementation(kotlin("test")) 20 | testImplementation(Libs.mockk) 21 | 22 | // Additional deps for analysis: 23 | testImplementation(files("src/test/resources/pointerbench.jar")) 24 | testImplementation(Libs.joda_time) 25 | testImplementation(Libs.juliet_support) 26 | for (cweNum in listOf(89, 476, 563, 690)) { 27 | testImplementation(Libs.juliet_cwe(cweNum)) 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /jacodb-analysis/src/main/kotlin/org/jacodb/analysis/graph/JcNoopInst.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 UnitTestBot contributors (utbot.org) 3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.analysis.graph
18 |
19 | import org.jacodb.api.cfg.JcExpr
20 | import org.jacodb.api.cfg.JcInst
21 | import org.jacodb.api.cfg.JcInstLocation
22 | import org.jacodb.api.cfg.JcInstVisitor
23 |
24 | data class JcNoopInst(override val location: JcInstLocation) : JcInst {
25 | override val operands: List
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.analysis.ifds
18 |
19 | import org.jacodb.api.JcField
20 |
21 | sealed interface Accessor {
22 | fun toSuffix(): String
23 | }
24 |
25 | data class FieldAccessor(
26 | val field: JcField,
27 | ) : Accessor {
28 | override fun toSuffix(): String = ".${field.name}"
29 | override fun toString(): String = field.name
30 | }
31 |
32 | object ElementAccessor : Accessor {
33 | override fun toSuffix(): String = "[*]"
34 | override fun toString(): String = "*"
35 | }
36 |
--------------------------------------------------------------------------------
/jacodb-analysis/src/main/kotlin/org/jacodb/analysis/ifds/Analyzer.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 UnitTestBot contributors (utbot.org)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.analysis.ifds
18 |
19 | interface Analyzer
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.analysis.ifds
18 |
19 | import org.jacodb.api.JcMethod
20 |
21 | data class Edge
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.analysis.ifds
18 |
19 | import kotlinx.coroutines.CoroutineScope
20 | import org.jacodb.api.JcMethod
21 |
22 | interface Manager
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.analysis.ifds
18 |
19 | sealed interface Reason
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.analysis.ifds
18 |
19 | import org.jacodb.api.JcMethod
20 | import org.jacodb.api.cfg.JcInst
21 |
22 | data class Vertex
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.analysis.impl.custom
18 |
19 | import org.jacodb.api.cfg.JcBytecodeGraph
20 |
21 | abstract class AbstractFlowAnalysis
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.analysis.impl.custom
18 |
19 | import org.jacodb.api.cfg.JcBytecodeGraph
20 |
21 | abstract class BackwardFlowAnalysis
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.analysis.impl.custom
18 |
19 | import org.jacodb.api.cfg.JcBytecodeGraph
20 |
21 | interface FlowAnalysis
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.analysis.impl.custom
18 |
19 | import org.jacodb.api.cfg.JcBytecodeGraph
20 |
21 |
22 | abstract class ForwardFlowAnalysis
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.analysis.npe
18 |
19 | import org.jacodb.analysis.ifds.AccessPath
20 | import org.jacodb.analysis.ifds.toPathOrNull
21 | import org.jacodb.analysis.util.startsWith
22 | import org.jacodb.api.cfg.JcExpr
23 | import org.jacodb.api.cfg.JcInst
24 | import org.jacodb.api.cfg.JcInstanceCallExpr
25 | import org.jacodb.api.cfg.JcLengthExpr
26 | import org.jacodb.api.cfg.values
27 |
28 | fun AccessPath?.isDereferencedAt(expr: JcExpr): Boolean {
29 | if (this == null) {
30 | return false
31 | }
32 |
33 | if (expr is JcInstanceCallExpr) {
34 | val instancePath = expr.instance.toPathOrNull()
35 | if (instancePath.startsWith(this)) {
36 | return true
37 | }
38 | }
39 |
40 | if (expr is JcLengthExpr) {
41 | val arrayPath = expr.array.toPathOrNull()
42 | if (arrayPath.startsWith(this)) {
43 | return true
44 | }
45 | }
46 |
47 | return expr.values
48 | .mapNotNull { it.toPathOrNull() }
49 | .any {
50 | (it - this)?.isNotEmpty() == true
51 | }
52 | }
53 |
54 | fun AccessPath?.isDereferencedAt(inst: JcInst): Boolean {
55 | if (this == null) return false
56 | return inst.operands.any { isDereferencedAt(it) }
57 | }
58 |
--------------------------------------------------------------------------------
/jacodb-analysis/src/main/kotlin/org/jacodb/analysis/sarif/SourceFileResolver.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 UnitTestBot contributors (utbot.org)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.analysis.sarif
18 |
19 | import org.jacodb.api.cfg.JcInst
20 |
21 | fun interface SourceFileResolver {
22 | fun resolve(inst: JcInst): String?
23 | }
24 |
--------------------------------------------------------------------------------
/jacodb-analysis/src/main/kotlin/org/jacodb/analysis/sarif/Vulnerability.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 UnitTestBot contributors (utbot.org)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.analysis.sarif
18 |
19 | import io.github.detekt.sarif4k.Level
20 | import org.jacodb.analysis.ifds.TraceGraph
21 |
22 | data class VulnerabilityInstance
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.analysis.taint
18 |
19 | import org.jacodb.analysis.ifds.TraceGraph
20 | import org.jacodb.analysis.sarif.VulnerabilityDescription
21 | import org.jacodb.analysis.sarif.VulnerabilityInstance
22 |
23 | fun TaintVulnerability.toSarif(
24 | graph: TraceGraph
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.analysis.taint
18 |
19 | import org.jacodb.analysis.ifds.Reason
20 |
21 | sealed interface TaintEvent
22 |
23 | data class NewSummaryEdge(
24 | val edge: TaintEdge,
25 | ) : TaintEvent
26 |
27 | data class NewVulnerability(
28 | val vulnerability: TaintVulnerability,
29 | ) : TaintEvent
30 |
31 | data class EdgeForOtherRunner(
32 | val edge: TaintEdge,
33 | val reason: Reason
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.analysis.taint
18 |
19 | import org.jacodb.analysis.ifds.AccessPath
20 | import org.jacodb.taint.configuration.TaintMark
21 |
22 | sealed interface TaintDomainFact
23 |
24 | object TaintZeroFact : TaintDomainFact {
25 | override fun toString(): String = "Zero"
26 | }
27 |
28 | data class Tainted(
29 | val variable: AccessPath,
30 | val mark: TaintMark,
31 | ) : TaintDomainFact
32 |
--------------------------------------------------------------------------------
/jacodb-analysis/src/main/kotlin/org/jacodb/analysis/taint/TaintSummaries.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 UnitTestBot contributors (utbot.org)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.analysis.taint
18 |
19 | import org.jacodb.analysis.ifds.SummaryEdge
20 | import org.jacodb.analysis.ifds.Vulnerability
21 | import org.jacodb.taint.configuration.TaintMethodSink
22 |
23 | data class TaintSummaryEdge(
24 | override val edge: TaintEdge,
25 | ) : SummaryEdge
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.analysis.taint
18 |
19 | import org.jacodb.analysis.ifds.Edge
20 | import org.jacodb.analysis.ifds.Runner
21 | import org.jacodb.analysis.ifds.Vertex
22 |
23 | typealias TaintVertex = Vertex
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.analysis.unused
18 |
19 | import org.jacodb.analysis.ifds.TraceGraph
20 | import org.jacodb.analysis.sarif.VulnerabilityDescription
21 | import org.jacodb.analysis.sarif.VulnerabilityInstance
22 |
23 | fun UnusedVariableVulnerability.toSarif(): VulnerabilityInstance
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.analysis.unused
18 |
19 | import org.jacodb.analysis.ifds.Analyzer
20 | import org.jacodb.analysis.ifds.Edge
21 | import org.jacodb.analysis.ifds.Vertex
22 | import org.jacodb.api.analysis.JcApplicationGraph
23 | import org.jacodb.api.cfg.JcInst
24 |
25 | class UnusedVariableAnalyzer(
26 | private val graph: JcApplicationGraph,
27 | ) : Analyzer
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.analysis.unused
18 |
19 | import org.jacodb.analysis.ifds.Edge
20 |
21 | sealed interface Event
22 |
23 | data class NewSummaryEdge(
24 | val edge: Edge
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.analysis.unused
18 |
19 | import org.jacodb.analysis.ifds.AccessPath
20 | import org.jacodb.api.cfg.JcInst
21 |
22 | sealed interface UnusedVariableDomainFact
23 |
24 | object UnusedVariableZeroFact : UnusedVariableDomainFact {
25 | override fun toString(): String = "Zero"
26 | }
27 |
28 | data class UnusedVariable(
29 | val variable: AccessPath,
30 | val initStatement: JcInst,
31 | ) : UnusedVariableDomainFact
32 |
--------------------------------------------------------------------------------
/jacodb-analysis/src/main/kotlin/org/jacodb/analysis/unused/UnusedVariableSummaries.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 UnitTestBot contributors (utbot.org)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.analysis.unused
18 |
19 | import org.jacodb.analysis.ifds.Edge
20 | import org.jacodb.analysis.ifds.SummaryEdge
21 | import org.jacodb.analysis.ifds.Vertex
22 | import org.jacodb.analysis.ifds.Vulnerability
23 |
24 | data class UnusedVariableSummaryEdge(
25 | override val edge: Edge
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.api
18 |
19 | /**
20 | * This exception should be thrown when classpath is incomplete
21 | */
22 | class NoClassInClasspathException(val className: String) : Exception("Class $className not found in classpath")
23 |
24 | /**
25 | * This exception should be thrown when classpath is incomplete
26 | */
27 | class TypeNotFoundException(val typeName: String) : Exception("Type $typeName not found in classpath")
28 |
29 | class MethodNotFoundException(msg: String) : Exception(msg)
30 |
31 | fun String.throwClassNotFound(): Nothing {
32 | throw NoClassInClasspathException(this)
33 | }
34 |
35 | inline fun
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.api
18 |
19 | interface Hook {
20 |
21 | suspend fun afterStart()
22 |
23 | fun afterStop() {}
24 | }
--------------------------------------------------------------------------------
/jacodb-api/src/main/kotlin/org/jacodb/api/Resolution.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 UnitTestBot contributors (utbot.org)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.api
18 |
19 |
20 | interface Resolution
21 | interface MethodResolution : Resolution
22 | interface RecordComponentResolution : Resolution
23 | interface FieldResolution : Resolution
24 | interface TypeResolution : Resolution
25 |
26 | object Malformed : TypeResolution, FieldResolution, MethodResolution, RecordComponentResolution
27 | object Pure : TypeResolution, FieldResolution, MethodResolution, RecordComponentResolution
28 |
--------------------------------------------------------------------------------
/jacodb-api/src/main/kotlin/org/jacodb/api/analysis/ApplicationGraph.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 UnitTestBot contributors (utbot.org)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.api.analysis
18 |
19 | /**
20 | * Provides both CFG and call graph (i.e., the supergraph in terms of RHS95 paper).
21 | */
22 | interface ApplicationGraph
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.api.analysis
18 |
19 | import org.jacodb.api.JcClasspath
20 | import org.jacodb.api.JcMethod
21 | import org.jacodb.api.cfg.JcInst
22 |
23 | /**
24 | * Interface for [ApplicationGraph] built with jacodb.
25 | */
26 | interface JcApplicationGraph : ApplicationGraph
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.api.cfg
18 |
19 | interface Graph
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.api.cfg
18 |
19 | interface JcInstList
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.api.ext
18 |
19 | import org.jacodb.api.JcClassOrInterface
20 | import org.jacodb.api.JcMethod
21 |
22 | /**
23 | * hierarchy extension for classpath
24 | */
25 | interface HierarchyExtension {
26 |
27 | /**
28 | * find all subclasses or implementations if name points to interface. If [allHierarchy] is true then search
29 | * will be done recursively
30 | *
31 | * @return list with unique ClassId
32 | */
33 | fun findSubClasses(name: String, allHierarchy: Boolean, includeOwn: Boolean = false): Sequence
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | @file:JvmName("JcFields")
18 |
19 | package org.jacodb.api.ext
20 |
21 | import org.jacodb.api.JcField
22 | import org.objectweb.asm.Opcodes
23 |
24 | /**
25 | * is item has `volatile` modifier
26 | */
27 | val JcField.isVolatile: Boolean
28 | get() {
29 | return access and Opcodes.ACC_VOLATILE != 0
30 | }
31 |
32 | /**
33 | * is field has `transient` modifier
34 | */
35 | val JcField.isTransient: Boolean
36 | get() {
37 | return access and Opcodes.ACC_TRANSIENT != 0
38 | }
39 |
40 |
41 | val JcField.isEnum: Boolean
42 | get() {
43 | return access and Opcodes.ACC_ENUM != 0
44 | }
45 |
--------------------------------------------------------------------------------
/jacodb-approximations/README.md:
--------------------------------------------------------------------------------
1 | # Module jacodb-approximation
2 |
3 | [Approximations] is used for overriding and extending existed classes by methods with their bodies.
4 |
5 | Use [Approximate] annotation on class and point it to target class.
6 |
7 | ```java
8 | @Approximate(java.lang.Integer.class)
9 | public class IntegerApprox {
10 | private final int value;
11 |
12 | public IntegerApprox(int value) {
13 | this.value = value;
14 | }
15 |
16 | public static IntegerApprox valueOf(int value) {
17 | return new IntegerApprox(value);
18 | }
19 |
20 | public int getValue() {
21 | return value;
22 | }
23 | }
24 | ```
25 |
26 | Let's assume code:
27 |
28 | ```kotlin
29 | val db = jacodb {
30 | installFeature(Approximations)
31 | }
32 | val cp = db.classpath(emptyList(), listOf(Approximations))
33 | val clazz = cp.findClass("java.lang.Integer")
34 | ```
35 |
36 | `clazz` object will represent mix between `java.lang.Integer` and `IntegerApprox`:
37 | - static `valueOf` method will be from `IntegerApprox` and will reduce all complexity of java runtime
38 | - `getValue` and `
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.approximation
18 |
19 | import org.jacodb.api.TypeName
20 | import org.jacodb.approximation.Approximations.findOriginalByApproximationOrNull
21 | import org.jacodb.impl.types.TypeNameImpl
22 |
23 | fun String.toApproximationName() = ApproximationClassName(this)
24 | fun String.toOriginalName() = OriginalClassName(this)
25 |
26 | fun TypeName.eliminateApproximation(): TypeName {
27 | val originalClassName = findOriginalByApproximationOrNull(typeName.toApproximationName()) ?: return this
28 | return TypeNameImpl(originalClassName)
29 | }
--------------------------------------------------------------------------------
/jacodb-approximations/src/main/kotlin/org/jacodb/approximation/annotation/ApproximationAnnotations.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 UnitTestBot contributors (utbot.org)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.approximation.annotation
18 |
19 | import kotlin.reflect.KClass
20 |
21 | @Suppress("unused")
22 | @Target(AnnotationTarget.CLASS)
23 | annotation class Approximate(val value: KClass<*>)
24 |
--------------------------------------------------------------------------------
/jacodb-approximations/src/test/java/org/jacodb/approximations/approx/IntegerApprox.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 UnitTestBot contributors (utbot.org)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.approximations.approx;
18 |
19 | import org.jacodb.approximation.annotation.Approximate;
20 |
21 |
22 | @Approximate(java.lang.Integer.class)
23 | public class IntegerApprox {
24 | private final int value;
25 |
26 | public IntegerApprox(int value) {
27 | this.value = value;
28 | }
29 |
30 | public static IntegerApprox valueOf(int value) {
31 | return new IntegerApprox(value);
32 | }
33 |
34 | public int getValue() {
35 | return value;
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/jacodb-approximations/src/test/kotlin/org/jacodb/approximations/target/KotlinClass.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 UnitTestBot contributors (utbot.org)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.approximations.target
18 |
19 | class KotlinClass {
20 | private val fieldToReplace: Int = 42
21 | private val sameApproximationTarget: KotlinClass? = null
22 | private val anotherApproximationTarget: Int? = null
23 | private val fieldWithoutApproximation: ClassForField = ClassForField()
24 |
25 | fun replaceBehaviour(value: Int): Int {
26 | if (value == fieldToReplace) {
27 | return -1;
28 | }
29 |
30 | return -2;
31 | }
32 |
33 | fun methodWithoutApproximation(): Int = 42
34 |
35 | fun useSameApproximationTarget(kotlinClass: KotlinClass): Int {
36 | if (kotlinClass == sameApproximationTarget) {
37 | return 1
38 | }
39 |
40 | return 0
41 | }
42 |
43 | fun useAnotherApproximationTarget(value: Int): Int {
44 | if (value == anotherApproximationTarget) {
45 | return 1
46 | }
47 |
48 | return 0
49 | }
50 |
51 | fun useFieldWithoutApproximation(classForField: ClassForField): Int {
52 | if (classForField == fieldWithoutApproximation) {
53 | return 1
54 | }
55 |
56 | return 0
57 | }
58 | }
59 |
60 | class ClassForField
--------------------------------------------------------------------------------
/jacodb-benchmarks/src/test/kotlin/org/jacodb/testing/performance/JcdbLifeCycleBenchmarks.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 UnitTestBot contributors (utbot.org)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.testing.performance
18 |
19 | import kotlinx.coroutines.runBlocking
20 | import org.jacodb.api.JcDatabase
21 | import org.jacodb.impl.features.Usages
22 | import org.jacodb.impl.jacodb
23 | import org.jacodb.testing.allJars
24 | import org.openjdk.jmh.annotations.*
25 | import java.util.concurrent.TimeUnit
26 |
27 | @State(Scope.Benchmark)
28 | @Fork(0)
29 | @Warmup(iterations = 2)
30 | @BenchmarkMode(Mode.AverageTime)
31 | @OutputTimeUnit(TimeUnit.MILLISECONDS)
32 | @Measurement(iterations = 5, time = 1, timeUnit = TimeUnit.MILLISECONDS)
33 | class JcdbLifeCycleBenchmarks {
34 |
35 | private lateinit var db: JcDatabase
36 |
37 | @Setup(Level.Iteration)
38 | fun setup() {
39 | db = runBlocking {
40 | jacodb {
41 | installFeatures(Usages)
42 | useProcessJavaRuntime()
43 | }
44 | }
45 | }
46 |
47 | @Benchmark
48 | fun loadAdditionalJars() {
49 | val jars = allJars
50 | runBlocking {
51 | db.load(jars)
52 | }
53 | }
54 |
55 | @Benchmark
56 | fun awaitIndexing() {
57 | runBlocking {
58 | db.awaitBackgroundJobs()
59 | }
60 | }
61 |
62 | @TearDown(Level.Iteration)
63 | fun tearDown() {
64 | db.close()
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/jacodb-cli/build.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | kotlin("plugin.serialization")
3 | }
4 |
5 | dependencies {
6 | api(project(":jacodb-core"))
7 | api(project(":jacodb-analysis"))
8 | api(project(":jacodb-api"))
9 |
10 | implementation(Libs.kotlin_logging)
11 | implementation(Libs.kotlinx_cli)
12 | implementation(Libs.kotlinx_serialization_json)
13 |
14 | testImplementation(testFixtures(project(":jacodb-core")))
15 | }
16 |
--------------------------------------------------------------------------------
/jacodb-cli/src/test/kotlin/org/jacodb/cli/CliTest.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 UnitTestBot contributors (utbot.org)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.cli
18 |
19 | import org.jacodb.testing.analysis.NpeExamples
20 | import org.junit.jupiter.api.Test
21 |
22 | class CliTest {
23 | @Test
24 | fun `test basic analysis cli api`() {
25 | val args = listOf(
26 | "-a", CliTest::class.java.getResource("/config.json")?.file ?: error("Can't find file with config"),
27 | "-s", NpeExamples::class.java.name
28 | )
29 | AnalysisMain().run(args)
30 | }
31 | }
--------------------------------------------------------------------------------
/jacodb-cli/src/test/resources/config.json:
--------------------------------------------------------------------------------
1 | {
2 | "analyses": {
3 | "NPE": {},
4 | "Unused": {
5 | "UnitResolver": "class"
6 | },
7 | "SQL": {}
8 | }
9 | }
--------------------------------------------------------------------------------
/jacodb-core/src/main/jooq/org/jacodb/impl/storage/jooq/DefaultCatalog.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 UnitTestBot contributors (utbot.org)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | /*
18 | * This file is generated by jOOQ.
19 | */
20 | package org.jacodb.impl.storage.jooq
21 |
22 |
23 | import org.jooq.Schema
24 | import org.jooq.impl.CatalogImpl
25 |
26 |
27 | /**
28 | * This class is generated by jOOQ.
29 | */
30 | @Suppress("UNCHECKED_CAST")
31 | open class DefaultCatalog : CatalogImpl("") {
32 | companion object {
33 |
34 | /**
35 | * The reference instance of
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.impl.bytecode
18 |
19 | import org.jacodb.api.JcClassOrInterface
20 | import org.jacodb.api.JcMethod
21 | import org.jacodb.api.JcMethodExtFeature
22 | import org.jacodb.impl.features.JcFeaturesChain
23 | import org.jacodb.impl.types.MethodInfo
24 |
25 | fun JcClassOrInterface.toJcMethod(
26 | methodInfo: MethodInfo,
27 | featuresChain: JcFeaturesChain
28 | ): JcMethod {
29 | return JcMethodImpl(methodInfo, featuresChain, this)
30 | }
--------------------------------------------------------------------------------
/jacodb-core/src/main/kotlin/org/jacodb/impl/bytecode/JcParameterImpl.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 UnitTestBot contributors (utbot.org)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.impl.bytecode
18 |
19 | import org.jacodb.api.JcAnnotation
20 | import org.jacodb.api.JcDeclaration
21 | import org.jacodb.api.JcMethod
22 | import org.jacodb.api.JcParameter
23 | import org.jacodb.api.TypeName
24 | import org.jacodb.impl.types.ParameterInfo
25 | import org.jacodb.impl.types.TypeNameImpl
26 |
27 | class JcParameterImpl(
28 | override val method: JcMethod,
29 | private val info: ParameterInfo
30 | ) : JcParameter {
31 |
32 | override val access: Int
33 | get() = info.access
34 |
35 | override val name: String? by lazy {
36 | info.name ?: kmParameter?.name
37 | }
38 |
39 | override val index: Int
40 | get() = info.index
41 |
42 | override val declaration: JcDeclaration
43 | get() = JcDeclarationImpl.of(method.enclosingClass.declaration.location, this)
44 |
45 | override val annotations: List
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.impl.cfg.util
18 |
19 | import org.jacodb.api.cfg.DefaultJcRawInstVisitor
20 | import org.jacodb.api.cfg.JcRawInst
21 |
22 | class InstructionFilter(val predicate: (JcRawInst) -> Boolean) : DefaultJcRawInstVisitor
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.impl.cfg.util
18 |
19 | import org.objectweb.asm.tree.AbstractInsnNode
20 | import org.objectweb.asm.tree.ClassNode
21 | import org.objectweb.asm.tree.MethodNode
22 | import org.objectweb.asm.tree.TryCatchBlockNode
23 | import org.objectweb.asm.util.Textifier
24 | import org.objectweb.asm.util.TraceMethodVisitor
25 | import java.io.PrintWriter
26 | import java.io.StringWriter
27 |
28 | private val printer = Textifier()
29 | private val mp = TraceMethodVisitor(printer)
30 |
31 | fun ClassNode.print() = buildString {
32 | appendLine("Class $name")
33 | for (mn in methods) {
34 | appendLine(mn.print())
35 | }
36 | }
37 |
38 | fun MethodNode.print() = buildString {
39 | appendLine(name)
40 | for (insn in instructions) {
41 | append(insn.print())
42 | }
43 | for (insn in tryCatchBlocks) {
44 | append(insn.print())
45 | }
46 | }
47 |
48 | fun AbstractInsnNode.print(): String {
49 | this.accept(mp)
50 | val sw = StringWriter()
51 | printer.print(PrintWriter(sw))
52 | printer.getText().clear()
53 | return sw.toString()
54 | }
55 |
56 | fun TryCatchBlockNode.print() = buildString {
57 | append("${start.print().dropLast(1)} ")
58 | append("${end.print().dropLast(1)} ")
59 | append("${handler.print().dropLast(1)} ")
60 | appendLine(type ?: "java/lang/Throwable")
61 | }
62 |
--------------------------------------------------------------------------------
/jacodb-core/src/main/kotlin/org/jacodb/impl/features/Diagnostics.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 UnitTestBot contributors (utbot.org)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | @file:JvmName("Diagnostics")
18 |
19 | package org.jacodb.impl.features
20 |
21 |
22 | import kotlinx.coroutines.GlobalScope
23 | import kotlinx.coroutines.future.future
24 | import org.jacodb.api.JcClasspath
25 | import org.jacodb.impl.storage.jooq.tables.references.CLASSES
26 | import org.jacodb.impl.storage.jooq.tables.references.SYMBOLS
27 | import org.jooq.impl.DSL
28 |
29 |
30 | /**
31 | * finds out duplicates classes
32 | *
33 | * @return map with name and count of classes
34 | */
35 | suspend fun JcClasspath.duplicatedClasses(): Map
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.impl.features
18 |
19 | import org.jacodb.api.JcClasspathFeature
20 | import org.jacodb.api.JcFeatureEvent
21 | import org.jacodb.api.JcLookupExtFeature
22 |
23 | class JcFeaturesChain(val features: List
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.impl.features
18 |
19 | import kotlinx.serialization.Serializable
20 | import org.jacodb.api.ClassSource
21 |
22 | @Serializable
23 | data class UsageFeatureRequest(
24 | val methodName: String?,
25 | val description: String?,
26 | val field: String?,
27 | val opcodes: Collection
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.impl.features.classpaths
18 |
19 | import org.jacodb.api.JcInstExtFeature
20 | import org.jacodb.api.JcMethod
21 | import org.jacodb.api.JcMethodExtFeature
22 | import org.jacodb.api.cfg.JcInst
23 | import org.jacodb.api.cfg.JcInstList
24 | import org.jacodb.impl.analysis.impl.StringConcatSimplifierTransformer
25 |
26 | object StringConcatSimplifier : JcInstExtFeature, JcMethodExtFeature {
27 |
28 | override fun transformInstList(method: JcMethod, list: JcInstList
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.impl.features.classpaths.virtual
18 |
19 | import org.jacodb.api.JcAnnotation
20 | import org.jacodb.api.JcClassOrInterface
21 | import org.jacodb.api.JcDeclaration
22 | import org.jacodb.api.JcField
23 | import org.jacodb.api.TypeName
24 | import org.jacodb.impl.bytecode.JcDeclarationImpl
25 | import org.objectweb.asm.Opcodes
26 |
27 | interface JcVirtualField : JcField {
28 | fun bind(clazz: JcClassOrInterface)
29 |
30 | }
31 |
32 | open class JcVirtualFieldImpl(
33 | override val name: String,
34 | override val access: Int = Opcodes.ACC_PUBLIC,
35 | override val type: TypeName,
36 | ) : JcVirtualField {
37 | override val declaration: JcDeclaration
38 | get() = JcDeclarationImpl.of(enclosingClass.declaration.location, this)
39 |
40 | override lateinit var enclosingClass: JcClassOrInterface
41 |
42 | override fun bind(clazz: JcClassOrInterface) {
43 | this.enclosingClass = clazz
44 | }
45 |
46 | override val signature: String?
47 | get() = null
48 | override val annotations: List
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.impl.fs
18 |
19 | import com.google.common.hash.Hashing
20 | import org.jacodb.api.JcByteCodeLocation
21 | import java.io.File
22 | import java.nio.charset.StandardCharsets
23 |
24 |
25 | abstract class AbstractByteCodeLocation(override val jarOrFolder: File) : JcByteCodeLocation {
26 |
27 | override val path: String
28 | get() = jarOrFolder.absolutePath
29 |
30 | abstract fun currentHash(): String
31 |
32 | override fun isChanged() = fileSystemId != currentHash()
33 |
34 |
35 | protected val String.shaHash: String
36 | get() {
37 | return Hashing.sha256()
38 | .hashString(this, StandardCharsets.UTF_8)
39 | .toString();
40 | }
41 |
42 | }
--------------------------------------------------------------------------------
/jacodb-core/src/main/kotlin/org/jacodb/impl/fs/ByteCodeLoaderImpl.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 UnitTestBot contributors (utbot.org)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.impl.fs
18 |
19 | import org.jacodb.api.ClassSource
20 | import org.jacodb.api.RegisteredLocation
21 |
22 | val RegisteredLocation.sources: List
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.impl.fs
18 |
19 | import mu.KLogging
20 | import org.jacodb.api.JavaVersion
21 | import org.jacodb.api.JcByteCodeLocation
22 | import java.io.File
23 |
24 | val logger = object : KLogging() {}.logger
25 |
26 | fun File.asByteCodeLocation(runtimeVersion: JavaVersion, isRuntime: Boolean = false): JcByteCodeLocation {
27 | if (!exists()) {
28 | throw IllegalArgumentException("file $absolutePath doesn't exist")
29 | }
30 | if (isFile && name.endsWith(".jar") || name.endsWith(".jmod")) {
31 | return JarLocation(this, isRuntime, runtimeVersion)
32 | } else if (!isFile) {
33 | return BuildFolderLocation(this)
34 | }
35 | throw IllegalArgumentException("file $absolutePath is not jar-file nor build dir folder")
36 | }
37 |
38 | fun List
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.impl.fs
18 |
19 | import org.jacodb.api.JavaVersion
20 |
21 | private class JavaVersionImpl(override val majorVersion: Int) : JavaVersion
22 |
23 | fun parseRuntimeVersion(version: String): JavaVersion {
24 | return when {
25 | version.startsWith("1.") -> JavaVersionImpl(version.substring(2, 3).toInt())
26 | else -> {
27 | val dot = version.indexOf(".")
28 | if (dot != -1) {
29 | JavaVersionImpl(version.substring(0, dot).toInt())
30 | } else {
31 | JavaVersionImpl(8)
32 | }
33 | }
34 | }
35 | }
--------------------------------------------------------------------------------
/jacodb-core/src/main/kotlin/org/jacodb/impl/jacodb.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 UnitTestBot contributors (utbot.org)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | @file:JvmName("JacoDB")
18 |
19 | package org.jacodb.impl
20 |
21 | import kotlinx.coroutines.GlobalScope
22 | import kotlinx.coroutines.future.future
23 | import org.jacodb.api.JcDatabase
24 | import org.jacodb.impl.fs.JavaRuntime
25 |
26 | suspend fun jacodb(builder: JcSettings.() -> Unit): JcDatabase {
27 | return jacodb(JcSettings().also(builder))
28 | }
29 |
30 | suspend fun jacodb(settings: JcSettings): JcDatabase {
31 | val featureRegistry = FeaturesRegistry(settings.features)
32 | val javaRuntime = JavaRuntime(settings.jre)
33 | val persistence = (settings.persistentType ?: PredefinedPersistenceType.SQLITE)
34 | .newPersistence(javaRuntime, featureRegistry, settings)
35 | return JcDatabaseImpl(
36 | javaRuntime = javaRuntime,
37 | persistence = persistence,
38 | featureRegistry = featureRegistry,
39 | settings = settings
40 | ).also {
41 | it.restore()
42 | it.afterStart()
43 | }
44 | }
45 |
46 | /** bridge for Java */
47 | fun async(settings: JcSettings) = GlobalScope.future { jacodb(settings) }
--------------------------------------------------------------------------------
/jacodb-core/src/main/kotlin/org/jacodb/impl/storage/Caches.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 UnitTestBot contributors (utbot.org)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.impl.storage
18 |
19 | import com.google.common.cache.Cache
20 | import com.google.common.cache.CacheBuilder
21 | import java.time.Duration
22 |
23 |
24 | fun
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.impl.storage
18 |
19 | class DataStorageException(msg: String) : Exception(msg)
--------------------------------------------------------------------------------
/jacodb-core/src/main/kotlin/org/jacodb/impl/storage/Enums.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 UnitTestBot contributors (utbot.org)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.impl.storage
18 |
19 | enum class AnnotationValueKind {
20 | BOOLEAN,
21 | BYTE,
22 | CHAR,
23 | SHORT,
24 | INT,
25 | FLOAT,
26 | LONG,
27 | DOUBLE,
28 | STRING;
29 |
30 | companion object {
31 | fun serialize(value: Any): String {
32 | return when (value) {
33 | is String -> value
34 | is Short -> value.toString()
35 | is Char -> value.toString()
36 | is Long -> value.toString()
37 | is Int -> value.toString()
38 | is Float -> value.toString()
39 | is Double -> value.toString()
40 | is Byte -> value.toString()
41 | is Boolean -> value.toString()
42 | else -> throw IllegalStateException("Unknown type ${value.javaClass}")
43 | }
44 | }
45 | }
46 |
47 | }
48 |
49 |
50 | enum class LocationState {
51 | INITIAL,
52 | AWAITING_INDEXING,
53 | PROCESSED,
54 | OUTDATED
55 | }
--------------------------------------------------------------------------------
/jacodb-core/src/main/kotlin/org/jacodb/impl/types/JcTypedMethodParameterImpl.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 UnitTestBot contributors (utbot.org)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.impl.types
18 |
19 | import org.jacodb.api.*
20 | import org.jacodb.api.ext.isNullable
21 | import org.jacodb.impl.bytecode.JcAnnotationImpl
22 | import org.jacodb.impl.bytecode.JcMethodImpl
23 |
24 | class JcTypedMethodParameterImpl(
25 | override val enclosingMethod: JcTypedMethod,
26 | private val parameter: JcParameter,
27 | private val jvmType: JvmType?,
28 | private val substitutor: JcSubstitutor
29 | ) : JcTypedMethodParameter {
30 |
31 | val classpath = enclosingMethod.method.enclosingClass.classpath
32 |
33 | override val type: JcType
34 | get() {
35 | val typeName = parameter.type.typeName
36 | val type = jvmType?.let {
37 | classpath.typeOf(substitutor.substitute(jvmType))
38 | } ?: classpath.findTypeOrNull(typeName)
39 | ?.copyWithAnnotations(
40 | (enclosingMethod.method as? JcMethodImpl)?.parameterTypeAnnotationInfos(parameter.index)?.map { JcAnnotationImpl(it, classpath) } ?: listOf()
41 | ) ?: typeName.throwClassNotFound()
42 |
43 | return parameter.isNullable?.let {
44 | (type as? JcRefType)?.copyWithNullability(it)
45 | } ?: type
46 | }
47 |
48 | override val name: String?
49 | get() = parameter.name
50 | }
--------------------------------------------------------------------------------
/jacodb-core/src/main/kotlin/org/jacodb/impl/types/signature/JvmTypeParameterDeclaration.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 UnitTestBot contributors (utbot.org)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.impl.types.signature
18 |
19 | import org.jacodb.api.JcAccessible
20 | import org.jacodb.api.JvmType
21 | import org.jacodb.api.JvmTypeParameterDeclaration
22 |
23 | internal class JvmTypeParameterDeclarationImpl(
24 | override val symbol: String,
25 | override val owner: JcAccessible,
26 | override val bounds: List
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.impl.types.signature
18 |
19 | import org.jacodb.api.JvmType
20 | import org.jacodb.api.Malformed
21 | import org.jacodb.api.Pure
22 | import org.jacodb.api.RecordComponentResolution
23 | import org.objectweb.asm.signature.SignatureReader
24 |
25 | internal class RecordSignature : TypeRegistrant {
26 |
27 | private lateinit var recordComponentType: JvmType
28 |
29 | override fun register(token: JvmType) {
30 | recordComponentType = token
31 | }
32 |
33 | protected fun resolve(): RecordComponentResolution {
34 | return RecordComponentResolutionImpl(recordComponentType)
35 | }
36 |
37 | companion object {
38 | fun of(signature: String?): RecordComponentResolution {
39 | signature ?: return Pure
40 | val signatureReader = SignatureReader(signature)
41 | val visitor = RecordSignature()
42 | return try {
43 | signatureReader.acceptType(TypeExtractor(visitor))
44 | visitor.resolve()
45 | } catch (ignored: RuntimeException) {
46 | Malformed
47 | }
48 | }
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/jacodb-core/src/main/kotlin/org/jacodb/impl/types/signature/Resolutions.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 UnitTestBot contributors (utbot.org)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.impl.types.signature
18 |
19 | import org.jacodb.api.*
20 |
21 | internal class FieldResolutionImpl(val fieldType: JvmType) : FieldResolution
22 |
23 | internal class RecordComponentResolutionImpl(val recordComponentType: JvmType) : RecordComponentResolution
24 |
25 | internal class MethodResolutionImpl(
26 | val returnType: JvmType,
27 | val parameterTypes: List
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.impl.vfs
18 |
19 | interface ClassTreeListener {
20 |
21 | /**
22 | * method called when bytecode is read from file
23 | * @param nodeWithLoadedByteCode - class node with fully loaded node
24 | */
25 | suspend fun notifyOnByteCodeLoaded(nodeWithLoadedByteCode: ClassVfsItem, globalClassVFS: GlobalClassesVfs)
26 |
27 | }
--------------------------------------------------------------------------------
/jacodb-core/src/main/kotlin/org/jacodb/impl/vfs/ClassVfsItem.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 UnitTestBot contributors (utbot.org)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.impl.vfs
18 |
19 | import org.jacodb.api.ClassSource
20 |
21 | class ClassVfsItem(
22 | override val name: String,
23 | packageNode: PackageVfsItem,
24 | internal val source: ClassSource
25 | ) : AbstractVfsItem
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.impl.vfs
18 |
19 | import org.jacodb.api.RegisteredLocation
20 | import org.jacodb.impl.LocationsRegistrySnapshot
21 |
22 | /**
23 | * ClassTree view limited by number of `locations`
24 | */
25 | class ClasspathVfs(
26 | private val globalClassVFS: GlobalClassesVfs,
27 | locations: List
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.impl.vfs
18 |
19 | import org.jacodb.api.RegisteredLocation
20 |
21 | abstract class AbstractVfsItem
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.testing;
18 |
19 | import org.jacodb.api.JcDatabase;
20 | import org.jacodb.api.cfg.JcArgument;
21 | import org.jacodb.api.cfg.JcExpr;
22 | import org.jacodb.api.cfg.TypedExprResolver;
23 | import org.jacodb.impl.JacoDB;
24 | import org.jacodb.impl.JcCacheSettings;
25 | import org.jacodb.impl.JcSettings;
26 | import org.jacodb.impl.features.Usages;
27 | import org.jetbrains.annotations.NotNull;
28 |
29 | import java.time.Duration;
30 | import java.time.temporal.ChronoUnit;
31 |
32 | public class JavaApi {
33 | private static class ArgumentResolver extends TypedExprResolver
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.testing
18 |
19 | class BarKt
--------------------------------------------------------------------------------
/jacodb-core/src/test/kotlin/org/jacodb/testing/JavaVersionTest.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 UnitTestBot contributors (utbot.org)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.testing
18 |
19 | import org.jacodb.impl.JcSettings
20 | import org.jacodb.impl.fs.JavaRuntime
21 | import org.junit.jupiter.api.Assertions.assertEquals
22 | import org.junit.jupiter.api.Test
23 | import org.junit.jupiter.api.condition.EnabledOnJre
24 | import org.junit.jupiter.api.condition.JRE
25 |
26 | class JavaVersionTest {
27 |
28 | @Test
29 | @EnabledOnJre(JRE.JAVA_11)
30 | fun `java version should be proper for 11 java`() {
31 | assertEquals(11, JavaRuntime(JcSettings().useProcessJavaRuntime().jre).version.majorVersion)
32 | }
33 | @Test
34 | @EnabledOnJre(JRE.JAVA_8)
35 | fun `java version should be proper for 8 java`() {
36 | assertEquals(8, JavaRuntime(JcSettings().useProcessJavaRuntime().jre).version.majorVersion)
37 | }
38 |
39 | }
--------------------------------------------------------------------------------
/jacodb-core/src/test/kotlin/org/jacodb/testing/SubclassesTest.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 UnitTestBot contributors (utbot.org)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.testing
18 |
19 | import kotlinx.coroutines.runBlocking
20 | import org.jacodb.api.JcClasspath
21 | import org.jacodb.api.ext.JAVA_OBJECT
22 | import org.jacodb.impl.features.hierarchyExt
23 | import org.junit.jupiter.api.AfterEach
24 | import org.junit.jupiter.api.Assertions
25 | import org.junit.jupiter.api.Test
26 |
27 | @LifecycleTest
28 | class SubclassesTest : BaseTest() {
29 |
30 | companion object : WithGlobalDB()
31 |
32 | private val withDB = WithDB()
33 |
34 | private val anotherDb = withDB.db
35 | private val anotherCp: JcClasspath by lazy {
36 | runBlocking {
37 | anotherDb.awaitBackgroundJobs()
38 | anotherDb.classpath(allClasspath)
39 | }
40 | }
41 |
42 | @Test
43 | fun `Object subclasses should be the same`() {
44 | runBlocking {
45 | val hierarchy = cp.hierarchyExt()
46 | val anotherHierarchy = anotherCp.hierarchyExt()
47 | Assertions.assertEquals(
48 | hierarchy.findSubClasses(JAVA_OBJECT, false, includeOwn = true).count(),
49 | anotherHierarchy.findSubClasses(JAVA_OBJECT, false, includeOwn = true).count()
50 | )
51 | }
52 | }
53 |
54 | @AfterEach
55 | fun `cleanup another db`() = runBlocking {
56 | withDB.cleanup()
57 | }
58 |
59 | }
--------------------------------------------------------------------------------
/jacodb-core/src/test/kotlin/org/jacodb/testing/persistence/RestoredDBTest.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 UnitTestBot contributors (utbot.org)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.testing.persistence
18 |
19 | import kotlinx.coroutines.runBlocking
20 | import org.jacodb.api.JcClasspath
21 | import org.jacodb.api.ext.HierarchyExtension
22 | import org.jacodb.impl.features.hierarchyExt
23 | import org.jacodb.testing.LifecycleTest
24 | import org.jacodb.testing.WithRestoredDB
25 | import org.jacodb.testing.allClasspath
26 | import org.jacodb.testing.tests.DatabaseEnvTest
27 | import org.jacodb.testing.withDB
28 |
29 | @LifecycleTest
30 | class RestoredDBTest : DatabaseEnvTest() {
31 |
32 | companion object : WithRestoredDB()
33 |
34 | override val cp: JcClasspath by lazy {
35 | runBlocking {
36 | val withDB = this@RestoredDBTest.javaClass.withDB
37 | withDB.db.classpath(allClasspath)
38 | }
39 | }
40 |
41 | override val hierarchyExt: HierarchyExtension by lazy { runBlocking { cp.hierarchyExt() } }
42 |
43 |
44 | }
45 |
46 |
--------------------------------------------------------------------------------
/jacodb-core/src/test/kotlin/org/jacodb/testing/tree/DummyCodeLocation.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 UnitTestBot contributors (utbot.org)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.testing.tree
18 |
19 | import org.jacodb.api.JcByteCodeLocation
20 | import org.jacodb.api.LocationType
21 | import org.jacodb.api.RegisteredLocation
22 | import org.jacodb.impl.storage.longHash
23 | import java.io.File
24 |
25 | open class DummyCodeLocation(private val name: String) : JcByteCodeLocation, RegisteredLocation {
26 |
27 | override val id: Long
28 | get() = name.longHash
29 |
30 | override val fileSystemId: String
31 | get() = name
32 |
33 | override val isRuntime: Boolean
34 | get() = false
35 |
36 | override val jcLocation: JcByteCodeLocation
37 | get() = this
38 |
39 | override val type = LocationType.APP
40 |
41 | override val classes: Map
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.testing.types
18 |
19 | import org.jacodb.api.JcClassType
20 | import org.jacodb.api.JcType
21 | import org.jacodb.testing.BaseTest
22 | import org.jacodb.testing.WithGlobalDB
23 | import org.junit.jupiter.api.Assertions.*
24 |
25 | abstract class BaseTypesTest : BaseTest() {
26 |
27 | companion object : WithGlobalDB()
28 |
29 | protected inline fun
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | import java.io.Closeable;
18 |
19 | public class GenericsApi
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | public class PhantomClass {
18 |
19 | public int intField;
20 | public String stringField;
21 |
22 | public void run() {
23 | }
24 |
25 | public static void staticRun() {
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/jacodb-core/src/test/resources/src/PhantomClassSubclass.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 UnitTestBot contributors (utbot.org)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | public class PhantomClassSubclass extends PhantomClass {
18 |
19 | @Override
20 | public void run() {
21 | super.run();
22 | System.out.println(super.intField);
23 | staticRun();
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/jacodb-core/src/test/resources/src/PhantomCodeConsumer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 UnitTestBot contributors (utbot.org)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | public class PhantomCodeConsumer {
18 |
19 | private final PhantomClass clazz = new PhantomClass();
20 |
21 | public void fieldRef() {
22 | System.out.println(clazz.intField);
23 | System.out.println(clazz.stringField);
24 | }
25 |
26 | public void methodRef() {
27 | clazz.run();
28 | }
29 | }
30 |
31 |
32 |
--------------------------------------------------------------------------------
/jacodb-core/src/test/resources/src/PhantomDeclaration.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 UnitTestBot contributors (utbot.org)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | public class PhantomDeclaration {
18 | int x = 0;
19 | int y = 0;
20 |
21 | public void run() {
22 | System.out.println("Hello world");
23 | }
24 |
25 | public void runSomething() {
26 | System.out.println("Hello world");
27 | }
28 |
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/jacodb-core/src/test/resources/src/PhantomDeclarationConsumer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 UnitTestBot contributors (utbot.org)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | public class PhantomDeclarationConsumer {
18 |
19 | PhantomDeclaration f = new PhantomDeclaration();
20 |
21 | public void call() {
22 | System.out.println(f.y);
23 | f.runSomething();
24 | }
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/jacodb-core/src/test/resources/src/PhantomInterface.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 UnitTestBot contributors (utbot.org)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | public interface PhantomInterface {
18 |
19 | static void staticFoo() {
20 | System.out.println("static foo");
21 | }
22 |
23 | void foo();
24 | }
25 |
--------------------------------------------------------------------------------
/jacodb-core/src/test/resources/src/PhantomInterfaceConsumer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 UnitTestBot contributors (utbot.org)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | public class PhantomInterfaceConsumer {
18 |
19 | private final PhantomInterface iface = new PhantomInterfaceImpl();
20 |
21 | public void methodRef() {
22 | iface.foo();
23 | }
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/jacodb-core/src/test/resources/src/PhantomInterfaceImpl.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 UnitTestBot contributors (utbot.org)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | public class PhantomInterfaceImpl implements PhantomInterface {
18 |
19 | @Override
20 | public void foo() {
21 | PhantomInterface.staticFoo();
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/jacodb-core/src/testFixtures/java/org/jacodb/testing/Bar.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 UnitTestBot contributors (utbot.org)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.testing;
18 |
19 | public class Bar {
20 | byte[] byteArray = new byte[19];
21 | Object[] objectArray = new Object[19];
22 | Object[][] objectObjectArray = new Object[19][];
23 |
24 | public byte[] smth(byte[] another) {
25 | return another;
26 | }
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/jacodb-core/src/testFixtures/java/org/jacodb/testing/Common.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 UnitTestBot contributors (utbot.org)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.testing;
18 |
19 | public class Common {
20 |
21 | public interface CommonInterface {
22 |
23 | default void defaultMethod() {
24 | System.out.println("Hello");
25 | }
26 | }
27 |
28 | public static class CommonClass implements CommonInterface {
29 |
30 | public void run() {
31 | defaultMethod();
32 | }
33 |
34 | }
35 |
36 | public static class Common1 {
37 | public int publicField;
38 | protected int protectedField;
39 | private int privateField;
40 | int packageField;
41 |
42 | public void publicMethod() {
43 | }
44 |
45 | protected void protectedMethod() {
46 | }
47 |
48 | private void privateMethod() {
49 | }
50 |
51 | void packageMethod() {
52 | }
53 |
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/jacodb-core/src/testFixtures/java/org/jacodb/testing/analysis/SqlInjectionExamples.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 UnitTestBot contributors (utbot.org)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.testing.analysis;
18 |
19 | import java.sql.Connection;
20 | import java.sql.DriverManager;
21 | import java.sql.SQLException;
22 | import java.sql.Statement;
23 |
24 | @SuppressWarnings("ALL")
25 | public class SqlInjectionExamples {
26 |
27 | void bad() {
28 | String data = System.getenv("USER");
29 | try (
30 | Connection dbConnection = DriverManager.getConnection("", "", "");
31 | Statement sqlStatement = dbConnection.createStatement();
32 | ) {
33 | boolean result = sqlStatement.execute("insert into users (status) values ('updated') where name='" + data + "'");
34 |
35 | if (result) {
36 | System.out.println("User '" + data + "' updated successfully");
37 | } else {
38 | System.out.println("Unable to update records for user '" + data + "'");
39 | }
40 | } catch (SQLException e) {
41 | System.err.println("Error: " + e);
42 | } finally {
43 | System.out.println("OK!");
44 | }
45 | }
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/jacodb-core/src/testFixtures/java/org/jacodb/testing/builders/Hierarchy.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 UnitTestBot contributors (utbot.org)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.testing.builders;
18 |
19 | public class Hierarchy {
20 |
21 | public interface HierarchyInterface {
22 | }
23 |
24 | public static class HierarchyImpl1 implements HierarchyInterface {
25 | }
26 |
27 | public HierarchyImpl1 build() {
28 | return new HierarchyImpl1();
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/jacodb-core/src/testFixtures/java/org/jacodb/testing/builders/Interfaces.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 UnitTestBot contributors (utbot.org)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.testing.builders;
18 |
19 | import java.util.List;
20 |
21 | public class Interfaces {
22 |
23 | public static interface Interface {
24 |
25 | }
26 |
27 | public static class Impl1 implements Interface {
28 | }
29 |
30 | public static class Impl2 extends Impl1 {
31 | }
32 |
33 |
34 |
35 | public Interface build1() {
36 | return new Impl1();
37 | }
38 |
39 | public Interface build2(Impl2 impl2) {
40 | return impl2;
41 | }
42 |
43 | public Interface build3(List
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.testing.builders;
18 |
19 | public class Simple {
20 |
21 | public static class SimpleBuilder {
22 |
23 | private Simple property;
24 |
25 | public Simple getProperty() {
26 | return property;
27 | }
28 |
29 | public void setProperty(Simple property) {
30 | this.property = property;
31 | }
32 |
33 | public Simple build() {
34 | return new Simple();
35 | }
36 |
37 | public Simple justReturnThis(Simple simple) {
38 | return simple;
39 | }
40 | }
41 |
42 | private Simple() {
43 |
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/jacodb-core/src/testFixtures/java/org/jacodb/testing/cfg/ArgAssignmentExample.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 UnitTestBot contributors (utbot.org)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.testing.cfg;
18 |
19 | public class ArgAssignmentExample {
20 | private static class X {
21 | public final int a = 0;
22 | }
23 |
24 | private static X sample(X arg) {
25 | if (arg.a == 0) {
26 | arg = null;
27 | }
28 | return arg;
29 | }
30 |
31 | public String box() {
32 | X result = sample(new X());
33 | return result == null ? "OK" : "BAD";
34 | }
35 | }
--------------------------------------------------------------------------------
/jacodb-core/src/testFixtures/java/org/jacodb/testing/cfg/Conditionals.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 UnitTestBot contributors (utbot.org)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.testing.cfg;
18 |
19 | import java.util.ArrayList;
20 | import java.util.Collections;
21 | import java.util.List;
22 | import java.util.Random;
23 |
24 | public class Conditionals {
25 | void main(int x, int y) {
26 | if (x < 0) {
27 | System.out.println("< 0");
28 | }
29 | if (x <= 0) {
30 | System.out.println("<= 0");
31 | }
32 | if (x < y) {
33 | System.out.println("<");
34 | }
35 | if (x <= y) {
36 | System.out.println("<=");
37 | }
38 | }
39 |
40 | public static Object conditionInFor() {
41 | Random rnd = new Random();
42 | List
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.testing.cfg;
18 |
19 | public class JavaArrays {
20 |
21 | public static void arrayClone() {
22 | byte[] x = new byte[1];
23 | System.out.println(x.clone().length);
24 | }
25 |
26 | public static void arrayObjectMethods() {
27 | byte[] x = new byte[1];
28 | x.notify();
29 | System.out.println(x.clone().length);
30 | }
31 |
32 | public static void arrayObjectMonitors() {
33 | byte[] x = new byte[1];
34 | synchronized (x) {
35 | System.out.println(x.length);
36 | }
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/jacodb-core/src/testFixtures/java/org/jacodb/testing/cfg/Lambdas.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 UnitTestBot contributors (utbot.org)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.testing.cfg;
18 |
19 | import java.util.Arrays;
20 | import java.util.Comparator;
21 | import java.util.List;
22 |
23 | public class Lambdas {
24 |
25 | public static Object lambdaTest() {
26 | List
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.testing.cfg;
18 |
19 | public class NullAssumptionAnalysisExample {
20 |
21 | public void test1(String a) {
22 | System.out.println("Hello from test1");
23 | System.out.println(a.length());
24 | }
25 |
26 | public void test2(Object a) {
27 | System.out.println("Hello from test2");
28 | System.out.println(a.hashCode());
29 | String x = (String) a;
30 | System.out.println(x.length());
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/jacodb-core/src/testFixtures/java/org/jacodb/testing/cfg/StaticInterfaceMethodCall.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 UnitTestBot contributors (utbot.org)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.testing.cfg;
18 |
19 | import java.util.function.Function;
20 |
21 | public class StaticInterfaceMethodCall {
22 | public static void callStaticInterfaceMethod() {
23 | Function.identity();
24 | }
25 | }
--------------------------------------------------------------------------------
/jacodb-core/src/testFixtures/java/org/jacodb/testing/hierarchies/Creature.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 UnitTestBot contributors (utbot.org)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.testing.hierarchies;
18 |
19 | public interface Creature {
20 |
21 | void say(String smth);
22 |
23 | default void hello() {
24 | say("Hello");
25 | }
26 |
27 | interface Animal extends Creature {
28 | }
29 |
30 | interface Fish extends Creature {
31 | @Override
32 | void say(String smth);
33 | }
34 |
35 | interface Dinosaur extends Creature, Animal {
36 | }
37 |
38 | interface Bird extends Creature {
39 | }
40 |
41 | class DinosaurImpl implements Dinosaur {
42 | @Override
43 | public void say(String smth) {
44 | System.out.println("Dino say:" + smth);
45 | }
46 | }
47 |
48 | class TRex extends DinosaurImpl implements Dinosaur {
49 | @Override
50 | public void say(String smth) {
51 | super.say("TRex say:" + smth);
52 | }
53 |
54 | @Override
55 | public void hello() {
56 | // do nothing
57 | }
58 | }
59 |
60 | class Pterodactyl extends DinosaurImpl implements Bird {
61 | @Override
62 | public void say(String smth) {
63 | super.say("Pterodactyl say:" + smth);
64 | }
65 | }
66 |
67 |
68 | }
69 |
--------------------------------------------------------------------------------
/jacodb-core/src/testFixtures/java/org/jacodb/testing/hierarchies/Inheritance.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 UnitTestBot contributors (utbot.org)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.testing.hierarchies;
18 |
19 | import java.beans.Statement;
20 |
21 | public class Inheritance {
22 |
23 | public static Object test(String[] args) throws Exception {
24 | new Statement(new Private(), "run", null).execute();
25 | new Statement(new PrivateGeneric(), "run", new Object[] {"generic"}).execute();
26 | return null;
27 | }
28 |
29 | public static class Public {
30 | public void run() {
31 | throw new Error("method is overridden");
32 | }
33 | }
34 |
35 | static class Private extends Public {
36 | public void run() {
37 | System.out.println("default");
38 | }
39 | }
40 |
41 | public static class PublicGeneric
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.testing.primitives;
18 |
19 | public class Primitives {
20 |
21 | public int example(short s, char c) {
22 | return s + c;
23 | }
24 |
25 | public int example(byte s, short c) {
26 | return s + c;
27 | }
28 |
29 | public long example(int s, long c) {
30 | return s + c;
31 | }
32 |
33 | public float example(int s, float c) {
34 | return s + c;
35 | }
36 |
37 | public int example(char s, char c) {
38 | return s + c;
39 | }
40 |
41 | public int unaryExample(char a) {
42 | return -a;
43 | }
44 |
45 | public int unaryExample(byte a) {
46 | return -a;
47 | }
48 |
49 | public int unaryExample(short a) {
50 | return -a;
51 | }
52 |
53 | public long unaryExample(long a) {
54 | return -a;
55 | }
56 |
57 | public float unaryExample(float a) {
58 | return -a;
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/jacodb-core/src/testFixtures/java/org/jacodb/testing/structure/EnumExamples.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 UnitTestBot contributors (utbot.org)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.testing.structure;
18 |
19 | public class EnumExamples {
20 | public enum SimpleEnum {
21 | SUCCESS, ERROR
22 | }
23 |
24 | public enum EnumWithField {
25 | OK(200), NOT_FOUND(404);
26 |
27 | EnumWithField(int statusCode) {
28 | this.statusCode = statusCode;
29 | }
30 |
31 | final int statusCode;
32 | }
33 |
34 | public enum EnumWithStaticInstance {
35 | C1, C2;
36 |
37 | public static final EnumWithStaticInstance instance = C1;
38 | }
39 |
40 | public static void main(String[] args) {
41 | System.out.println(EnumWithStaticInstance.values().length);
42 | }
43 |
44 | }
45 |
46 |
--------------------------------------------------------------------------------
/jacodb-core/src/testFixtures/java/org/jacodb/testing/structure/FieldsAndMethods.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 UnitTestBot contributors (utbot.org)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.testing.structure;
18 |
19 | import org.jacodb.testing.Common;
20 |
21 | public class FieldsAndMethods {
22 |
23 | public static class Common1Child extends Common.Common1 {
24 | private int privateFieldsAndMethods;
25 |
26 | private boolean publicField;
27 |
28 | private void privateFieldsAndMethods() {
29 | }
30 |
31 | private int accessIntField() {
32 | return ((Common.Common1) this).publicField;
33 | }
34 |
35 | private boolean accessBooleanField() {
36 | return publicField;
37 | }
38 | }
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/jacodb-core/src/testFixtures/java/org/jacodb/testing/structure/HiddenFieldSuperClass.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 UnitTestBot contributors (utbot.org)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.testing.structure;
18 |
19 | public class HiddenFieldSuperClass {
20 | public int a, b;
21 |
22 | public static class HiddenFieldSuccClass extends HiddenFieldSuperClass {
23 | public double b;
24 | }
25 | }
26 |
27 |
--------------------------------------------------------------------------------
/jacodb-core/src/testFixtures/java/org/jacodb/testing/types/AAA.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 UnitTestBot contributors (utbot.org)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.testing.types;
18 |
19 | public class AAA {
20 |
21 | public class BBB {
22 |
23 | }
24 |
25 | static public class CCC {
26 |
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/jacodb-core/src/testFixtures/java/org/jacodb/testing/types/Comparables.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 UnitTestBot contributors (utbot.org)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.testing.types;
18 |
19 | import org.jetbrains.annotations.NotNull;
20 |
21 | public class Comparables {
22 |
23 | public static class ComparableTest1 implements Comparable
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.testing.types;
18 |
19 | import java.util.ArrayList;
20 | import java.util.List;
21 |
22 | public class Generics {
23 |
24 |
25 | static class LinkedBase
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.testing.types;
18 |
19 | import java.util.ArrayList;
20 | import java.util.List;
21 |
22 | public class MultipleParametrization {
23 |
24 | public static class SuperTest1
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.testing.types;
18 |
19 | abstract public class PrimitiveAndArrays {
20 |
21 | private int value = 0;
22 | private int[] intArray = new int[1];
23 |
24 | abstract int[] run(String[] stringArray);
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/jacodb-core/src/testFixtures/java/org/jacodb/testing/types/WildcardBounds.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 UnitTestBot contributors (utbot.org)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.testing.types;
18 |
19 | import java.util.List;
20 |
21 | public class WildcardBounds {
22 |
23 | public static class DirectBound
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.testing.usages;
18 |
19 | import java.util.Collection;
20 | import java.util.List;
21 |
22 | public class Generics
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.testing.usages;
18 |
19 | import java.util.Collection;
20 | import java.util.List;
21 |
22 | public class WithInner {
23 |
24 | public class Inner {
25 | public void hello() {
26 | System.out.println("hello");
27 | }
28 | }
29 |
30 | public static class StaticInner {
31 | public void helloStatic() {
32 | System.out.println("hello static");
33 | }
34 | }
35 |
36 | public void sayHello() {
37 | new Inner().hello();
38 | new StaticInner().helloStatic();
39 | new Runnable() {
40 | @Override
41 | public void run() {
42 | System.out.println("hello anonymous");
43 | }
44 | }.run();
45 |
46 | }
47 |
48 | public static void main(String[] args) {
49 | new WithInner1
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.testing.usages.direct;
18 |
19 | import com.google.common.collect.Lists;
20 |
21 | public class DirectA {
22 |
23 | public static boolean called;
24 |
25 | private boolean result;
26 |
27 | public static void setCalled() {
28 | called = true;
29 | System.out.println(called);
30 | }
31 |
32 | public void newSmth() {
33 | this.result = Lists.newArrayList().add(1);
34 | System.out.println(result);
35 | called = true;
36 | System.out.println(called);
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/jacodb-core/src/testFixtures/java/org/jacodb/testing/usages/fields/FakeFieldA.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 UnitTestBot contributors (utbot.org)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.testing.usages.fields;
18 |
19 |
20 | public class FakeFieldA {
21 |
22 | public int a;
23 | public int b;
24 | private final FieldB fieldB = new FieldB(a);
25 |
26 | public FakeFieldA(int a, int b) {
27 | this.a = a;
28 | this.b = b;
29 | }
30 |
31 | public Boolean isPositive() {
32 | System.out.println(b);
33 | return a >= 0;
34 | }
35 |
36 | public void useA(int a) {
37 | System.out.println(b);
38 | this.a = a;
39 | }
40 |
41 | private void useCPrivate(int c) {
42 | System.out.println(a);
43 | fieldB.c = c;
44 | }
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/jacodb-core/src/testFixtures/java/org/jacodb/testing/usages/fields/FieldA.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 UnitTestBot contributors (utbot.org)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.testing.usages.fields;
18 |
19 | public class FieldA {
20 |
21 | public int a;
22 | public int b;
23 | private final FieldB fieldB = new FieldB(a);
24 |
25 | public FieldA(int a, int b) {
26 | this.a = a;
27 | this.b = b;
28 | }
29 |
30 | public Boolean isPositive() {
31 | System.out.println(b);
32 | return a >= 0;
33 | }
34 |
35 | public void useA(int a) {
36 | System.out.println(b);
37 | this.a = a;
38 | }
39 |
40 | private void useCPrivate(int c) {
41 | System.out.println(a);
42 | fieldB.c = c;
43 | }
44 |
45 | }
46 |
47 |
48 | class FieldAImpl extends FieldA {
49 |
50 | public final FieldB fieldB = new FieldB(1);
51 |
52 | public FieldAImpl() {
53 | super(1, 1);
54 | }
55 |
56 | void hello() {
57 | System.out.println(a);
58 | }
59 |
60 | void fieldB() {
61 | System.out.println(fieldB);
62 | }
63 | }
64 |
65 |
66 |
--------------------------------------------------------------------------------
/jacodb-core/src/testFixtures/java/org/jacodb/testing/usages/fields/FieldB.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 UnitTestBot contributors (utbot.org)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.testing.usages.fields;
18 |
19 | public class FieldB {
20 |
21 | int c;
22 |
23 | FieldB(int c) {
24 | this.c = c;
25 | }
26 |
27 | private void useCPrivate() {
28 | c = 10;
29 | }
30 |
31 | private void dumpCPrivate() {
32 | System.out.println(c);
33 | }
34 |
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/jacodb-core/src/testFixtures/java/org/jacodb/testing/usages/methods/MethodA.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 UnitTestBot contributors (utbot.org)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.testing.usages.methods;
18 |
19 | public class MethodA {
20 |
21 | public void hello() {
22 | System.out.println("hello");
23 | }
24 |
25 | public void hello1() {
26 | System.out.println("hello");
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/jacodb-core/src/testFixtures/java/org/jacodb/testing/usages/methods/MethodB.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 UnitTestBot contributors (utbot.org)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.testing.usages.methods;
18 |
19 | public class MethodB {
20 |
21 | private void hoho() {
22 | new MethodA().hello();
23 | new MethodC().hello();
24 | new MethodC().hello1();
25 | }
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/jacodb-core/src/testFixtures/java/org/jacodb/testing/usages/methods/MethodC.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 UnitTestBot contributors (utbot.org)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.testing.usages.methods;
18 |
19 | public class MethodC extends MethodA {
20 |
21 | @Override
22 | public void hello() {
23 | super.hello();
24 | System.out.println("from MethodC");
25 | }
26 |
27 | @Override
28 | public void hello1() {
29 | System.out.println("from MethodC");
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/jacodb-core/src/testFixtures/kotlin/org/jacodb/testing/Enums.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 UnitTestBot contributors (utbot.org)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.testing
18 |
19 | enum class Enums {
20 | SIMPLE,
21 | COMPLEX,
22 | SUPER_COMPLEX;
23 | }
24 |
--------------------------------------------------------------------------------
/jacodb-core/src/testFixtures/kotlin/org/jacodb/testing/Foo.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 UnitTestBot contributors (utbot.org)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.testing
18 |
19 | import org.junit.jupiter.api.Nested
20 |
21 | @Nested
22 | class Foo {
23 |
24 | var foo: Int = 0
25 | private var bar: String = ""
26 |
27 | fun smthPublic(foo: Int) = foo
28 |
29 | private fun smthPrivate(): Int = foo
30 | }
31 |
--------------------------------------------------------------------------------
/jacodb-core/src/testFixtures/kotlin/org/jacodb/testing/Hierarchy.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 UnitTestBot contributors (utbot.org)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.testing
18 |
19 |
20 | interface SuperDuper {
21 | fun say() {}
22 | }
23 |
24 | open class A : SuperDuper
25 |
26 | open class B : A() {
27 | fun saySmth(phrase: String) {
28 | }
29 | }
30 |
31 | open class C() : B() {
32 |
33 | constructor(smth: String) : this()
34 | constructor(smth: String, smth2: String) : this()
35 |
36 | fun saySmth() {
37 |
38 | }
39 | }
40 |
41 | open class D : B()
--------------------------------------------------------------------------------
/jacodb-core/src/testFixtures/kotlin/org/jacodb/testing/cfg/DefaultArgs.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 UnitTestBot contributors (utbot.org)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.testing.cfg
18 |
19 | class DefaultArgs {
20 | class A(
21 | val c1: Boolean,
22 | val c2: Boolean,
23 | val c3: Boolean,
24 | val c4: String
25 | ) {
26 | override fun equals(o: Any?): Boolean {
27 | if (o !is A) return false;
28 | return c1 == o.c1 &&
29 | c2 == o.c2 &&
30 | c3 == o.c3 &&
31 | c4 == o.c4
32 | }
33 | }
34 |
35 | fun reformat(
36 | str : String,
37 | normalizeCase : Boolean = true,
38 | uppercaseFirstLetter : Boolean = true,
39 | divideByCamelHumps : Boolean = true,
40 | wordSeparator : String = " "
41 | ) =
42 | A(normalizeCase, uppercaseFirstLetter, divideByCamelHumps, wordSeparator)
43 |
44 |
45 | fun box() : String {
46 | val expected = A(true, true, true, " ")
47 | if(reformat("", true, true) != expected) return "fail"
48 | return "OK"
49 | }
50 |
51 | }
--------------------------------------------------------------------------------
/jacodb-core/src/testFixtures/kotlin/org/jacodb/testing/cfg/DifferentReceivers.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 UnitTestBot contributors (utbot.org)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.testing.cfg
18 |
19 | import org.junit.jupiter.api.Assertions.assertEquals
20 |
21 | class DifferentReceivers {
22 |
23 | var log: String = ""
24 |
25 | class MyClass(val value: String)
26 |
27 | inline fun
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.testing.cfg
18 |
19 | class DoubleComparison {
20 | fun box(): String {
21 | if ((-0.0 as Comparable
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.testing.cfg
18 |
19 | class Equals {
20 |
21 | fun equals1(a: Float, b: Float) = a == b
22 |
23 | fun equals2(a: Float?, b: Float?) = a!! == b!!
24 |
25 | fun equals3(a: Float?, b: Float?) = a != null && b != null && a == b
26 |
27 | fun equals4(a: Float?, b: Float?) = if (a is Float && b is Float) a == b else null!!
28 |
29 | fun equals5(a: Any?, b: Any?): Boolean {
30 | return if (a is Float && b is Float) a == b else null!!
31 | }
32 |
33 | fun box(): String {
34 | if (-0.0F != 0.0F) return "fail 0"
35 | if (!equals1(-0.0F, 0.0F)) return "fail 1"
36 | if (!equals2(-0.0F, 0.0F)) return "fail 2"
37 | if (!equals3(-0.0F, 0.0F)) return "fail 3"
38 | if (!equals4(-0.0F, 0.0F)) return "fail 4"
39 |
40 | // Smart casts behavior in 1.2
41 | if (!equals5(-0.0F, 0.0F)) return "fail 5"
42 |
43 | return "OK"
44 | }
45 |
46 | }
--------------------------------------------------------------------------------
/jacodb-core/src/testFixtures/kotlin/org/jacodb/testing/cfg/InvokeMethodWithException.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 UnitTestBot contributors (utbot.org)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.testing.cfg
18 |
19 | class InvokeMethodWithException {
20 |
21 | class A {
22 | fun lol(a: Int): Int {
23 | return 888/a
24 | }
25 | }
26 |
27 | fun box():String {
28 | val method = A::class.java.getMethod("lol", Int::class.java)
29 | var failed = false
30 | try {
31 | method.invoke(null, 0)
32 | }
33 | catch(e: Exception) {
34 | failed = true
35 | }
36 |
37 | return if (!failed) "fail" else "OK"
38 | }
39 |
40 | }
41 |
42 | fun main() {
43 | println(InvokeMethodWithException().box())
44 | }
--------------------------------------------------------------------------------
/jacodb-core/src/testFixtures/kotlin/org/jacodb/testing/cfg/Overloading.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 UnitTestBot contributors (utbot.org)
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package org.jacodb.testing.cfg
18 |
19 | import kotlin.reflect.KClass
20 | import kotlin.reflect.KFunction0
21 |
22 | class Overloading {
23 |
24 | inline fun DEFAULT_CATALOG
36 | */
37 | val DEFAULT_CATALOG = DefaultCatalog()
38 | }
39 |
40 | /**
41 | * The schema DEFAULT_SCHEMA
.
42 | */
43 | val DEFAULT_SCHEMA get() = DefaultSchema.DEFAULT_SCHEMA
44 |
45 | override fun getSchemas(): List>();
50 | }
51 | }
52 |
53 |
54 | class WithInner1
>();
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/jacodb-core/src/testFixtures/java/org/jacodb/testing/usages/direct/DirectA.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2022 UnitTestBot contributors (utbot.org)
3 | *