├── .classpath ├── .gitignore ├── .project ├── .settings ├── org.eclipse.core.resources.prefs ├── org.eclipse.jdt.core.prefs └── org.eclipse.m2e.core.prefs ├── META-INF └── MANIFEST.MF ├── README.md ├── build.properties ├── contexts.xml ├── eclipse_project.xml ├── html ├── maintopic.html ├── subtopic.html └── toc.html ├── icons ├── releng_gears.gif ├── sample.png └── sample@2x.png ├── lib ├── JavaDataFlow-0.0.3.jar ├── commons-lang3-3.8.1.jar ├── guava-27.0-jre.jar ├── javaparser-core-3.15.4.jar ├── javaparser-core-3.22.1.jar ├── javaparser-symbol-solver-core-3.22.1.jar ├── slf4j-api-1.7.36.jar └── soot-2.5.0.jar ├── plugin.xml ├── src ├── TriangleClass.Triangle java.lang.String triangle(int,int,int).dot ├── TriangleClass │ └── Triangle.java ├── ast.dot ├── ast.png ├── cfg.dot ├── cfg.png ├── dtc_java │ └── views │ │ └── DtcView.java ├── example │ └── Example1.java ├── org │ └── eclipse │ │ └── wb │ │ └── swt │ │ ├── ResourceManager.java │ │ └── SWTResourceManager.java └── soot │ ├── AstGeneratror.java │ ├── CFGGenerate.java │ ├── DataFlowGraph.java │ └── GenerateGraph.java └── swing2swt.jar /.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | DTC_JAVA 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.pde.ManifestBuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.pde.SchemaBuilder 20 | 21 | 22 | 23 | 24 | org.eclipse.m2e.core.maven2Builder 25 | 26 | 27 | 28 | 29 | 30 | org.eclipse.m2e.core.maven2Nature 31 | org.eclipse.pde.PluginNature 32 | org.eclipse.jdt.core.javanature 33 | 34 | 35 | -------------------------------------------------------------------------------- /.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding//src/dtc_java/views/DtcView.java=UTF-8 3 | -------------------------------------------------------------------------------- /.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.builder.annotationPath.allLocations=disabled 3 | org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=disabled 4 | org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore 5 | org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull 6 | org.eclipse.jdt.core.compiler.annotation.nonnull.secondary= 7 | org.eclipse.jdt.core.compiler.annotation.nonnullbydefault=org.eclipse.jdt.annotation.NonNullByDefault 8 | org.eclipse.jdt.core.compiler.annotation.nonnullbydefault.secondary= 9 | org.eclipse.jdt.core.compiler.annotation.nullable=org.eclipse.jdt.annotation.Nullable 10 | org.eclipse.jdt.core.compiler.annotation.nullable.secondary= 11 | org.eclipse.jdt.core.compiler.annotation.nullanalysis=disabled 12 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 13 | org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate 14 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 15 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve 16 | org.eclipse.jdt.core.compiler.compliance=1.8 17 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate 18 | org.eclipse.jdt.core.compiler.debug.localVariable=generate 19 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate 20 | org.eclipse.jdt.core.compiler.problem.APILeak=warning 21 | org.eclipse.jdt.core.compiler.problem.annotatedTypeArgumentToUnannotated=info 22 | org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning 23 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 24 | org.eclipse.jdt.core.compiler.problem.autoboxing=ignore 25 | org.eclipse.jdt.core.compiler.problem.comparingIdentical=warning 26 | org.eclipse.jdt.core.compiler.problem.deadCode=warning 27 | org.eclipse.jdt.core.compiler.problem.deprecation=warning 28 | org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled 29 | org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled 30 | org.eclipse.jdt.core.compiler.problem.discouragedReference=warning 31 | org.eclipse.jdt.core.compiler.problem.emptyStatement=ignore 32 | org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled 33 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 34 | org.eclipse.jdt.core.compiler.problem.explicitlyClosedAutoCloseable=ignore 35 | org.eclipse.jdt.core.compiler.problem.fallthroughCase=ignore 36 | org.eclipse.jdt.core.compiler.problem.fatalOptionalError=disabled 37 | org.eclipse.jdt.core.compiler.problem.fieldHiding=ignore 38 | org.eclipse.jdt.core.compiler.problem.finalParameterBound=warning 39 | org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=warning 40 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 41 | org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=warning 42 | org.eclipse.jdt.core.compiler.problem.includeNullInfoFromAsserts=disabled 43 | org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=warning 44 | org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=warning 45 | org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=ignore 46 | org.eclipse.jdt.core.compiler.problem.localVariableHiding=ignore 47 | org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=warning 48 | org.eclipse.jdt.core.compiler.problem.missingDefaultCase=ignore 49 | org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=ignore 50 | org.eclipse.jdt.core.compiler.problem.missingEnumCaseDespiteDefault=disabled 51 | org.eclipse.jdt.core.compiler.problem.missingHashCodeMethod=ignore 52 | org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=ignore 53 | org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotationForInterfaceMethodImplementation=enabled 54 | org.eclipse.jdt.core.compiler.problem.missingSerialVersion=warning 55 | org.eclipse.jdt.core.compiler.problem.missingSynchronizedOnInheritedMethod=ignore 56 | org.eclipse.jdt.core.compiler.problem.noEffectAssignment=warning 57 | org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=warning 58 | org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=ignore 59 | org.eclipse.jdt.core.compiler.problem.nonnullParameterAnnotationDropped=warning 60 | org.eclipse.jdt.core.compiler.problem.nonnullTypeVariableFromLegacyInvocation=warning 61 | org.eclipse.jdt.core.compiler.problem.nullAnnotationInferenceConflict=error 62 | org.eclipse.jdt.core.compiler.problem.nullReference=warning 63 | org.eclipse.jdt.core.compiler.problem.nullSpecViolation=error 64 | org.eclipse.jdt.core.compiler.problem.nullUncheckedConversion=warning 65 | org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning 66 | org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore 67 | org.eclipse.jdt.core.compiler.problem.pessimisticNullAnalysisForFreeTypeVariables=warning 68 | org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=ignore 69 | org.eclipse.jdt.core.compiler.problem.potentialNullReference=ignore 70 | org.eclipse.jdt.core.compiler.problem.potentiallyUnclosedCloseable=ignore 71 | org.eclipse.jdt.core.compiler.problem.rawTypeReference=warning 72 | org.eclipse.jdt.core.compiler.problem.redundantNullAnnotation=warning 73 | org.eclipse.jdt.core.compiler.problem.redundantNullCheck=ignore 74 | org.eclipse.jdt.core.compiler.problem.redundantSpecificationOfTypeArguments=ignore 75 | org.eclipse.jdt.core.compiler.problem.redundantSuperinterface=ignore 76 | org.eclipse.jdt.core.compiler.problem.reportMethodCanBePotentiallyStatic=ignore 77 | org.eclipse.jdt.core.compiler.problem.reportMethodCanBeStatic=ignore 78 | org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning 79 | org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled 80 | org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=warning 81 | org.eclipse.jdt.core.compiler.problem.suppressOptionalErrors=disabled 82 | org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled 83 | org.eclipse.jdt.core.compiler.problem.suppressWarningsNotFullyAnalysed=info 84 | org.eclipse.jdt.core.compiler.problem.syntacticNullAnalysisForFields=disabled 85 | org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=ignore 86 | org.eclipse.jdt.core.compiler.problem.terminalDeprecation=warning 87 | org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning 88 | org.eclipse.jdt.core.compiler.problem.unavoidableGenericTypeProblems=enabled 89 | org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=warning 90 | org.eclipse.jdt.core.compiler.problem.unclosedCloseable=warning 91 | org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=ignore 92 | org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning 93 | org.eclipse.jdt.core.compiler.problem.unlikelyCollectionMethodArgumentType=warning 94 | org.eclipse.jdt.core.compiler.problem.unlikelyCollectionMethodArgumentTypeStrict=disabled 95 | org.eclipse.jdt.core.compiler.problem.unlikelyEqualsArgumentType=info 96 | org.eclipse.jdt.core.compiler.problem.unnecessaryElse=ignore 97 | org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=ignore 98 | org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore 99 | org.eclipse.jdt.core.compiler.problem.unstableAutoModuleName=warning 100 | org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=ignore 101 | org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionExemptExceptionAndThrowable=enabled 102 | org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled 103 | org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=disabled 104 | org.eclipse.jdt.core.compiler.problem.unusedExceptionParameter=ignore 105 | org.eclipse.jdt.core.compiler.problem.unusedImport=warning 106 | org.eclipse.jdt.core.compiler.problem.unusedLabel=warning 107 | org.eclipse.jdt.core.compiler.problem.unusedLocal=warning 108 | org.eclipse.jdt.core.compiler.problem.unusedObjectAllocation=ignore 109 | org.eclipse.jdt.core.compiler.problem.unusedParameter=ignore 110 | org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference=enabled 111 | org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=disabled 112 | org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled 113 | org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning 114 | org.eclipse.jdt.core.compiler.problem.unusedTypeParameter=ignore 115 | org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning 116 | org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning 117 | org.eclipse.jdt.core.compiler.release=disabled 118 | org.eclipse.jdt.core.compiler.source=1.8 119 | -------------------------------------------------------------------------------- /.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Bundle-ManifestVersion: 2 3 | Bundle-Name: DTC_JAVA 4 | Bundle-SymbolicName: DTC_JAVA;singleton:=true 5 | Bundle-Version: 1.0.0 6 | Bundle-Vendor: DTC 7 | Require-Bundle: javax.inject, 8 | org.eclipse.osgi, 9 | org.eclipse.jface, 10 | org.eclipse.e4.ui.model.workbench, 11 | org.eclipse.e4.ui.di, 12 | org.eclipse.e4.ui.services, 13 | org.eclipse.e4.core.di.annotations, 14 | org.eclipse.core.runtime, 15 | org.eclipse.ui, 16 | org.eclipse.ui.console, 17 | org.eclipse.jdt.ui, 18 | org.eclipse.e4.ui.workbench, 19 | org.eclipse.help 20 | Bundle-RequiredExecutionEnvironment: JavaSE-1.8 21 | Automatic-Module-Name: DTC.JAVA 22 | Import-Package: javax.inject 23 | Bundle-ActivationPolicy: lazy 24 | Bundle-ClassPath: ., 25 | swing2swt.jar, 26 | lib/soot-2.5.0.jar, 27 | lib/JavaDataFlow-0.0.3.jar, 28 | lib/javaparser-core-3.22.1.jar, 29 | lib/javaparser-symbol-solver-core-3.22.1.jar, 30 | lib/commons-lang3-3.8.1.jar, 31 | lib/guava-27.0-jre.jar, 32 | lib/javaparser-core-3.15.4.jar, 33 | lib/slf4j-api-1.7.36.jar 34 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # DTC_JAVA 2 | Static analysis tool for the impact of Java-based code fixes on other code 3 | -------------------------------------------------------------------------------- /build.properties: -------------------------------------------------------------------------------- 1 | source.. = src/ 2 | output.. = bin/ 3 | bin.includes = plugin.xml,\ 4 | META-INF/,\ 5 | .,\ 6 | icons/,\ 7 | pom.xml,\ 8 | contexts.xml,\ 9 | lib/,\ 10 | swing2swt.jar 11 | 12 | 13 | src.includes = src/,\ 14 | lib/ 15 | 16 | -------------------------------------------------------------------------------- /contexts.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | This is the context help for the sample view with a table viewer. It was generated by a PDE template. 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /eclipse_project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /html/maintopic.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Main Topic 7 | 8 | 9 | 10 |

Main Topic

11 | Please enter your text here. 12 | 13 | -------------------------------------------------------------------------------- /html/subtopic.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Sub Topic 7 | 8 | 9 | 10 |

Sub Topic

11 | Please enter your text here. 12 | 13 | -------------------------------------------------------------------------------- /html/toc.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Table of Contents 7 | 8 | 9 | 10 |

Table of Contents

11 | Please enter your text here. 12 | 13 | -------------------------------------------------------------------------------- /icons/releng_gears.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ambrosecm/DTC_JAVA/346b25a3fa7dba542214150d2f471c8a2cefcd87/icons/releng_gears.gif -------------------------------------------------------------------------------- /icons/sample.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ambrosecm/DTC_JAVA/346b25a3fa7dba542214150d2f471c8a2cefcd87/icons/sample.png -------------------------------------------------------------------------------- /icons/sample@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ambrosecm/DTC_JAVA/346b25a3fa7dba542214150d2f471c8a2cefcd87/icons/sample@2x.png -------------------------------------------------------------------------------- /lib/JavaDataFlow-0.0.3.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ambrosecm/DTC_JAVA/346b25a3fa7dba542214150d2f471c8a2cefcd87/lib/JavaDataFlow-0.0.3.jar -------------------------------------------------------------------------------- /lib/commons-lang3-3.8.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ambrosecm/DTC_JAVA/346b25a3fa7dba542214150d2f471c8a2cefcd87/lib/commons-lang3-3.8.1.jar -------------------------------------------------------------------------------- /lib/guava-27.0-jre.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ambrosecm/DTC_JAVA/346b25a3fa7dba542214150d2f471c8a2cefcd87/lib/guava-27.0-jre.jar -------------------------------------------------------------------------------- /lib/javaparser-core-3.15.4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ambrosecm/DTC_JAVA/346b25a3fa7dba542214150d2f471c8a2cefcd87/lib/javaparser-core-3.15.4.jar -------------------------------------------------------------------------------- /lib/javaparser-core-3.22.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ambrosecm/DTC_JAVA/346b25a3fa7dba542214150d2f471c8a2cefcd87/lib/javaparser-core-3.22.1.jar -------------------------------------------------------------------------------- /lib/javaparser-symbol-solver-core-3.22.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ambrosecm/DTC_JAVA/346b25a3fa7dba542214150d2f471c8a2cefcd87/lib/javaparser-symbol-solver-core-3.22.1.jar -------------------------------------------------------------------------------- /lib/slf4j-api-1.7.36.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ambrosecm/DTC_JAVA/346b25a3fa7dba542214150d2f471c8a2cefcd87/lib/slf4j-api-1.7.36.jar -------------------------------------------------------------------------------- /lib/soot-2.5.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ambrosecm/DTC_JAVA/346b25a3fa7dba542214150d2f471c8a2cefcd87/lib/soot-2.5.0.jar -------------------------------------------------------------------------------- /plugin.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 7 | 10 | 11 | 18 | 19 | 20 | 22 | 24 | 29 | 30 | 31 | 32 | 34 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /src/TriangleClass.Triangle java.lang.String triangle(int,int,int).dot: -------------------------------------------------------------------------------- 1 | digraph "java.lang.String triangle(int,int,int)" { 2 | label="java.lang.String triangle(int,int,int)"; 3 | node [shape=box]; 4 | "0" [style=filled,fillcolor=gray,label="this := @this",]; 5 | "1" [label="a := @parameter0",]; 6 | "0"->"1"; 7 | "2" [label="b := @parameter1",]; 8 | "1"->"2"; 9 | "3" [label="c := @parameter2",]; 10 | "2"->"3"; 11 | "4" [label="if a > 0 goto label0",]; 12 | "3"->"4"; 13 | "5" [label="goto label12",]; 14 | "4"->"5"; 15 | "6" [label="label0: nop",]; 16 | "4"->"6"; 17 | "49" [label="label12: nop",]; 18 | "5"->"49"; 19 | "7" [label="if b > 0 goto label1",]; 20 | "6"->"7"; 21 | "8" [label="goto label12",]; 22 | "7"->"8"; 23 | "10" [label="label1: nop",]; 24 | "7"->"10"; 25 | "8"->"49"; 26 | "9" [style=filled,fillcolor=gray,label="goto label1",]; 27 | "9"->"10"; 28 | "11" [label="if c > 0 goto label2",]; 29 | "10"->"11"; 30 | "12" [label="goto label12",]; 31 | "11"->"12"; 32 | "14" [label="label2: nop",]; 33 | "11"->"14"; 34 | "12"->"49"; 35 | "13" [style=filled,fillcolor=gray,label="goto label2",]; 36 | "13"->"14"; 37 | "15" [label="temp$0 = a",]; 38 | "14"->"15"; 39 | "16" [label="temp$1 = temp$0 + b",]; 40 | "15"->"16"; 41 | "17" [label="if temp$1 > c goto label3",]; 42 | "16"->"17"; 43 | "18" [label="goto label11",]; 44 | "17"->"18"; 45 | "19" [label="label3: nop",]; 46 | "17"->"19"; 47 | "46" [label="label11: nop",]; 48 | "18"->"46"; 49 | "20" [label="if a == b goto label6",]; 50 | "19"->"20"; 51 | "21" [label="goto label4",]; 52 | "20"->"21"; 53 | "30" [label="label6: nop",]; 54 | "20"->"30"; 55 | "22" [label="label4: nop",]; 56 | "21"->"22"; 57 | "23" [label="if b == c goto label6",]; 58 | "22"->"23"; 59 | "24" [label="goto label5",]; 60 | "23"->"24"; 61 | "23"->"30"; 62 | "26" [label="label5: nop",]; 63 | "24"->"26"; 64 | "25" [style=filled,fillcolor=gray,label="goto label5",]; 65 | "25"->"26"; 66 | "27" [label="if a == c goto label6",]; 67 | "26"->"27"; 68 | "28" [label="goto label10",]; 69 | "27"->"28"; 70 | "27"->"30"; 71 | "43" [label="label10: nop",]; 72 | "28"->"43"; 73 | "29" [style=filled,fillcolor=gray,label="goto label10",]; 74 | "29"->"43"; 75 | "31" [label="if a == b goto label7",]; 76 | "30"->"31"; 77 | "32" [label="goto label9",]; 78 | "31"->"32"; 79 | "33" [label="label7: nop",]; 80 | "31"->"33"; 81 | "40" [label="label9: nop",]; 82 | "32"->"40"; 83 | "34" [label="if b == c goto label8",]; 84 | "33"->"34"; 85 | "35" [label="goto label9",]; 86 | "34"->"35"; 87 | "37" [label="label8: nop",]; 88 | "34"->"37"; 89 | "35"->"40"; 90 | "36" [style=filled,fillcolor=gray,label="goto label8",]; 91 | "36"->"37"; 92 | "38" [label="temp$2 = \"equilateral\"",]; 93 | "37"->"38"; 94 | "39" [style=filled,fillcolor=lightgray,label="return temp$2",]; 95 | "38"->"39"; 96 | "41" [label="temp$3 = \"isosceles\"",]; 97 | "40"->"41"; 98 | "42" [style=filled,fillcolor=lightgray,label="return temp$3",]; 99 | "41"->"42"; 100 | "44" [label="temp$4 = \"scalene\"",]; 101 | "43"->"44"; 102 | "45" [style=filled,fillcolor=lightgray,label="return temp$4",]; 103 | "44"->"45"; 104 | "47" [label="temp$5 = \"Not Triangle\"",]; 105 | "46"->"47"; 106 | "48" [style=filled,fillcolor=lightgray,label="return temp$5",]; 107 | "47"->"48"; 108 | "50" [label="temp$6 = \"Not Triangle\"",]; 109 | "49"->"50"; 110 | "51" [style=filled,fillcolor=lightgray,label="return temp$6",]; 111 | "50"->"51"; 112 | } 113 | -------------------------------------------------------------------------------- /src/TriangleClass/Triangle.java: -------------------------------------------------------------------------------- 1 | package TriangleClass; 2 | 3 | public class Triangle { 4 | 5 | 6 | public String triangle(int a, int b, int c){ 7 | 8 | if(a > 0 && b > 0 && c >0){ 9 | if(a + b >c) 10 | { 11 | if(a == b || b ==c || a ==c) 12 | { 13 | if(a == b && b == c) 14 | { 15 | return "equilateral"; 16 | } 17 | return "isosceles"; 18 | } 19 | else{ 20 | return "scalene"; 21 | } 22 | } 23 | else{ 24 | return "Not Triangle"; 25 | } 26 | } 27 | else{ 28 | return "Not Triangle"; 29 | } 30 | 31 | 32 | 33 | } 34 | 35 | public int a; 36 | public int b; 37 | public int c; 38 | 39 | } -------------------------------------------------------------------------------- /src/ast.dot: -------------------------------------------------------------------------------- 1 | digraph { 2 | n0 [label="root (CompilationUnit)"]; 3 | n1 [label="packageDeclaration (PackageDeclaration)"]; 4 | n0 -> n1; 5 | n2 [label="name (Name)"]; 6 | n1 -> n2; 7 | n3 [label="identifier='example'"]; 8 | n2 -> n3; 9 | n4 [label="comment (BlockComment)"]; 10 | n0 -> n4; 11 | n5 [label="content=' 12 | * Copyright (c) 2022 by Eyefreight BV (www.eyefreight.com). All rights reserved. 13 | * 14 | * This software is provided by the copyright holder and contributors \"as is\" and any express or implied warranties, including, but 15 | * not limited to, the implied warranties of merchantability and fitness for a particular purpose are disclaimed. In no event shall 16 | * Eyefreight BV or contributors be liable for any direct, indirect, incidental, special, exemplary, or consequential damages 17 | * (including, but not limited to, procurement of substitute goods or services; * loss of use, data, or profits; or business 18 | * interruption) however caused and on any theory of liability, whether in contract, strict liability, or tort (including 19 | * negligence or otherwise) arising in any way out of the use of this software, even if advised of the possibility of such damage. 20 | '"]; 21 | n4 -> n5; 22 | n6 [label="types"]; 23 | n0 -> n6; 24 | n7 [label="type (ClassOrInterfaceDeclaration)"]; 25 | n6 -> n7; 26 | n8 [label="isInterface='false'"]; 27 | n7 -> n8; 28 | n9 [label="name (SimpleName)"]; 29 | n7 -> n9; 30 | n10 [label="identifier='Example1'"]; 31 | n9 -> n10; 32 | n11 [label="comment (JavadocComment)"]; 33 | n7 -> n11; 34 | n12 [label="content=' 35 | * TODO javadoc 36 | * 37 | * @author daan.vandenheuvel 38 | '"]; 39 | n11 -> n12; 40 | n13 [label="members"]; 41 | n7 -> n13; 42 | n14 [label="member (FieldDeclaration)"]; 43 | n13 -> n14; 44 | n15 [label="variables"]; 45 | n14 -> n15; 46 | n16 [label="variable (VariableDeclarator)"]; 47 | n15 -> n16; 48 | n17 [label="name (SimpleName)"]; 49 | n16 -> n17; 50 | n18 [label="identifier='a'"]; 51 | n17 -> n18; 52 | n19 [label="type (PrimitiveType)"]; 53 | n16 -> n19; 54 | n20 [label="type='INT'"]; 55 | n19 -> n20; 56 | n21 [label="member (MethodDeclaration)"]; 57 | n13 -> n21; 58 | n22 [label="body (BlockStmt)"]; 59 | n21 -> n22; 60 | n23 [label="statements"]; 61 | n22 -> n23; 62 | n24 [label="statement (ReturnStmt)"]; 63 | n23 -> n24; 64 | n25 [label="expression (NameExpr)"]; 65 | n24 -> n25; 66 | n26 [label="name (SimpleName)"]; 67 | n25 -> n26; 68 | n27 [label="identifier='a'"]; 69 | n26 -> n27; 70 | n28 [label="type (PrimitiveType)"]; 71 | n21 -> n28; 72 | n29 [label="type='INT'"]; 73 | n28 -> n29; 74 | n30 [label="name (SimpleName)"]; 75 | n21 -> n30; 76 | n31 [label="identifier='getA'"]; 77 | n30 -> n31; 78 | n32 [label="modifiers"]; 79 | n21 -> n32; 80 | n33 [label="modifier (Modifier)"]; 81 | n32 -> n33; 82 | n34 [label="keyword='PUBLIC'"]; 83 | n33 -> n34; 84 | n35 [label="member (MethodDeclaration)"]; 85 | n13 -> n35; 86 | n36 [label="body (BlockStmt)"]; 87 | n35 -> n36; 88 | n37 [label="statements"]; 89 | n36 -> n37; 90 | n38 [label="statement (ExpressionStmt)"]; 91 | n37 -> n38; 92 | n39 [label="expression (AssignExpr)"]; 93 | n38 -> n39; 94 | n40 [label="operator='ASSIGN'"]; 95 | n39 -> n40; 96 | n41 [label="target (FieldAccessExpr)"]; 97 | n39 -> n41; 98 | n42 [label="name (SimpleName)"]; 99 | n41 -> n42; 100 | n43 [label="identifier='a'"]; 101 | n42 -> n43; 102 | n44 [label="scope (ThisExpr)"]; 103 | n41 -> n44; 104 | n45 [label="value (NameExpr)"]; 105 | n39 -> n45; 106 | n46 [label="name (SimpleName)"]; 107 | n45 -> n46; 108 | n47 [label="identifier='inputA'"]; 109 | n46 -> n47; 110 | n48 [label="type (VoidType)"]; 111 | n35 -> n48; 112 | n49 [label="name (SimpleName)"]; 113 | n35 -> n49; 114 | n50 [label="identifier='setA'"]; 115 | n49 -> n50; 116 | n51 [label="modifiers"]; 117 | n35 -> n51; 118 | n52 [label="modifier (Modifier)"]; 119 | n51 -> n52; 120 | n53 [label="keyword='PUBLIC'"]; 121 | n52 -> n53; 122 | n54 [label="parameters"]; 123 | n35 -> n54; 124 | n55 [label="parameter (Parameter)"]; 125 | n54 -> n55; 126 | n56 [label="isVarArgs='false'"]; 127 | n55 -> n56; 128 | n57 [label="name (SimpleName)"]; 129 | n55 -> n57; 130 | n58 [label="identifier='inputA'"]; 131 | n57 -> n58; 132 | n59 [label="type (PrimitiveType)"]; 133 | n55 -> n59; 134 | n60 [label="type='INT'"]; 135 | n59 -> n60; 136 | n61 [label="modifiers"]; 137 | n7 -> n61; 138 | n62 [label="modifier (Modifier)"]; 139 | n61 -> n62; 140 | n63 [label="keyword='PUBLIC'"]; 141 | n62 -> n63; 142 | } -------------------------------------------------------------------------------- /src/ast.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ambrosecm/DTC_JAVA/346b25a3fa7dba542214150d2f471c8a2cefcd87/src/ast.png -------------------------------------------------------------------------------- /src/cfg.dot: -------------------------------------------------------------------------------- 1 | digraph "java.lang.String triangle(int,int,int)" { 2 | label="java.lang.String triangle(int,int,int)"; 3 | node [shape=box]; 4 | "0" [style=filled,fillcolor=gray,label="this := @this",]; 5 | "1" [label="a := @parameter0",]; 6 | "0"->"1"; 7 | "2" [label="b := @parameter1",]; 8 | "1"->"2"; 9 | "3" [label="c := @parameter2",]; 10 | "2"->"3"; 11 | "4" [label="if a > 0 goto label0",]; 12 | "3"->"4"; 13 | "5" [label="goto label12",]; 14 | "4"->"5"; 15 | "6" [label="label0: nop",]; 16 | "4"->"6"; 17 | "49" [label="label12: nop",]; 18 | "5"->"49"; 19 | "7" [label="if b > 0 goto label1",]; 20 | "6"->"7"; 21 | "8" [label="goto label12",]; 22 | "7"->"8"; 23 | "10" [label="label1: nop",]; 24 | "7"->"10"; 25 | "8"->"49"; 26 | "9" [style=filled,fillcolor=gray,label="goto label1",]; 27 | "9"->"10"; 28 | "11" [label="if c > 0 goto label2",]; 29 | "10"->"11"; 30 | "12" [label="goto label12",]; 31 | "11"->"12"; 32 | "14" [label="label2: nop",]; 33 | "11"->"14"; 34 | "12"->"49"; 35 | "13" [style=filled,fillcolor=gray,label="goto label2",]; 36 | "13"->"14"; 37 | "15" [label="temp$0 = a",]; 38 | "14"->"15"; 39 | "16" [label="temp$1 = temp$0 + b",]; 40 | "15"->"16"; 41 | "17" [label="if temp$1 > c goto label3",]; 42 | "16"->"17"; 43 | "18" [label="goto label11",]; 44 | "17"->"18"; 45 | "19" [label="label3: nop",]; 46 | "17"->"19"; 47 | "46" [label="label11: nop",]; 48 | "18"->"46"; 49 | "20" [label="if a == b goto label6",]; 50 | "19"->"20"; 51 | "21" [label="goto label4",]; 52 | "20"->"21"; 53 | "30" [label="label6: nop",]; 54 | "20"->"30"; 55 | "22" [label="label4: nop",]; 56 | "21"->"22"; 57 | "23" [label="if b == c goto label6",]; 58 | "22"->"23"; 59 | "24" [label="goto label5",]; 60 | "23"->"24"; 61 | "23"->"30"; 62 | "26" [label="label5: nop",]; 63 | "24"->"26"; 64 | "25" [style=filled,fillcolor=gray,label="goto label5",]; 65 | "25"->"26"; 66 | "27" [label="if a == c goto label6",]; 67 | "26"->"27"; 68 | "28" [label="goto label10",]; 69 | "27"->"28"; 70 | "27"->"30"; 71 | "43" [label="label10: nop",]; 72 | "28"->"43"; 73 | "29" [style=filled,fillcolor=gray,label="goto label10",]; 74 | "29"->"43"; 75 | "31" [label="if a == b goto label7",]; 76 | "30"->"31"; 77 | "32" [label="goto label9",]; 78 | "31"->"32"; 79 | "33" [label="label7: nop",]; 80 | "31"->"33"; 81 | "40" [label="label9: nop",]; 82 | "32"->"40"; 83 | "34" [label="if b == c goto label8",]; 84 | "33"->"34"; 85 | "35" [label="goto label9",]; 86 | "34"->"35"; 87 | "37" [label="label8: nop",]; 88 | "34"->"37"; 89 | "35"->"40"; 90 | "36" [style=filled,fillcolor=gray,label="goto label8",]; 91 | "36"->"37"; 92 | "38" [label="temp$2 = \"equilateral\"",]; 93 | "37"->"38"; 94 | "39" [style=filled,fillcolor=lightgray,label="return temp$2",]; 95 | "38"->"39"; 96 | "41" [label="temp$3 = \"isosceles\"",]; 97 | "40"->"41"; 98 | "42" [style=filled,fillcolor=lightgray,label="return temp$3",]; 99 | "41"->"42"; 100 | "44" [label="temp$4 = \"scalene\"",]; 101 | "43"->"44"; 102 | "45" [style=filled,fillcolor=lightgray,label="return temp$4",]; 103 | "44"->"45"; 104 | "47" [label="temp$5 = \"Not Triangle\"",]; 105 | "46"->"47"; 106 | "48" [style=filled,fillcolor=lightgray,label="return temp$5",]; 107 | "47"->"48"; 108 | "50" [label="temp$6 = \"Not Triangle\"",]; 109 | "49"->"50"; 110 | "51" [style=filled,fillcolor=lightgray,label="return temp$6",]; 111 | "50"->"51"; 112 | } 113 | -------------------------------------------------------------------------------- /src/cfg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ambrosecm/DTC_JAVA/346b25a3fa7dba542214150d2f471c8a2cefcd87/src/cfg.png -------------------------------------------------------------------------------- /src/dtc_java/views/DtcView.java: -------------------------------------------------------------------------------- 1 | package dtc_java.views; 2 | 3 | import org.eclipse.swt.widgets.Composite; 4 | import org.eclipse.ui.part.*; 5 | import org.eclipse.jface.viewers.*; 6 | import org.eclipse.swt.graphics.Image; 7 | import org.eclipse.swt.graphics.ImageData; 8 | import org.eclipse.swt.layout.GridData; 9 | import org.eclipse.jface.action.*; 10 | import org.eclipse.jface.dialogs.MessageDialog; 11 | import org.eclipse.ui.*; 12 | import org.eclipse.swt.widgets.Menu; 13 | import org.eclipse.swt.graphics.GC; 14 | import org.eclipse.swt.widgets.Shell; 15 | import org.eclipse.swt.SWT; 16 | 17 | import java.io.BufferedReader; 18 | import java.io.File; 19 | import java.io.FileReader; 20 | import java.io.IOException; 21 | 22 | import org.eclipse.swt.widgets.Button; 23 | import org.eclipse.swt.widgets.DirectoryDialog; 24 | import org.eclipse.swt.widgets.Display; 25 | import org.eclipse.swt.widgets.Event; 26 | import org.eclipse.swt.widgets.FileDialog; 27 | import org.eclipse.swt.widgets.Label; 28 | import org.eclipse.swt.widgets.Listener; 29 | 30 | import javax.inject.Inject; 31 | import org.eclipse.swt.widgets.Group; 32 | import org.eclipse.swt.custom.ScrolledComposite; 33 | import org.eclipse.swt.custom.SashForm; 34 | import org.eclipse.swt.custom.ViewForm; 35 | import org.eclipse.swt.widgets.List; 36 | import org.eclipse.swt.widgets.MenuItem; 37 | import org.eclipse.swt.layout.FillLayout; 38 | import org.eclipse.swt.layout.FormLayout; 39 | import org.eclipse.swt.layout.FormData; 40 | import org.eclipse.swt.layout.FormAttachment; 41 | import org.eclipse.swt.widgets.ToolBar; 42 | import org.eclipse.swt.layout.GridLayout; 43 | import org.eclipse.wb.swt.SWTResourceManager; 44 | 45 | import com.github.javaparser.ParseResult; 46 | import com.github.javaparser.ast.CompilationUnit; 47 | 48 | import soot.*; 49 | 50 | 51 | import org.eclipse.swt.widgets.Text; 52 | import org.eclipse.swt.layout.RowLayout; 53 | import org.eclipse.swt.layout.RowData; 54 | import org.eclipse.swt.custom.StackLayout; 55 | import swing2swt.layout.FlowLayout; 56 | import org.eclipse.swt.events.SelectionAdapter; 57 | import org.eclipse.swt.events.SelectionEvent; 58 | import org.eclipse.wb.swt.ResourceManager; 59 | import org.eclipse.swt.widgets.ProgressBar; 60 | import org.eclipse.swt.widgets.ExpandBar; 61 | import org.eclipse.swt.widgets.ExpandItem; 62 | import org.eclipse.swt.widgets.Combo; 63 | import org.eclipse.swt.widgets.MessageBox; 64 | import org.eclipse.swt.widgets.Canvas; 65 | 66 | public class DtcView extends ViewPart { 67 | public DtcView() { 68 | } 69 | 70 | /** 71 | * The ID of the view as specified by the extension. 72 | */ 73 | public static final String ID = "dtc_java.views.DtcView"; 74 | private ParseResult astresult=null; 75 | private String cfgresult=""; 76 | private String dfgresult=null; 77 | private String resultpath=""; 78 | 79 | @Inject 80 | IWorkbench workbench; 81 | private Text text; 82 | private Text text_1; 83 | 84 | class ViewLabelProvider extends LabelProvider implements ITableLabelProvider { 85 | @Override 86 | public String getColumnText(Object obj, int index) { 87 | return getText(obj); 88 | } 89 | 90 | @Override 91 | public Image getColumnImage(Object obj, int index) { 92 | return getImage(obj); 93 | } 94 | 95 | @Override 96 | public Image getImage(Object obj) { 97 | return workbench.getSharedImages().getImage(ISharedImages.IMG_OBJ_ELEMENT); 98 | } 99 | } 100 | 101 | @Override 102 | public void createPartControl(Composite parent) { 103 | parent.setBackground(SWTResourceManager.getColor(240, 248, 255)); 104 | parent.setLayout(null); 105 | 106 | Button btnNewButton = new Button(parent, SWT.NONE); 107 | btnNewButton.setImage(ResourceManager.getPluginImage("DTC_JAVA", "icons/releng_gears.gif")); 108 | btnNewButton.setBounds(41, 96, 96, 27); 109 | btnNewButton.addSelectionListener(new SelectionAdapter() { 110 | @Override 111 | public void widgetSelected(SelectionEvent e) { 112 | FileDialog fileDialog = new FileDialog(Display.getCurrent().getActiveShell(), SWT.OPEN); 113 | fileDialog.setFilterNames(new String[] { "java文件 (*.java)" });// 设置扩展名 114 | fileDialog.setFilterExtensions(new String[] { "*.java" });// 设置文件扩展名 115 | String selectedFile = fileDialog.open(); 116 | text.setText(selectedFile); 117 | } 118 | }); 119 | btnNewButton.setFont(SWTResourceManager.getFont("Microsoft YaHei UI", 9, SWT.NORMAL)); 120 | btnNewButton.setText("选择文件"); 121 | 122 | text = new Text(parent, SWT.BORDER); 123 | text.setBounds(143, 98, 295, 23); 124 | 125 | Button btnNewButton_1 = new Button(parent, SWT.CENTER); 126 | btnNewButton_1.setImage(ResourceManager.getPluginImage("DTC_JAVA", "icons/releng_gears.gif")); 127 | btnNewButton_1.setBounds(98, 151, 131, 27); 128 | btnNewButton_1.setText("Start Analyse"); 129 | 130 | 131 | 132 | Label lblNewLabel_2 = new Label(parent, SWT.BORDER | SWT.WRAP); 133 | lblNewLabel_2.setBackground(SWTResourceManager.getColor(255, 255, 240)); 134 | lblNewLabel_2.setFont(SWTResourceManager.getFont("Microsoft JhengHei", 7, SWT.NORMAL)); 135 | lblNewLabel_2.setBounds(41, 22, 529, 34); 136 | lblNewLabel_2.setText("针对Java程序在代码级别进行的增加语句、修改语句、删除语句等修复操作,采用静态分析技术分析出影响的变量、语句、路径、方法、类等程序成分,生成控制流图、数据流图、抽象语法树"); 137 | 138 | ProgressBar progressBar = new ProgressBar(parent, SWT.HORIZONTAL); 139 | progressBar.setBounds(252, 153, 193, 23); 140 | GridData data = new GridData(); 141 | data.horizontalSpan = 2; 142 | data.grabExcessHorizontalSpace = true; 143 | progressBar.setLayoutData(data); 144 | progressBar.setMaximum(100); 145 | progressBar.setMinimum(0); 146 | final int maximun = progressBar.getMaximum(); 147 | final int minimus = progressBar.getMinimum(); 148 | 149 | Combo combo = new Combo(parent, SWT.READ_ONLY); 150 | combo.setEnabled(false); 151 | String[] items = new String[] { "NONE", "控制流图CFG", "数据流图DFG", "抽象语法树AST" }; 152 | combo.setItems(items); 153 | combo.setToolTipText("NONE"); 154 | combo.setBounds(198, 202, 131, 28); 155 | combo.select(0); 156 | combo.setText("NONE"); 157 | 158 | text_1 = new Text(parent, SWT.BORDER | SWT.READ_ONLY | SWT.H_SCROLL | SWT.V_SCROLL | SWT.CANCEL); 159 | text_1.setBounds(361, 245, 224, 346); 160 | 161 | ScrolledComposite scrolledComposite = new ScrolledComposite(parent, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); 162 | scrolledComposite.setBounds(10, 245, 333, 346); 163 | scrolledComposite.setExpandHorizontal(true); 164 | scrolledComposite.setExpandVertical(true); 165 | 166 | Label label = new Label(scrolledComposite, SWT.NONE); 167 | label.setImage( null ); 168 | label.setSize( label.computeSize( SWT.DEFAULT, SWT.DEFAULT )); 169 | scrolledComposite.setContent(label); 170 | scrolledComposite.setMinSize(label.computeSize(SWT.DEFAULT, SWT.DEFAULT)); 171 | 172 | combo.addSelectionListener(new SelectionAdapter() { 173 | @Override 174 | public void widgetSelected(SelectionEvent e) { 175 | String text = combo.getText(); 176 | Image cfgimage=new Image(Display.getDefault(),resultpath+"/cfg.png"); 177 | Image astimage=new Image(Display.getDefault(),resultpath+"/ast.png"); 178 | if (text.equals(items[0])) { 179 | text_1.setText(""); 180 | label.setImage( null ); 181 | 182 | } else if (text.equals(items[1])) { 183 | text_1.setText(cfgresult); 184 | label.setImage( cfgimage ); 185 | label.setSize( label.computeSize( SWT.DEFAULT, SWT.DEFAULT )); 186 | scrolledComposite.setContent(label); 187 | scrolledComposite.setMinSize(label.computeSize(SWT.DEFAULT, SWT.DEFAULT)); 188 | } else if (text.equals(items[2])) { 189 | text_1.setText(dfgresult); 190 | label.setImage( null ); 191 | } else if (text.equals(items[3])) { 192 | text_1.setText(astresult.getResult().get().toString()); 193 | label.setImage( astimage ); 194 | label.setSize( label.computeSize( SWT.DEFAULT, SWT.DEFAULT )); 195 | scrolledComposite.setContent(label); 196 | scrolledComposite.setMinSize(label.computeSize(SWT.DEFAULT, SWT.DEFAULT)); 197 | } 198 | } 199 | }); 200 | 201 | // 开始分析 202 | btnNewButton_1.addSelectionListener(new SelectionAdapter() { 203 | @Override 204 | public void widgetSelected(SelectionEvent e) { 205 | if (text.getText() == null || text.getText().equals("")) { 206 | MessageBox mb = new MessageBox(Display.getCurrent().getActiveShell(), SWT.ICON_SEARCH); 207 | mb.setText("Message"); 208 | mb.setMessage("请先选择要分析的文件"); 209 | mb.open(); 210 | return; 211 | } 212 | btnNewButton_1.setEnabled(false); 213 | progressBar.setSelection(0); 214 | String filepath=text.getText().replaceAll("\\\\","/"); 215 | 216 | AstGeneratror ast=new AstGeneratror(); 217 | try { 218 | astresult=ast.generate(filepath); 219 | } catch (Exception ee) { 220 | // TODO Auto-generated catch block 221 | ee.printStackTrace(); 222 | } 223 | 224 | CFGGenerate cfg=new CFGGenerate(); 225 | String split[]=filepath.split("/"); 226 | String arg1=""; 227 | for(int i=0;idispose() method to 47 | * release the operating system resources managed by cached objects when those 48 | * objects and OS resources are no longer needed. 49 | * 50 | * This class may be freely distributed as part of any application or plugin. 51 | *

52 | * 53 | * @author scheglov_ke 54 | * @author Dan Rubel 55 | * @author Wim Jongman 56 | */ 57 | public class ResourceManager extends SWTResourceManager { 58 | 59 | /** 60 | * The map where we store our images. 61 | */ 62 | private static Map m_descriptorImageMap = new HashMap(); 63 | 64 | /** 65 | * Returns an {@link ImageDescriptor} stored in the file at the specified path 66 | * relative to the specified class. 67 | * 68 | * @param clazz the {@link Class} relative to which to find the image 69 | * descriptor. 70 | * @param path the path to the image file. 71 | * @return the {@link ImageDescriptor} stored in the file at the specified path. 72 | */ 73 | public static ImageDescriptor getImageDescriptor(Class clazz, String path) { 74 | return ImageDescriptor.createFromFile(clazz, path); 75 | } 76 | 77 | /** 78 | * Returns an {@link ImageDescriptor} stored in the file at the specified path. 79 | * 80 | * @param path the path to the image file. 81 | * @return the {@link ImageDescriptor} stored in the file at the specified path. 82 | */ 83 | public static ImageDescriptor getImageDescriptor(String path) { 84 | try { 85 | return ImageDescriptor.createFromURL(new File(path).toURI().toURL()); 86 | } catch (MalformedURLException e) { 87 | return null; 88 | } 89 | } 90 | 91 | /** 92 | * Returns an {@link Image} based on the specified {@link ImageDescriptor}. 93 | * 94 | * @param descriptor the {@link ImageDescriptor} for the {@link Image}. 95 | * @return the {@link Image} based on the specified {@link ImageDescriptor}. 96 | */ 97 | public static Image getImage(ImageDescriptor descriptor) { 98 | if (descriptor == null) { 99 | return null; 100 | } 101 | Image image = m_descriptorImageMap.get(descriptor); 102 | if (image == null) { 103 | image = descriptor.createImage(); 104 | m_descriptorImageMap.put(descriptor, image); 105 | } 106 | return image; 107 | } 108 | 109 | /** 110 | * Maps images to decorated images. 111 | */ 112 | @SuppressWarnings("unchecked") 113 | private static Map>[] m_decoratedImageMap = new Map[LAST_CORNER_KEY]; 114 | 115 | /** 116 | * Returns an {@link Image} composed of a base image decorated by another image. 117 | * 118 | * @param baseImage the base {@link Image} that should be decorated. 119 | * @param decorator the {@link Image} to decorate the base image. 120 | * @return {@link Image} The resulting decorated image. 121 | */ 122 | public static Image decorateImage(Image baseImage, Image decorator) { 123 | return decorateImage(baseImage, decorator, BOTTOM_RIGHT); 124 | } 125 | 126 | /** 127 | * Returns an {@link Image} composed of a base image decorated by another image. 128 | * 129 | * @param baseImage 130 | * the base {@link Image} that should be decorated. 131 | * @param decorator 132 | * the {@link Image} to decorate the base image. 133 | * @param corner 134 | * the corner to place decorator image. 135 | * @return the resulting decorated {@link Image}. 136 | */ 137 | public static Image decorateImage(final Image baseImage, final Image decorator, final int corner) { 138 | if (corner <= 0 || corner >= LAST_CORNER_KEY) { 139 | throw new IllegalArgumentException("Wrong decorate corner"); 140 | } 141 | Map> cornerDecoratedImageMap = m_decoratedImageMap[corner]; 142 | if (cornerDecoratedImageMap == null) { 143 | cornerDecoratedImageMap = new HashMap>(); 144 | m_decoratedImageMap[corner] = cornerDecoratedImageMap; 145 | } 146 | Map decoratedMap = cornerDecoratedImageMap.get(baseImage); 147 | if (decoratedMap == null) { 148 | decoratedMap = new HashMap(); 149 | cornerDecoratedImageMap.put(baseImage, decoratedMap); 150 | } 151 | // 152 | Image result = decoratedMap.get(decorator); 153 | if (result == null) { 154 | final Rectangle bib = baseImage.getBounds(); 155 | final Rectangle dib = decorator.getBounds(); 156 | final Point baseImageSize = new Point(bib.width, bib.height); 157 | CompositeImageDescriptor compositImageDesc = new CompositeImageDescriptor() { 158 | @Override 159 | protected void drawCompositeImage(int width, int height) { 160 | drawImage(createCachedImageDataProvider(baseImage), 0, 0); 161 | if (corner == TOP_LEFT) { 162 | drawImage(getUnzoomedImageDataProvider(decorator.getImageData()) , 0, 0); 163 | } else if (corner == TOP_RIGHT) { 164 | drawImage(getUnzoomedImageDataProvider(decorator.getImageData()), bib.width - dib.width, 0); 165 | } else if (corner == BOTTOM_LEFT) { 166 | drawImage(getUnzoomedImageDataProvider(decorator.getImageData()), 0, bib.height - dib.height); 167 | } else if (corner == BOTTOM_RIGHT) { 168 | drawImage(getUnzoomedImageDataProvider(decorator.getImageData()), bib.width - dib.width, bib.height - dib.height); 169 | } 170 | } 171 | @Override 172 | protected Point getSize() { 173 | return baseImageSize; 174 | } 175 | }; 176 | // 177 | result = compositImageDesc.createImage(); 178 | decoratedMap.put(decorator, result); 179 | } 180 | return result; 181 | } 182 | 183 | private static ImageDataProvider getUnzoomedImageDataProvider(ImageData imageData) { 184 | return zoom -> zoom == 100 ? imageData : null; 185 | } 186 | 187 | 188 | /** 189 | * Dispose all of the cached images. 190 | */ 191 | public static void disposeImages() { 192 | SWTResourceManager.disposeImages(); 193 | // dispose ImageDescriptor images 194 | { 195 | for (Iterator I = m_descriptorImageMap.values().iterator(); I.hasNext();) { 196 | I.next().dispose(); 197 | } 198 | m_descriptorImageMap.clear(); 199 | } 200 | // dispose decorated images 201 | for (int i = 0; i < m_decoratedImageMap.length; i++) { 202 | Map> cornerDecoratedImageMap = m_decoratedImageMap[i]; 203 | if (cornerDecoratedImageMap != null) { 204 | for (Map decoratedMap : cornerDecoratedImageMap.values()) { 205 | for (Image image : decoratedMap.values()) { 206 | image.dispose(); 207 | } 208 | decoratedMap.clear(); 209 | } 210 | cornerDecoratedImageMap.clear(); 211 | } 212 | } 213 | // dispose plugin images 214 | { 215 | for (Iterator I = m_URLImageMap.values().iterator(); I.hasNext();) { 216 | I.next().dispose(); 217 | } 218 | m_URLImageMap.clear(); 219 | } 220 | } 221 | 222 | //////////////////////////////////////////////////////////////////////////// 223 | // 224 | // Plugin images support 225 | // 226 | //////////////////////////////////////////////////////////////////////////// 227 | /** 228 | * Maps URL to images. 229 | */ 230 | private static Map m_URLImageMap = new HashMap(); 231 | 232 | /** 233 | * Provider for plugin resources, used by WindowBuilder at design time. 234 | */ 235 | public interface PluginResourceProvider { 236 | URL getEntry(String symbolicName, String path); 237 | } 238 | 239 | /** 240 | * Instance of {@link PluginResourceProvider}, used by WindowBuilder at design 241 | * time. 242 | */ 243 | private static PluginResourceProvider m_designTimePluginResourceProvider = null; 244 | 245 | /** 246 | * Returns an {@link Image} based on a plugin and file path. 247 | * 248 | * @param plugin the plugin {@link Object} containing the image 249 | * @param name the path to the image within the plugin 250 | * @return the {@link Image} stored in the file at the specified path 251 | * 252 | * @deprecated Use {@link #getPluginImage(String, String)} instead. 253 | */ 254 | @Deprecated 255 | public static Image getPluginImage(Object plugin, String name) { 256 | try { 257 | URL url = getPluginImageURL(plugin, name); 258 | if (url != null) { 259 | return getPluginImageFromUrl(url); 260 | } 261 | } catch (Throwable e) { 262 | // Ignore any exceptions 263 | } 264 | return null; 265 | } 266 | 267 | /** 268 | * Returns an {@link Image} based on a {@link Bundle} and resource entry path. 269 | * 270 | * @param symbolicName the symbolic name of the {@link Bundle}. 271 | * @param path the path of the resource entry. 272 | * @return the {@link Image} stored in the file at the specified path. 273 | */ 274 | public static Image getPluginImage(String symbolicName, String path) { 275 | try { 276 | URL url = getPluginImageURL(symbolicName, path); 277 | if (url != null) { 278 | return getPluginImageFromUrl(url); 279 | } 280 | } catch (Throwable e) { 281 | // Ignore any exceptions 282 | } 283 | return null; 284 | } 285 | 286 | /** 287 | * Returns an {@link Image} based on given {@link URL}. 288 | */ 289 | private static Image getPluginImageFromUrl(URL url) { 290 | try { 291 | try { 292 | String key = url.toExternalForm(); 293 | Image image = m_URLImageMap.get(key); 294 | if (image == null) { 295 | InputStream stream = url.openStream(); 296 | try { 297 | image = getImage(stream); 298 | m_URLImageMap.put(key, image); 299 | } finally { 300 | stream.close(); 301 | } 302 | } 303 | return image; 304 | } catch (Throwable e) { 305 | // Ignore any exceptions 306 | } 307 | } catch (Throwable e) { 308 | // Ignore any exceptions 309 | } 310 | return null; 311 | } 312 | 313 | /** 314 | * Returns an {@link ImageDescriptor} based on a plugin and file path. 315 | * 316 | * @param plugin the plugin {@link Object} containing the image. 317 | * @param name the path to th eimage within the plugin. 318 | * @return the {@link ImageDescriptor} stored in the file at the specified path. 319 | * 320 | * @deprecated Use {@link #getPluginImageDescriptor(String, String)} instead. 321 | */ 322 | @Deprecated 323 | public static ImageDescriptor getPluginImageDescriptor(Object plugin, String name) { 324 | try { 325 | try { 326 | URL url = getPluginImageURL(plugin, name); 327 | return ImageDescriptor.createFromURL(url); 328 | } catch (Throwable e) { 329 | // Ignore any exceptions 330 | } 331 | } catch (Throwable e) { 332 | // Ignore any exceptions 333 | } 334 | return null; 335 | } 336 | 337 | /** 338 | * Returns an {@link ImageDescriptor} based on a {@link Bundle} and resource 339 | * entry path. 340 | * 341 | * @param symbolicName the symbolic name of the {@link Bundle}. 342 | * @param path the path of the resource entry. 343 | * @return the {@link ImageDescriptor} based on a {@link Bundle} and resource 344 | * entry path. 345 | */ 346 | public static ImageDescriptor getPluginImageDescriptor(String symbolicName, String path) { 347 | try { 348 | URL url = getPluginImageURL(symbolicName, path); 349 | if (url != null) { 350 | return ImageDescriptor.createFromURL(url); 351 | } 352 | } catch (Throwable e) { 353 | // Ignore any exceptions 354 | } 355 | return null; 356 | } 357 | 358 | /** 359 | * Returns an {@link URL} based on a {@link Bundle} and resource entry path. 360 | */ 361 | private static URL getPluginImageURL(String symbolicName, String path) { 362 | // try runtime plugins 363 | { 364 | Bundle bundle = Platform.getBundle(symbolicName); 365 | if (bundle != null) { 366 | return bundle.getEntry(path); 367 | } 368 | } 369 | // try design time provider 370 | if (m_designTimePluginResourceProvider != null) { 371 | return m_designTimePluginResourceProvider.getEntry(symbolicName, path); 372 | } 373 | // no such resource 374 | return null; 375 | } 376 | 377 | /** 378 | * Returns an {@link URL} based on a plugin and file path. 379 | * 380 | * @param plugin the plugin {@link Object} containing the file path. 381 | * @param name the file path. 382 | * @return the {@link URL} representing the file at the specified path. 383 | * @throws Exception 384 | */ 385 | private static URL getPluginImageURL(Object plugin, String name) throws Exception { 386 | // try to work with 'plugin' as with OSGI BundleContext 387 | try { 388 | Class BundleClass = Class.forName("org.osgi.framework.Bundle"); //$NON-NLS-1$ 389 | Class BundleContextClass = Class.forName("org.osgi.framework.BundleContext"); //$NON-NLS-1$ 390 | if (BundleContextClass.isAssignableFrom(plugin.getClass())) { 391 | Method getBundleMethod = BundleContextClass.getMethod("getBundle", new Class[0]); //$NON-NLS-1$ 392 | Object bundle = getBundleMethod.invoke(plugin, new Object[0]); 393 | // 394 | Class PathClass = Class.forName("org.eclipse.core.runtime.Path"); //$NON-NLS-1$ 395 | Constructor pathConstructor = PathClass.getConstructor(new Class[] { String.class }); 396 | Object path = pathConstructor.newInstance(new Object[] { name }); 397 | // 398 | Class IPathClass = Class.forName("org.eclipse.core.runtime.IPath"); //$NON-NLS-1$ 399 | Class PlatformClass = Class.forName("org.eclipse.core.runtime.Platform"); //$NON-NLS-1$ 400 | Method findMethod = PlatformClass.getMethod("find", new Class[] { BundleClass, IPathClass }); //$NON-NLS-1$ 401 | return (URL) findMethod.invoke(null, new Object[] { bundle, path }); 402 | } 403 | } catch (Throwable e) { 404 | // Ignore any exceptions 405 | } 406 | // else work with 'plugin' as with usual Eclipse plugin 407 | { 408 | Class PluginClass = Class.forName("org.eclipse.core.runtime.Plugin"); //$NON-NLS-1$ 409 | if (PluginClass.isAssignableFrom(plugin.getClass())) { 410 | // 411 | Class PathClass = Class.forName("org.eclipse.core.runtime.Path"); //$NON-NLS-1$ 412 | Constructor pathConstructor = PathClass.getConstructor(new Class[] { String.class }); 413 | Object path = pathConstructor.newInstance(new Object[] { name }); 414 | // 415 | Class IPathClass = Class.forName("org.eclipse.core.runtime.IPath"); //$NON-NLS-1$ 416 | Method findMethod = PluginClass.getMethod("find", new Class[] { IPathClass }); //$NON-NLS-1$ 417 | return (URL) findMethod.invoke(plugin, new Object[] { path }); 418 | } 419 | } 420 | return null; 421 | } 422 | 423 | //////////////////////////////////////////////////////////////////////////// 424 | // 425 | // General 426 | // 427 | //////////////////////////////////////////////////////////////////////////// 428 | /** 429 | * Dispose of cached objects and their underlying OS resources. This should only 430 | * be called when the cached objects are no longer needed (e.g. on application 431 | * shutdown). 432 | */ 433 | public static void dispose() { 434 | disposeColors(); 435 | disposeFonts(); 436 | disposeImages(); 437 | } 438 | } -------------------------------------------------------------------------------- /src/org/eclipse/wb/swt/SWTResourceManager.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright (c) 2011 Google, Inc. 3 | * All rights reserved. This program and the accompanying materials 4 | * are made available under the terms of the Eclipse Public License v1.0 5 | * which accompanies this distribution, and is available at 6 | * http://www.eclipse.org/legal/epl-v10.html 7 | * 8 | * Contributors: 9 | * Google, Inc. - initial API and implementation 10 | *******************************************************************************/ 11 | package org.eclipse.wb.swt; 12 | 13 | import java.io.FileInputStream; 14 | import java.io.IOException; 15 | import java.io.InputStream; 16 | import java.util.HashMap; 17 | import java.util.Map; 18 | 19 | import org.eclipse.swt.SWT; 20 | import org.eclipse.swt.graphics.Color; 21 | import org.eclipse.swt.graphics.Cursor; 22 | import org.eclipse.swt.graphics.Font; 23 | import org.eclipse.swt.graphics.FontData; 24 | import org.eclipse.swt.graphics.GC; 25 | import org.eclipse.swt.graphics.Image; 26 | import org.eclipse.swt.graphics.ImageData; 27 | import org.eclipse.swt.graphics.RGB; 28 | import org.eclipse.swt.graphics.Rectangle; 29 | import org.eclipse.swt.widgets.Display; 30 | 31 | /** 32 | * Utility class for managing OS resources associated with SWT controls such as colors, fonts, images, etc. 33 | *

34 | * !!! IMPORTANT !!! Application code must explicitly invoke the dispose() method to release the 35 | * operating system resources managed by cached objects when those objects and OS resources are no longer 36 | * needed (e.g. on application shutdown) 37 | *

38 | * This class may be freely distributed as part of any application or plugin. 39 | *

40 | * @author scheglov_ke 41 | * @author Dan Rubel 42 | */ 43 | public class SWTResourceManager { 44 | //////////////////////////////////////////////////////////////////////////// 45 | // 46 | // Color 47 | // 48 | //////////////////////////////////////////////////////////////////////////// 49 | private static Map m_colorMap = new HashMap(); 50 | /** 51 | * Returns the system {@link Color} matching the specific ID. 52 | * 53 | * @param systemColorID 54 | * the ID value for the color 55 | * @return the system {@link Color} matching the specific ID 56 | */ 57 | public static Color getColor(int systemColorID) { 58 | Display display = Display.getCurrent(); 59 | return display.getSystemColor(systemColorID); 60 | } 61 | /** 62 | * Returns a {@link Color} given its red, green and blue component values. 63 | * 64 | * @param r 65 | * the red component of the color 66 | * @param g 67 | * the green component of the color 68 | * @param b 69 | * the blue component of the color 70 | * @return the {@link Color} matching the given red, green and blue component values 71 | */ 72 | public static Color getColor(int r, int g, int b) { 73 | return getColor(new RGB(r, g, b)); 74 | } 75 | /** 76 | * Returns a {@link Color} given its RGB value. 77 | * 78 | * @param rgb 79 | * the {@link RGB} value of the color 80 | * @return the {@link Color} matching the RGB value 81 | */ 82 | public static Color getColor(RGB rgb) { 83 | Color color = m_colorMap.get(rgb); 84 | if (color == null) { 85 | Display display = Display.getCurrent(); 86 | color = new Color(display, rgb); 87 | m_colorMap.put(rgb, color); 88 | } 89 | return color; 90 | } 91 | /** 92 | * Dispose of all the cached {@link Color}'s. 93 | */ 94 | public static void disposeColors() { 95 | for (Color color : m_colorMap.values()) { 96 | color.dispose(); 97 | } 98 | m_colorMap.clear(); 99 | } 100 | //////////////////////////////////////////////////////////////////////////// 101 | // 102 | // Image 103 | // 104 | //////////////////////////////////////////////////////////////////////////// 105 | /** 106 | * Maps image paths to images. 107 | */ 108 | private static Map m_imageMap = new HashMap(); 109 | /** 110 | * Returns an {@link Image} encoded by the specified {@link InputStream}. 111 | * 112 | * @param stream 113 | * the {@link InputStream} encoding the image data 114 | * @return the {@link Image} encoded by the specified input stream 115 | */ 116 | protected static Image getImage(InputStream stream) throws IOException { 117 | try { 118 | Display display = Display.getCurrent(); 119 | ImageData data = new ImageData(stream); 120 | if (data.transparentPixel > 0) { 121 | return new Image(display, data, data.getTransparencyMask()); 122 | } 123 | return new Image(display, data); 124 | } finally { 125 | stream.close(); 126 | } 127 | } 128 | /** 129 | * Returns an {@link Image} stored in the file at the specified path. 130 | * 131 | * @param path 132 | * the path to the image file 133 | * @return the {@link Image} stored in the file at the specified path 134 | */ 135 | public static Image getImage(String path) { 136 | Image image = m_imageMap.get(path); 137 | if (image == null) { 138 | try { 139 | image = getImage(new FileInputStream(path)); 140 | m_imageMap.put(path, image); 141 | } catch (Exception e) { 142 | image = getMissingImage(); 143 | m_imageMap.put(path, image); 144 | } 145 | } 146 | return image; 147 | } 148 | /** 149 | * Returns an {@link Image} stored in the file at the specified path relative to the specified class. 150 | * 151 | * @param clazz 152 | * the {@link Class} relative to which to find the image 153 | * @param path 154 | * the path to the image file, if starts with '/' 155 | * @return the {@link Image} stored in the file at the specified path 156 | */ 157 | public static Image getImage(Class clazz, String path) { 158 | String key = clazz.getName() + '|' + path; 159 | Image image = m_imageMap.get(key); 160 | if (image == null) { 161 | try { 162 | image = getImage(clazz.getResourceAsStream(path)); 163 | m_imageMap.put(key, image); 164 | } catch (Exception e) { 165 | image = getMissingImage(); 166 | m_imageMap.put(key, image); 167 | } 168 | } 169 | return image; 170 | } 171 | private static final int MISSING_IMAGE_SIZE = 10; 172 | /** 173 | * @return the small {@link Image} that can be used as placeholder for missing image. 174 | */ 175 | private static Image getMissingImage() { 176 | Image image = new Image(Display.getCurrent(), MISSING_IMAGE_SIZE, MISSING_IMAGE_SIZE); 177 | // 178 | GC gc = new GC(image); 179 | gc.setBackground(getColor(SWT.COLOR_RED)); 180 | gc.fillRectangle(0, 0, MISSING_IMAGE_SIZE, MISSING_IMAGE_SIZE); 181 | gc.dispose(); 182 | // 183 | return image; 184 | } 185 | /** 186 | * Style constant for placing decorator image in top left corner of base image. 187 | */ 188 | public static final int TOP_LEFT = 1; 189 | /** 190 | * Style constant for placing decorator image in top right corner of base image. 191 | */ 192 | public static final int TOP_RIGHT = 2; 193 | /** 194 | * Style constant for placing decorator image in bottom left corner of base image. 195 | */ 196 | public static final int BOTTOM_LEFT = 3; 197 | /** 198 | * Style constant for placing decorator image in bottom right corner of base image. 199 | */ 200 | public static final int BOTTOM_RIGHT = 4; 201 | /** 202 | * Internal value. 203 | */ 204 | protected static final int LAST_CORNER_KEY = 5; 205 | /** 206 | * Maps images to decorated images. 207 | */ 208 | @SuppressWarnings("unchecked") 209 | private static Map>[] m_decoratedImageMap = new Map[LAST_CORNER_KEY]; 210 | /** 211 | * Returns an {@link Image} composed of a base image decorated by another image. 212 | * 213 | * @param baseImage 214 | * the base {@link Image} that should be decorated 215 | * @param decorator 216 | * the {@link Image} to decorate the base image 217 | * @return {@link Image} The resulting decorated image 218 | */ 219 | public static Image decorateImage(Image baseImage, Image decorator) { 220 | return decorateImage(baseImage, decorator, BOTTOM_RIGHT); 221 | } 222 | /** 223 | * Returns an {@link Image} composed of a base image decorated by another image. 224 | * 225 | * @param baseImage 226 | * the base {@link Image} that should be decorated 227 | * @param decorator 228 | * the {@link Image} to decorate the base image 229 | * @param corner 230 | * the corner to place decorator image 231 | * @return the resulting decorated {@link Image} 232 | */ 233 | public static Image decorateImage(final Image baseImage, final Image decorator, final int corner) { 234 | if (corner <= 0 || corner >= LAST_CORNER_KEY) { 235 | throw new IllegalArgumentException("Wrong decorate corner"); 236 | } 237 | Map> cornerDecoratedImageMap = m_decoratedImageMap[corner]; 238 | if (cornerDecoratedImageMap == null) { 239 | cornerDecoratedImageMap = new HashMap>(); 240 | m_decoratedImageMap[corner] = cornerDecoratedImageMap; 241 | } 242 | Map decoratedMap = cornerDecoratedImageMap.get(baseImage); 243 | if (decoratedMap == null) { 244 | decoratedMap = new HashMap(); 245 | cornerDecoratedImageMap.put(baseImage, decoratedMap); 246 | } 247 | // 248 | Image result = decoratedMap.get(decorator); 249 | if (result == null) { 250 | Rectangle bib = baseImage.getBounds(); 251 | Rectangle dib = decorator.getBounds(); 252 | // 253 | result = new Image(Display.getCurrent(), bib.width, bib.height); 254 | // 255 | GC gc = new GC(result); 256 | gc.drawImage(baseImage, 0, 0); 257 | if (corner == TOP_LEFT) { 258 | gc.drawImage(decorator, 0, 0); 259 | } else if (corner == TOP_RIGHT) { 260 | gc.drawImage(decorator, bib.width - dib.width, 0); 261 | } else if (corner == BOTTOM_LEFT) { 262 | gc.drawImage(decorator, 0, bib.height - dib.height); 263 | } else if (corner == BOTTOM_RIGHT) { 264 | gc.drawImage(decorator, bib.width - dib.width, bib.height - dib.height); 265 | } 266 | gc.dispose(); 267 | // 268 | decoratedMap.put(decorator, result); 269 | } 270 | return result; 271 | } 272 | /** 273 | * Dispose all of the cached {@link Image}'s. 274 | */ 275 | public static void disposeImages() { 276 | // dispose loaded images 277 | { 278 | for (Image image : m_imageMap.values()) { 279 | image.dispose(); 280 | } 281 | m_imageMap.clear(); 282 | } 283 | // dispose decorated images 284 | for (int i = 0; i < m_decoratedImageMap.length; i++) { 285 | Map> cornerDecoratedImageMap = m_decoratedImageMap[i]; 286 | if (cornerDecoratedImageMap != null) { 287 | for (Map decoratedMap : cornerDecoratedImageMap.values()) { 288 | for (Image image : decoratedMap.values()) { 289 | image.dispose(); 290 | } 291 | decoratedMap.clear(); 292 | } 293 | cornerDecoratedImageMap.clear(); 294 | } 295 | } 296 | } 297 | //////////////////////////////////////////////////////////////////////////// 298 | // 299 | // Font 300 | // 301 | //////////////////////////////////////////////////////////////////////////// 302 | /** 303 | * Maps font names to fonts. 304 | */ 305 | private static Map m_fontMap = new HashMap(); 306 | /** 307 | * Maps fonts to their bold versions. 308 | */ 309 | private static Map m_fontToBoldFontMap = new HashMap(); 310 | /** 311 | * Returns a {@link Font} based on its name, height and style. 312 | * 313 | * @param name 314 | * the name of the font 315 | * @param height 316 | * the height of the font 317 | * @param style 318 | * the style of the font 319 | * @return {@link Font} The font matching the name, height and style 320 | */ 321 | public static Font getFont(String name, int height, int style) { 322 | return getFont(name, height, style, false, false); 323 | } 324 | /** 325 | * Returns a {@link Font} based on its name, height and style. Windows-specific strikeout and underline 326 | * flags are also supported. 327 | * 328 | * @param name 329 | * the name of the font 330 | * @param size 331 | * the size of the font 332 | * @param style 333 | * the style of the font 334 | * @param strikeout 335 | * the strikeout flag (warning: Windows only) 336 | * @param underline 337 | * the underline flag (warning: Windows only) 338 | * @return {@link Font} The font matching the name, height, style, strikeout and underline 339 | */ 340 | public static Font getFont(String name, int size, int style, boolean strikeout, boolean underline) { 341 | String fontName = name + '|' + size + '|' + style + '|' + strikeout + '|' + underline; 342 | Font font = m_fontMap.get(fontName); 343 | if (font == null) { 344 | FontData fontData = new FontData(name, size, style); 345 | if (strikeout || underline) { 346 | try { 347 | Class logFontClass = Class.forName("org.eclipse.swt.internal.win32.LOGFONT"); //$NON-NLS-1$ 348 | Object logFont = FontData.class.getField("data").get(fontData); //$NON-NLS-1$ 349 | if (logFont != null && logFontClass != null) { 350 | if (strikeout) { 351 | logFontClass.getField("lfStrikeOut").set(logFont, Byte.valueOf((byte) 1)); //$NON-NLS-1$ 352 | } 353 | if (underline) { 354 | logFontClass.getField("lfUnderline").set(logFont, Byte.valueOf((byte) 1)); //$NON-NLS-1$ 355 | } 356 | } 357 | } catch (Throwable e) { 358 | System.err.println("Unable to set underline or strikeout" + " (probably on a non-Windows platform). " + e); //$NON-NLS-1$ //$NON-NLS-2$ 359 | } 360 | } 361 | font = new Font(Display.getCurrent(), fontData); 362 | m_fontMap.put(fontName, font); 363 | } 364 | return font; 365 | } 366 | /** 367 | * Returns a bold version of the given {@link Font}. 368 | * 369 | * @param baseFont 370 | * the {@link Font} for which a bold version is desired 371 | * @return the bold version of the given {@link Font} 372 | */ 373 | public static Font getBoldFont(Font baseFont) { 374 | Font font = m_fontToBoldFontMap.get(baseFont); 375 | if (font == null) { 376 | FontData fontDatas[] = baseFont.getFontData(); 377 | FontData data = fontDatas[0]; 378 | font = new Font(Display.getCurrent(), data.getName(), data.getHeight(), SWT.BOLD); 379 | m_fontToBoldFontMap.put(baseFont, font); 380 | } 381 | return font; 382 | } 383 | /** 384 | * Dispose all of the cached {@link Font}'s. 385 | */ 386 | public static void disposeFonts() { 387 | // clear fonts 388 | for (Font font : m_fontMap.values()) { 389 | font.dispose(); 390 | } 391 | m_fontMap.clear(); 392 | // clear bold fonts 393 | for (Font font : m_fontToBoldFontMap.values()) { 394 | font.dispose(); 395 | } 396 | m_fontToBoldFontMap.clear(); 397 | } 398 | //////////////////////////////////////////////////////////////////////////// 399 | // 400 | // Cursor 401 | // 402 | //////////////////////////////////////////////////////////////////////////// 403 | /** 404 | * Maps IDs to cursors. 405 | */ 406 | private static Map m_idToCursorMap = new HashMap(); 407 | /** 408 | * Returns the system cursor matching the specific ID. 409 | * 410 | * @param id 411 | * int The ID value for the cursor 412 | * @return Cursor The system cursor matching the specific ID 413 | */ 414 | public static Cursor getCursor(int id) { 415 | Integer key = Integer.valueOf(id); 416 | Cursor cursor = m_idToCursorMap.get(key); 417 | if (cursor == null) { 418 | cursor = new Cursor(Display.getDefault(), id); 419 | m_idToCursorMap.put(key, cursor); 420 | } 421 | return cursor; 422 | } 423 | /** 424 | * Dispose all of the cached cursors. 425 | */ 426 | public static void disposeCursors() { 427 | for (Cursor cursor : m_idToCursorMap.values()) { 428 | cursor.dispose(); 429 | } 430 | m_idToCursorMap.clear(); 431 | } 432 | //////////////////////////////////////////////////////////////////////////// 433 | // 434 | // General 435 | // 436 | //////////////////////////////////////////////////////////////////////////// 437 | /** 438 | * Dispose of cached objects and their underlying OS resources. This should only be called when the cached 439 | * objects are no longer needed (e.g. on application shutdown). 440 | */ 441 | public static void dispose() { 442 | disposeColors(); 443 | disposeImages(); 444 | disposeFonts(); 445 | disposeCursors(); 446 | } 447 | } -------------------------------------------------------------------------------- /src/soot/AstGeneratror.java: -------------------------------------------------------------------------------- 1 | package soot; 2 | 3 | import java.io.File; 4 | import java.io.FileWriter; 5 | import java.io.PrintWriter; 6 | import java.nio.file.Paths; 7 | 8 | import com.github.javaparser.JavaParser; 9 | import com.github.javaparser.ParseResult; 10 | import com.github.javaparser.StaticJavaParser; 11 | import com.github.javaparser.ast.CompilationUnit; 12 | import com.github.javaparser.ast.expr.VariableDeclarationExpr; 13 | import com.github.javaparser.printer.YamlPrinter; 14 | import com.github.javaparser.printer.XmlPrinter; 15 | import com.github.javaparser.printer.DotPrinter; 16 | 17 | 18 | public class AstGeneratror { 19 | 20 | public ParseResult generate(String filepath) throws Exception { 21 | 22 | // 1. java file 23 | String absolutePath = filepath; 24 | ParseResult result = new JavaParser().parse(Paths.get(absolutePath)); 25 | System.out.println(result.getResult().get()); 26 | // 2. java code 27 | // ParseResult exprResult = new JavaParser().parseVariableDeclarationExpr("int x = 3"); 28 | // System.out.println(exprResult.getResult().get()); 29 | // YamlPrinter printer = new YamlPrinter(true); 30 | // System.out.println(printer.output(result.getResult().get())); 31 | 32 | // YamlPrinter printer = new YamlPrinter(true); 33 | // System.out.println(printer.output(result.getResult().get())); 34 | // 35 | // XmlPrinter printer = new XmlPrinter(true); 36 | // System.out.println(printer.output(result.getResult().get())); 37 | // 38 | String split[]=filepath.split("/"); 39 | String arg1=""; 40 | for(int i=0;i options) { 104 | if (drawer == null) { 105 | drawer = new CFGToDotGraph(); 106 | drawer.setBriefLabels(PhaseOptions.getBoolean(options, briefLabelOptionName)); 107 | drawer.setOnePage(!PhaseOptions.getBoolean(options, multipageOptionName)); 108 | drawer.setUnexceptionalControlFlowAttr("color", "black"); 109 | drawer.setExceptionalControlFlowAttr("color", "red"); 110 | drawer.setExceptionEdgeAttr("color", "lightgray"); 111 | drawer.setShowExceptions(Options.v().show_exception_dests()); 112 | ir = CFGIntermediateRep.getIR(PhaseOptions.getString(options, irOptionName)); 113 | graphtype = CFGGraphType.getGraphType(PhaseOptions.getString(options, graphTypeOptionName)); 114 | 115 | AltClassLoader.v().setAltClassPath(PhaseOptions.getString(options, altClassPathOptionName)); 116 | AltClassLoader.v().setAltClasses( 117 | new String[] { "soot.toolkits.graph.ArrayRefBlockGraph", "soot.toolkits.graph.Block", 118 | "soot.toolkits.graph.Block$AllMapTo", "soot.toolkits.graph.BlockGraph", 119 | "soot.toolkits.graph.BriefBlockGraph", "soot.toolkits.graph.BriefUnitGraph", 120 | "soot.toolkits.graph.CompleteBlockGraph", "soot.toolkits.graph.CompleteUnitGraph", 121 | "soot.toolkits.graph.TrapUnitGraph", "soot.toolkits.graph.UnitGraph", 122 | "soot.toolkits.graph.ZonedBlockGraph", }); 123 | } 124 | } 125 | 126 | protected void print_cfg(Body body) { 127 | DirectedGraph graph = graphtype.buildGraph(body); 128 | //System.out.println(graph); 129 | DotGraph canvas = graphtype.drawGraph(drawer, graph, body); 130 | //GenerateFlow gen = new GenerateFlow((UnitGraph) graph); 131 | 132 | 133 | 134 | String methodname = body.getMethod().getSubSignature(); 135 | String classname = body.getMethod().getDeclaringClass().getName().replaceAll("\\$", "\\."); 136 | String filename = soot.SourceLocator.v().getOutputDir(); 137 | if (filename.length() > 0) { 138 | filename = filename + java.io.File.separator; 139 | } 140 | String pathname = filename + classname + " " + methodname.replace(java.io.File.separatorChar, '.') + DotGraph.DOT_EXTENSION; 141 | 142 | G.v().out.println("Generate dot file in " + pathname); 143 | canvas.plot(pathname); 144 | 145 | 146 | 147 | try { 148 | Runtime.getRuntime().exec("cmd /c copy "+eclipsepath+filename+classname+"*.dot "+path.replaceAll("/","\\\\")+" && " 149 | + "ren "+path.replaceAll("/","\\\\")+classname+"*.dot cfg.dot"); 150 | } catch (IOException e) { 151 | // TODO Auto-generated catch block 152 | e.printStackTrace(); 153 | } 154 | } 155 | } -------------------------------------------------------------------------------- /src/soot/DataFlowGraph.java: -------------------------------------------------------------------------------- 1 | package soot; 2 | 3 | 4 | import java.util.List; 5 | 6 | import facade.JavaDataFlow; 7 | import facade.StaticJavaDataFlow; 8 | import model.DataFlowMethod; 9 | import model.DataFlowNode; 10 | 11 | 12 | public class DataFlowGraph { 13 | 14 | public model.DataFlowGraph generate(String filepath) { 15 | 16 | String split[]=filepath.split("/"); 17 | String arg1=""; 18 | for(int i=0;i m.getName().equals(nodeName)).findFirst().get(); 37 | // List inputNodes = getA.getReturnNode().get().walkBackUntil(DataFlowNode::isInputParameter, dfg::owns); 38 | // System.out.println(inputNodes.get(0).getName()); 39 | 40 | System.out.println("================Printing all fields in the DFG================"); 41 | System.out.println(dfg); 42 | return dfg; 43 | } 44 | 45 | 46 | } 47 | -------------------------------------------------------------------------------- /src/soot/GenerateGraph.java: -------------------------------------------------------------------------------- 1 | package soot; 2 | 3 | import java.io.IOException; 4 | 5 | public class GenerateGraph { 6 | public void genera(String filepath) { 7 | String split[]=filepath.split("/"); 8 | String arg1=""; 9 | for(int i=0;i