[java, java-decompiler] type annotations in class files
Step 1: add top-level field/method/parameter annotations to stubs; include them in decompiled text.
This commit is contained in:
@@ -47,22 +47,31 @@ public class AnnotationExprent extends Exprent {
|
||||
buffer.append('@');
|
||||
buffer.append(DecompilerContext.getImportCollector().getShortName(ExprProcessor.buildJavaClassName(className)));
|
||||
|
||||
if (!parNames.isEmpty()) {
|
||||
int type = getAnnotationType();
|
||||
|
||||
if (type != ANNOTATION_MARKER) {
|
||||
buffer.append('(');
|
||||
if (getAnnotationType() == ANNOTATION_SINGLE_ELEMENT) {
|
||||
buffer.append(parValues.get(0).toJava(indent + 1, tracer));
|
||||
}
|
||||
else {
|
||||
for (int i = 0; i < parNames.size(); i++) {
|
||||
|
||||
boolean oneLiner = type == ANNOTATION_SINGLE_ELEMENT || indent < 0;
|
||||
|
||||
for (int i = 0; i < parNames.size(); i++) {
|
||||
if (!oneLiner) {
|
||||
buffer.appendLineSeparator().appendIndent(indent + 1);
|
||||
}
|
||||
|
||||
if (type != ANNOTATION_SINGLE_ELEMENT) {
|
||||
buffer.append(parNames.get(i));
|
||||
buffer.append(" = ");
|
||||
buffer.append(parValues.get(i).toJava(0, tracer));
|
||||
|
||||
if (i < parNames.size() - 1) {
|
||||
buffer.append(',');
|
||||
}
|
||||
}
|
||||
|
||||
buffer.append(parValues.get(i).toJava(0, tracer));
|
||||
|
||||
if (i < parNames.size() - 1) {
|
||||
buffer.append(',');
|
||||
}
|
||||
}
|
||||
|
||||
if (!oneLiner) {
|
||||
buffer.appendLineSeparator().appendIndent(indent);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* 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.modules.decompiler.exps;
|
||||
|
||||
public class TypeAnnotation {
|
||||
public static final int CLASS_TYPE_PARAMETER = 0x00;
|
||||
public static final int METHOD_TYPE_PARAMETER = 0x01;
|
||||
public static final int SUPER_TYPE_REFERENCE = 0x10;
|
||||
public static final int CLASS_TYPE_PARAMETER_BOUND = 0x11;
|
||||
public static final int METHOD_TYPE_PARAMETER_BOUND = 0x12;
|
||||
public static final int FIELD = 0x13;
|
||||
public static final int METHOD_RETURN_TYPE = 0x14;
|
||||
public static final int METHOD_RECEIVER = 0x15;
|
||||
public static final int METHOD_PARAMETER = 0x16;
|
||||
public static final int THROWS_REFERENCE = 0x17;
|
||||
public static final int LOCAL_VARIABLE = 0x40;
|
||||
public static final int RESOURCE_VARIABLE = 0x41;
|
||||
public static final int CATCH_CLAUSE = 0x42;
|
||||
public static final int EXPR_INSTANCEOF = 0x43;
|
||||
public static final int EXPR_NEW = 0x44;
|
||||
public static final int EXPR_CONSTRUCTOR_REF = 0x45;
|
||||
public static final int EXPR_METHOD_REF = 0x46;
|
||||
public static final int TYPE_ARG_CAST = 0x47;
|
||||
public static final int TYPE_ARG_CONSTRUCTOR_CALL = 0x48;
|
||||
public static final int TYPE_ARG_METHOD_CALL = 0x49;
|
||||
public static final int TYPE_ARG_CONSTRUCTOR_REF = 0x4A;
|
||||
public static final int TYPE_ARG_METHOD_REF = 0x4B;
|
||||
|
||||
private final int target;
|
||||
private final byte[] path;
|
||||
private final AnnotationExprent annotation;
|
||||
|
||||
public TypeAnnotation(int target, byte[] path, AnnotationExprent annotation) {
|
||||
this.target = target;
|
||||
this.path = path;
|
||||
this.annotation = annotation;
|
||||
}
|
||||
|
||||
public int getTargetType() {
|
||||
return target >> 24;
|
||||
}
|
||||
|
||||
public int getIndex() {
|
||||
return target & 0x0FFFF;
|
||||
}
|
||||
|
||||
public boolean isTopLevel() {
|
||||
return path == null;
|
||||
}
|
||||
|
||||
public AnnotationExprent getAnnotation() {
|
||||
return annotation;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user