Skip to content

Commit

Permalink
Merge pull request #24 from nbauma109/typemaker-tests-16052023
Browse files Browse the repository at this point in the history
added test to testMakeFieldType
  • Loading branch information
nbauma109 authored May 17, 2023
2 parents d2efaee + a1c46e7 commit 0e1db97
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.apache.bcel.classfile.FieldOrMethod;
import org.apache.bcel.classfile.Method;
import org.apache.bcel.classfile.Signature;
import org.apache.commons.lang3.Validate;
import org.jd.core.v1.api.loader.Loader;
import org.jd.core.v1.loader.ClassPathLoader;
import org.jd.core.v1.model.classfile.ClassFile;
Expand Down Expand Up @@ -696,7 +697,7 @@ Type parseReferenceTypeSignature(SignatureReader reader) {

return new GenericType(identifier, dimension);
case 'V':
assert dimension == 0;
Validate.isTrue(dimension == 0);
return PrimitiveType.TYPE_VOID;
case 'Z':
return dimension == 0 ? PrimitiveType.TYPE_BOOLEAN : PrimitiveType.TYPE_BOOLEAN.createType(dimension);
Expand Down
22 changes: 22 additions & 0 deletions src/test/java/org/jd/core/v1/SignatureParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/
package org.jd.core.v1;

import org.jd.core.v1.api.loader.Loader;
import org.jd.core.v1.loader.ClassPathLoader;
import org.jd.core.v1.model.classfile.ClassFile;
import org.jd.core.v1.model.javasyntax.type.BaseType;
Expand Down Expand Up @@ -463,6 +464,27 @@ public void testQualityLevel() throws Exception {
}
}

@Test
public void testExceptionTypes() throws Exception {
PrintTypeVisitor visitor = new PrintTypeVisitor();
Loader loader = new ClassPathLoader();
TypeMaker typeMaker = new TypeMaker(loader);

ClassFile classFile = deserializer.loadClassFile(loader, "org/apache/commons/lang3/function/FailableBooleanSupplier");

MethodTypes methodTypes = typeMaker.parseMethodSignature(classFile, classFile.getMethods()[0]);

// Check exceptionTypes
assertNotNull(methodTypes.getExceptionTypes());
assertEquals(1, methodTypes.getExceptionTypes().size());

BaseType type = methodTypes.getExceptionTypes();
type.accept(visitor);
String source = visitor.toString();

assertEquals("E", source);
}

@Test
public void testEnumPlanet() throws Exception {
PrintTypeVisitor visitor = new PrintTypeVisitor();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
package org.jd.core.v1.service.converter.classfiletojavasyntax.util;

import org.apache.bcel.Const;
import org.apache.commons.collections4.bidimap.AbstractDualBidiMap;
import org.apache.commons.collections4.iterators.AbstractUntypedIteratorDecorator;
import org.apache.commons.io.filefilter.AbstractFileFilter;
import org.jd.core.v1.loader.ClassPathLoader;
Expand All @@ -27,12 +28,12 @@
import org.jd.core.v1.model.javasyntax.type.TypeArguments;
import org.jd.core.v1.model.javasyntax.type.TypeParameter;
import org.jd.core.v1.model.javasyntax.type.TypeParameterWithTypeBounds;
import org.jd.core.v1.model.javasyntax.type.Types;
import org.jd.core.v1.model.javasyntax.type.WildcardExtendsTypeArgument;
import org.jd.core.v1.model.javasyntax.type.WildcardSuperTypeArgument;
import org.jd.core.v1.model.javasyntax.type.WildcardTypeArgument;
import org.jd.core.v1.service.converter.classfiletojavasyntax.util.TypeMaker.MethodTypes;
import org.jd.core.v1.service.converter.classfiletojavasyntax.util.TypeMaker.SignatureReader;
import org.jd.core.v1.service.converter.classfiletojavasyntax.util.TypeMaker.TypeTypes;
import org.jd.core.v1.util.StringConstants;
import org.jd.core.v1.util.ZipLoader;
import org.junit.Test;
Expand Down Expand Up @@ -967,6 +968,9 @@ public void testMakeMethodTypes() throws Exception {

@Test
public void testMakeFieldType() throws Exception {
testMakeFieldType(AbstractDualBidiMap.class, "java/io/ObjectInputStream", "STREAM_MAGIC", "S");
testMakeFieldType(AbstractDualBidiMap.class, "org/apache/commons/collections4/list/NodeCachingLinkedList", "size", "I");
testMakeFieldType(AbstractDualBidiMap.class, "org/apache/commons/collections4/bidimap/AbstractDualBidiMap$EntrySet", "parent", "Lorg/apache/commons/collections4/bidimap/AbstractDualBidiMap;");
testMakeFieldType(AbstractFileFilter.class, "org/apache/commons/io/filefilter/AbstractFileFilter", "EMPTY_STRING_ARRAY", "[Ljava/lang/String;");
}

Expand Down

0 comments on commit 0e1db97

Please sign in to comment.