Package com.google.gwt.dev.jjs.ast

Examples of com.google.gwt.dev.jjs.ast.JReferenceType


      accept(method);
      newline();
      newline();
    }
    for (int i = 0; i < x.getDeclaredTypes().size(); ++i) {
      JReferenceType type = (JReferenceType) x.getDeclaredTypes().get(i);
      accept(type);
      newline();
      newline();
    }
    return false;
View Full Code Here


    public boolean visit(FieldDeclaration fieldDeclaration, MethodScope scope) {
      try {
        FieldBinding b = fieldDeclaration.binding;
        SourceInfo info = makeSourceInfo(fieldDeclaration);
        JReferenceType enclosingType = (JReferenceType) typeMap.get(scope.enclosingSourceType());
        createField(info, b, enclosingType,
            fieldDeclaration.initialization != null);
        return true;
      } catch (Throwable e) {
        throw translateException(fieldDeclaration, e);
View Full Code Here

    public boolean visit(MethodDeclaration methodDeclaration, ClassScope scope) {
      try {
        MethodBinding b = methodDeclaration.binding;
        SourceInfo info = makeSourceInfo(methodDeclaration);
        JType returnType = (JType) typeMap.get(methodDeclaration.returnType.resolvedType);
        JReferenceType enclosingType = (JReferenceType) typeMap.get(scope.enclosingSourceType());
        JMethod newMethod = program.createMethod(info,
            methodDeclaration.selector, enclosingType, returnType,
            b.isAbstract(), b.isStatic(), b.isFinal(), b.isPrivate(),
            b.isNative());

        mapThrownExceptions(newMethod, methodDeclaration);
        mapParameters(newMethod, methodDeclaration);
        typeMap.put(b, newMethod);

        if (newMethod.isNative()) {
          // Handle JSNI block
          char[] source = methodDeclaration.compilationResult().getCompilationUnit().getContents();
          String jsniCode = String.valueOf(source, methodDeclaration.bodyStart,
              methodDeclaration.bodyEnd - methodDeclaration.bodyStart + 1);
          int startPos = jsniCode.indexOf("/*-{");
          int endPos = jsniCode.lastIndexOf("}-*/");
          if (startPos < 0 && endPos < 0) {
            GenerateJavaAST.reportJsniError(
                info,
                methodDeclaration,
                "Native methods require a JavaScript implementation enclosed with /*-{ and }-*/");
            return true;
          }
          if (startPos < 0) {
            GenerateJavaAST.reportJsniError(info, methodDeclaration,
                "Unable to find start of native block; begin your JavaScript block with: /*-{");
            return true;
          }
          if (endPos < 0) {
            GenerateJavaAST.reportJsniError(
                info,
                methodDeclaration,
                "Unable to find end of native block; terminate your JavaScript block with: }-*/");
            return true;
          }

          startPos += 3; // move up to open brace
          endPos += 1; // move past close brace

          jsniCode = jsniCode.substring(startPos, endPos);

          // Here we parse it as an anonymous function, but we will give it a
          // name later when we generate the JavaScript during code generation.
          //
          String syntheticFnHeader = "function (";
          boolean first = true;
          for (int i = 0; i < newMethod.params.size(); ++i) {
            JParameter param = (JParameter) newMethod.params.get(i);
            if (first) {
              first = false;
            } else {
              syntheticFnHeader += ',';
            }
            syntheticFnHeader += param.getName();
          }
          syntheticFnHeader += ')';
          StringReader sr = new StringReader(syntheticFnHeader + '\n'
              + jsniCode);
          try {
            // start at -1 to avoid counting our synthetic header
            // TODO: get the character position start correct
            JsStatements result = jsParser.parse(jsProgram.getScope(), sr, -1);
            JsExprStmt jsExprStmt = (JsExprStmt) result.get(0);
            JsFunction jsFunction = (JsFunction) jsExprStmt.getExpression();
            ((JsniMethod) newMethod).setFunc(jsFunction);
          } catch (IOException e) {
            throw new InternalCompilerException(
                "Internal error parsing JSNI in method '" + newMethod
                    + "' in type '" + enclosingType.getName() + "'", e);
          } catch (JsParserException e) {
            /*
             * count the number of characters to the problem (from the start of
             * the JSNI code)
             */
 
View Full Code Here

    }

    private JMethod findEnclosingMethod(BlockScope scope) {
      MethodScope methodScope = scope.methodScope();
      if (methodScope.isInsideInitializer()) {
        JReferenceType enclosingType = (JReferenceType) typeMap.get(scope.classScope().referenceContext.binding);
        if (methodScope.isStatic) {
          // clinit
          return (JMethod) enclosingType.methods.get(0);
        } else {
          // init
View Full Code Here

         * Weird case: if JDT determines that this local class is totally
         * uninstantiable, it won't bother allocating a local name.
         */
        return false;
      }
      JReferenceType type = (JReferenceType) typeMap.get(binding);
      try {
        if (binding.isNestedType() && !binding.isStatic()) {
          // add synthetic fields for outer this and locals
          assert (type instanceof JClassType);
          NestedTypeBinding nestedBinding = (NestedTypeBinding) binding;
View Full Code Here

    }

    // @Override
    public boolean visit(JProgram x, Context ctx) {
      for (int i = 0; i < x.getDeclaredTypes().size(); ++i) {
        JReferenceType type = (JReferenceType) x.getDeclaredTypes().get(i);
        accept(type);
      }
      return false;
    }
View Full Code Here

      JStatement cur = new JThrowStatement(program, null, exRef);
      for (int i = x.getCatchBlocks().size() - 1; i >= 0; --i) {
        JBlock block = (JBlock) x.getCatchBlocks().get(i);
        JLocalRef arg = (JLocalRef) x.getCatchArgs().get(i);
        catchInfo = block.getSourceInfo();
        JReferenceType argType = (JReferenceType) arg.getType();
        // if ($e instanceof Argtype) { userVar = $e; <user code> }
        JExpression ifTest = new JInstanceOf(program, catchInfo, argType, exRef);
        asg = program.createAssignmentStmt(catchInfo, arg, exRef);
        if (!block.statements.isEmpty()) {
          // Only bother adding the assingment if the block is non-empty
View Full Code Here

    }

    JExpression processExpression(InstanceOfExpression x) {
      SourceInfo info = makeSourceInfo(x);
      JExpression expr = dispProcessExpression(x.expression);
      JReferenceType testType = (JReferenceType) typeMap.get(x.type.resolvedType);
      return new JInstanceOf(program, info, testType, expr);
    }
View Full Code Here

    private HasEnclosingType parseJsniRef(SourceInfo info,
        AbstractMethodDeclaration x, String ident) {
      String[] parts = ident.substring(1).split("::");
      assert (parts.length == 2);
      String className = parts[0];
      JReferenceType type = program.getFromTypeMap(className);
      if (type == null) {
        reportJsniError(info, x, "Unresolvable native reference to type '"
            + className + "'");
        return null;
      }
View Full Code Here

        null, program.getTypeVoid(), false, true, true, false, false);
    bootStrapMethod.freezeParamTypes();

    for (int i = 0; i < mainClassNames.length; ++i) {
      String mainClassName = mainClassNames[i];
      JReferenceType referenceType = program.getFromTypeMap(mainClassName);

      if (referenceType == null) {
        logger.log(TreeLogger.ERROR,
            "Could not find module entry point class '" + mainClassName + "'",
            null);
View Full Code Here

TOP

Related Classes of com.google.gwt.dev.jjs.ast.JReferenceType

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.