Skip to content

Commit

Permalink
Merge branch 'develop' into devfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
StevenArzt authored Nov 11, 2024
2 parents 71116ce + e36861e commit 12efaa6
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 3 deletions.
26 changes: 23 additions & 3 deletions src/main/java/soot/SootClass.java
Original file line number Diff line number Diff line change
Expand Up @@ -909,12 +909,17 @@ public boolean isInnerClass() {
}

/**
* Returns the name of this class.
* Returns the full name of this class (including package).
*/
public String getName() {
return name;
}

/**
* Returns the full name of this class (including package).
*
* Considers Dava {@link PackageNamer} fixed names.
*/
public String getJavaStyleName() {
if (PackageNamer.v().has_FixedNames()) {
if (fixedShortName == null) {
Expand All @@ -923,12 +928,17 @@ public String getJavaStyleName() {
if (!PackageNamer.v().use_ShortName(getJavaPackageName(), fixedShortName)) {
return getJavaPackageName() + '.' + fixedShortName;
}
return fixedShortName;
return getPackageName() + '.' + fixedShortName;
} else {
return shortName;
return name;
}
}

/**
* Returns the name of this class without package as returned by {@link Class#getSimpleName()}
*
* Considers Dava {@link PackageNamer} fixed names.
*/
public String getShortJavaStyleName() {
if (PackageNamer.v().has_FixedNames()) {
if (fixedShortName == null) {
Expand All @@ -940,6 +950,9 @@ public String getShortJavaStyleName() {
}
}

/**
* Returns the name of this class without package as returned by {@link Class#getSimpleName()}
*/
public String getShortName() {
return shortName;
}
Expand All @@ -951,6 +964,13 @@ public String getPackageName() {
return packageName;
}

/**
* Get package name of this class.
*
* Considers Dava {@link PackageNamer} fixed names.
*
* @return
*/
public String getJavaPackageName() {
if (PackageNamer.v().has_FixedNames()) {
if (fixedPackageName == null) {
Expand Down
66 changes: 66 additions & 0 deletions src/test/java/soot/BasicTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*-
* #%L
* Soot - a J*va Optimization Framework
* %%
* Copyright (C) 1997 - 2014 Raja Vallee-Rai and others
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
package soot;

import static org.junit.Assert.assertEquals;

import org.junit.Test;

public class BasicTest {

@Test
public void sootClassNamePackageTests() {
G.reset();

Scene.v().loadNecessaryClasses();

SootClass sc1 = new SootClass("Class1");
SootClass sc2 = new SootClass("package1.Class2");
SootClass sc3 = new SootClass("package2.Class3");

Scene.v().addClass(sc1);
Scene.v().addClass(sc2);
Scene.v().addClass(sc3);

assertEquals("Class1", sc1.getName());
assertEquals("Class1", sc1.getShortName());
assertEquals("Class1", sc1.getJavaStyleName());
assertEquals("Class1", sc1.getShortJavaStyleName());
assertEquals("", sc1.getPackageName());
assertEquals("", sc1.getJavaPackageName());

assertEquals("package1.Class2", sc2.getName());
assertEquals("Class2", sc2.getShortName());
assertEquals("package1.Class2", sc2.getJavaStyleName());
assertEquals("Class2", sc2.getShortJavaStyleName());
assertEquals("package1", sc2.getPackageName());
assertEquals("package1", sc2.getJavaPackageName());

assertEquals("package2.Class3", sc3.getName());
assertEquals("Class3", sc3.getShortName());
assertEquals("package2.Class3", sc3.getJavaStyleName());
assertEquals("Class3", sc3.getShortJavaStyleName());
assertEquals("package2", sc3.getPackageName());
assertEquals("package2", sc3.getJavaPackageName());
}

}

0 comments on commit 12efaa6

Please sign in to comment.