Skip to content

Commit 7948708

Browse files
authored
Merge pull request #67 from BobHanson/hanson1
JAXB marshalling/unmarshalling working; marginally tested @XmlAccessorType @XmlAttribute @xmlelement @XmlJavaTypeAdapter @XmlRootElement @XmlSeeAlso @XmlType @XmlValue not implemented: @xmlid, @XmlEnum, @XmlEnumValue
2 parents 2207f32 + 48cd462 commit 7948708

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+10733
-6371
lines changed
54.7 KB
Binary file not shown.
1.11 KB
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20181007153006
1+
20181020060436
54.7 KB
Binary file not shown.
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20181007153006
1+
20181020060436

sources/net.sf.j2s.core/src/net/sf/j2s/core/Java2ScriptVisitor.java

Lines changed: 91 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2500,7 +2500,7 @@ private static boolean isObjectOrNull(ITypeBinding type) {
25002500
*/
25012501
class TrailingBuffer {
25022502

2503-
private StringBuffer buf;
2503+
StringBuffer buf;
25042504
private String added = "";
25052505

25062506
boolean hasAssert;
@@ -4239,7 +4239,7 @@ private boolean isStaticBinding(IVariableBinding varBinding) {
42394239
return (isStatic(varBinding) && varBinding.getDeclaringClass() != null);
42404240
}
42414241

4242-
private static String getJavaClassNameQualified(ITypeBinding binding) {
4242+
static String getJavaClassNameQualified(ITypeBinding binding) {
42434243
String binaryName = null, bindingKey;
42444244

42454245
// about binding.isLocal()
@@ -4308,7 +4308,7 @@ private String getMyJavaClassNameLambda(boolean andIncrement) {
43084308
+ (andIncrement ? ++lambdaCount : lambdaCount);
43094309
}
43104310

4311-
private static String stripJavaLang(String name) {
4311+
static String stripJavaLang(String name) {
43124312
// shorten java.lang.XXX.YYY but not java.lang.xxx.YYY
43134313
return (!name.startsWith("java.lang.") || name.equals("java.lang.Object")
43144314
|| name.length() > 10 && !Character.isUpperCase(name.charAt(10)) ? name : name.substring(10));
@@ -5065,7 +5065,7 @@ private static String j2sGetParamCode(ITypeBinding binding, boolean addAAA, bool
50655065
* @param qName
50665066
* @return
50675067
*/
5068-
private static String removeBracketsAndFixNullPackageName(String qName) {
5068+
static String removeBracketsAndFixNullPackageName(String qName) {
50695069
if (qName == null)
50705070
return null;
50715071
qName = NameMapper.fixPackageName(qName);
@@ -5334,6 +5334,7 @@ private Object checkAnnotations(BodyDeclaration node, String tagName) {
53345334
}
53355335
List<?> modifiers = node.modifiers();
53365336
if (modifiers != null && modifiers.size() > 0) {
5337+
53375338
for (Iterator<?> iter = modifiers.iterator(); iter.hasNext();) {
53385339
Object obj = iter.next();
53395340
if (obj instanceof Annotation) {
@@ -5348,14 +5349,13 @@ private Object checkAnnotations(BodyDeclaration node, String tagName) {
53485349
}
53495350
} else if (!qName.equals("Override")
53505351
&& !qName.equals("Deprecated")
5351-
&& !qName.equals("Suppress")
5352+
&& !qName.startsWith("Suppress")
53525353
&& !qName.equals("XmlTransient")
53535354
) {
53545355
if (class_annotations == null)
53555356
class_annotations = new ArrayList<ClassAnnotation>();
5356-
ClassAnnotation ann = ClassAnnotation.newAnnotation(qName, annotation, node);
5357-
if (ann != null)
5358-
class_annotations.add(ann);
5357+
ClassAnnotation ann = new ClassAnnotation(qName, annotation, node);
5358+
class_annotations.add(ann);
53595359
}
53605360
}
53615361
}
@@ -6128,50 +6128,105 @@ static class ClassAnnotation {
61286128
protected Annotation annotation;
61296129
private String qName;
61306130

6131-
public static ClassAnnotation newAnnotation(String qName, Annotation annotation, BodyDeclaration node) {
6132-
6133-
// TODO Auto-generated method stub
6134-
return null;
6135-
}
6136-
61376131
protected ClassAnnotation(String qName, Annotation annotation, BodyDeclaration node) {
61386132
System.out.println(">>>>" + qName + " " + annotation.getClass().getName() + " " + annotation);
61396133
this.qName = qName;
61406134
this.annotation = annotation;
61416135
this.node = node;
61426136
}
61436137

6138+
@SuppressWarnings("unchecked")
61446139
public static void addClassAnnotations(List<ClassAnnotation> class_annotations, TrailingBuffer trailingBuffer) {
61456140
if (class_annotations == null)
61466141
return;
6147-
int pt = 0;
6142+
int pt = 0, ptBuf = 0;
6143+
ASTNode lastNode = null;
6144+
List<?> fragments = null;
61486145
for (int i = 0; i < class_annotations.size(); i++) {
61496146
ClassAnnotation a = class_annotations.get(i);
61506147
String str = a.annotation.toString();
6151-
if (str.startsWith("@SuppressWarnings"))
6152-
continue;
6153-
String nodeType = a.qName;
6154-
String varName = null;
6155-
if (a.node instanceof FieldDeclaration) {
6156-
FieldDeclaration field = (FieldDeclaration) a.node;
6157-
List<?> fragments = field.fragments();
6158-
VariableDeclarationFragment identifier = (VariableDeclarationFragment) fragments.get(0);
6159-
IVariableBinding var = identifier.resolveBinding();
6160-
nodeType = (var.getType().isArray() ? "[array]" : field.getType().toString());
6161-
varName = var.getName();
6162-
} else if (a.node instanceof MethodDeclaration) {
6163-
MethodDeclaration method = (MethodDeclaration) a.node;
6164-
IMethodBinding var = method.resolveBinding();
6165-
ITypeBinding type = var.getReturnType();
6166-
nodeType = (type.isArray() ? "[array]" : type.getName());
6167-
varName = "M:" + var.getName();
6148+
if (a.annotation instanceof SingleMemberAnnotation) {
6149+
// resolve classes
6150+
List<ASTNode> expressions = null;
6151+
Expression e = ((SingleMemberAnnotation) a.annotation).getValue();
6152+
if (e instanceof TypeLiteral) {
6153+
expressions = new ArrayList<ASTNode>();
6154+
expressions.add(e);
6155+
} else if (e instanceof ArrayInitializer) {
6156+
expressions = ((ArrayInitializer) e).expressions();
6157+
}
6158+
if (expressions != null) {
6159+
str = str.substring(0, str.indexOf("(") + 1);
6160+
int n = expressions.size();
6161+
String sep = (n > 1 ? "{" : "");
6162+
for (int j = 0; j < n; j++) {
6163+
str += sep;
6164+
e = (Expression) expressions.get(j);
6165+
if (e instanceof TypeLiteral) {
6166+
str += ((TypeLiteral) e).getType().resolveBinding().getQualifiedName() + ".class";
6167+
} else {
6168+
str += e.toString();
6169+
}
6170+
sep = ",";
6171+
}
6172+
str += (n > 1 ? "})" : ")");
6173+
}
6174+
}
6175+
if (a.node == lastNode) {
6176+
trailingBuffer.append(",");
6177+
} else {
6178+
lastNode = a.node;
6179+
String varName = null;
6180+
ITypeBinding type = null;
6181+
// time to pick up the fragments
6182+
addTrailingFragments(fragments, trailingBuffer, ptBuf);
6183+
fragments = null;
6184+
if (a.node instanceof TypeDeclaration) {
6185+
type = ((TypeDeclaration) a.node).resolveBinding();
6186+
} else if (a.node instanceof FieldDeclaration) {
6187+
FieldDeclaration field = (FieldDeclaration) a.node;
6188+
fragments = field.fragments();
6189+
VariableDeclarationFragment identifier = (VariableDeclarationFragment) fragments.get(0);
6190+
IVariableBinding var = identifier.resolveBinding();
6191+
varName = var.getName();
6192+
type = var.getType();
6193+
} else if (a.node instanceof MethodDeclaration) {
6194+
MethodDeclaration method = (MethodDeclaration) a.node;
6195+
IMethodBinding var = method.resolveBinding();
6196+
varName = "M:" + var.getName();
6197+
type = var.getReturnType();
6198+
}
6199+
String className = (type == null ? null
6200+
: stripJavaLang(
6201+
//NameMapper.checkClassReplacement(
6202+
//removeBracketsAndFixNullPackageName(
6203+
NameMapper.fixPackageName(
6204+
getJavaClassNameQualified(type)
6205+
)
6206+
//))
6207+
));
6208+
trailingBuffer.append(pt++ == 0 ? "C$.__ANN__ = [[[" : "]],\n [[");
6209+
trailingBuffer.append((varName == null ? null : "'" + varName + "'"));
6210+
ptBuf = trailingBuffer.buf.length();
6211+
trailingBuffer.append(",'" + className + "'],[");
61686212
}
6169-
trailingBuffer.append(pt++ == 0 ? "C$.__ANN__ = [\n " : " ,");
6170-
trailingBuffer.append("[" + (varName == null ? null : "'" + varName + "'")
6171-
+ ",'" + nodeType + "','" + str + "']\n");
6213+
trailingBuffer.append("'" + str + "'");
61726214
}
6215+
addTrailingFragments(fragments, trailingBuffer, ptBuf);
61736216
if (pt > 0)
6174-
trailingBuffer.append("];\n");
6217+
trailingBuffer.append("]]];\n");
6218+
}
6219+
6220+
private static void addTrailingFragments(List<?> fragments, TrailingBuffer trailingBuffer, int ptBuf) {
6221+
if (fragments == null || fragments.size() == 0)
6222+
return;
6223+
String line = trailingBuffer.buf.substring(ptBuf);
6224+
for (int f = 1; f < fragments.size(); f++) {
6225+
VariableDeclarationFragment identifier = (VariableDeclarationFragment) fragments.get(f);
6226+
IVariableBinding var = identifier.resolveBinding();
6227+
trailingBuffer.append("]],\n [['" + var.getName() + "'");
6228+
trailingBuffer.append(line);
6229+
}
61756230
}
61766231

61776232
}

sources/net.sf.j2s.java.core/.settings/org.eclipse.jdt.core.prefs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,7 @@ org.eclipse.jdt.core.compiler.annotation.nonnullbydefault.secondary=
88
org.eclipse.jdt.core.compiler.annotation.nullable=org.eclipse.jdt.annotation.Nullable
99
org.eclipse.jdt.core.compiler.annotation.nullable.secondary=
1010
org.eclipse.jdt.core.compiler.annotation.nullanalysis=disabled
11-
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
12-
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
13-
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
14-
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
15-
org.eclipse.jdt.core.compiler.compliance=1.8
16-
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
17-
org.eclipse.jdt.core.compiler.debug.localVariable=generate
18-
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
1911
org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning
20-
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
2112
org.eclipse.jdt.core.compiler.problem.autoboxing=ignore
2213
org.eclipse.jdt.core.compiler.problem.comparingIdentical=warning
2314
org.eclipse.jdt.core.compiler.problem.deadCode=warning
@@ -26,7 +17,6 @@ org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled
2617
org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled
2718
org.eclipse.jdt.core.compiler.problem.discouragedReference=warning
2819
org.eclipse.jdt.core.compiler.problem.emptyStatement=ignore
29-
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
3020
org.eclipse.jdt.core.compiler.problem.explicitlyClosedAutoCloseable=ignore
3121
org.eclipse.jdt.core.compiler.problem.fallthroughCase=ignore
3222
org.eclipse.jdt.core.compiler.problem.fatalOptionalError=disabled
@@ -103,5 +93,3 @@ org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning
10393
org.eclipse.jdt.core.compiler.problem.unusedTypeParameter=ignore
10494
org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning
10595
org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
106-
org.eclipse.jdt.core.compiler.release=disabled
107-
org.eclipse.jdt.core.compiler.source=1.8
27.3 KB
Binary file not shown.

0 commit comments

Comments
 (0)