01: /*******************************************************************************
02: * Copyright (c) 2007 BEA Systems, Inc.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * wharley@bea.com - initial API and implementation
10: *******************************************************************************/package org.eclipse.jdt.apt.tests.annotations.pause;
11:
12: import java.util.Collection;
13: import java.util.Set;
14:
15: import org.eclipse.jdt.apt.tests.annotations.BaseProcessor;
16:
17: import com.sun.mirror.apt.AnnotationProcessorEnvironment;
18: import com.sun.mirror.declaration.AnnotationTypeDeclaration;
19: import com.sun.mirror.declaration.Declaration;
20:
21: /**
22: * Used to test performance in the IDE. Processing @Pause
23: * causes the processor to pause for a defined interval.
24: */
25: public class PauseAnnotationProcessor extends BaseProcessor {
26:
27: private final AnnotationTypeDeclaration _annotationDecl;
28:
29: public PauseAnnotationProcessor(
30: Set<AnnotationTypeDeclaration> decls,
31: AnnotationProcessorEnvironment env) {
32: super (env);
33: assert decls.size() == 1;
34: _annotationDecl = decls.iterator().next();
35: }
36:
37: /* (non-Javadoc)
38: * @see com.sun.mirror.apt.AnnotationProcessor#process()
39: */
40: public void process() {
41: String phase = _env.getOptions().get("phase");
42: Collection<Declaration> annotatedDecls = _env
43: .getDeclarationsAnnotatedWith(_annotationDecl);
44: for (Declaration decl : annotatedDecls) {
45: Pause a = decl.getAnnotation(Pause.class);
46: int pause = a.value();
47: System.out.println(phase + " pausing for " + pause
48: + " to process " + decl.getSimpleName() + "...");
49: // busy sleep
50: long end = System.currentTimeMillis() + pause;
51: while (System.currentTimeMillis() < end)
52: for (int i = 0; i < 100000; ++i) {
53: /* pausing */
54: }
55: System.out.println(phase + " finished pausing");
56: }
57: }
58:
59: }
|