Generates a deterministic signature for an {@link AnnotatedCallable}. Two
<code>AnnotatedCallable</code>s that have the same annotations and
underlying callable will generate the same signature.
322833
public static <X> String createCallableId(AnnotatedCallable<X> method) {
        StringBuilder builder = new StringBuilder();
        builder.append(method.getJavaMember().getDeclaringClass().getName());
        builder.append('.');
        builder.append(method.getJavaMember().getName());
        builder.append(createAnnotationCollectionId(method.getAnnotations()));
        builder.append(createParameterListId(method.getParameters()));
        return builder.toString();
    }
971463
public static boolean compareAnnotatedParameters(AnnotatedParameter<?> p1, AnnotatedParameter<?> p2) {
        return compareAnnotatedCallable(p1.getDeclaringCallable(), p2.getDeclaringCallable()) && p1.getPosition() == p2.getPosition() && compareAnnotated(p1, p2);
    }
1215752
@Override
    public Pair<T1, T2> generateId() {
        return new Pair<T1, T2>(firstIdGenerator.generateId(), secondIdGenerator.generateId());
    }
510780
protected void generateMethodSignature(SQLiteModelMethod method, MethodSpec.Builder methodBuilder, TypeName returnTypeName, ParameterSpec... additionalParameterSpec) {
		boolean finalParameter = false;
		if (method.hasLiveData() && returnTypeName.equals(method.liveDataReturnClass)) {
			finalParameter = true;
		}

		// add parameter for method
		for (Pair<String, TypeName> item : method.getParameters()) {
			ParameterSpec.Builder builder = ParameterSpec.builder(item.value1, item.value0);

			if (finalParameter) {
				builder.addModifiers(Modifier.FINAL);
			}

			methodBuilder.addParameter(builder.build());
		}

		// add additional params
		for (ParameterSpec item : additionalParameterSpec) {
			methodBuilder.addParameter(item);
		}

		// add return type
		methodBuilder.returns(returnTypeName);
	}
107192
private String createMethodSignature(Method method)
   {
      StringBuilder sb = new StringBuilder();
      sb.append("(");
      for (Class<?> type : method.getParameterTypes())
      {
         sb.append(getTypeString(type));
      }
      sb.append(")");
      Class<?> type = method.getReturnType();
      if (type.getName().equals("void"))
      {
         sb.append("V");
      }
      else
      {
         sb.append(getTypeString(type));
      }
      return sb.toString();
   }
258256
@Override
	protected Annotation[] createParameterAnnotations(
			String parmName,
			MethodInfo methodInfo,
			java.lang.annotation.Annotation[] annotations,
			ConstPool parameterConstPool) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {
		List<Annotation> ctParmAnnotations = new LinkedList<Annotation>();

		for(java.lang.annotation.Annotation annotation : annotations) {
			Annotation clone = cloneAnnotation(parameterConstPool, annotation);

			// Special case: since Javaassist doesn't allow me to set the name of the parameter,
			// I need to ensure that RequestParam's value is set to the parm name if there isn't already
			// a value set
			//
			if (RequestParam.class.isAssignableFrom(annotation.annotationType())) {
				if ("".equals(((RequestParam)annotation).value()) && !StringUtils.isEmpty(parmName)) {
					MemberValue value = createMemberValue(parameterConstPool, parmName);
					clone.addMemberValue("value", value);
				}
			}

			ctParmAnnotations.add(clone);
		}
		return ctParmAnnotations.toArray(new Annotation[]{});
	}
1191124
private MethodMetadata<?, ?> createResultOfMetadata(AnnotatedMethod annotatedMethod, ResultOf resultOf) {
        Method method = annotatedMethod.getAnnotatedElement();

        // Determine query type
        Class<?> methodReturnType = method.getReturnType();
        Class<?> returnType;
        if (Result.class.isAssignableFrom(methodReturnType)) {
            Type genericReturnType = method.getGenericReturnType();
            ParameterizedType parameterizedType = (ParameterizedType) genericReturnType;
            returnType = (Class<?>) parameterizedType.getActualTypeArguments()[0];
        } else {
            returnType = methodReturnType;
        }

        // Determine query type
        AnnotatedElement query = resultOf.query();
        if (Object.class.equals(query)) {
            if (annotatedMethod.getByMetaAnnotation(QueryDefinition.class) != null) {
                query = annotatedMethod.getAnnotatedElement();
            } else {
                query = returnType;
            }
        }
        // Determine parameter bindings
        Annotation[][] parameterAnnotations = method.getParameterAnnotations();
        List<Parameter> parameters = new ArrayList<>();
        for (Annotation[] parameterAnnotation : parameterAnnotations) {
            Parameter parameter = null;
            for (Annotation annotation : parameterAnnotation) {
                if (Parameter.class.equals(annotation.annotationType())) {
                    parameter = (Parameter) annotation;
                }
            }
            if (parameter == null) {
                throw new XOException("Cannot determine parameter names for '" + method.getName() + "', all parameters must be annotated with '"
                        + Parameter.class.getName() + "'.");
            }
            parameters.add(parameter);
        }
        boolean singleResult = !Iterable.class.isAssignableFrom(methodReturnType);
        return new ResultOfMethodMetadata<>(annotatedMethod, query, returnType, resultOf.usingThisAs(), parameters, singleResult);
    }
829396
private <RequestT, ResponseT> UnaryCallable<RequestT, ResponseT> createUserFacingUnaryCallable(
      String methodName, UnaryCallable<RequestT, ResponseT> inner) {

    UnaryCallable<RequestT, ResponseT> traced =
        new TracedUnaryCallable<>(
            inner,
            clientContext.getTracerFactory(),
            SpanName.of(TRACING_OUTER_CLIENT_NAME, methodName));

    return traced.withDefaultCallContext(clientContext.getDefaultCallContext());
  }
1133241
@Override
    public void generate() throws CodeGenerationException
    {
        super.generate();

        /*
        The annotation processor may be passed multiple control client types.  Build a map that
        links each control client type with the set of control types that it uses.
        */

        Map<TypeDeclaration,Set<TypeMirror>> clientsMap = new HashMap<TypeDeclaration,Set<TypeMirror>>();

        for (AnnotationTypeDeclaration atd : _atds)
        {
            if (atd.getSimpleName().equals("Control") )
            {
                AnnotationProcessorEnvironment env = getAnnotationProcessorEnvironment();
                Collection<Declaration> decls = env.getDeclarationsAnnotatedWith(atd);
                for (Declaration decl : decls)
                {
                    if ( decl instanceof FieldDeclaration )
                    {
                        FieldDeclaration fd = (FieldDeclaration)decl;
                        TypeDeclaration clientType = fd.getDeclaringType();
                        TypeMirror controlFieldType = fd.getType();
                        addControlType( clientsMap, clientType, controlFieldType );

                        /*
                        Add the control type to any derived class.  Fields with
                        private and default (package) access are also included
                        here as the controls in superclasses may be exposed
                        through public or protected methods to subclasses.
                        */
                        Collection<TypeDeclaration> specifiedTypeDeclartions = env.getSpecifiedTypeDeclarations();
                        for (TypeDeclaration td : specifiedTypeDeclartions)
                        {
                            if (td instanceof ClassDeclaration)
                            {
                                ClassType superclass = ((ClassDeclaration) td).getSuperclass();
                                while (superclass != null)
                                {
                                    if (superclass.getDeclaration().equals(clientType))
                                    {
                                        addControlType(clientsMap, td, controlFieldType);
                                        break;
                                    }

                                    superclass = superclass.getSuperclass();
                                }
                            }
                        }
                    }
                }
            }
            else if (atd.getSimpleName().equals("ControlReferences"))
            {
                Collection<Declaration> decls = getAnnotationProcessorEnvironment().getDeclarationsAnnotatedWith(atd);
                for (Declaration decl : decls)
                {
                    if ( decl instanceof TypeDeclaration )
                    {
                        TypeDeclaration clientType = (TypeDeclaration)decl;
                        Set<TypeMirror> controlTypes = clientsMap.get( clientType );
                        if ( controlTypes == null )
                        {
                            controlTypes = new HashSet<TypeMirror>();
                            clientsMap.put( clientType, controlTypes );
                        }

                        // Read ControlReferences annotation
                        AnnotationMirror controlMirror = null;
                        for (AnnotationMirror annot : clientType.getAnnotationMirrors())
                        {
                            if (annot.getAnnotationType().getDeclaration().getQualifiedName().equals(
                                    "org.apache.beehive.controls.api.bean.ControlReferences"))
                            {
                                controlMirror = annot;
                                break;
                            }
                        }

                        assert( controlMirror != null );

                        // Add each control type listed in the ControlReferences annotation
                        AptAnnotationHelper controlAnnot = new AptAnnotationHelper(controlMirror);
                        Collection<AnnotationValue> references = (Collection<AnnotationValue>)controlAnnot.getObjectValue("value");
                        if ( references != null )
                        {
                            for ( AnnotationValue av : references )
                            {
                                TypeMirror crType = (TypeMirror)av.getValue();
                                controlTypes.add( crType );
                            }
                        }
                    }
                }
            }
        }

        // For each client type:
        //   1 - emit a controls client manifest in the same dir as the client type's class.
        //   2 - emit a controls client initializer class in the same pkg/dir as the client type's class

        Filer f = getAnnotationProcessorEnvironment().getFiler();
        Set<TypeDeclaration> clientTypes = clientsMap.keySet();
        for ( TypeDeclaration clientType : clientTypes )
        {
            // Emit manifest

            String clientPkg = clientType.getPackage().getQualifiedName();
            File clientManifestName =
                new File( clientType.getSimpleName() + ControlClientManifest.FILE_EXTENSION );

            ControlClientManifest mf = new ControlClientManifest( clientType.getQualifiedName() );

            try
            {
                Set<TypeMirror> controlTypes = clientsMap.get( clientType );
                for ( TypeMirror controlType : controlTypes )
                {
                    InterfaceDeclaration controlIntfOrExt = getControlInterfaceOrExtension(controlType);
                    InterfaceDeclaration controlIntf = getMostDerivedControlInterface( controlIntfOrExt );

                    assert controlIntf != null : "Can't find most derived control intf for=" + controlIntfOrExt;

                    ControlInterface annot = controlIntf.getAnnotation(ControlInterface.class);
                    String defBinding = annot.defaultBinding();

                    defBinding = ControlUtils.resolveDefaultBinding( defBinding, controlIntf.getQualifiedName() );

                    mf.addControlType( controlIntfOrExt.getQualifiedName(), defBinding );
                }

                mf.emit( f, clientPkg, clientManifestName, null );
            }
            catch ( IOException ie )
            {
                printError( clientType, "controls.client.manifest.ioerror" );
                ie.printStackTrace( );
            }

            // Emit initializer

            AnnotationProcessorEnvironment env = getAnnotationProcessorEnvironment();
            Generator genClass = new AptControlClient( clientType, this );

            if ( genClass != null )
            {
                try
                {
                    List<GeneratorOutput> genList = genClass.getGenerateOutput(env.getFiler());
                    if (genList == null || genList.size() == 0)
                        return;

                    for (GeneratorOutput genOut : genList)
                    {
                        getGenerator().generate(genOut);
                    }
                }
                catch (IOException ioe)
                {
                    throw new CodeGenerationException("Code generation failure: ", ioe);
                }
            }
        }
    }
904224
@VisibleForTesting
    static String generateSignature(Credential signingCredential, String algorithmURI, String input) {
        try {
            final byte[] signature =
                    XMLSigningUtil.signWithURI(signingCredential, algorithmURI,
                                               input.getBytes(StandardCharsets.UTF_8));
            return Base64.getEncoder().encodeToString(signature);
        } catch (SecurityException e) {
            throw new SamlException("failed to generate a signature", e);
        }
    }
905073
void annotation( AnnotatedDescrBuilder<?> adb ) {
        AnnotationDescrBuilder<?> annotation = null;

        try {
            if (speculateFullAnnotation()) {
                boolean buildState = exprParser.isBuildDescr();
                exprParser.setBuildDescr(true);
                exprParser.fullAnnotation(adb);
                exprParser.setBuildDescr(buildState);
            } else {

                // '@'
                Token at = match(input,
                        DRL6Lexer.AT,
                        null,
                        null,
                        DroolsEditorType.SYMBOL);
                if (state.failed)
                    return;

                // identifier
                String fqn = qualifiedIdentifier();
                if (state.failed)
                    return;

                if (state.backtracking == 0) {
                    annotation = adb.newAnnotation(fqn);
                    helper.setStart(annotation,
                            at);
                }

                try {
                    if (input.LA(1) == DRL6Lexer.LEFT_PAREN) {
                        String value = chunk(DRL6Lexer.LEFT_PAREN,
                                DRL6Lexer.RIGHT_PAREN,
                                -1).trim();
                        if (state.failed)
                            return;
                        if (state.backtracking == 0) {
                            annotation.value(value);
                        }
                    }
                } finally {
                    if (state.backtracking == 0) {
                        helper.setEnd(annotation);
                    }
                }
            }

        } catch (RecognitionException re) {
            reportError(re);
        }
    }
551420
@SuppressWarnings("unchecked")
    public <T extends Annotation> T getSetterAnnotation(Method method, Class<T> annotationType) {
        T annotation = method.getAnnotation(annotationType);
        if (annotation != null) {
            return annotation;
        }
        Annotation[][] parameterAnnotations = method.getParameterAnnotations();
        if (parameterAnnotations.length > 0 ) {
            for (Annotation anno : parameterAnnotations[0]) {
                if (annotationType.isInstance(anno)) {
                    return (T)anno;
                }
            }
        }
        return null;
    }
1154259
private CodeBlock constructorCallCode( ClassName className, ImmutableList<? extends JParameterizedMapper> parameters ) {
        CodeBlock.Builder builder = CodeBlock.builder();
        builder.add( "new $T", className );
        return methodCallCodeWithJParameterizedMapperParameters( builder, parameters );
    }
1048314
static String getMethodSignature(Method m) {
      StringBuilder result = new StringBuilder();
      result.append('(');
      for (Class<?> parameterType : m.getParameterTypes()) {
        result.append(getSignature(parameterType));
      }
      result.append(")");
      result.append(getSignature(m.getReturnType()));
      return result.toString();
    }
402148
public MultipleObjectsBundle generate() {
    // we actually need some clusters.
    if(generators.isEmpty()) {
      throw new AbortException("No clusters specified.");
    }
    // Assert that cluster dimensions agree.
    final int dim = generators.get(0).getDim();
    for(GeneratorInterface c : generators) {
      if(c.getDim() != dim) {
        throw new AbortException("Cluster dimensions do not agree.");
      }
    }
    // Prepare result bundle
    MultipleObjectsBundle bundle = new MultipleObjectsBundle();
    VectorFieldTypeInformation<DoubleVector> type = new VectorFieldTypeInformation<>(DoubleVector.FACTORY, dim);
    bundle.appendColumn(type, new ArrayList<>());
    bundle.appendColumn(TypeUtil.CLASSLABEL, new ArrayList<>());
    bundle.appendColumn(Model.TYPE, new ArrayList<Model>());

    // generate clusters
    ClassLabel[] labels = new ClassLabel[generators.size()];
    Model[] models = new Model[generators.size()];
    initLabelsAndModels(generators, labels, models, relabelClusters);
    final AssignPoint assignment;
    if(!testAgainstModel) {
      assignment = new AssignPoint();
    }
    else if(relabelClusters == null) {
      assignment = new TestModel();
    }
    else if(!relabelDistance) {
      assignment = new AssignLabelsByDensity(labels);
    }
    else {
      assignment = new AssignLabelsByDistance(labels);
    }
    for(int i = 0; i < labels.length; i++) {
      final GeneratorInterface curclus = generators.get(i);
      assignment.newCluster(i, curclus);
      // Only dynamic generators allow rejection / model testing:
      GeneratorInterfaceDynamic cursclus = (curclus instanceof GeneratorInterfaceDynamic) ? (GeneratorInterfaceDynamic) curclus : null;
      int kept = 0;
      while(kept < curclus.getSize()) {
        // generate the "missing" number of points
        List<double[]> newp = curclus.generate(curclus.getSize() - kept);
        for(double[] p : newp) {
          int bestc = assignment.getAssignment(i, p);
          if(bestc < 0) {
            cursclus.incrementDiscarded();
            continue;
          }
          bundle.appendSimple(DoubleVector.wrap(p), labels[bestc], models[bestc]);
          ++kept;
        }
      }
    }
    return bundle;
  }
992444
public static <T> T call(Callable<T> c)
   {
      if (c == null)
      {
         return null;
      }
      try
      {
         return c.call();
      }
      catch (RuntimeException e)
      {
         throw e;
      }
      catch (Exception e)
      {
         throw new RuntimeException("Error invoking Callable [c]", e);
      }
   }
861781
public static String generatedNameOf(Class<?> clazz, Class<? extends Annotation> annotationClass)
    {
        return builder(clazz, annotationClass).build();
    }