Skip to content

Commit

Permalink
Added simple Java module wrapper.
Browse files Browse the repository at this point in the history
  • Loading branch information
raphw committed May 31, 2016
1 parent 44360b1 commit d83bfcc
Show file tree
Hide file tree
Showing 22 changed files with 262 additions and 117 deletions.
Expand Up @@ -21,7 +21,7 @@ public interface NamedElement {
*
* @return The name of this element as given in a Java program's source code.
*/
String getSourceCodeName();
String getActualName();

/**
* A named element with a name that has a particular meaning to the Java runtime.
Expand All @@ -43,6 +43,12 @@ interface WithRuntimeName extends NamedElement {
String getInternalName();
}


interface WithOptionalName extends NamedElement {

boolean isNamed();
}

/**
* A named element with a generic type name.
*/
Expand Down
Expand Up @@ -91,7 +91,7 @@ public String getInternalName() {
}

@Override
public String getSourceCodeName() {
public String getActualName() {
return getName();
}

Expand Down Expand Up @@ -159,8 +159,8 @@ public String toGenericString() {
if (getModifiers() != EMPTY_MASK) {
stringBuilder.append(Modifier.toString(getModifiers())).append(" ");
}
stringBuilder.append(getType().getSourceCodeName()).append(" ");
stringBuilder.append(getDeclaringType().asErasure().getSourceCodeName()).append(".");
stringBuilder.append(getType().getActualName()).append(" ");
stringBuilder.append(getDeclaringType().asErasure().getActualName()).append(".");
return stringBuilder.append(getName()).toString();
}

Expand All @@ -170,8 +170,8 @@ public String toString() {
if (getModifiers() != EMPTY_MASK) {
stringBuilder.append(Modifier.toString(getModifiers())).append(" ");
}
stringBuilder.append(getType().asErasure().getSourceCodeName()).append(" ");
stringBuilder.append(getDeclaringType().asErasure().getSourceCodeName()).append(".");
stringBuilder.append(getType().asErasure().getActualName()).append(" ");
stringBuilder.append(getDeclaringType().asErasure().getActualName()).append(".");
return stringBuilder.append(getName()).toString();
}
}
Expand Down
Expand Up @@ -372,7 +372,7 @@ public String getName() {
}

@Override
public String getSourceCodeName() {
public String getActualName() {
return isMethod()
? getName()
: EMPTY_NAME;
Expand Down Expand Up @@ -666,8 +666,8 @@ public String toGenericString() {
stringBuilder.append(Modifier.toString(modifiers)).append(" ");
}
if (isMethod()) {
stringBuilder.append(getReturnType().getSourceCodeName()).append(" ");
stringBuilder.append(getDeclaringType().asErasure().getSourceCodeName()).append(".");
stringBuilder.append(getReturnType().getActualName()).append(" ");
stringBuilder.append(getDeclaringType().asErasure().getActualName()).append(".");
}
stringBuilder.append(getName()).append("(");
boolean first = true;
Expand All @@ -677,7 +677,7 @@ public String toGenericString() {
} else {
first = false;
}
stringBuilder.append(typeDescription.getSourceCodeName());
stringBuilder.append(typeDescription.getActualName());
}
stringBuilder.append(")");
TypeList.Generic exceptionTypes = getExceptionTypes();
Expand All @@ -690,7 +690,7 @@ public String toGenericString() {
} else {
first = false;
}
stringBuilder.append(typeDescription.getSourceCodeName());
stringBuilder.append(typeDescription.getActualName());
}
}
return stringBuilder.toString();
Expand All @@ -704,8 +704,8 @@ public String toString() {
stringBuilder.append(Modifier.toString(modifiers)).append(" ");
}
if (isMethod()) {
stringBuilder.append(getReturnType().asErasure().getSourceCodeName()).append(" ");
stringBuilder.append(getDeclaringType().asErasure().getSourceCodeName()).append(".");
stringBuilder.append(getReturnType().asErasure().getActualName()).append(" ");
stringBuilder.append(getDeclaringType().asErasure().getActualName()).append(".");
}
stringBuilder.append(getName()).append("(");
boolean first = true;
Expand All @@ -715,7 +715,7 @@ public String toString() {
} else {
first = false;
}
stringBuilder.append(typeDescription.getSourceCodeName());
stringBuilder.append(typeDescription.getActualName());
}
stringBuilder.append(")");
TypeList exceptionTypes = getExceptionTypes().asErasures();
Expand All @@ -728,7 +728,7 @@ public String toString() {
} else {
first = false;
}
stringBuilder.append(typeDescription.getSourceCodeName());
stringBuilder.append(typeDescription.getActualName());
}
}
return stringBuilder.toString();
Expand Down
Expand Up @@ -24,6 +24,7 @@
*/
public interface ParameterDescription extends AnnotatedCodeElement,
NamedElement.WithRuntimeName,
NamedElement.WithOptionalName,
ModifierReviewable,
ByteCodeElement.TypeDependant<ParameterDescription.InDefinedShape, ParameterDescription.Token> {

Expand Down Expand Up @@ -53,14 +54,6 @@ public interface ParameterDescription extends AnnotatedCodeElement,
*/
int getIndex();

/**
* Checks if this parameter has an explicit name. A parameter without an explicit name is named implicitly by
* {@code argX} with {@code X} denoting the zero-based index.
*
* @return {@code true} if the parameter has an explicit name.
*/
boolean isNamed();

/**
* Checks if this parameter has an explicit modifier. A parameter without a modifier is simply treated as
* if it had a modifier of zero.
Expand Down Expand Up @@ -121,7 +114,7 @@ public String getInternalName() {
}

@Override
public String getSourceCodeName() {
public String getActualName() {
return isNamed()
? getName()
: EMPTY_NAME;
Expand Down
Expand Up @@ -45,7 +45,7 @@ public String getInternalName() {
}

@Override
public String getSourceCodeName() {
public String getActualName() {
return getName();
}

Expand Down
Expand Up @@ -4129,8 +4129,8 @@ public StackSize getStackSize() {
}

@Override
public String getSourceCodeName() {
return asErasure().getSourceCodeName();
public String getActualName() {
return asErasure().getActualName();
}

@Override
Expand Down Expand Up @@ -4437,9 +4437,9 @@ public String getTypeName() {
}

@Override
public String getSourceCodeName() {
public String getActualName() {
return getSort().isNonGeneric()
? asErasure().getSourceCodeName()
? asErasure().getActualName()
: toString();
}

Expand Down Expand Up @@ -4650,7 +4650,7 @@ public String getTypeName() {
}

@Override
public String getSourceCodeName() {
public String getActualName() {
return toString();
}

Expand Down Expand Up @@ -4992,7 +4992,7 @@ public String getTypeName() {
}

@Override
public String getSourceCodeName() {
public String getActualName() {
return toString();
}

Expand Down Expand Up @@ -5391,7 +5391,7 @@ public String getTypeName() {
}

@Override
public String getSourceCodeName() {
public String getActualName() {
return getSymbol();
}

Expand Down Expand Up @@ -5546,7 +5546,7 @@ public String getTypeName() {
}

@Override
public String getSourceCodeName() {
public String getActualName() {
return getSymbol();
}

Expand Down Expand Up @@ -5785,8 +5785,8 @@ public String getSymbol() {
}

@Override
public String getSourceCodeName() {
return resolve().getSourceCodeName();
public String getActualName() {
return resolve().getActualName();
}

@Override
Expand Down Expand Up @@ -7071,7 +7071,7 @@ public AnnotationList getInheritedAnnotations() {
}

@Override
public String getSourceCodeName() {
public String getActualName() {
if (isArray()) {
TypeDescription typeDescription = this;
int dimensions = 0;
Expand All @@ -7080,7 +7080,7 @@ public String getSourceCodeName() {
typeDescription = typeDescription.getComponentType();
} while (typeDescription.isArray());
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(typeDescription.getSourceCodeName());
stringBuilder.append(typeDescription.getActualName());
for (int i = 0; i < dimensions; i++) {
stringBuilder.append("[]");
}
Expand Down
Expand Up @@ -181,7 +181,7 @@ public static AssignerConfigurable value(TypeDescription fixedValue) {
*/
public static AssignerConfigurable value(JavaConstant fixedValue) {
return new ForPoolValue(fixedValue.asStackManipulation(),
fixedValue.getInstanceType(),
fixedValue.getType(),
Assigner.DEFAULT,
Assigner.Typing.STATIC);
}
Expand Down
Expand Up @@ -2458,7 +2458,7 @@ public ForJavaConstant(JavaConstant javaConstant) {

@Override
public Resolved resolve(TypeDescription instrumentedType, MethodDescription instrumentedMethod, Assigner assigner, Assigner.Typing typing) {
return new Resolved.Simple(javaConstant.asStackManipulation(), javaConstant.getInstanceType());
return new Resolved.Simple(javaConstant.asStackManipulation(), javaConstant.getType());
}

@Override
Expand Down
Expand Up @@ -2344,7 +2344,7 @@ public ForJavaConstant(JavaConstant javaConstant) {
public StackManipulation resolve(ParameterDescription target, Assigner assigner, Assigner.Typing typing) {
StackManipulation stackManipulation = new StackManipulation.Compound(
javaConstant.asStackManipulation(),
assigner.assign(javaConstant.getInstanceType().asGenericType(), target.getType(), typing));
assigner.assign(javaConstant.getType().asGenericType(), target.getType(), typing));
if (!stackManipulation.isValid()) {
throw new IllegalStateException("Cannot assign Class value to " + target);
}
Expand Down
Expand Up @@ -32,7 +32,7 @@ public NameMatcher(ElementMatcher<String> nameMatcher) {

@Override
public boolean matches(T target) {
return nameMatcher.matches(target.getSourceCodeName());
return nameMatcher.matches(target.getActualName());
}

@Override
Expand Down
Expand Up @@ -46,7 +46,7 @@ public interface JavaConstant {
*
* @return A description of the type of the represented instance or at least a stub.
*/
TypeDescription getInstanceType();
TypeDescription getType();

/**
* Represents a {@code java.lang.invoke.MethodType} object.
Expand Down Expand Up @@ -276,7 +276,7 @@ public StackManipulation asStackManipulation() {
}

@Override
public TypeDescription getInstanceType() {
public TypeDescription getType() {
return JavaType.METHOD_TYPE.getTypeStub();
}

Expand Down Expand Up @@ -711,7 +711,7 @@ public StackManipulation asStackManipulation() {
}

@Override
public TypeDescription getInstanceType() {
public TypeDescription getType() {
return JavaType.METHOD_HANDLE.getTypeStub();
}

Expand Down

0 comments on commit d83bfcc

Please sign in to comment.