@Override public Expr copy(final QueryContext qc, final VarScope scp, final IntObjMap<Var> vs) { final Var v = scp.addCopy(var, qc); vs.put(var.id, v); final Spec spec = new Spec(info, v, expr.copy(qc, scp, vs), coll); spec.occluded = occluded; return spec; }
public void draw(GOut g) { Coord c = new Coord(xoff, 0); for (Spec s : inputs) { GOut sg = g.reclip(c, Inventory.invsq.sz()); sg.image(Inventory.invsq, Coord.z); s.draw(sg); c = c.add(Inventory.sqsz.x, 0); } if (qmod != null) { g.image(qmodl.tex(), new Coord(0, qmy + 4)); c = new Coord(xoff, qmy); int mx = -1; int pw = 0; int vl = 1; for (Indir<Resource> qm : qmod) { try { Tex t = qm.get().layer(Resource.imgc).tex(); g.image(t, c); c = c.add(t.sz().x + 1, 0); if (c.x > mx) mx = c.x; try { Glob.CAttr attr = ui.gui.chrwdg.findattr(qm.get().basename()); if (attr != null) { pw++; vl *= attr.comp; Tex txt = attr.comptex(); g.image(txt, c); c = c.add(txt.sz().x + 8, 0); } } catch (Exception ignored) { } } catch (Loading l) { } } if (pw > 0) { g.image( Text.renderstroked( String.format("Cap: %.0f", Math.floor(Math.pow(vl, 1.0f / pw))), Color.WHITE, Color.BLACK, new Text.Foundry(Text.fraktur, 14).aa(true)) .tex(), new Coord(mx + 30, qmy)); } } c = new Coord(xoff, outy); for (Spec s : outputs) { GOut sg = g.reclip(c, Inventory.invsq.sz()); sg.image(Inventory.invsq, Coord.z); s.draw(sg); c = c.add(Inventory.sqsz.x, 0); } super.draw(g); }
@Test public void testParserClass() throws Exception { SpecParser parser = new SpecParser(ImmutableList.of(DUMMY_CLASS_NAME)); List<Spec> specs = parser.parse(); assertEquals(1, specs.size()); Spec spec = specs.get(0); assertEquals(UnannotatedTestClass.class, spec.getSpecClass()); assertEquals(DUMMY_CLASS_NAME, spec.getSpecName()); assertEquals(0, spec.getMethods().size()); }
@Test public void testParserMethod() throws Exception { String specString = DUMMY_CLASS_NAME + "#" + DUMMY_METHOD_NAME; SpecParser parser = new SpecParser(ImmutableList.of(specString)); List<Spec> specs = parser.parse(); assertEquals(1, specs.size()); Spec spec = specs.get(0); assertEquals(UnannotatedTestClass.class, spec.getSpecClass()); assertEquals(DUMMY_CLASS_NAME, spec.getSpecName()); assertEquals(ImmutableList.of(DUMMY_METHOD_NAME), spec.getMethods()); }
/** * Parse the specs passed in to the constructor. * * @return List of parsed specs * @throws SpecException */ public List<Spec> parse() throws SpecException { for (String specString : testSpecStrings) { if (specString.indexOf('#') >= 0) { addMethod(specString); continue; } // The specString is expected to be the same as the fully qualified class name if (classNamesInSpecs.contains(specString)) { Spec spec = getOrCreateSpec(specString, specString); if (!spec.getMethods().isEmpty()) { throw new SpecException( specString, "Request for entire class already requesting individual methods"); } continue; } getOrCreateSpec(specString, specString); } return ImmutableList.copyOf(specs.values()); }
/** * Updates the given measure spec with respect to the aspect ratio. * * <p>Note: Measure spec is not changed if the aspect ratio is not greater than zero or if * layoutParams is null. * * <p>Measure spec of the layout dimension (width or height) specified as "0dp" is updated to * match the measure spec of the other dimension adjusted by the aspect ratio. Exactly one layout * dimension should be specified as "0dp". * * <p>Padding is taken into account so that the aspect ratio refers to the content without * padding: {@code aspectRatio == (viewWidth - widthPadding) / (viewHeight - heightPadding)} * * <p>Updated measure spec respects the parent's constraints. I.e. measure spec is not changed if * the parent has specified mode {@code EXACTLY}, and it doesn't exceed measure size if parent has * specified mode {@code AT_MOST}. * * @param spec in/out measure spec to be updated * @param aspectRatio desired aspect ratio * @param layoutParams view's layout params * @param widthPadding view's left + right padding * @param heightPadding view's top + bottom padding */ public static void updateMeasureSpec( Spec spec, float aspectRatio, @Nullable ViewGroup.LayoutParams layoutParams, int widthPadding, int heightPadding) { if (aspectRatio <= 0 || layoutParams == null) { return; } if (shouldAdjust(layoutParams.height)) { int widthSpecSize = View.MeasureSpec.getSize(spec.width); int desiredHeight = (int) ((widthSpecSize - widthPadding) / aspectRatio + heightPadding); int resolvedHeight = View.resolveSize(desiredHeight, spec.height); spec.height = View.MeasureSpec.makeMeasureSpec(resolvedHeight, View.MeasureSpec.EXACTLY); } else if (shouldAdjust(layoutParams.width)) { int heightSpecSize = View.MeasureSpec.getSize(spec.height); int desiredWidth = (int) ((heightSpecSize - heightPadding) * aspectRatio + widthPadding); int resolvedWidth = View.resolveSize(desiredWidth, spec.width); spec.width = View.MeasureSpec.makeMeasureSpec(resolvedWidth, View.MeasureSpec.EXACTLY); } }
/** Handle a spec that looks like package.className#methodName */ public void addMethod(String specString) throws SpecException { String[] results = specString.split("#"); if (results.length != 2) { throw new SpecException(specString, "Expected only one # in spec"); } String className = results[0]; String methodName = results[1]; Spec spec = getOrCreateSpec(className, specString); boolean found = false; for (Method clazzMethod : spec.getSpecClass().getMethods()) { if (clazzMethod.getName().equals(methodName)) { found = true; break; } } if (!found) { throw new SpecException( specString, String.format("Method %s not found in class %s", methodName, className)); } spec.addMethod(methodName); }
public void visitSledFile(SledFile aSledFile) { out.print("SledFile("); ++indentLevel; out.println(); printIndent(); out.print("specs="); if (aSledFile.getSpecs() != null) { out.println("["); ++indentLevel; for (Spec e : aSledFile.getSpecs()) { printIndent(); e.visit(this); } --indentLevel; printIndent(); out.println("]"); } else { out.println("null"); } --indentLevel; printIndent(); out.println(")"); }
@Override public void plan(final FElem plan) { final FElem e = planElem(); for (final Spec spec : specs) spec.plan(e); plan.add(e); }
@Override public boolean removable(final Var var) { for (final Spec b : specs) if (!b.removable(var)) return false; return true; }
@Override public GroupBy compile(final QueryContext qc, final VarScope sc) throws QueryException { for (final Expr e : preExpr) e.compile(qc, sc); for (final Spec b : specs) b.compile(qc, sc); return optimize(qc, sc); }
@Override public boolean has(final Flag flag) { for (final Spec sp : specs) if (sp.has(flag)) return true; return false; }
public static void main(String[] args) { Enacter e = new Enacter(Spec.getSpec()); e.exec(); }