Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified sources/net.sf.j2s.core/dist/swingjs/SwingJS-site.zip
Binary file not shown.
Binary file modified sources/net.sf.j2s.core/dist/swingjs/net.sf.j2s.core.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion sources/net.sf.j2s.core/dist/swingjs/timestamp
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20181007153006
20181020060436
Binary file modified sources/net.sf.j2s.core/dist/swingjs/ver/3.2.4/SwingJS-site.zip
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion sources/net.sf.j2s.core/dist/swingjs/ver/3.2.4/timestamp
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20181007153006
20181020060436
127 changes: 91 additions & 36 deletions sources/net.sf.j2s.core/src/net/sf/j2s/core/Java2ScriptVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -2500,7 +2500,7 @@ private static boolean isObjectOrNull(ITypeBinding type) {
*/
class TrailingBuffer {

private StringBuffer buf;
StringBuffer buf;
private String added = "";

boolean hasAssert;
Expand Down Expand Up @@ -4239,7 +4239,7 @@ private boolean isStaticBinding(IVariableBinding varBinding) {
return (isStatic(varBinding) && varBinding.getDeclaringClass() != null);
}

private static String getJavaClassNameQualified(ITypeBinding binding) {
static String getJavaClassNameQualified(ITypeBinding binding) {
String binaryName = null, bindingKey;

// about binding.isLocal()
Expand Down Expand Up @@ -4308,7 +4308,7 @@ private String getMyJavaClassNameLambda(boolean andIncrement) {
+ (andIncrement ? ++lambdaCount : lambdaCount);
}

private static String stripJavaLang(String name) {
static String stripJavaLang(String name) {
// shorten java.lang.XXX.YYY but not java.lang.xxx.YYY
return (!name.startsWith("java.lang.") || name.equals("java.lang.Object")
|| name.length() > 10 && !Character.isUpperCase(name.charAt(10)) ? name : name.substring(10));
Expand Down Expand Up @@ -5065,7 +5065,7 @@ private static String j2sGetParamCode(ITypeBinding binding, boolean addAAA, bool
* @param qName
* @return
*/
private static String removeBracketsAndFixNullPackageName(String qName) {
static String removeBracketsAndFixNullPackageName(String qName) {
if (qName == null)
return null;
qName = NameMapper.fixPackageName(qName);
Expand Down Expand Up @@ -5334,6 +5334,7 @@ private Object checkAnnotations(BodyDeclaration node, String tagName) {
}
List<?> modifiers = node.modifiers();
if (modifiers != null && modifiers.size() > 0) {

for (Iterator<?> iter = modifiers.iterator(); iter.hasNext();) {
Object obj = iter.next();
if (obj instanceof Annotation) {
Expand All @@ -5348,14 +5349,13 @@ private Object checkAnnotations(BodyDeclaration node, String tagName) {
}
} else if (!qName.equals("Override")
&& !qName.equals("Deprecated")
&& !qName.equals("Suppress")
&& !qName.startsWith("Suppress")
&& !qName.equals("XmlTransient")
) {
if (class_annotations == null)
class_annotations = new ArrayList<ClassAnnotation>();
ClassAnnotation ann = ClassAnnotation.newAnnotation(qName, annotation, node);
if (ann != null)
class_annotations.add(ann);
ClassAnnotation ann = new ClassAnnotation(qName, annotation, node);
class_annotations.add(ann);
}
}
}
Expand Down Expand Up @@ -6128,50 +6128,105 @@ static class ClassAnnotation {
protected Annotation annotation;
private String qName;

public static ClassAnnotation newAnnotation(String qName, Annotation annotation, BodyDeclaration node) {

// TODO Auto-generated method stub
return null;
}

protected ClassAnnotation(String qName, Annotation annotation, BodyDeclaration node) {
System.out.println(">>>>" + qName + " " + annotation.getClass().getName() + " " + annotation);
this.qName = qName;
this.annotation = annotation;
this.node = node;
}

@SuppressWarnings("unchecked")
public static void addClassAnnotations(List<ClassAnnotation> class_annotations, TrailingBuffer trailingBuffer) {
if (class_annotations == null)
return;
int pt = 0;
int pt = 0, ptBuf = 0;
ASTNode lastNode = null;
List<?> fragments = null;
for (int i = 0; i < class_annotations.size(); i++) {
ClassAnnotation a = class_annotations.get(i);
String str = a.annotation.toString();
if (str.startsWith("@SuppressWarnings"))
continue;
String nodeType = a.qName;
String varName = null;
if (a.node instanceof FieldDeclaration) {
FieldDeclaration field = (FieldDeclaration) a.node;
List<?> fragments = field.fragments();
VariableDeclarationFragment identifier = (VariableDeclarationFragment) fragments.get(0);
IVariableBinding var = identifier.resolveBinding();
nodeType = (var.getType().isArray() ? "[array]" : field.getType().toString());
varName = var.getName();
} else if (a.node instanceof MethodDeclaration) {
MethodDeclaration method = (MethodDeclaration) a.node;
IMethodBinding var = method.resolveBinding();
ITypeBinding type = var.getReturnType();
nodeType = (type.isArray() ? "[array]" : type.getName());
varName = "M:" + var.getName();
if (a.annotation instanceof SingleMemberAnnotation) {
// resolve classes
List<ASTNode> expressions = null;
Expression e = ((SingleMemberAnnotation) a.annotation).getValue();
if (e instanceof TypeLiteral) {
expressions = new ArrayList<ASTNode>();
expressions.add(e);
} else if (e instanceof ArrayInitializer) {
expressions = ((ArrayInitializer) e).expressions();
}
if (expressions != null) {
str = str.substring(0, str.indexOf("(") + 1);
int n = expressions.size();
String sep = (n > 1 ? "{" : "");
for (int j = 0; j < n; j++) {
str += sep;
e = (Expression) expressions.get(j);
if (e instanceof TypeLiteral) {
str += ((TypeLiteral) e).getType().resolveBinding().getQualifiedName() + ".class";
} else {
str += e.toString();
}
sep = ",";
}
str += (n > 1 ? "})" : ")");
}
}
if (a.node == lastNode) {
trailingBuffer.append(",");
} else {
lastNode = a.node;
String varName = null;
ITypeBinding type = null;
// time to pick up the fragments
addTrailingFragments(fragments, trailingBuffer, ptBuf);
fragments = null;
if (a.node instanceof TypeDeclaration) {
type = ((TypeDeclaration) a.node).resolveBinding();
} else if (a.node instanceof FieldDeclaration) {
FieldDeclaration field = (FieldDeclaration) a.node;
fragments = field.fragments();
VariableDeclarationFragment identifier = (VariableDeclarationFragment) fragments.get(0);
IVariableBinding var = identifier.resolveBinding();
varName = var.getName();
type = var.getType();
} else if (a.node instanceof MethodDeclaration) {
MethodDeclaration method = (MethodDeclaration) a.node;
IMethodBinding var = method.resolveBinding();
varName = "M:" + var.getName();
type = var.getReturnType();
}
String className = (type == null ? null
: stripJavaLang(
//NameMapper.checkClassReplacement(
//removeBracketsAndFixNullPackageName(
NameMapper.fixPackageName(
getJavaClassNameQualified(type)
)
//))
));
trailingBuffer.append(pt++ == 0 ? "C$.__ANN__ = [[[" : "]],\n [[");
trailingBuffer.append((varName == null ? null : "'" + varName + "'"));
ptBuf = trailingBuffer.buf.length();
trailingBuffer.append(",'" + className + "'],[");
}
trailingBuffer.append(pt++ == 0 ? "C$.__ANN__ = [\n " : " ,");
trailingBuffer.append("[" + (varName == null ? null : "'" + varName + "'")
+ ",'" + nodeType + "','" + str + "']\n");
trailingBuffer.append("'" + str + "'");
}
addTrailingFragments(fragments, trailingBuffer, ptBuf);
if (pt > 0)
trailingBuffer.append("];\n");
trailingBuffer.append("]]];\n");
}

private static void addTrailingFragments(List<?> fragments, TrailingBuffer trailingBuffer, int ptBuf) {
if (fragments == null || fragments.size() == 0)
return;
String line = trailingBuffer.buf.substring(ptBuf);
for (int f = 1; f < fragments.size(); f++) {
VariableDeclarationFragment identifier = (VariableDeclarationFragment) fragments.get(f);
IVariableBinding var = identifier.resolveBinding();
trailingBuffer.append("]],\n [['" + var.getName() + "'");
trailingBuffer.append(line);
}
}

}
Expand Down
12 changes: 0 additions & 12 deletions sources/net.sf.j2s.java.core/.settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,7 @@ org.eclipse.jdt.core.compiler.annotation.nonnullbydefault.secondary=
org.eclipse.jdt.core.compiler.annotation.nullable=org.eclipse.jdt.annotation.Nullable
org.eclipse.jdt.core.compiler.annotation.nullable.secondary=
org.eclipse.jdt.core.compiler.annotation.nullanalysis=disabled
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.autoboxing=ignore
org.eclipse.jdt.core.compiler.problem.comparingIdentical=warning
org.eclipse.jdt.core.compiler.problem.deadCode=warning
Expand All @@ -26,7 +17,6 @@ org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled
org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled
org.eclipse.jdt.core.compiler.problem.discouragedReference=warning
org.eclipse.jdt.core.compiler.problem.emptyStatement=ignore
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.explicitlyClosedAutoCloseable=ignore
org.eclipse.jdt.core.compiler.problem.fallthroughCase=ignore
org.eclipse.jdt.core.compiler.problem.fatalOptionalError=disabled
Expand Down Expand Up @@ -103,5 +93,3 @@ org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning
org.eclipse.jdt.core.compiler.problem.unusedTypeParameter=ignore
org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning
org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8
Binary file modified sources/net.sf.j2s.java.core/dist/SwingJS-site.zip
Binary file not shown.
Loading