Skip to content

Commit 15aa520

Browse files
author
zhourenjian
committed
Support @j2s* annotation
Fixed bug that class dependencies are not included for those methods marked as "@j2sIgnore"
1 parent c865d21 commit 15aa520

File tree

4 files changed

+357
-239
lines changed

4 files changed

+357
-239
lines changed

src/net/sf/j2s/core/astvisitors/ASTJ2SDocVisitor.java

Lines changed: 100 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,14 @@
1717
import java.util.regex.Pattern;
1818

1919
import org.eclipse.jdt.core.dom.ASTNode;
20+
import org.eclipse.jdt.core.dom.Annotation;
2021
import org.eclipse.jdt.core.dom.Block;
2122
import org.eclipse.jdt.core.dom.BodyDeclaration;
2223
import org.eclipse.jdt.core.dom.CatchClause;
2324
import org.eclipse.jdt.core.dom.Comment;
2425
import org.eclipse.jdt.core.dom.CompilationUnit;
26+
import org.eclipse.jdt.core.dom.IAnnotationBinding;
27+
import org.eclipse.jdt.core.dom.IMemberValuePairBinding;
2528
import org.eclipse.jdt.core.dom.IMethodBinding;
2629
import org.eclipse.jdt.core.dom.ITypeBinding;
2730
import org.eclipse.jdt.core.dom.IfStatement;
@@ -193,6 +196,82 @@ private void visitJavadocJ2SSource(TagElement tagEl) {
193196
}
194197
buffer.append(fixCommentBlock(buf.toString()));
195198
}
199+
/*
200+
* Read JavaScript sources from @j2sNative, @J2SPrefix or others
201+
*/
202+
boolean readSources(BodyDeclaration node, String tagName, String prefix, String suffix, boolean both) {
203+
boolean existed = false;
204+
Javadoc javadoc = node.getJavadoc();
205+
if (javadoc != null) {
206+
List tags = javadoc.tags();
207+
if (tags.size() != 0) {
208+
for (Iterator iter = tags.iterator(); iter.hasNext();) {
209+
TagElement tagEl = (TagElement) iter.next();
210+
if (tagName.equals(tagEl.getTagName())) {
211+
if (tagEl != null) {
212+
List fragments = tagEl.fragments();
213+
StringBuffer buf = new StringBuffer();
214+
boolean isFirstLine = true;
215+
for (Iterator iterator = fragments.iterator(); iterator
216+
.hasNext();) {
217+
TextElement commentEl = (TextElement) iterator.next();
218+
String text = commentEl.getText().trim();
219+
if (isFirstLine) {
220+
if (text.length() == 0) {
221+
continue;
222+
}
223+
}
224+
buf.append(text);
225+
buf.append("\r\n");
226+
}
227+
buffer.append(prefix + buf.toString().trim() + suffix);
228+
existed = true;
229+
}
230+
}
231+
}
232+
}
233+
}
234+
if (existed && !both) {
235+
return existed;
236+
}
237+
List modifiers = node.modifiers();
238+
for (Iterator iter = modifiers.iterator(); iter.hasNext();) {
239+
Object obj = (Object) iter.next();
240+
if (obj instanceof Annotation) {
241+
Annotation annotation = (Annotation) obj;
242+
String qName = annotation.getTypeName().getFullyQualifiedName();
243+
int index = qName.indexOf("J2S");
244+
if (index != -1) {
245+
String annName = qName.substring(index);
246+
annName = annName.replaceFirst("J2S", "@j2s");
247+
if (annName.startsWith(tagName)) {
248+
StringBuffer buf = new StringBuffer();
249+
IAnnotationBinding annotationBinding = annotation.resolveAnnotationBinding();
250+
if (annotationBinding != null) {
251+
IMemberValuePairBinding[] valuePairs = annotationBinding.getAllMemberValuePairs();
252+
if (valuePairs != null && valuePairs.length > 0) {
253+
for (int i = 0; i < valuePairs.length; i++) {
254+
Object value = valuePairs[i].getValue();
255+
if (value != null) {
256+
if (value instanceof Object[]) {
257+
Object[] lines = (Object[]) value;
258+
for (int j = 0; j < lines.length; j++) {
259+
buf.append(lines[j]);
260+
buf.append("\r\n");
261+
}
262+
}
263+
}
264+
}
265+
}
266+
}
267+
buffer.append(prefix + buf.toString().trim() + suffix);
268+
existed = true;
269+
}
270+
}
271+
}
272+
}
273+
return existed;
274+
}
196275

197276
private String fixCommentBlock(String text) {
198277
if (text == null || text.length() == 0) {
@@ -274,14 +353,13 @@ private int getPreviousStartPosition(Block node) {
274353
return previousStart;
275354
}
276355

277-
278356
/**
279357
* Method with "j2s*" tag.
280358
*
281359
* @param node
282360
* @return
283361
*/
284-
protected TagElement getJ2SDocTag(BodyDeclaration node, String tagName) {
362+
protected Object getJ2STag(BodyDeclaration node, String tagName) {
285363
Javadoc javadoc = node.getJavadoc();
286364
if (javadoc != null) {
287365
List tags = javadoc.tags();
@@ -294,6 +372,24 @@ protected TagElement getJ2SDocTag(BodyDeclaration node, String tagName) {
294372
}
295373
}
296374
}
375+
List modifiers = node.modifiers();
376+
if (modifiers != null && modifiers.size() > 0) {
377+
for (Iterator iter = modifiers.iterator(); iter.hasNext();) {
378+
Object obj = (Object) iter.next();
379+
if (obj instanceof Annotation) {
380+
Annotation annotation = (Annotation) obj;
381+
String qName = annotation.getTypeName().getFullyQualifiedName();
382+
int idx = qName.indexOf("J2S");
383+
if (idx != -1) {
384+
String annName = qName.substring(idx);
385+
annName = annName.replaceFirst("J2S", "@j2s");
386+
if (annName.startsWith(tagName)) {
387+
return annotation;
388+
}
389+
}
390+
}
391+
}
392+
}
297393
return null;
298394
}
299395

@@ -306,10 +402,10 @@ protected TagElement getJ2SDocTag(BodyDeclaration node, String tagName) {
306402
*/
307403
protected boolean isMethodNativeIgnored(MethodDeclaration node) {
308404
if ((node.getModifiers() & Modifier.NATIVE) != 0) {
309-
if (isDebugging() && getJ2SDocTag(node, "@j2sDebug") != null) {
405+
if (isDebugging() && getJ2STag(node, "@j2sDebug") != null) {
310406
return false;
311407
}
312-
if (getJ2SDocTag(node, "@j2sNative") != null) {
408+
if (getJ2STag(node, "@j2sNative") != null) {
313409
return false;
314410
}
315411
return true;

0 commit comments

Comments
 (0)