/*
(non-Javadoc)

@see javax.annotation.processing.AbstractProcessor#process(java.util.Set, javax.annotation.processing.RoundEnvironment)
960951
@Override
	public boolean process(final Set<? extends TypeElement> annotations, final RoundEnvironment roundEnv) {
		try {
			count++;
			if (count == 1) {

				many2ManyProcessor.clear();
				typeProcessor.clear();
				sharedPreferencesProcessor.clear();
				dataSourceProcessor.clear();

				// generate @BindGeneratedDao
				many2ManyProcessor.process(annotations, roundEnv);

				// generate bindmap
				typeProcessor.process(annotations, roundEnv);

				sharedPreferencesProcessor.process(annotations, roundEnv);
				sharedPreferencesProcessor.generateClasses();

				dataSourceProcessor.generatedEntities = many2ManyProcessor.result.value0;
				dataSourceProcessor.generatedDaos = many2ManyProcessor.result.value1;
				// dump(1, roundEnv);
				dataSourceProcessor.analyzeRound(annotations, roundEnv);
				dataSourceProcessor.process(annotations, roundEnv);
				dataSourceProcessor.generateClasses(roundEnv);
			} else if (count == 2) {
				dataSourceProcessor.analyzeSecondRound(annotations, roundEnv);
				dataSourceProcessor.processSecondRound(annotations, roundEnv);
				dataSourceProcessor.generateClassesSecondRound(roundEnv);
			}

			return true;
		} catch (Throwable e) {
			String msg = StringUtils.nvl(e.getMessage());
			error(null, e.getClass().getCanonicalName() + ": " + msg);

			if (DEBUG_MODE) {
				if (JUNIT_TEST_MODE) {
					logger.log(Level.SEVERE, msg);
					//e.printStackTrace();
				} else {
					StackTraceElement[] stackTrace = e.getStackTrace();
					for (StackTraceElement item : stackTrace) {
						error(null, String.format("\tat %s.%s(%s:%s)", item.getClassName(), item.getMethodName(), item.getFileName(), item.getLineNumber()));
					}					
				}
			}
			return false;
		}

	}
478776
public Set<Element> filter(RoundEnvironment roundEnv) {
		Set<Element> result=new HashSet<Element>();		
		for (Class<? extends Annotation> annotation: getSupportedAnnotationClasses()) {
			result.addAll(roundEnv.getElementsAnnotatedWith(annotation));	
		}
		
		return result;
		
	}
379425
public void setEnvironmentVariables(Map<String, String> environment) {
    for (Map.Entry<String, String> entry : environment.entrySet()) {
      setEnvironmentVariable(entry.getKey(), entry.getValue());
    }
  }
1288925
private static void setEnv(Map<String, String> newEnv, boolean overwrite) {

		for (Entry<String, String> entry : newEnv.entrySet()) {
			if (overwrite || System.getProperty(entry.getKey()) != null) {
				System.setProperty(entry.getKey(), entry.getValue());
			}
		}

		if (!overwrite) {
			Iterator<Entry<String, String>> iterator = newEnv.entrySet().iterator();
			while (iterator.hasNext()) {
				Entry<String, String> next = iterator.next();
				if (System.getenv(next.getKey()) != null) {
					iterator.remove();
				}
			}
		}

		try {
			Class<?> processEnvironmentClass = Class.forName("java.lang.ProcessEnvironment");
			Method variableMethod = Class.forName("java.lang.ProcessEnvironment$Variable").getMethod("valueOf", String.class);
			variableMethod.setAccessible(true);
			Method valueMethod = Class.forName("java.lang.ProcessEnvironment$Value").getMethod("valueOf", String.class);
			valueMethod.setAccessible(true);

			Map<Object, Object> newEnvVarVal = new HashMap<Object, Object>();
			for (Map.Entry<String, String> entry : newEnv.entrySet()) {
				Object key = variableMethod.invoke(null, entry.getKey());
				String valueText = entry.getValue();
				Object value = valueText != null ? valueMethod.invoke(null, valueText) : null;
				newEnvVarVal.put(key, value);
			}

			Field theEnvironmentField = processEnvironmentClass.getDeclaredField("theEnvironment");
			theEnvironmentField.setAccessible(true);
			Map<Object, Object> env = (Map<Object, Object>) theEnvironmentField.get(null);
			for (Entry<Object, Object> entry : newEnvVarVal.entrySet()) {
				if (entry.getValue() == null) {
					env.remove(entry.getKey());
				} else {
					env.put(entry.getKey(), entry.getValue());
				}
			}
			Field theCaseInsensitiveEnvironmentField = processEnvironmentClass.getDeclaredField("theCaseInsensitiveEnvironment");
			theCaseInsensitiveEnvironmentField.setAccessible(true);
			Map<Object, Object> cienv = (Map<Object, Object>) theCaseInsensitiveEnvironmentField.get(null);
			cienv.putAll(newEnvVarVal);

		} catch (NoSuchFieldException e) {
			try {
				Class[] classes = Collections.class.getDeclaredClasses();
				Map<String, String> env = System.getenv();
				for (Class cl : classes) {
					if ("java.util.Collections$UnmodifiableMap".equals(cl.getName())) {
						Field field = cl.getDeclaredField("m");
						field.setAccessible(true);
						Object obj = field.get(env);
						Map<String, String> map = (Map<String, String>) obj;
						for (Entry<String, String> entry : newEnv.entrySet()) {
							if (entry.getValue() == null) {
								map.remove(entry.getKey());
							} else {
								map.put(entry.getKey(), entry.getValue());
							}
						}
					}
				}
			} catch (Exception e2) {
				LOGGER.error(e2.getMessage(), e2);
			}
		} catch (Exception e1) {
			LOGGER.error(e1.getMessage(), e1);
		}
	}
562514
@Override
    public void preProcess(DataSet toPreProcess) {
        for (DataSetPreProcessor preProcessor : preProcessors) {
            preProcessor.preProcess(toPreProcess);
        }
    }
970025
@Override
	public synchronized void init(ProcessingEnvironment processingEnv) {
		super.init(processingEnv);

		KriptonProcessor.trees = Trees.instance(processingEnv);

		KriptonOptions.init(this, processingEnv);

		typeProcessor.init(processingEnv);
		many2ManyProcessor.init(processingEnv);
		sharedPreferencesProcessor.init(processingEnv);
		dataSourceProcessor.init(processingEnv);

		count = 0;
	}
656078
@Override
	public void setEnvironment(ConfigurableEnvironment environment) {
		super.setEnvironment(environment);
		this.reader.setEnvironment(environment);
		this.scanner.setEnvironment(environment);
	}
356069
protected void generateClassesSecondRound(RoundEnvironment roundEnv) throws Exception {
		for (SQLiteDatabaseSchema currentSchema : schemas) {
			BindDaoBuilder.generateSecondRound(elementUtils, filer, currentSchema);
		}
	}
868483
@Override
    public void init(ProcessingEnvironment processingEnv) {
        super.init(processingEnv);
        trees = Trees.instance(processingEnv);
        messager = processingEnv.getMessager();
        types = processingEnv.getTypeUtils();
        elements = processingEnv.getElementUtils();

        try {
            logInvocationScanner = new LogInvocationScanner(
                    processingEnv
            );
        } catch (IOException e) {
            messager.printMessage(
                    Diagnostic.Kind.ERROR,
                    "IOException caught"
            );
            initFailed = true;
        } catch (PackageNameException e) {
            messager.printMessage(
                    Diagnostic.Kind.ERROR,
                    "generatedEventsPackage compiler argument is not valid, either it contains java keyword or subpackage or class name starts with number"
            );
            initFailed = true;
        }

        final String schemasRoot = processingEnv.getOptions().get("schemasRoot");

        if (schemasRoot != null) {
            try {
                new URI(schemasRoot); //check that schemasRoot is valid path
            } catch (URISyntaxException e) {
                initFailed = true;
                messager.printMessage(
                        Diagnostic.Kind.ERROR,
                        format("Provided schemasRoot compiler argument value [%s] is not valid path", schemasRoot)
                );
            }

            // Used for generating json schemas by {@link SchemaGenerator}
            SchemaGenerator schemaGenerator = new SchemaGenerator(generatedClassesInfo, schemasRoot);
            JavacTask.instance(processingEnv).addTaskListener(schemaGenerator);
        }
        else {
            messager.printMessage(
                    Diagnostic.Kind.MANDATORY_WARNING,
                    "schemasRoot compiler argument is not set, no schemas will be created"
            );
        }
    }
1271226
@Override
    public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
        if (CollectionUtils.isNotEmpty(annotations)) {
            Set<? extends Element> routeElements = roundEnv.getElementsAnnotatedWith(Route.class);
            try {
                logger.info(">>> Found routes, start... <<<");
                this.parseRoutes(routeElements);

            } catch (Exception e) {
                logger.error(e);
            }
            return true;
        }

        return false;
    }
1273474
@Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
		if (errorToShow != null) {
			if (errorToShow != null) {
				Set<? extends Element> rootElements = roundEnv.getRootElements();
				if (!rootElements.isEmpty()) {
					processingEnv.getMessager().printMessage(Kind.WARNING, errorToShow, rootElements.iterator().next());
					errorToShow = null;
				}
			}
		}
		return false;
	}
1210879
public void setProcesses(java.util.Collection<ProcessType> processes) {
        if (processes == null) {
            this.processes = null;
            return;
        }

        this.processes = new com.amazonaws.internal.SdkInternalList<ProcessType>(processes);
    }
174169
protected static void checkSameExecutionContext(DataSet<?> set1, DataSet<?> set2) {
		if (set1.getExecutionEnvironment() != set2.getExecutionEnvironment()) {
			throw new IllegalArgumentException("The two inputs have different execution contexts.");
		}
	}
554916
protected void setProcessor(final Processor processor) throws BuildException, NullPointerException {
    if (processor == null) {
      throw new NullPointerException("processor");
    }
    if (isReference()) {
      throw super.tooManyAttributes();
    }
    if (this.env == null && !this.newEnvironment) {
      this.processor = processor;
    } else {
      this.processor = processor.changeEnvironment(this.newEnvironment, this.env);
    }
  }
220834
public void process() throws ConstraintException
    {
        ClassDescriptorDef otherClassDef;
        
        for (Iterator it = getDirectBaseTypes(); it.hasNext();)
        {
            otherClassDef = (ClassDescriptorDef)it.next();
            if (!otherClassDef.hasBeenProcessed())
            {
                otherClassDef.process();
            }
        }
        for (Iterator it = getNested(); it.hasNext();)
        {
            otherClassDef = ((NestedDef)it.next()).getNestedType();
            if (!otherClassDef.hasBeenProcessed())
            {
                otherClassDef.process();
            }
        }
        
        ArrayList               newFields      = new ArrayList();
        ArrayList               newReferences  = new ArrayList();
        ArrayList               newCollections = new ArrayList();
        FieldDescriptorDef      newFieldDef;
        ReferenceDescriptorDef  newRefDef;
        CollectionDescriptorDef newCollDef;
        
        // adding base features
        if (getBooleanProperty(PropertyHelper.OJB_PROPERTY_INCLUDE_INHERITED, true))
        {
            ArrayList baseTypes = new ArrayList();
            DefBase   featureDef;
            
            addRelevantBaseTypes(this, baseTypes);
            for (Iterator it = baseTypes.iterator(); it.hasNext();)
            {
                cloneInheritedFeatures((ClassDescriptorDef)it.next(), newFields, newReferences, newCollections);
            }

            for (Iterator it = newFields.iterator(); it.hasNext();)
            {
                newFieldDef = (FieldDescriptorDef)it.next();
                featureDef  = getFeature(newFieldDef.getName());
                if (featureDef != null)
                {    
                    if (!getBooleanProperty(PropertyHelper.OJB_PROPERTY_IGNORE, false))
                    {
                        // we have the implicit constraint that an anonymous field cannot redefine/be redefined
                        // except if it is ignored
                        if ("anonymous".equals(featureDef.getProperty(PropertyHelper.OJB_PROPERTY_ACCESS)))
                        {
                            throw new ConstraintException("The anonymous field "+featureDef.getName()+" in class "+getName()+" overrides an inherited field");
                        }
                        if ("anonymous".equals(newFieldDef.getProperty(PropertyHelper.OJB_PROPERTY_ACCESS)))
                        {
                            throw new ConstraintException("The inherited anonymous field "+newFieldDef.getName()+" is overriden in class "+getName());
                        }
                    }
                    LogHelper.warn(true, ClassDescriptorDef.class, "process", "Class "+getName()+" redefines the inherited field "+newFieldDef.getName());
                    it.remove();
                }
            }
            for (Iterator it = newReferences.iterator(); it.hasNext();)
            {
                newRefDef = (ReferenceDescriptorDef)it.next();
                if ("super".equals(newRefDef.getName()))
                {
                    // we don't inherit super-references
                    it.remove();
                }
                else if (hasFeature(newRefDef.getName()))
                {
                    LogHelper.warn(true, ClassDescriptorDef.class, "process", "Class "+getName()+" redefines the inherited reference "+newRefDef.getName());
                    it.remove();
                }
            }
            for (Iterator it = newCollections.iterator(); it.hasNext();)
            {
                newCollDef = (CollectionDescriptorDef)it.next();
                if (hasFeature(newCollDef.getName()))
                {
                    LogHelper.warn(true, ClassDescriptorDef.class, "process", "Class "+getName()+" redefines the inherited collection "+newCollDef.getName());
                    it.remove();
                }
            }
        }
        // adding nested features
        for (Iterator it = getNested(); it.hasNext();)
        {
            cloneNestedFeatures((NestedDef)it.next(), newFields, newReferences, newCollections);
        }
        _fields.addAll(0, newFields);
        _references.addAll(0, newReferences);
        _collections.addAll(0, newCollections);
        sortFields();
        _hasBeenProcessed = true;
    }
354138
public boolean process(Context context) throws NestingException {
        for(ProcPattern pattern: patterns){
            Context codeContext = new Context(context);
            if (pattern.parse(codeContext)) {
                if(transparent) {
                    codeContext.mergeWithParent();
                }
                template.generate(codeContext);

                if(logContext.isTraceEnabled()){
                    for(Map.Entry<String, CharSequence> entry:context.getAttributes().entrySet()){
                        logContext.trace("Context: {} = {}", entry.getKey(), entry.getValue());
                    }
                }

                if(logGenerate.isTraceEnabled()){
                    logGenerate.trace("Generated text: {}", codeContext.getTarget());
                }

                return true;
            }
        }

        return false;
    }
117123
@Override
  public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    if (!roundEnv.processingOver()) {
      for (TypeElement te : annotations) {
        for (Element elt : roundEnv.getElementsAnnotatedWith(te)) {
          if (!elt.toString().startsWith("org.apache.heron")) {
            env.getMessager().printMessage(
                Kind.WARNING,
                String.format("%s extends from a class annotated with %s", elt, te),
                elt);
          }
        }
      }
    }
    return true;
  }