當前位置: 首頁>>代碼示例>>Java>>正文


Java JsContext類代碼示例

本文整理匯總了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;
}
 
開發者ID:gwt-plugins,項目名稱:gwt-eclipse-plugin,代碼行數:46,代碼來源:JsniParser.java

示例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);
    }
  }
}
 
開發者ID:WeTheInternet,項目名稱:xapi,代碼行數:42,代碼來源:GwtAstBuilder.java

示例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);
}
 
開發者ID:WeTheInternet,項目名稱:xapi,代碼行數:6,代碼來源:GwtAstBuilder.java

示例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);
}
 
開發者ID:WeTheInternet,項目名稱:xapi,代碼行數:6,代碼來源:GwtAstBuilder.java


注:本文中的com.google.gwt.dev.js.ast.JsContext類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。