private void generateView( Map<String, DesignDocument.View> views, Method me, Class<?> handledType) { String name = me.getName(); if (!name.startsWith("findBy") && !name.equals("getAll")) { throw new ViewGenerationException( String.format( "The method: %s in %s annotated with GenerateView does not conform to the naming convention of 'findByXxxx'", name, me.getDeclaringClass())); } Class<?> type = resolveReturnType(me); if (type == null) { if (handledType != null) { type = handledType; } else { throw new ViewGenerationException( "Could not resolve return type for method: %s in %s", me.getName(), me.getDeclaringClass()); } } String typeDiscriminator = resolveTypeDiscriminator(type); if (name.equals("getAll")) { if (typeDiscriminator.length() < 1) { throw new ViewGenerationException( String.format( "Cannot generate 'all' view for %s. No type discriminator could be resolved. Try annotate unique field(s) with @TypeDiscriminator", type.getDeclaringClass())); } views.put("all", generateAllView(typeDiscriminator)); return; } String finderName = name.substring(6); String fieldName = resolveFieldName(me, finderName); Method getter = findMethod(type, "get" + fieldName); if (getter == null) { // try pluralis fieldName += "s"; getter = findMethod(type, "get" + fieldName); } if (getter == null) { throw new ViewGenerationException( "Could not generate view for method %s. No get method found for property %s in %s", name, name.substring(6), type); } fieldName = firstCharToLowerCase(fieldName); DesignDocument.View view; if (isIterable(getter.getReturnType())) { view = generateFindByIterableView(fieldName, typeDiscriminator); } else { view = generateFindByView(fieldName, typeDiscriminator); } views.put("by_" + firstCharToLowerCase(finderName), view); }
public ProxiedMethod(Method method) { this.method = method; this.name = // method instanceof Constructor ? "<init>" : method.getName(); this.owner = method.getDeclaringClass(); StringBuffer jni_sig = new StringBuffer("("), c_sig = new StringBuffer(); retCapitalized = jni_capitalized(method.getReturnType()); String[] sigArg = c_signature(method.getReturnType(), "?"); c_sig.append(retType = sigArg[0]).append(" ").append(name).append("("); int i = 0; for (Class c : method.getParameterTypes()) { jni_sig.append(jni_signature(c)); if (i > 0) c_sig.append(", "); String argName = "arg" + (i + 1); sigArg = c_signature(c, argName); String argType = sigArg[0]; argTypes.add(argType); argNames.add(argName); argValues.add(sigArg[1]); c_sig.append(argType).append(" ").append(argName); i++; } c_sig.append(")"); jni_sig.append(")").append(jni_signature(method.getReturnType())); this.jni_signature = jni_sig.toString(); this.c_signature = c_sig.toString(); }
// // Returns true if this method is allowed to raise SQLFeatureNotSupportedException. // private boolean isExcludable(Method method) throws Exception { Class iface = method.getDeclaringClass(); HashSet<Method> excludableMethods = excludableMap.get(iface); if (excludableMethods == null) { return false; } return excludableMethods.contains(method); }
/* Processing assignments of allocation statements. Left hand side is either a variable or the field of a variable. The right hand side is the allocation site, represented by the allocation instruction. */ public void assignAlloc(Var x, Field f, New a) { Node nodeL = getNode(x, f); nodeL.hasallocs = true; nodeL.istouched = true; setTouched(x); if (IRHelper.isLibrary(method.getDeclaringClass())) nodeL.hasliballocs = true; Node nodeR = allocmap.get(a); assert (nodeR == null) : "Allocation site already entered"; allocmap.put(a, nodeL); }
protected void generateView( Map<String, org.ektorp.support.DesignDocument.View> views, Method me) { DocumentReferences referenceMetaData = me.getAnnotation(DocumentReferences.class); if (referenceMetaData == null) { LOG.warn("No DocumentReferences annotation found in method: ", me.getName()); return; } if (!me.getName().startsWith("get")) { throw new ViewGenerationException( String.format( "The method: %s in %s annotated with DocumentReferences does not conform to the naming convention of 'getXxxx'", me.getName(), me.getDeclaringClass())); } if (Set.class.isAssignableFrom(me.getReturnType())) { generateSetBasedDocRefView(views, me, referenceMetaData); } else { throw new ViewGenerationException( String.format( "The return type of: %s in %s annotated with DocumentReferences is not supported. (Must be assignable from java.util.Set)", me.getName(), me.getDeclaringClass())); } }
public Java8RestMethodWrapper(Object pOwner, Method pMethod) { super(pOwner, pMethod); try { mMethodHandle = MethodHandles.lookup().unreflect(pMethod).bindTo(pOwner); mParameterAnnotations = pMethod.getParameterAnnotations(); mElementWrapper = pMethod.getAnnotation(XmlElementWrapper.class); mGenericReturnType = pMethod.getGenericReturnType(); mReturnType = pMethod.getReturnType(); mRestMethod = pMethod.getAnnotation(RestMethod.class); mDeclaringClass = pMethod.getDeclaringClass(); } catch (IllegalAccessException e) { throw new RuntimeException(e); } }
static Method findSingleMethod(Method[] methods, String name) { Method found = null; for (int i = 0, N = methods.length; i != N; ++i) { Method method = methods[i]; if ((method != null) && name.equals(method.getName())) { if (found != null) { throw Context.reportRuntimeError2( "msg.no.overload", name, method.getDeclaringClass().getName()); } found = method; } } return found; }
/** * Given class of the interface for a fluid engine, build a concrete instance of that interface * that calls back into a Basic Engine for all methods in the interface. */ private static BasicEngine buildCallbackEngine(String engineInterface, Class cEngine) { // build up list of callbacks for <engineInterface> StringBuffer decls = new StringBuffer(); Method[] engineMethods = cEngine.getMethods(); for (int i = 0; i < engineMethods.length; i++) { Method meth = engineMethods[i]; // skip methods that aren't declared in the interface if (meth.getDeclaringClass() != cEngine) { continue; } decls.append( " public " + Utils.asTypeDecl(meth.getReturnType()) + " " + meth.getName() + "("); Class[] params = meth.getParameterTypes(); for (int j = 0; j < params.length; j++) { decls.append(Utils.asTypeDecl(params[j]) + " p" + j); if (j != params.length - 1) { decls.append(", "); } } decls.append(") {\n"); decls.append( " return (" + Utils.asTypeDecl(meth.getReturnType()) + ")super.callNative(\"" + meth.getName() + "\", new Object[] {"); for (int j = 0; j < params.length; j++) { decls.append("p" + j); if (j != params.length - 1) { decls.append(", "); } } decls.append("} );\n"); decls.append(" }\n\n"); } // write template file String engineName = "BasicEngine_" + engineInterface; String fileName = engineName + ".java"; try { String contents = Utils.readFile("lava/engine/basic/BasicEngineTemplate.java").toString(); // remove package name contents = Utils.replaceAll(contents, "package lava.engine.basic;", ""); // for class decl contents = Utils.replaceAll( contents, "extends BasicEngine", "extends BasicEngine implements " + engineInterface); // for constructor contents = Utils.replaceAll(contents, "BasicEngineTemplate", engineName); // for methods contents = Utils.replaceAll(contents, "// INSERT METHODS HERE", decls.toString()); Utils.writeFile(fileName, contents); } catch (IOException e) { e.printStackTrace(); System.exit(1); } // compile the file try { Process jProcess = Runtime.getRuntime().exec("jikes " + fileName, null, null); jProcess.waitFor(); } catch (Exception e) { System.err.println("Error compiling auto-generated file " + fileName); e.printStackTrace(); System.exit(1); } // instantiate the class BasicEngine result = null; try { result = (BasicEngine) Class.forName(engineName).newInstance(); // cleanup the files we made new File(engineName + ".java").delete(); new File(engineName + ".class").delete(); } catch (Exception e) { e.printStackTrace(); System.exit(1); } return result; }
/** * {@inheritDoc} * * @see java.lang.reflect.InvocationHandler#invoke(java.lang.Object, java.lang.reflect.Method, * java.lang.Object[]) */ @Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { if (MBeanServerConnection.class != method.getDeclaringClass()) { return method.invoke(Modifier.isStatic(method.getModifiers()) ? null : this, args); } if (channel.getPipeline().get(getClass().getSimpleName()) == null) { throw new IOException("This MBeanServerConnection has been closed", new Throwable()); } // SimpleLogger.debug("MBeanServerConnection [", method.getName(), "] Payload Size [", // sargs.length+6+4, "]"); final int reqId = requestId.incrementAndGet(); if ("addNotificationListener".equals(method.getName()) && !method.getParameterTypes()[1].equals(ObjectName.class)) { NotificationListener listener = (NotificationListener) args[1]; args[1] = reqId; addRegisteredListener(reqId, listener); } else if ("removeNotificationListener".equals(method.getName()) && !method.getParameterTypes()[1].equals(ObjectName.class)) { removeRegisteredListener((NotificationListener) args[1]); args = new Object[0]; } byte[] sargs = getOutput(args); ChannelBuffer cb = ChannelBuffers.directBuffer(1 + domainInfoData.length + 4 + 1 + 4 + sargs.length); cb.writeByte(OpCode.JMX_REQUEST.op()); // 1 cb.writeBytes(domainInfoData); // domain data cb.writeInt(reqId); // 4 cb.writeByte(methodToKey.get(method)); // 1 cb.writeInt(sargs.length); // 4 cb.writeBytes(sargs); // sargs.length if (listener == null) { synchTimeoutMap.addListener( new TimeoutListener<Integer, CountDownLatch>() { @Override public void onTimeout(Integer key, CountDownLatch value) { if (reqId == key) { synchTimeoutMap.remove(key); synchTimeoutMap.removeListener(this); onSynchronousResponse( reqId, new IOException( "Operation timed out after [" + timeout + "] ms.", new Throwable())); } } }); } else { asynchTimeoutMap.put(reqId, listener, timeout); asynchTimeoutMap.addListener( new TimeoutListener<Integer, AsynchJMXResponseListener>() { @Override public void onTimeout(Integer key, AsynchJMXResponseListener value) { if (reqId == key) { asynchTimeoutMap.remove(key); listener.onTimeout(reqId, timeout); asynchTimeoutMap.removeListener(this); } } }); } channel .write(cb, remoteAddress) .addListener( new ChannelFutureListener() { @Override public void operationComplete(ChannelFuture future) throws Exception { if (future.isSuccess()) { SimpleLogger.debug("Sent JMX Request to [", remoteAddress, "]"); } else { SimpleLogger.error( "Failed to send JMX Request to [", remoteAddress, "]", future.getCause()); } } }); if (listener == null) { waitForSynchronousResponse(reqId, timeout); Object result = synchResultMap.get(reqId); if (result != null && result instanceof Throwable) { throw (Throwable) result; } return result; } return null; }
private void reportTestAsNotApplicableInCurrentTestRun(Method method) { Class<?> testClass = method.getDeclaringClass(); Description testDescription = Description.createTestDescription(testClass, method.getName()); runNotifier.fireTestAssumptionFailed(new Failure(testDescription, NOT_APPLICABLE)); }
private void printComponentTree( PrintWriter out, String errorId, FacesContext context, UIComponent comp, int depth) { for (int i = 0; i < depth; i++) out.print(' '); boolean isError = false; if (errorId != null && errorId.equals(comp.getClientId(context))) { isError = true; out.print("<span style='color:red'>"); } out.print("<" + comp.getClass().getSimpleName()); if (comp.getId() != null) out.print(" id=\"" + comp.getId() + "\""); for (Method method : comp.getClass().getMethods()) { if (!method.getName().startsWith("get") && !method.getName().startsWith("is")) continue; else if (method.getParameterTypes().length != 0) continue; String name; if (method.getName().startsWith("get")) name = method.getName().substring(3); else if (method.getName().startsWith("is")) name = method.getName().substring(2); else continue; // XXX: getURL name = Character.toLowerCase(name.charAt(0)) + name.substring(1); ValueExpression expr = comp.getValueExpression(name); Class type = method.getReturnType(); if (expr != null) { out.print(" " + name + "=\"" + expr.getExpressionString() + "\""); } else if (method.getDeclaringClass().equals(UIComponent.class) || method.getDeclaringClass().equals(UIComponentBase.class)) { } else if (name.equals("family")) { } else if (String.class.equals(type)) { try { Object value = method.invoke(comp); if (value != null) out.print(" " + name + "=\"" + value + "\""); } catch (Exception e) { } } } int facetCount = comp.getFacetCount(); int childCount = comp.getChildCount(); if (facetCount == 0 && childCount == 0) { out.print("/>"); if (isError) out.print("</span>"); out.println(); return; } out.println(">"); if (isError) out.print("</span>"); for (int i = 0; i < childCount; i++) { printComponentTree(out, errorId, context, comp.getChildren().get(i), depth + 1); } for (int i = 0; i < depth; i++) out.print(' '); if (isError) out.print("<span style='color:red'>"); out.println("</" + comp.getClass().getSimpleName() + ">"); if (isError) out.print("</span>"); }