Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 9f96249c635f63e204c388392d7610bf7378389f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*******************************************************************************
 * Copyright (c) 2007 BEA Systems, Inc.
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *   wharley@bea.com - initial API and implementation
 *******************************************************************************/

package org.eclipse.jdt.apt.tests.annotations.pause;

import java.util.Collection;
import java.util.Set;

import org.eclipse.jdt.apt.tests.annotations.BaseProcessor;

import com.sun.mirror.apt.AnnotationProcessorEnvironment;
import com.sun.mirror.declaration.AnnotationTypeDeclaration;
import com.sun.mirror.declaration.Declaration;

/**
 * Used to test performance in the IDE.  Processing @Pause
 * causes the processor to pause for a defined interval.
 */
public class PauseAnnotationProcessor extends BaseProcessor {

	private final AnnotationTypeDeclaration _annotationDecl;
	
	public PauseAnnotationProcessor(
			Set<AnnotationTypeDeclaration> decls, AnnotationProcessorEnvironment env) {
		super(env);
        assert decls.size() == 1;
        _annotationDecl = decls.iterator().next();
	}

	/* (non-Javadoc)
	 * @see com.sun.mirror.apt.AnnotationProcessor#process()
	 */
	public void process() {
		String phase = _env.getOptions().get("phase");
        Collection<Declaration> annotatedDecls = _env.getDeclarationsAnnotatedWith(_annotationDecl);
        for (Declaration decl : annotatedDecls) {
        	Pause a = decl.getAnnotation(Pause.class);
        	int pause = a.value();
        	System.out.println(phase + " pausing for " + pause + " to process " + decl.getSimpleName() + "...");
        	// busy sleep
        	long end = System.currentTimeMillis() + pause;
        	while (System.currentTimeMillis() < end)
        		for (int i = 0; i < 100000; ++i) {
        			/* pausing */
        		}
        	System.out.println(phase + " finished pausing");
        }
	}

}

Back to the top