summaryrefslogtreecommitdiffstats
path: root/src/org/jetbrains/java/decompiler/struct/gen/generics
diff options
context:
space:
mode:
Diffstat (limited to 'src/org/jetbrains/java/decompiler/struct/gen/generics')
-rw-r--r--src/org/jetbrains/java/decompiler/struct/gen/generics/GenericClassDescriptor.java32
-rw-r--r--src/org/jetbrains/java/decompiler/struct/gen/generics/GenericFieldDescriptor.java22
-rw-r--r--src/org/jetbrains/java/decompiler/struct/gen/generics/GenericMain.java436
-rw-r--r--src/org/jetbrains/java/decompiler/struct/gen/generics/GenericMethodDescriptor.java34
-rw-r--r--src/org/jetbrains/java/decompiler/struct/gen/generics/GenericType.java514
5 files changed, 520 insertions, 518 deletions
diff --git a/src/org/jetbrains/java/decompiler/struct/gen/generics/GenericClassDescriptor.java b/src/org/jetbrains/java/decompiler/struct/gen/generics/GenericClassDescriptor.java
index d4551ac..66fab96 100644
--- a/src/org/jetbrains/java/decompiler/struct/gen/generics/GenericClassDescriptor.java
+++ b/src/org/jetbrains/java/decompiler/struct/gen/generics/GenericClassDescriptor.java
@@ -1,17 +1,18 @@
/*
- * Fernflower - The Analytical Java Decompiler
- * http://www.reversed-java.com
+ * Copyright 2000-2014 JetBrains s.r.o.
*
- * (C) 2008 - 2010, Stiver
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
*
- * This software is NEITHER public domain NOR free software
- * as per GNU License. See license.txt for more details.
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * This software is distributed WITHOUT ANY WARRANTY; without
- * even the implied warranty of MERCHANTABILITY or FITNESS FOR
- * A PARTICULAR PURPOSE.
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
*/
-
package org.jetbrains.java.decompiler.struct.gen.generics;
import java.util.ArrayList;
@@ -19,12 +20,11 @@ import java.util.List;
public class GenericClassDescriptor {
- public GenericType superclass;
-
- public List<GenericType> superinterfaces = new ArrayList<GenericType>();
-
- public List<String> fparameters = new ArrayList<String>();
+ public GenericType superclass;
+
+ public List<GenericType> superinterfaces = new ArrayList<GenericType>();
+
+ public List<String> fparameters = new ArrayList<String>();
- public List<List<GenericType>> fbounds = new ArrayList<List<GenericType>>();
-
+ public List<List<GenericType>> fbounds = new ArrayList<List<GenericType>>();
}
diff --git a/src/org/jetbrains/java/decompiler/struct/gen/generics/GenericFieldDescriptor.java b/src/org/jetbrains/java/decompiler/struct/gen/generics/GenericFieldDescriptor.java
index 4b4114d..598d17b 100644
--- a/src/org/jetbrains/java/decompiler/struct/gen/generics/GenericFieldDescriptor.java
+++ b/src/org/jetbrains/java/decompiler/struct/gen/generics/GenericFieldDescriptor.java
@@ -1,21 +1,21 @@
/*
- * Fernflower - The Analytical Java Decompiler
- * http://www.reversed-java.com
+ * Copyright 2000-2014 JetBrains s.r.o.
*
- * (C) 2008 - 2010, Stiver
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
*
- * This software is NEITHER public domain NOR free software
- * as per GNU License. See license.txt for more details.
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * This software is distributed WITHOUT ANY WARRANTY; without
- * even the implied warranty of MERCHANTABILITY or FITNESS FOR
- * A PARTICULAR PURPOSE.
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
*/
-
package org.jetbrains.java.decompiler.struct.gen.generics;
public class GenericFieldDescriptor {
- public GenericType type;
-
+ public GenericType type;
}
diff --git a/src/org/jetbrains/java/decompiler/struct/gen/generics/GenericMain.java b/src/org/jetbrains/java/decompiler/struct/gen/generics/GenericMain.java
index 50433a9..db7d84b 100644
--- a/src/org/jetbrains/java/decompiler/struct/gen/generics/GenericMain.java
+++ b/src/org/jetbrains/java/decompiler/struct/gen/generics/GenericMain.java
@@ -1,229 +1,233 @@
/*
- * Fernflower - The Analytical Java Decompiler
- * http://www.reversed-java.com
+ * Copyright 2000-2014 JetBrains s.r.o.
*
- * (C) 2008 - 2010, Stiver
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
*
- * This software is NEITHER public domain NOR free software
- * as per GNU License. See license.txt for more details.
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * This software is distributed WITHOUT ANY WARRANTY; without
- * even the implied warranty of MERCHANTABILITY or FITNESS FOR
- * A PARTICULAR PURPOSE.
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
*/
-
package org.jetbrains.java.decompiler.struct.gen.generics;
-import java.util.ArrayList;
-import java.util.List;
-
import org.jetbrains.java.decompiler.code.CodeConstants;
import org.jetbrains.java.decompiler.main.DecompilerContext;
import org.jetbrains.java.decompiler.struct.StructClass;
+import java.util.ArrayList;
+import java.util.List;
+
public class GenericMain {
-
- private static final String[] typeNames = new String[] {
- "byte",
- "char",
- "double",
- "float",
- "int",
- "long",
- "short",
- "boolean",
- };
-
- public static GenericClassDescriptor parseClassSignature(String signature) {
-
- GenericClassDescriptor descriptor = new GenericClassDescriptor();
-
- signature = parseFormalParameters(signature, descriptor.fparameters, descriptor.fbounds);
-
- String supercl = GenericType.getNextType(signature);
- descriptor.superclass = new GenericType(supercl);
-
- signature = signature.substring(supercl.length());
- while(signature.length() > 0) {
- String superintr = GenericType.getNextType(signature);
- descriptor.superinterfaces.add(new GenericType(superintr));
- signature = signature.substring(superintr.length());
- }
-
- return descriptor;
- }
-
- public static GenericFieldDescriptor parseFieldSignature(String signature) {
- GenericFieldDescriptor descriptor = new GenericFieldDescriptor();
- descriptor.type = new GenericType(signature);
- return descriptor;
- }
-
- public static GenericMethodDescriptor parseMethodSignature(String signature) {
-
- GenericMethodDescriptor descriptor = new GenericMethodDescriptor();
-
- signature = parseFormalParameters(signature, descriptor.fparameters, descriptor.fbounds);
-
- int to = signature.indexOf(")");
- String pars = signature.substring(1, to);
- signature = signature.substring(to+1);
-
- while(pars.length() > 0) {
- String par = GenericType.getNextType(pars);
- descriptor.params.add(new GenericType(par));
- pars = pars.substring(par.length());
- }
-
- String par = GenericType.getNextType(signature);
- descriptor.ret = new GenericType(par);
- signature = signature.substring(par.length());
-
- if(signature.length() > 0) {
- String[] excs = signature.split("\\^");
-
- for(int i=1;i<excs.length;i++) {
- descriptor.exceptions.add(new GenericType(excs[i]));
- }
- }
-
- return descriptor;
- }
-
- private static String parseFormalParameters(String signature, List<String> fparameters, List<List<GenericType>> fbounds) {
-
- if(signature.charAt(0) != '<') {
- return signature;
- }
-
- int counter = 1;
- int index = 1;
-
- loop:
- while(index < signature.length()) {
- switch(signature.charAt(index)) {
- case '<':
- counter++;
- break;
- case '>':
- counter--;
- if(counter == 0) {
- break loop;
- }
- }
-
- index++;
- }
-
- String value = signature.substring(1, index);
- signature = signature.substring(index+1);
-
- while(value.length() > 0) {
- int parto = value.indexOf(":");
-
- String param = value.substring(0, parto);
- value = value.substring(parto+1);
-
- List<GenericType> lstBounds = new ArrayList<GenericType>();
-
- for(;;) {
- if(value.charAt(0) == ':') {
- // empty superclass, skip
- value = value.substring(1);
- }
-
- String bound = GenericType.getNextType(value);
- lstBounds.add(new GenericType(bound));
- value = value.substring(bound.length());
-
-
- if(value.length() == 0 || value.charAt(0) != ':') {
- break;
- } else {
- value = value.substring(1);
- }
- }
-
- fparameters.add(param);
- fbounds.add(lstBounds);
- }
-
- return signature;
- }
-
- public static String getGenericCastTypeName(GenericType type) {
- String s = getTypeName(type);
- int dim = type.arraydim;
- while(dim-->0) {
- s+="[]";
- }
- return s;
- }
-
- public static String getTypeName(GenericType type) {
-
- int tp = type.type;
- if(tp <= CodeConstants.TYPE_BOOLEAN) {
- return typeNames[tp];
- } else if(tp == CodeConstants.TYPE_VOID) {
- return "void";
- } else if(tp == CodeConstants.TYPE_GENVAR) {
- return type.value;
- } else if(tp == CodeConstants.TYPE_OBJECT) {
- StringBuilder buffer = new StringBuilder();
- buffer.append(DecompilerContext.getImpcollector().getShortName(buildJavaClassName(type)));
-
- if(!type.getArguments().isEmpty()) {
- buffer.append("<");
- for(int i=0;i<type.getArguments().size();i++) {
- if(i>0) {
- buffer.append(", ");
- }
- int wildcard = type.getWildcards().get(i);
- if(wildcard != GenericType.WILDCARD_NO) {
- buffer.append("?");
-
- switch(wildcard){
- case GenericType.WILDCARD_EXTENDS:
- buffer.append(" extends ");
- break;
- case GenericType.WILDCARD_SUPER:
- buffer.append(" super ");
- }
- }
-
- GenericType genpar = type.getArguments().get(i);
- if(genpar != null) {
- buffer.append(GenericMain.getGenericCastTypeName(genpar));
- }
- }
- buffer.append(">");
- }
-
- return buffer.toString();
- }
-
- throw new RuntimeException("invalid type");
- }
-
- public static String buildJavaClassName(GenericType type) {
-
- String name = "";
- for(GenericType tp : type.getEnclosingClasses()) {
- name += tp.value+"$";
- }
- name+=type.value;
-
- String res = name.replace('/', '.');
-
- if(res.indexOf("$") >=0) {
- StructClass cl = DecompilerContext.getStructcontext().getClass(name);
- if(cl == null || !cl.isOwn()) {
- res = res.replace('$', '.');
- }
- }
-
- return res;
- }
-
+
+ private static final String[] typeNames = new String[]{
+ "byte",
+ "char",
+ "double",
+ "float",
+ "int",
+ "long",
+ "short",
+ "boolean",
+ };
+
+ public static GenericClassDescriptor parseClassSignature(String signature) {
+
+ GenericClassDescriptor descriptor = new GenericClassDescriptor();
+
+ signature = parseFormalParameters(signature, descriptor.fparameters, descriptor.fbounds);
+
+ String supercl = GenericType.getNextType(signature);
+ descriptor.superclass = new GenericType(supercl);
+
+ signature = signature.substring(supercl.length());
+ while (signature.length() > 0) {
+ String superintr = GenericType.getNextType(signature);
+ descriptor.superinterfaces.add(new GenericType(superintr));
+ signature = signature.substring(superintr.length());
+ }
+
+ return descriptor;
+ }
+
+ public static GenericFieldDescriptor parseFieldSignature(String signature) {
+ GenericFieldDescriptor descriptor = new GenericFieldDescriptor();
+ descriptor.type = new GenericType(signature);
+ return descriptor;
+ }
+
+ public static GenericMethodDescriptor parseMethodSignature(String signature) {
+
+ GenericMethodDescriptor descriptor = new GenericMethodDescriptor();
+
+ signature = parseFormalParameters(signature, descriptor.fparameters, descriptor.fbounds);
+
+ int to = signature.indexOf(")");
+ String pars = signature.substring(1, to);
+ signature = signature.substring(to + 1);
+
+ while (pars.length() > 0) {
+ String par = GenericType.getNextType(pars);
+ descriptor.params.add(new GenericType(par));
+ pars = pars.substring(par.length());
+ }
+
+ String par = GenericType.getNextType(signature);
+ descriptor.ret = new GenericType(par);
+ signature = signature.substring(par.length());
+
+ if (signature.length() > 0) {
+ String[] excs = signature.split("\\^");
+
+ for (int i = 1; i < excs.length; i++) {
+ descriptor.exceptions.add(new GenericType(excs[i]));
+ }
+ }
+
+ return descriptor;
+ }
+
+ private static String parseFormalParameters(String signature, List<String> fparameters, List<List<GenericType>> fbounds) {
+
+ if (signature.charAt(0) != '<') {
+ return signature;
+ }
+
+ int counter = 1;
+ int index = 1;
+
+ loop:
+ while (index < signature.length()) {
+ switch (signature.charAt(index)) {
+ case '<':
+ counter++;
+ break;
+ case '>':
+ counter--;
+ if (counter == 0) {
+ break loop;
+ }
+ }
+
+ index++;
+ }
+
+ String value = signature.substring(1, index);
+ signature = signature.substring(index + 1);
+
+ while (value.length() > 0) {
+ int parto = value.indexOf(":");
+
+ String param = value.substring(0, parto);
+ value = value.substring(parto + 1);
+
+ List<GenericType> lstBounds = new ArrayList<GenericType>();
+
+ for (; ; ) {
+ if (value.charAt(0) == ':') {
+ // empty superclass, skip
+ value = value.substring(1);
+ }
+
+ String bound = GenericType.getNextType(value);
+ lstBounds.add(new GenericType(bound));
+ value = value.substring(bound.length());
+
+
+ if (value.length() == 0 || value.charAt(0) != ':') {
+ break;
+ }
+ else {
+ value = value.substring(1);
+ }
+ }
+
+ fparameters.add(param);
+ fbounds.add(lstBounds);
+ }
+
+ return signature;
+ }
+
+ public static String getGenericCastTypeName(GenericType type) {
+ String s = getTypeName(type);
+ int dim = type.arraydim;
+ while (dim-- > 0) {
+ s += "[]";
+ }
+ return s;
+ }
+
+ public static String getTypeName(GenericType type) {
+
+ int tp = type.type;
+ if (tp <= CodeConstants.TYPE_BOOLEAN) {
+ return typeNames[tp];
+ }
+ else if (tp == CodeConstants.TYPE_VOID) {
+ return "void";
+ }
+ else if (tp == CodeConstants.TYPE_GENVAR) {
+ return type.value;
+ }
+ else if (tp == CodeConstants.TYPE_OBJECT) {
+ StringBuilder buffer = new StringBuilder();
+ buffer.append(DecompilerContext.getImpcollector().getShortName(buildJavaClassName(type)));
+
+ if (!type.getArguments().isEmpty()) {
+ buffer.append("<");
+ for (int i = 0; i < type.getArguments().size(); i++) {
+ if (i > 0) {
+ buffer.append(", ");
+ }
+ int wildcard = type.getWildcards().get(i);
+ if (wildcard != GenericType.WILDCARD_NO) {
+ buffer.append("?");
+
+ switch (wildcard) {
+ case GenericType.WILDCARD_EXTENDS:
+ buffer.append(" extends ");
+ break;
+ case GenericType.WILDCARD_SUPER:
+ buffer.append(" super ");
+ }
+ }
+
+ GenericType genpar = type.getArguments().get(i);
+ if (genpar != null) {
+ buffer.append(GenericMain.getGenericCastTypeName(genpar));
+ }
+ }
+ buffer.append(">");
+ }
+
+ return buffer.toString();
+ }
+
+ throw new RuntimeException("invalid type");
+ }
+
+ public static String buildJavaClassName(GenericType type) {
+
+ String name = "";
+ for (GenericType tp : type.getEnclosingClasses()) {
+ name += tp.value + "$";
+ }
+ name += type.value;
+
+ String res = name.replace('/', '.');
+
+ if (res.indexOf("$") >= 0) {
+ StructClass cl = DecompilerContext.getStructcontext().getClass(name);
+ if (cl == null || !cl.isOwn()) {
+ res = res.replace('$', '.');
+ }
+ }
+
+ return res;
+ }
}
diff --git a/src/org/jetbrains/java/decompiler/struct/gen/generics/GenericMethodDescriptor.java b/src/org/jetbrains/java/decompiler/struct/gen/generics/GenericMethodDescriptor.java
index 7a0a4d1..7b4c9dc 100644
--- a/src/org/jetbrains/java/decompiler/struct/gen/generics/GenericMethodDescriptor.java
+++ b/src/org/jetbrains/java/decompiler/struct/gen/generics/GenericMethodDescriptor.java
@@ -1,17 +1,18 @@
/*
- * Fernflower - The Analytical Java Decompiler
- * http://www.reversed-java.com
+ * Copyright 2000-2014 JetBrains s.r.o.
*
- * (C) 2008 - 2010, Stiver
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
*
- * This software is NEITHER public domain NOR free software
- * as per GNU License. See license.txt for more details.
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * This software is distributed WITHOUT ANY WARRANTY; without
- * even the implied warranty of MERCHANTABILITY or FITNESS FOR
- * A PARTICULAR PURPOSE.
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
*/
-
package org.jetbrains.java.decompiler.struct.gen.generics;
import java.util.ArrayList;
@@ -19,14 +20,13 @@ import java.util.List;
public class GenericMethodDescriptor {
- public List<String> fparameters = new ArrayList<String>();
+ public List<String> fparameters = new ArrayList<String>();
+
+ public List<List<GenericType>> fbounds = new ArrayList<List<GenericType>>();
+
+ public List<GenericType> params = new ArrayList<GenericType>();
- public List<List<GenericType>> fbounds = new ArrayList<List<GenericType>>();
+ public GenericType ret;
- public List<GenericType> params = new ArrayList<GenericType>();
-
- public GenericType ret;
-
- public List<GenericType> exceptions = new ArrayList<GenericType>();
-
+ public List<GenericType> exceptions = new ArrayList<GenericType>();
}
diff --git a/src/org/jetbrains/java/decompiler/struct/gen/generics/GenericType.java b/src/org/jetbrains/java/decompiler/struct/gen/generics/GenericType.java
index 1f720e6..e2faa4a 100644
--- a/src/org/jetbrains/java/decompiler/struct/gen/generics/GenericType.java
+++ b/src/org/jetbrains/java/decompiler/struct/gen/generics/GenericType.java
@@ -1,270 +1,268 @@
/*
- * Fernflower - The Analytical Java Decompiler
- * http://www.reversed-java.com
+ * Copyright 2000-2014 JetBrains s.r.o.
*
- * (C) 2008 - 2010, Stiver
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
*
- * This software is NEITHER public domain NOR free software
- * as per GNU License. See license.txt for more details.
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * This software is distributed WITHOUT ANY WARRANTY; without
- * even the implied warranty of MERCHANTABILITY or FITNESS FOR
- * A PARTICULAR PURPOSE.
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
*/
-
package org.jetbrains.java.decompiler.struct.gen.generics;
+import org.jetbrains.java.decompiler.code.CodeConstants;
+
import java.util.ArrayList;
import java.util.List;
-import org.jetbrains.java.decompiler.code.CodeConstants;
-
public class GenericType {
-
- public static final int WILDCARD_EXTENDS = 1;
- public static final int WILDCARD_SUPER = 2;
- public static final int WILDCARD_UNBOUND = 3;
- public static final int WILDCARD_NO = 4;
-
- public int type;
-
- public int arraydim;
-
- public String value;
-
-
- private List<GenericType> enclosingClasses = new ArrayList<GenericType>();
-
- private List<GenericType> arguments = new ArrayList<GenericType>();
-
- private List<Integer> wildcards = new ArrayList<Integer>();
-
-
- public GenericType(int type, int arraydim, String value) {
- this.type = type;
- this.arraydim = arraydim;
- this.value = value;
- }
-
-
- public GenericType(String strtype) {
-
- parseSignature(strtype);
-
- }
-
- private void parseSignature(String sig) {
-
- int index = 0;
- while(index < sig.length()) {
-
- switch(sig.charAt(index)){
- case '[':
- arraydim++;
- break;
- case 'T':
- type = CodeConstants.TYPE_GENVAR;
- value = sig.substring(index+1, sig.length()-1);
- return;
- case 'L':
- type = CodeConstants.TYPE_OBJECT;
- sig = sig.substring(index+1, sig.length()-1);
-
- for(;;) {
- String cl = getNextClassSignature(sig);
-
- String name = cl;
- String args = null;
-
- int argfrom = cl.indexOf("<");
- if(argfrom >= 0) {
- name = cl.substring(0, argfrom);
- args = cl.substring(argfrom+1, cl.length()-1);
- }
-
- if(cl.length() < sig.length()) {
- sig = sig.substring(cl.length()+1); // skip '.'
- GenericType type = new GenericType(CodeConstants.TYPE_OBJECT, 0, name);
- parseArgumentsList(args, type);
- enclosingClasses.add(type);
- } else {
- value = name;
- parseArgumentsList(args, this);
- break;
- }
- }
-
- return;
- default:
- value = sig.substring(index, index+1);
- type = getType(value.charAt(0));
- }
-
- index++;
- }
-
- }
-
- private String getNextClassSignature(String value) {
-
- int counter = 0;
- int index = 0;
-
- loop:
- while(index < value.length()) {
- switch(value.charAt(index)) {
- case '<':
- counter++;
- break;
- case '>':
- counter--;
- break;
- case '.':
- if(counter == 0) {
- break loop;
- }
- }
-
- index++;
- }
-
- return value.substring(0, index);
- }
-
- private void parseArgumentsList(String value, GenericType type) {
-
- if(value == null) {
- return;
- }
-
- while(value.length() > 0) {
-
- String tstr = getNextType(value);
- int len = tstr.length();
- int wildcard = WILDCARD_NO;
-
- switch(tstr.charAt(0)) {
- case '*':
- wildcard = WILDCARD_UNBOUND;
- break;
- case '+':
- wildcard = WILDCARD_EXTENDS;
- break;
- case '-':
- wildcard = WILDCARD_SUPER;
- break;
- }
-
- type.getWildcards().add(wildcard);
-
- if(wildcard != WILDCARD_NO) {
- tstr = tstr.substring(1);
- }
-
- type.getArguments().add(tstr.length() == 0?null:new GenericType(tstr));
-
- value = value.substring(len);
- }
-
- }
-
- public static String getNextType(String value) {
-
- int counter = 0;
- int index = 0;
-
- boolean contmode = false;
-
- loop:
- while(index < value.length()) {
- switch(value.charAt(index)) {
- case '*':
- if(!contmode) {
- break loop;
- }
- break;
- case 'L':
- case 'T':
- if(!contmode) {
- contmode = true;
- }
- case '[':
- case '+':
- case '-':
- break;
- default:
- if(!contmode) {
- break loop;
- }
- break;
- case '<':
- counter++;
- break;
- case '>':
- counter--;
- break;
- case ';':
- if(counter == 0) {
- break loop;
- }
- }
-
- index++;
- }
-
- return value.substring(0, index+1);
- }
-
- private int getType(char c) {
- switch(c) {
- case 'B':
- return CodeConstants.TYPE_BYTE;
- case 'C':
- return CodeConstants.TYPE_CHAR;
- case 'D':
- return CodeConstants.TYPE_DOUBLE;
- case 'F':
- return CodeConstants.TYPE_FLOAT;
- case 'I':
- return CodeConstants.TYPE_INT;
- case 'J':
- return CodeConstants.TYPE_LONG;
- case 'S':
- return CodeConstants.TYPE_SHORT;
- case 'Z':
- return CodeConstants.TYPE_BOOLEAN;
- case 'V':
- return CodeConstants.TYPE_VOID;
- case 'G':
- return CodeConstants.TYPE_GROUP2EMPTY;
- case 'N':
- return CodeConstants.TYPE_NOTINITIALIZED;
- case 'A':
- return CodeConstants.TYPE_ADDRESS;
- case 'X':
- return CodeConstants.TYPE_BYTECHAR;
- case 'Y':
- return CodeConstants.TYPE_SHORTCHAR;
- case 'U':
- return CodeConstants.TYPE_UNKNOWN;
- default:
- throw new RuntimeException("Invalid type");
- }
- }
-
-
- public List<GenericType> getArguments() {
- return arguments;
- }
-
-
- public List<GenericType> getEnclosingClasses() {
- return enclosingClasses;
- }
-
-
- public List<Integer> getWildcards() {
- return wildcards;
- }
-
+
+ public static final int WILDCARD_EXTENDS = 1;
+ public static final int WILDCARD_SUPER = 2;
+ public static final int WILDCARD_UNBOUND = 3;
+ public static final int WILDCARD_NO = 4;
+
+ public int type;
+
+ public int arraydim;
+
+ public String value;
+
+
+ private List<GenericType> enclosingClasses = new ArrayList<GenericType>();
+
+ private List<GenericType> arguments = new ArrayList<GenericType>();
+
+ private List<Integer> wildcards = new ArrayList<Integer>();
+
+
+ public GenericType(int type, int arraydim, String value) {
+ this.type = type;
+ this.arraydim = arraydim;
+ this.value = value;
+ }
+
+
+ public GenericType(String strtype) {
+
+ parseSignature(strtype);
+ }
+
+ private void parseSignature(String sig) {
+
+ int index = 0;
+ while (index < sig.length()) {
+
+ switch (sig.charAt(index)) {
+ case '[':
+ arraydim++;
+ break;
+ case 'T':
+ type = CodeConstants.TYPE_GENVAR;
+ value = sig.substring(index + 1, sig.length() - 1);
+ return;
+ case 'L':
+ type = CodeConstants.TYPE_OBJECT;
+ sig = sig.substring(index + 1, sig.length() - 1);
+
+ for (; ; ) {
+ String cl = getNextClassSignature(sig);
+
+ String name = cl;
+ String args = null;
+
+ int argfrom = cl.indexOf("<");
+ if (argfrom >= 0) {
+ name = cl.substring(0, argfrom);
+ args = cl.substring(argfrom + 1, cl.length() - 1);
+ }
+
+ if (cl.length() < sig.length()) {
+ sig = sig.substring(cl.length() + 1); // skip '.'
+ GenericType type = new GenericType(CodeConstants.TYPE_OBJECT, 0, name);
+ parseArgumentsList(args, type);
+ enclosingClasses.add(type);
+ }
+ else {
+ value = name;
+ parseArgumentsList(args, this);
+ break;
+ }
+ }
+
+ return;
+ default:
+ value = sig.substring(index, index + 1);
+ type = getType(value.charAt(0));
+ }
+
+ index++;
+ }
+ }
+
+ private String getNextClassSignature(String value) {
+
+ int counter = 0;
+ int index = 0;
+
+ loop:
+ while (index < value.length()) {
+ switch (value.charAt(index)) {
+ case '<':
+ counter++;
+ break;
+ case '>':
+ counter--;
+ break;
+ case '.':
+ if (counter == 0) {
+ break loop;
+ }
+ }
+
+ index++;
+ }
+
+ return value.substring(0, index);
+ }
+
+ private void parseArgumentsList(String value, GenericType type) {
+
+ if (value == null) {
+ return;
+ }
+
+ while (value.length() > 0) {
+
+ String tstr = getNextType(value);
+ int len = tstr.length();
+ int wildcard = WILDCARD_NO;
+
+ switch (tstr.charAt(0)) {
+ case '*':
+ wildcard = WILDCARD_UNBOUND;
+ break;
+ case '+':
+ wildcard = WILDCARD_EXTENDS;
+ break;
+ case '-':
+ wildcard = WILDCARD_SUPER;
+ break;
+ }
+
+ type.getWildcards().add(wildcard);
+
+ if (wildcard != WILDCARD_NO) {
+ tstr = tstr.substring(1);
+ }
+
+ type.getArguments().add(tstr.length() == 0 ? null : new GenericType(tstr));
+
+ value = value.substring(len);
+ }
+ }
+
+ public static String getNextType(String value) {
+
+ int counter = 0;
+ int index = 0;
+
+ boolean contmode = false;
+
+ loop:
+ while (index < value.length()) {
+ switch (value.charAt(index)) {
+ case '*':
+ if (!contmode) {
+ break loop;
+ }
+ break;
+ case 'L':
+ case 'T':
+ if (!contmode) {
+ contmode = true;
+ }
+ case '[':
+ case '+':
+ case '-':
+ break;
+ default:
+ if (!contmode) {
+ break loop;
+ }
+ break;
+ case '<':
+ counter++;
+ break;
+ case '>':
+ counter--;
+ break;
+ case ';':
+ if (counter == 0) {
+ break loop;
+ }
+ }
+
+ index++;
+ }
+
+ return value.substring(0, index + 1);
+ }
+
+ private int getType(char c) {
+ switch (c) {
+ case 'B':
+ return CodeConstants.TYPE_BYTE;
+ case 'C':
+ return CodeConstants.TYPE_CHAR;
+ case 'D':
+ return CodeConstants.TYPE_DOUBLE;
+ case 'F':
+ return CodeConstants.TYPE_FLOAT;
+ case 'I':
+ return CodeConstants.TYPE_INT;
+ case 'J':
+ return CodeConstants.TYPE_LONG;
+ case 'S':
+ return CodeConstants.TYPE_SHORT;
+ case 'Z':
+ return CodeConstants.TYPE_BOOLEAN;
+ case 'V':
+ return CodeConstants.TYPE_VOID;
+ case 'G':
+ return CodeConstants.TYPE_GROUP2EMPTY;
+ case 'N':
+ return CodeConstants.TYPE_NOTINITIALIZED;
+ case 'A':
+ return CodeConstants.TYPE_ADDRESS;
+ case 'X':
+ return CodeConstants.TYPE_BYTECHAR;
+ case 'Y':
+ return CodeConstants.TYPE_SHORTCHAR;
+ case 'U':
+ return CodeConstants.TYPE_UNKNOWN;
+ default:
+ throw new RuntimeException("Invalid type");
+ }
+ }
+
+
+ public List<GenericType> getArguments() {
+ return arguments;
+ }
+
+
+ public List<GenericType> getEnclosingClasses() {
+ return enclosingClasses;
+ }
+
+
+ public List<Integer> getWildcards() {
+ return wildcards;
+ }
}