int idx = line.indexOf(':'); if (idx < 0) { throw new InternalCompilerException( "invalid selection information line: " + line);
@Override public JExpression injectMagic(TreeLogger logger, JMethodCall methodCall, JMethod currentMethod, Context context, UnifyAstView ast) throws UnableToCompleteException { return ast.getProgram().getLiteralBoolean(false); }
@Override public void endVisit(EqualExpression x, BlockScope scope) { JBinaryOperator op; switch ((x.bits & ASTNode.OperatorMASK) >> ASTNode.OperatorSHIFT) { case OperatorIds.EQUAL_EQUAL: op = JBinaryOperator.EQ; break; case OperatorIds.NOT_EQUAL: op = JBinaryOperator.NEQ; break; default: throw translateException(x, new InternalCompilerException( "Unexpected operator for EqualExpression")); } pushBinaryOp(x, op); }
@Override public JExpression injectMagic(final TreeLogger logger, final JMethodCall methodCall, final JMethod enclosingMethod, final Context context, final UnifyAstView ast) throws UnableToCompleteException { final JExpression ctorProvider = super.injectMagic(logger, methodCall, enclosingMethod, context, ast); // Find the invoker method // call the newInstance method on the result of our ctorProvider final JDeclaredType ctor = ast.searchForTypeBySource(Constructor.class.getName()); for (final JMethod method : ctor.getMethods()) { if (method.getName().equals("newInstance")) { final JMethodCall call = new JMethodCall(methodCall.getSourceInfo().makeChild(), ctorProvider, method); call.addArg(methodCall.getArgs().get(2)); return call; } } logger.log(Type.ERROR, "Unable to implement GwtReflect.construct from "+methodCall.toSource()); throw new UnableToCompleteException(); }
private void findMethods(final UnifyAstView ast) { final JDeclaredType arrayType = ast.searchForTypeBySource(Array.class.getName()); for (final JMethod method : arrayType.getMethods()) { if ("register".equals(method.getName())) { registerArray = ast.translate(method); if (newArrayMethod != null) { return; } } else if ("newMultiDimArray".equals(method.getName())) { newArrayMethod = ast.translate(method); if (registerArray != null) { return; } } } }
public com.google.gwt.dev.jjs.ast.JMethod initMethod(UnifyAstView ast) { if (initMethod == null) { JDeclaredType type = ast.searchForTypeBySource("com.google.gwt.reflect.shared.JsMemberPool"); for (com.google.gwt.dev.jjs.ast.JMethod method : type.getMethods()) { if (method.getName().equals("getMembers")) { initMethod = method; break; } } } return initMethod; } }
@Override public void endVisit(PostfixExpression x, BlockScope scope) { try { SourceInfo info = makeSourceInfo(x); JUnaryOperator op; switch (x.operator) { case OperatorIds.MINUS: op = JUnaryOperator.DEC; break; case OperatorIds.PLUS: op = JUnaryOperator.INC; break; default: throw new InternalCompilerException("Unexpected postfix operator"); } JExpression lhs = pop(x.lhs); push(new JPostfixOperation(info, op, lhs)); } catch (Throwable e) { throw translateException(x, e); } }
@Override public void endVisit(PrefixExpression x, BlockScope scope) { try { SourceInfo info = makeSourceInfo(x); JUnaryOperator op; switch (x.operator) { case OperatorIds.MINUS: op = JUnaryOperator.DEC; break; case OperatorIds.PLUS: op = JUnaryOperator.INC; break; default: throw new InternalCompilerException("Unexpected prefix operator"); } JExpression lhs = pop(x.lhs); push(new JPrefixOperation(info, op, lhs)); } catch (Throwable e) { throw translateException(x, e); } }
InternalCompilerException translateException(ASTNode node, Throwable e) { if (e instanceof VirtualMachineError) { // Always rethrow VM errors (an attempt to wrap may fail). throw (VirtualMachineError) e; } InternalCompilerException ice; if (e instanceof InternalCompilerException) { ice = (InternalCompilerException) e; } else { ice = new InternalCompilerException("Error constructing Java AST", e); } if (node != null) { ice.addNode(node.getClass().getName(), node.toString(), makeSourceInfo(node)); } return ice; }
public StandardGeneratorContext getGeneratorContext() { return getAst().getGeneratorContext(); }
@Override public void error(JNode x, String errorMessage) { errorsFound = true; TreeLogger branch = logger .branch(TreeLogger.ERROR, "Errors in '" + x.getSourceInfo().getFileName() + "'", null); // Append 'Line #: msg' to the error message. StringBuffer msgBuf = new StringBuffer(); int line = x.getSourceInfo().getStartLine(); if (line > 0) { msgBuf.append("Line "); msgBuf.append(line); msgBuf.append(": "); } msgBuf.append(errorMessage); branch.log(TreeLogger.ERROR, msgBuf.toString()); }
SourceInfo makeSourceInfo(ASTNode x) { int startLine = Util.getLineNumber(x.sourceStart, curCud.separatorPositions, 0, curCud.separatorPositions.length - 1); return SourceOrigin.create(x.sourceStart, x.sourceEnd, startLine, sourceMapPath); }
private static MinimalRebuildCacheManager createMinimalRebuildCacheManager( PrintWriterTreeLogger logger, Options options,File baseCacheDir) { return new MinimalRebuildCacheManager( logger, baseCacheDir, ImmutableMap.of( "style", options.getOutput().name(), "closureFormattedOutput", String.valueOf(options.isClosureFormattedOutput()), "generateJsInteropExports", String.valueOf(options.shouldGenerateJsInteropExports()), "exportFilters", options.getJsInteropExportFilter().toString(), "methodDisplayMode", options.getMethodNameDisplayMode().name())); }
public JMethod getThrowMethod(final TreeLogger logger, final UnifyAstView ast) { if (doThrow == null) { final JDeclaredType gwtReflect = ast.searchForTypeBySource(GwtReflect.class.getName()); for (final JMethod method : gwtReflect.getMethods()) { if (method.getName().equals("doThrow")) { doThrow = method; break; } } } return doThrow; } }
private String getBinaryOrPrimitiveName(JType type) { JArrayType asArray = type.isArray(); JClassType asClass = type.isClassOrInterface(); JPrimitiveType asPrimitive = type.isPrimitive(); if (asClass != null) { return getBinaryName(asClass); } else if (asPrimitive != null) { return asPrimitive.getQualifiedSourceName(); } else if (asArray != null) { JType componentType = asArray.getComponentType(); return getBinaryOrPrimitiveName(componentType) + "[]"; } else { throw new InternalCompilerException("Cannot create binary name for " + type.getQualifiedSourceName()); } }
@Override public JExpression injectMagic(TreeLogger logger, JMethodCall methodCall, JMethod currentMethod, Context context, UnifyAstView ast) throws UnableToCompleteException { return ast.getProgram().getLiteralBoolean(true); }
public StandardGeneratorContext getGeneratorContext() { return getAst().getGeneratorContext(); }
SourceInfo makeSourceInfo(AbstractMethodDeclaration x) { int startLine = Util.getLineNumber(x.sourceStart, curCud.separatorPositions, 0, curCud.separatorPositions.length - 1); return SourceOrigin.create(x.sourceStart, x.bodyEnd, startLine, sourceMapPath); }
private String getBinaryOrPrimitiveName(JType type) { JArrayType asArray = type.isArray(); JClassType asClass = type.isClassOrInterface(); JPrimitiveType asPrimitive = type.isPrimitive(); if (asClass != null) { return getBinaryName(asClass); } else if (asPrimitive != null) { return asPrimitive.getQualifiedSourceName(); } else if (asArray != null) { JType componentType = asArray.getComponentType(); return getBinaryOrPrimitiveName(componentType) + "[]"; } else { throw new InternalCompilerException("Cannot create binary name for " + type.getQualifiedSourceName()); } }
public void finish(final TreeLogger logger) throws UnableToCompleteException { getAst().getGeneratorContext().finish(logger); }