public Iterable<URL> getResources(String name) throws IOException { final Enumeration<URL> resources = getClassLoaderNotNull().getResources(name); //noinspection unchecked return new IteratorIterable<URL>( new EnumerationIterator(resources)); }
public Object change(Object value) throws EternaException { if (value == null) { return null; } if (value instanceof Iterator) { if (!(value instanceof PreFetchIterator)) { return new PreFetchIterator((Iterator) value); } return value; } else if (value instanceof Collection) { return new PreFetchIterator(((Collection) value).iterator()); } else if (value instanceof Object[]) { return new PreFetchIterator(Arrays.asList((Object[]) value).iterator()); } else if (value instanceof Map) { return new PreFetchIterator(((Map) value).entrySet().iterator()); } else if (value instanceof Enumeration) { return new PreFetchIterator(new EnumerationIterator((Enumeration) value)); } throw new EternaException("Error Object type:" + value.getClass() + "."); }
public Statement initStatement(SourceLocation sourceLocation) { return new Statement(sourceLocation) { @Override public VbValue eval(Interpreter interpreter, CallFrame frame) throws VbRuntimeException { VbValue col = collection.eval(interpreter, frame); if (col.varType.vbType == VbVarType.vbVariant) { col = (VbValue) col.value; } if (col.varType.vbType == VbVarType.vbArray) { VbArray arr = (VbArray) col; iterator = arr.iterator(); } else if (col.varType.isJavaObject()) { if (col.value.getClass().isArray()) { iterator = new JavaArrayIterator(col.value); } else if (col.value instanceof Iterable) { iterator = new VbValueIterator(((Iterable) col.value).iterator()); } else if (col.value instanceof Enumeration) { iterator = new VbValueIterator(new EnumerationIterator((Enumeration) col.value)); } else if (col.value instanceof Map) { Map map = (Map) col.value; iterator = new VbValueIterator(map.values().iterator()); } } if (iterator == null && col.isObject()) { ClassModuleDecl c = col.varType.getClassModuleDecl(); ModuleMemberDecl it = (c != null ? c.getIteratorMember() : null); if (it == null) { throw new VbRuntimeException(VbRuntimeException.类型不匹配, sourceLocation); } MethodDecl itMethod = null; if (it instanceof PropertyDecl) { PropertyDecl p = (PropertyDecl) it; if (p.get == null || p.get.arguments.size() > 0) { throw new VbRuntimeException(VbRuntimeException.无效的过程调用, sourceLocation); } itMethod = p.get; } else if (it instanceof MethodDecl) { itMethod = (MethodDecl) it; if (itMethod.arguments.size() > 0) { throw new VbRuntimeException(VbRuntimeException.无效的过程调用, sourceLocation); } } try { VbValue itr = interpreter.callMethod((ModuleInstance) col.value, itMethod); if (itr != null) { if (itr.value instanceof JavaModuleInstance) { JavaModuleInstance inst = (JavaModuleInstance) itr.value; Object obj = inst.getInstance(); if (obj instanceof Iterator) { iterator = (Iterator) obj; } } else if (itr.value instanceof Iterator) { iterator = (Iterator<VbValue>) itr.value; } } if (iterator == null) { throw new VbRuntimeException(VbRuntimeException.类型不匹配, sourceLocation); } } catch (ArgumentException e) { // no arguments } } return null; } @Override public String toString() { return "For Each Iterator At " + varDecl; } }; }