Creates module stater class according to the annotations

@param annotationMap map of annotations to process
@param processingEnv environment to access facilities the tool framework provides to the processor
@return Module name
974322
private String createModuleStarter(final Map<Class<?>, Set<? extends Element>> annotationMap, ProcessingEnvironment processingEnv) {
        String moduleName;
        try {
            moduleName = getModuleStarterName(processingEnv);
            final String starterName = moduleName.substring(moduleName.lastIndexOf('.') + 1);
            final String pkg = moduleName.substring(0, moduleName.lastIndexOf('.'));

            final JavaClassSource javaClass = Roaster.create(JavaClassSource.class);

            javaClass.setPackage(pkg).setName(starterName);

            javaClass.extendSuperType(AbstractModuleStarter.class);

            final StringBuilder body = new StringBuilder();

            appendRegistrationPoints(javaClass, body, annotationMap.get(RegistrationPoint.class));

            appendRegistrations(javaClass, body, annotationMap.get(Register.class));

            appendPreload(javaClass, body, annotationMap.get(Preload.class));

            appendBootComponent(javaClass, body, annotationMap.get(BootComponent.class));

            if (!javaClass.hasMethodSignature("start")) {
                final MethodSource<?> method = javaClass.addMethod()
                                                        .setName("start")
                                                        .setPublic()
                                                        .setBody(body.toString())
                                                        .setReturnTypeVoid();
                method.getJavaDoc().setFullText("{@inheritDoc}");
                method.addAnnotation(Override.class);

            } else {
                javaClass.getMethod("start").setBody(javaClass.getMethod("start").getBody() + body.toString());
            }

            final Properties prefs = new Properties();
            prefs.load(this.getClass().getResourceAsStream(FORMATTER_PROPERTIES_FILE));
            final String formattedSource = Formatter.format(prefs, javaClass);

            // System.out.println(formattedSource);

            final JavaFileObject jfo = this.processingEnv.getFiler().createSourceFile(moduleName);
            this.processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE, "creating source file: " + jfo.toUri());

            final Writer writer = jfo.openWriter();
            writer.write(formattedSource);
            writer.close();
        } catch (final Exception e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        }

        return moduleName;
    }
137516
public static JavacTrees instance(ProcessingEnvironment env) {
        if (!(env instanceof JavacProcessingEnvironment))
            throw new IllegalArgumentException();
        return instance(((JavacProcessingEnvironment)env).getContext());
    }
518702
private static Map<String, Object> getEnumNamesMap(Class<? extends Enum<?>> enumType) {
		final String sourceMethod = "getEnumNameMap"; //$NON-NLS-1$
		final boolean isTraceLogging = log.isLoggable(Level.FINER);
		if (isTraceLogging) {
			log.entering(sourceClass, sourceMethod, new Object[]{enumType});
		}
		Map<String, Object> result = new HashMap<String, Object>();
		Enum<?>[] values = enumType.getEnumConstants();
		for (Enum<?> value : values) {
			result.put(value.name(), value);
		}
		if (isTraceLogging) {
			log.exiting(sourceMethod, sourceMethod, result);
		}
		return result;
	}
26757
@SuppressWarnings("static-method")
	protected String generateYaml(Map<String, Object> map) throws JsonProcessingException {
		final YAMLFactory yamlFactory = new YAMLFactory();
		yamlFactory.configure(Feature.WRITE_DOC_START_MARKER, false);
		final ObjectMapper mapper = new ObjectMapper(yamlFactory);
		return mapper.writerWithDefaultPrettyPrinter().writeValueAsString(map);
	}
149183
private Object processJavaColonModule(String lookupName) throws NamingException {
        ComponentMetaData cmd = getComponentMetaData(JavaColonNamespace.MODULE, lookupName);
        ModuleMetaData mmd = cmd.getModuleMetaData();
        JavaColonNamespaceBindings<EJBBinding> modMap = getModuleBindingMap(mmd);
        EJBBinding binding = modMap.lookup(lookupName);

        return processJavaColon(binding, JavaColonNamespace.MODULE, lookupName);
    }
859372
static String sourceFormForInitializer(
      AnnotationValue annotationValue,
      ProcessingEnvironment processingEnv,
      String memberName,
      Element context) {
    SourceFormVisitor visitor =
        new InitializerSourceFormVisitor(processingEnv, memberName, context);
    StringBuilder sb = new StringBuilder();
    visitor.visit(annotationValue, sb);
    return sb.toString();
  }
143185
protected void _generate(SarlAnnotationType annotation, IExtraLanguageGeneratorContext context) {
		final JvmDeclaredType jvmType = getJvmModelAssociations().getInferredType(annotation);
		final PyAppendable appendable = createAppendable(jvmType, context);
		if (generateTypeDeclaration(
				this.qualifiedNameProvider.getFullyQualifiedName(annotation).toString(),
				annotation.getName(), false, Collections.emptyList(),
				getTypeBuilder().getDocumentation(annotation),
				true,
				annotation.getMembers(), appendable, context, null)) {
			final QualifiedName name = getQualifiedNameProvider().getFullyQualifiedName(annotation);
			writeFile(name, appendable, context);
		}
	}
1219289
public static void init(ProcessingEnvironment env) {
		processingEnv = env;
		typeUtils = processingEnv.getTypeUtils();
		elementUtils = processingEnv.getElementUtils();
	}
1049405
private <T extends PackageDoc> void mapAnnotations(Map<String,List<T>> map, PackageDoc doc,
            T holder) {
        AnnotationDesc[] annotations;
        annotations = doc.annotations();
        for (int i = 0; i < annotations.length; i++) {
            AnnotationTypeDoc annotationDoc = annotations[i].annotationType();
            refList(map, annotationDoc).add(holder);
        }
    }
1071071
private static Map<String, Method> createOperationMethods(BeanInfo beanInfo) throws ManagementException {
        Set<Method> allAccessors = allAccessors(beanInfo);
        Map<String, Method> operationMethods = new HashMap<String, Method>();
        for (MethodDescriptor descriptor : beanInfo.getMethodDescriptors()) {
            Method method = descriptor.getMethod();
            ManagedOperation operationAnnotation = method.getAnnotation(ManagedOperation.class);
            if (operationAnnotation != null && allAccessors.contains(method)) {
                throw new ManagementException(
                        String.format("Accessor method %s is annotated as an @%s", method, ManagedOperation.class.getName()));
            }
            /* consider the Method an automatic operation if it satisfies all of:
             * 1. its class is annotated with @MBean(automatic=OPERATION)
             * 2. it is a public instance (non static) method
             * 3. it is NOT considered a bean accessor (getter/setter)
             */
            boolean isAutomatic = isAutomatic(method.getDeclaringClass(), AutomaticType.OPERATION);
            boolean autoOperation = (isAutomatic && isPublicInstance(method) && !allAccessors.contains(method));
            if (operationAnnotation != null || autoOperation) {
                // This method is an operation
                Method old = operationMethods.put(method.getName(), method);
                if (old != null) {
                    //TODO support multiple identically named operation methods
                    throw new ManagementException(format("Multiple Operation annotations for operation %s of %s",
                            method.getName(), old.getDeclaringClass()));
                }
            }
        }
        return operationMethods;
    }
664038
@Override
    protected ImmutableMap<Class<? extends QueryOptimizationProposal>, Class<? extends ProposalExecutor>>
    generateOptimizationConfigurationMap() {
        return Stream.concat(
                    super.generateOptimizationConfigurationMap().entrySet().stream(),
                    systemConfiguration.generateOptimizationConfigurationMap().entrySet().stream())
                .distinct()
                .collect(ImmutableCollectors.toMap());
    }
1243378
public <A2 extends Annotation> AnnotationMetadata annotate(
            AnnotationMetadata annotationMetadata,
            AnnotationValue<A2> annotationValue) {
        if (annotationMetadata instanceof DefaultAnnotationMetadata) {
            final Optional<T> annotationMirror = getAnnotationMirror(annotationValue.getAnnotationName());
            final DefaultAnnotationMetadata defaultMetadata = (DefaultAnnotationMetadata) annotationMetadata;
            defaultMetadata.addDeclaredAnnotation(
                    annotationValue.getAnnotationName(),
                    annotationValue.getValues()
            );
            annotationMirror.ifPresent(annotationType ->
                    processAnnotationStereotypes(
                            defaultMetadata,
                            true,
                            annotationType,
                            annotationValue.getAnnotationName()
                    )
            );
        }
        return annotationMetadata;
    }
324432
private void processClientModulePersistenceXml(JPAApplInfo applInfo, ContainerInfo module, ClassLoader loader) {
        final boolean isTraceOn = TraceComponent.isAnyTracingEnabled();
        if (isTraceOn && tc.isEntryEnabled())
            Tr.entry(tc, "processClientModulePersistenceXml : " + applInfo.getApplName() +
                         "#" + module.getName());

        String archiveName = module.getName();
        Container clientContainer = module.getContainer();
        ClassLoader clientClassLoader = loader;

        // ------------------------------------------------------------------------
        // JPA 2.0 Specification - 8.2 Persistence Unit Packaging
        //
        // A persistence unit is defined by a persistence.xml file. The jar file or
        // directory whose META-INF directory contains the persistence.xml file is
        // termed the root of the persistence unit. In Java EE environments, the
        // root of a persistence unit may be one of the following:
        //
        // -> an EJB-JAR file
        // ------------------------------------------------------------------------

        // Obtain persistence.xml in META-INF
        Entry pxml = clientContainer.getEntry("META-INF/persistence.xml");
        if (pxml != null) {
            String appName = applInfo.getApplName();
            URL puRoot = getPXmlRootURL(appName, archiveName, pxml);
            applInfo.addPersistenceUnits(new OSGiJPAPXml(applInfo, archiveName, JPAPuScope.Client_Scope, puRoot, clientClassLoader, pxml));
        }

        if (isTraceOn && tc.isEntryEnabled())
            Tr.exit(tc, "processClientModulePersistenceXml : " + applInfo.getApplName() +
                        "#" + module.getName());
    }
1080510
public JavaCompiler processAnnotations(List<JCCompilationUnit> roots) {
        return processAnnotations(roots, List.<String>nil());
    }
1087591
public static PropertyMap getAnnotationMap(ControlBeanContext cbc, AnnotatedElement annotElem)
    {
        if ( cbc == null )
            return new AnnotatedElementMap(annotElem);

        return cbc.getAnnotationMap(annotElem);
    }
715487
public MapSchema.MessageFactory getEnumMapFactory()
    {
        MapSchema.MessageFactory enumMapFactory = this.enumMapFactory;
        if (enumMapFactory == null)
        {
            synchronized (this)
            {
                if ((enumMapFactory = this.enumMapFactory) == null)
                    this.enumMapFactory = enumMapFactory = newEnumMapFactory(this);
            }
        }
        return enumMapFactory;
    }
762818
@SuppressWarnings("unused")
	private String listAnnotationProcessorsBeforeOurs() {
		try {
			Object discoveredProcessors = javacProcessingEnvironment_discoveredProcs.get(this.javacProcessingEnv);
			ArrayList<?> states = (ArrayList<?>) discoveredProcessors_procStateList.get(discoveredProcessors);
			if (states == null || states.isEmpty()) return null;
			if (states.size() == 1) return processorState_processor.get(states.get(0)).getClass().getName();
			
			int idx = 0;
			StringBuilder out = new StringBuilder();
			for (Object processState : states) {
				idx++;
				String name = processorState_processor.get(processState).getClass().getName();
				if (out.length() > 0) out.append(", ");
				out.append("[").append(idx).append("] ").append(name);
			}
			return out.toString();
		} catch (Exception e) {
			return null;
		}
	}