Skip to content

Commit b7575a7

Browse files
committed
code cleanup; removing ability to use @j2sIgnore with constructors
1 parent 0423e38 commit b7575a7

File tree

1 file changed

+23
-38
lines changed

1 file changed

+23
-38
lines changed

sources/net.sf.j2s.core/src/net/sf/j2s/core/astvisitors/ASTScriptVisitor.java

Lines changed: 23 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,11 +1153,11 @@ public boolean visit(MethodDeclaration node) {
11531153

11541154
boolean isConstructor = node.isConstructor();
11551155
if (isConstructor) {
1156-
// TODO: This is not sufficient for variable args. We are not finding the correct constructor, only the first-stated
1157-
// For example, this(int...) and this(float...) will be wrong here.
1158-
// fortunately this only affects anonymous class definitions - BH
1159-
if (mBinding.getParameterTypes().length == 0 || mBinding.isVarargs()
1160-
&& (defaultConstructor == null)) {
1156+
// TODO: This is not sufficient for variable args. We are not
1157+
// finding the correct constructor, only the first-stated
1158+
// For example, this(int...) and this(float...) will be wrong here.
1159+
// fortunately this only affects anonymous class definitions - BH
1160+
if (mBinding.getParameterTypes().length == 0 || mBinding.isVarargs() && (defaultConstructor == null)) {
11611161
defaultConstructor = mBinding;
11621162
}
11631163
}
@@ -1171,8 +1171,8 @@ public boolean visit(MethodDeclaration node) {
11711171

11721172
boolean isNative = ((node.getModifiers() & Modifier.NATIVE) != 0);
11731173
if (node.getBody() == null && !isNative) {
1174-
//Abstract method
1175-
return false;
1174+
// Abstract method
1175+
return false;
11761176
}
11771177
String name = (isConstructor ? "construct" : getJ2SName(node.getName())) + getJ2SParamQualifier(null, mBinding);
11781178
buffer.append("\r\nClazz.newMethod$(C$, '").append(name).append("', ").append("function (");
@@ -1181,40 +1181,29 @@ public boolean visit(MethodDeclaration node) {
11811181
visitList(parameters, ", ");
11821182
buffer.append(") ");
11831183
if (node.isConstructor()) {
1184-
boolean hasSuperOrThis = false;
1185-
@SuppressWarnings("unchecked")
1186-
List<ASTNode> statements = node.getBody().statements();
1187-
if (statements.size() > 0) {
1188-
ASTNode firstStatement = statements.get(0);
1189-
if (firstStatement instanceof SuperConstructorInvocation
1190-
|| firstStatement instanceof ConstructorInvocation) {
1191-
hasSuperOrThis = true;
1192-
}
1193-
}
11941184
// BH @j2sIgnoreSuperConstructor removed from options
11951185
// as it is too risky to do this -- lose all initialization.
1196-
if (hasSuperOrThis) {
1197-
if (!checkJ2STags(node, true))
1198-
node.getBody().accept(this);
1199-
} else {
1200-
IMethodBinding binding = node.resolveBinding();
1201-
boolean existedSuperClass = binding != null && hasSuperClass(binding.getDeclaringClass());
1186+
@SuppressWarnings("unchecked")
1187+
List<ASTNode> statements = node.getBody().statements();
1188+
ASTNode firstStatement = statements.get(0);
1189+
if (statements.size() == 0 || !(firstStatement instanceof SuperConstructorInvocation)
1190+
&& !(firstStatement instanceof ConstructorInvocation)) {
12021191
buffer.append("{\r\n");
1203-
if (existedSuperClass) {
1192+
IMethodBinding binding = node.resolveBinding();
1193+
boolean needSuperClassCall = binding != null && hasSuperClass(binding.getDeclaringClass());
1194+
if (needSuperClassCall) {
12041195
addSuperConstructor(null, null);
12051196
} else {
12061197
addCallInit();
12071198
}
1208-
if (checkJ2STags(node, false)) {
1209-
buffer.append("}");
1210-
} else {
1211-
blockLevel++;
1212-
visitList(statements, "");
1213-
endVisit(node.getBody());
1214-
}
1199+
blockLevel++;
1200+
visitList(statements, "");
1201+
endVisit(node.getBody());
1202+
} else {
1203+
node.getBody().accept(this);
12151204
}
12161205
} else if (node.getBody() == null) {
1217-
// not a constructor
1206+
// not a constructor and no body -- possibly native or an interface
12181207
blockLevel++;
12191208
if (!checkJ2STags(node, true)) {
12201209
buffer.append("{\r\n");
@@ -1323,12 +1312,8 @@ public void endVisit(MethodDeclaration node) {
13231312
* Check to see whether there are @j2s* and append sources to buffer
13241313
*/
13251314
private boolean checkJ2STags(MethodDeclaration node, boolean needScope) {
1326-
String prefix = "{\r\n";
1327-
String suffix = "\r\n}";
1328-
if (!needScope) {
1329-
prefix = "";
1330-
suffix = "";
1331-
}
1315+
String prefix = (needScope ? "{\r\n" : "");
1316+
String suffix = (needScope ? "\r\n}" : "");
13321317
boolean read = false;
13331318
if (isDebugging()) {
13341319
read = readSources(node, "@j2sDebug", prefix, suffix, false);

0 commit comments

Comments
 (0)