Commit f6859c62 authored by andrei's avatar andrei

Some changes for better integration with signature package, implemented...

Some changes for better integration with signature package, implemented selection on generic methods.
parent 45a4e32e
......@@ -43,20 +43,22 @@ public class CommentedClassVisitor extends TraceClassVisitor {
protected void appendDescriptor(final StringBuffer buf1, final int type,
final String desc, final boolean raw1) {
if (desc == null) {
buf1.append("null");
//buf1.append("null");
return;
}
if (raw1) {
buf1.append(desc);
if(type == CLASS_SIGNATURE || type == FIELD_SIGNATURE || type == METHOD_SIGNATURE) {
if(type != CLASS_SIGNATURE) {
buf1.append(tab);
}
buf1.append( "// signature ").append( desc ).append('\n');
} else {
buf1.append(desc);
}
} else {
switch (type) {
case INTERNAL_NAME :
int p = desc.lastIndexOf('/');
if (p == -1) {
buf1.append(desc);
} else {
buf1.append(desc.substring(p + 1));
}
buf1.append(eatPackageNames(desc, '/'));
break;
case FIELD_DESCRIPTOR :
buf1.append(getSimpleName(Type.getType(desc)));
......@@ -74,38 +76,85 @@ public class CommentedClassVisitor extends TraceClassVisitor {
buf1.append(") : ");
buf1.append(getSimpleName(res));
break;
case METHOD_SIGNATURE :
// TODO implement raw/not raw view of signature -
// remove package names like here:
// ()Ljava/util/List<Lde/loskutov/xml/impl/DummyForXml;>;
// to ()List<DummyForXml>
// (Ljava/util/Map<Ljava/lang/String;Ljava/lang/String;>;)V
// to (Map<String,String>)void
case FIELD_SIGNATURE :
case CLASS_SIGNATURE :
// ignore - show only in "raw" mode
break;
case TYPE_DECLARATION :
buf1.append(eatPackageNames(desc, '.'));
break;
case CLASS_DECLARATION :
buf1.append(eatPackageNames(desc, '.'));
break;
case PARAMETERS_DECLARATION :
buf1.append(eatPackageNames(desc, '.'));
break;
default :
buf1.append(desc);
}
}
}
private String getSimpleName(Type t) {
/**
*
* @param t
* @return simply class name without any package/outer class information
*/
private static String getSimpleName(Type t) {
String name = t.getClassName();
int p = name.lastIndexOf('.');
if (p == -1) {
return eatPackageNames(name, '.');
}
/**
*
* @param name Java type name(s).
* @return simply class name(s) without any package/outer class information,
* but with "generics" information from given name parameter.
*/
private static String eatPackageNames(String name, char separator){
int lastPoint = name.lastIndexOf(separator);
if(lastPoint < 0){
return name;
}
return name.substring(p + 1);
}
StringBuffer sb = new StringBuffer(name);
do {
int start = getPackageStartIndex(sb, separator, lastPoint);
sb.delete(start, lastPoint + 1);
lastPoint = lastIndexOf(sb, separator, start);
} while (lastPoint > 0);
class CommentedAnnotationVisitor extends TraceAnnotationVisitor {
return sb.toString();
}
private static int lastIndexOf(StringBuffer chars, char c, int lastPoint){
for (int i = lastPoint - 1; i > 0; i--) {
if(chars.charAt(i) == c){
return i;
}
}
return -1;
}
protected void appendDescriptor(final String desc) {
CommentedClassVisitor.this.appendDescriptor(
buf, FIELD_DESCRIPTOR, desc, raw);
private static int getPackageStartIndex(StringBuffer chars, char c, int firstPoint){
for (int i = firstPoint - 1; i >= 0; i--) {
char curr = chars.charAt(i);
if(curr != c && !Character.isJavaIdentifierPart(curr)){
return i + 1;
}
}
return 0;
}
class CommentedAnnotationVisitor extends TraceAnnotationVisitor {
protected TraceAnnotationVisitor createTraceAnnotationVisitor() {
return new CommentedAnnotationVisitor();
}
protected void appendDescriptor(final int type, final String desc) {
CommentedClassVisitor.this.appendDescriptor(buf, type, desc, raw);
}
}
class CommentedFieldVisitor extends TraceFieldVisitor {
......@@ -120,7 +169,7 @@ public class CommentedClassVisitor extends TraceClassVisitor {
}
class CommentedMethodVisitor extends TraceMethodVisitor {
private Index getIndex(Label label){
Index index;
for (int i = 0; i < text.size(); i++) {
......@@ -134,7 +183,7 @@ public class CommentedClassVisitor extends TraceClassVisitor {
}
return null;
}
public void visitMethodInsn (
final int opcode,
final String owner,
......@@ -144,12 +193,12 @@ public class CommentedClassVisitor extends TraceClassVisitor {
buf.setLength(0);
buf.append(tab2).append(OPCODES[opcode]).append(' ');
appendDescriptor(INTERNAL_NAME, owner);
buf.append(' ').append(name);
buf.append('.').append(name);
appendDescriptor(METHOD_DESCRIPTOR, desc);
buf.append('\n');
text.add(buf.toString());
}
}
public void visitVarInsn(final int opcode, final int var) {
text.add(tab2 + OPCODES[opcode] + " " + var);
if (!raw) {
......@@ -169,7 +218,7 @@ public class CommentedClassVisitor extends TraceClassVisitor {
buf.append('\n');
text.add(buf.toString());
}
public void visitIincInsn(final int var, final int increment) {
text.add(tab2 + "IINC " + var);
if (!raw) {
......@@ -207,6 +256,6 @@ public class CommentedClassVisitor extends TraceClassVisitor {
CommentedClassVisitor.this.appendDescriptor(buf, type, desc, raw);
}
}
}
......@@ -42,6 +42,7 @@ import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.eclipse.jdt.core.IParent;
import org.eclipse.jdt.core.ISourceRange;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.ITypeParameter;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.core.Signature;
import org.eclipse.jdt.internal.core.BinaryMember;
......@@ -85,18 +86,62 @@ public class JdtUtils {
sb.append('(');
IType declaringType = iMethod.getDeclaringType();
String[] parameterTypes = iMethod.getParameterTypes();
// doSomething(Lgenerics/DummyForAsmGenerics;)Lgenerics/DummyForAsmGenerics;
for (int i = 0; i < parameterTypes.length; i++) {
sb.append(getResolvedType(parameterTypes[i], declaringType));
String resolvedType = getResolvedType(parameterTypes[i], declaringType);
if(resolvedType != null && resolvedType.length() > 0){
sb.append(resolvedType);
} else {
// this is a generic type
appendGenericType(sb, iMethod, parameterTypes[i]);
}
}
sb.append(')');
// continue here with adding resolved return type
String returnType = iMethod.getReturnType();
sb.append(getResolvedType(returnType, declaringType));
String resolvedType = getResolvedType(returnType, declaringType);
if(resolvedType != null && resolvedType.length() > 0){
sb.append(getResolvedType(returnType, declaringType));
} else {
// this is a generic type
appendGenericType(sb, iMethod, returnType);
}
return sb.toString();
}
private static void appendGenericType(StringBuffer sb, IMethod iMethod,
String unresolvedType) throws JavaModelException{
IType declaringType = iMethod.getDeclaringType();
// unresolvedType is here like "QA;" => we remove "Q" and ";"
if(unresolvedType.length() < 3){
// ???? something wrong here ....
sb.append(unresolvedType);
return;
}
unresolvedType = unresolvedType.substring(1, unresolvedType.length() - 1);
ITypeParameter typeParameter = iMethod.getTypeParameter(unresolvedType);
if(typeParameter == null || !typeParameter.exists()){
typeParameter = declaringType.getTypeParameter(unresolvedType);
}
String[] bounds = typeParameter.getBounds();
if(bounds.length == 0){
sb.append("Ljava/lang/Object;");
} else {
for (int i = 0; i < bounds.length; i++) {
String simplyName = bounds[i];
simplyName = Signature.C_UNRESOLVED + simplyName + Signature.C_NAME_END;
String resolvedType = getResolvedType(simplyName, declaringType);
sb.append(resolvedType);
}
}
}
/**
* @param typeToResolve
* @param declaringType
......@@ -115,14 +160,15 @@ public class JdtUtils {
} else {
// we need resolved types
String resolved = getResolvedTypeName(typeToResolve, declaringType);
while (arrayCount > 0) {
sb.append(Signature.C_ARRAY);
arrayCount--;
if(resolved != null) {
while (arrayCount > 0) {
sb.append(Signature.C_ARRAY);
arrayCount--;
}
sb.append(Signature.C_RESOLVED);
sb.append(resolved);
sb.append(Signature.C_SEMICOLON);
}
sb.append(Signature.C_RESOLVED);
sb.append(resolved);
sb.append(Signature.C_SEMICOLON);
}
return sb.toString();
}
......@@ -813,7 +859,7 @@ public class JdtUtils {
*/
public static ClassLoader getClassLoader(IJavaElement type) {
ClassLoader cl;
IJavaProject javaProject = type.getJavaProject();
IPath projectPath = javaProject.getProject().getLocation();
IClasspathEntry[] paths = null;
......@@ -843,7 +889,7 @@ public class JdtUtils {
} else {
p = cpEntry.getPath();
}
if (p == null) {
continue;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment