Android Open Source - bad Var Expression






From Project

Back to project page bad.

License

The source code is released under:

Copyright (C) 2013 Madis Pink Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Softwa...

If you think the Android project bad listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.madisp.bad.expr;
/*from  w  ww  .  j a  va2 s  .c o m*/
import com.madisp.bad.eval.BadVar;
import com.madisp.bad.eval.Scope;
import com.madisp.bad.eval.Watcher;

/**
 * Created with IntelliJ IDEA.
 * User: madis
 * Date: 3/23/13
 * Time: 1:57 PM
 */
public class VarExpression extends BasableExpression {
  String var;
  public VarExpression(BasableExpression base, String var) {
    super(base);
    this.var = var;
  }

  @Override
  public Object value(Scope scope) {
    if (var == null) {
      return null;
    }
    if (!hasBase()) {
      return scope.getVar(null, var);
    }
    Object base = getBase(scope);
    if (base != null) {
      return scope.getVar(base, var);
    }
    return null;
  }

  public String getIdentifier() {
    return var;
  }

  @SuppressWarnings("unchecked")
  @Override
  public void addWatcher(final Scope scope, final Watcher w) {
    super.addWatcher(scope, w);
    Object o = value(scope);
    final BadVar.BadWatcher watcher = new BadVar.BadWatcher() {
      @Override
      public void fire(BadVar var) {
        w.fire(scope);
      }
    };
    if (o instanceof BadVar) {
      ((BadVar)o).addWatcher(watcher);
    }
    scope.addOnRebasedListener(new Scope.OnScopeRebasedListener() {
      @Override
      public void onScopeDetached(Scope scope) {
        Object o = value(scope);
        if (o instanceof BadVar) {
          ((BadVar)o).removeWatcher(watcher);
        }
      }
      @Override
      public void onScopeAttached(Scope scope) {
        Object o = value(scope);
        if (o instanceof BadVar) {
          ((BadVar)o).addWatcher(watcher);
        }
        w.fire(scope);
      }
    });
  }
}




Java Source Code List

com.madisp.bad.ConsoleRepl.java
com.madisp.bad.Freezer.java
com.madisp.bad.Persist.java
com.madisp.bad.decor.BadDecorator.java
com.madisp.bad.decor.BaseDecorator.java
com.madisp.bad.decor.CheckableDecorator.java
com.madisp.bad.decor.EditTextDecorator.java
com.madisp.bad.decor.ListViewDecorator.java
com.madisp.bad.decor.TextViewDecorator.java
com.madisp.bad.decor.ViewDecorator.java
com.madisp.bad.decor.WebViewDecorator.java
com.madisp.bad.demo.ListFragment.java
com.madisp.bad.demo.LoginFragment.java
com.madisp.bad.demo.MainActivity.java
com.madisp.bad.demo.PersistFragment.java
com.madisp.bad.demo.ReplFragment.java
com.madisp.bad.demo.ShopFragment.java
com.madisp.bad.demo.TwoWayFragment.java
com.madisp.bad.eval.BadCollections.java
com.madisp.bad.eval.BadConverter.java
com.madisp.bad.eval.BadScope.java
com.madisp.bad.eval.BadVar.java
com.madisp.bad.eval.ScopeWrapper.java
com.madisp.bad.eval.Scope.java
com.madisp.bad.eval.Watcher.java
com.madisp.bad.expr.AndExpression.java
com.madisp.bad.expr.AssignExpression.java
com.madisp.bad.expr.BasableExpression.java
com.madisp.bad.expr.BlockExpression.java
com.madisp.bad.expr.ConstantExpression.java
com.madisp.bad.expr.DivisionExpression.java
com.madisp.bad.expr.ExpressionFactory.java
com.madisp.bad.expr.Expression.java
com.madisp.bad.expr.MethodExpression.java
com.madisp.bad.expr.MinusExpression.java
com.madisp.bad.expr.MultiplyExpression.java
com.madisp.bad.expr.NotExpression.java
com.madisp.bad.expr.OrExpression.java
com.madisp.bad.expr.PlusExpression.java
com.madisp.bad.expr.StatementList.java
com.madisp.bad.expr.UnaryMinusExpression.java
com.madisp.bad.expr.VarExpression.java
com.madisp.bad.lib.BadFragment.java
com.madisp.bad.lib.BadLayoutFactory.java
com.madisp.bad.lib.BadStdLib.java
com.madisp.bad.lib.ui.BadAdapter.java
com.madisp.bad.lib.ui.BadTextWatcher.java
com.madisp.bad.parse.ExprBaseVisitor.java
com.madisp.bad.parse.ExprLexer.java
com.madisp.bad.parse.ExprParser.java
com.madisp.bad.parse.ExprVisitor.java