本文整理汇总了Java中com.google.gwt.dev.js.ast.JsContext类的典型用法代码示例。如果您正苦于以下问题:Java JsContext类的具体用法?Java JsContext怎么用?Java JsContext使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JsContext类属于com.google.gwt.dev.js.ast包,在下文中一共展示了JsContext类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findJavaRefs
import com.google.gwt.dev.js.ast.JsContext; //导入依赖的package包/类
private static List<JsniJavaRef> findJavaRefs(
final MethodDeclaration jsniMethod) throws IOException,
JavaScriptParseException, BadLocationException {
final String jsniSource = JavaASTUtils.getSource(jsniMethod);
ICompilationUnit cu = JavaASTUtils.getCompilationUnit(jsniMethod);
final IPath cuPath = cu.getResource().getFullPath();
final List<JsniJavaRef> javaRefs = new ArrayList<JsniJavaRef>();
JsBlock js = JsniParser.parse(jsniSource);
if (js != null) {
// Visit the JavaScript AST to find all Java references
new JsVisitor() {
@Override
public void endVisit(JsNameRef x, @SuppressWarnings("rawtypes") JsContext ctx) {
String ident = x.getIdent();
if (ident.indexOf("@") != -1) {
JsniJavaRef javaRef = JsniJavaRef.parse(ident);
if (javaRef != null) {
// Set the reference's Java source file
javaRef.setSource(cuPath);
// To get the Java reference offset, we have to do an indexOf on
// its identifier. To make sure we catch multiple references to
// the same Java element, we need to start at the index one past
// the start of the last Java reference we found (if any)
int fromIndex = 0;
if (javaRefs.size() > 0) {
fromIndex = javaRefs.get(javaRefs.size() - 1).getOffset()
- jsniMethod.getStartPosition() + 1;
}
int offset = jsniSource.indexOf(ident, fromIndex)
+ jsniMethod.getStartPosition();
// Set the reference's offset within the Java source file
javaRef.setOffset(offset);
javaRefs.add(javaRef);
}
}
}
}.accept(js);
}
return javaRefs;
}
示例2: endVisit
import com.google.gwt.dev.js.ast.JsContext; //导入依赖的package包/类
@Override
public void endVisit(JsNameRef x, JsContext ctx) {
String ident = x.getIdent();
if (ident.charAt(0) == '@') {
Binding binding = jsniRefs.get(ident);
SourceInfo info = x.getSourceInfo();
if (binding == null) {
assert ident.startsWith("@null::");
if ("@null::nullMethod()".equals(ident)) {
processMethod(x, info, JMethod.NULL_METHOD);
} else {
assert "@null::nullField".equals(ident);
processField(x, info, JField.NULL_FIELD, ctx);
}
} else if (binding instanceof TypeBinding) {
JType type = typeMap.get((TypeBinding) binding);
processClassLiteral(x, info, type, ctx);
} else if (binding instanceof FieldBinding) {
FieldBinding fieldBinding = (FieldBinding) binding;
/*
* We must replace any compile-time constants with the constant
* value of the field.
*/
if (isCompileTimeConstant(fieldBinding)) {
assert !ctx.isLvalue();
JExpression constant = getConstant(info, fieldBinding.constant());
generator.accept(constant);
JsExpression result = generator.pop();
assert (result != null);
ctx.replaceMe(result);
} else {
// Normal: create a jsniRef.
JField field = typeMap.get(fieldBinding);
processField(x, info, field, ctx);
}
} else {
JMethod method = typeMap.get((MethodBinding) binding);
processMethod(x, info, method);
}
}
}
示例3: processClassLiteral
import com.google.gwt.dev.js.ast.JsContext; //导入依赖的package包/类
private void processClassLiteral(JsNameRef nameRef, SourceInfo info, JType type, JsContext ctx) {
assert !ctx.isLvalue();
JsniClassLiteral classLiteral = new JsniClassLiteral(info, nameRef.getIdent(), type);
nativeMethodBody.addClassRef(classLiteral);
}
示例4: processField
import com.google.gwt.dev.js.ast.JsContext; //导入依赖的package包/类
private void processField(JsNameRef nameRef, SourceInfo info, JField field, JsContext ctx) {
JsniFieldRef fieldRef =
new JsniFieldRef(info, nameRef.getIdent(), field, curClass.type, ctx.isLvalue());
nativeMethodBody.addJsniRef(fieldRef);
}