From 20a3b07578a2ebec2d9a0569764e78af37761eaf Mon Sep 17 00:00:00 2001 From: Walter Harley Date: Tue, 13 Mar 2007 23:45:22 +0000 Subject: Processor and annotation to be used for discovering unexpected reconciles, like the one that Quick Outline does. --- org.eclipse.jdt.apt.tests/plugin.xml | 1 + .../jdt/apt/tests/annotations/pause/Pause.java | 20 ++++++++ .../pause/PauseAnnotationProcessor.java | 57 ++++++++++++++++++++++ .../pause/PauseAnnotationProcessorFactory.java | 38 +++++++++++++++ 4 files changed, 116 insertions(+) create mode 100644 org.eclipse.jdt.apt.tests/src/org/eclipse/jdt/apt/tests/annotations/pause/Pause.java create mode 100644 org.eclipse.jdt.apt.tests/src/org/eclipse/jdt/apt/tests/annotations/pause/PauseAnnotationProcessor.java create mode 100644 org.eclipse.jdt.apt.tests/src/org/eclipse/jdt/apt/tests/annotations/pause/PauseAnnotationProcessorFactory.java diff --git a/org.eclipse.jdt.apt.tests/plugin.xml b/org.eclipse.jdt.apt.tests/plugin.xml index a834b1682a..707a8c8d56 100644 --- a/org.eclipse.jdt.apt.tests/plugin.xml +++ b/org.eclipse.jdt.apt.tests/plugin.xml @@ -69,6 +69,7 @@ class="org.eclipse.jdt.apt.tests.annotations.exceptionhandling.ExceptionHandlingProcessorFactory"> + diff --git a/org.eclipse.jdt.apt.tests/src/org/eclipse/jdt/apt/tests/annotations/pause/Pause.java b/org.eclipse.jdt.apt.tests/src/org/eclipse/jdt/apt/tests/annotations/pause/Pause.java new file mode 100644 index 0000000000..0d9406f39c --- /dev/null +++ b/org.eclipse.jdt.apt.tests/src/org/eclipse/jdt/apt/tests/annotations/pause/Pause.java @@ -0,0 +1,20 @@ +/******************************************************************************* + * Copyright (c) 2007 BEA Systems, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * wharley@bea.com - initial API and implementation + *******************************************************************************/ + +package org.eclipse.jdt.apt.tests.annotations.pause; + +/** + * Processing this annotation causes a delay proportional to the + * value specified. + */ +public @interface Pause { + int value() default 500; +} diff --git a/org.eclipse.jdt.apt.tests/src/org/eclipse/jdt/apt/tests/annotations/pause/PauseAnnotationProcessor.java b/org.eclipse.jdt.apt.tests/src/org/eclipse/jdt/apt/tests/annotations/pause/PauseAnnotationProcessor.java new file mode 100644 index 0000000000..335385b7c5 --- /dev/null +++ b/org.eclipse.jdt.apt.tests/src/org/eclipse/jdt/apt/tests/annotations/pause/PauseAnnotationProcessor.java @@ -0,0 +1,57 @@ +/******************************************************************************* + * Copyright (c) 2007 BEA Systems, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * 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 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 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) + ; + System.out.println(phase + " finished pausing"); + } + } + +} diff --git a/org.eclipse.jdt.apt.tests/src/org/eclipse/jdt/apt/tests/annotations/pause/PauseAnnotationProcessorFactory.java b/org.eclipse.jdt.apt.tests/src/org/eclipse/jdt/apt/tests/annotations/pause/PauseAnnotationProcessorFactory.java new file mode 100644 index 0000000000..4d264f5895 --- /dev/null +++ b/org.eclipse.jdt.apt.tests/src/org/eclipse/jdt/apt/tests/annotations/pause/PauseAnnotationProcessorFactory.java @@ -0,0 +1,38 @@ +/******************************************************************************* + * Copyright (c) 2007 BEA Systems, Inc. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * wharley@bea.com - initial API and implementation + *******************************************************************************/ + +package org.eclipse.jdt.apt.tests.annotations.pause; + +import java.util.Set; + +import org.eclipse.jdt.apt.tests.annotations.BaseFactory; + +import com.sun.mirror.apt.AnnotationProcessor; +import com.sun.mirror.apt.AnnotationProcessorEnvironment; +import com.sun.mirror.declaration.AnnotationTypeDeclaration; + +public class PauseAnnotationProcessorFactory extends BaseFactory { + + private final static String annotationName = "org.eclipse.jdt.apt.tests.annotations.pause.Pause"; + public PauseAnnotationProcessorFactory() { + super(annotationName); + } + + /* (non-Javadoc) + * @see com.sun.mirror.apt.AnnotationProcessorFactory#getProcessorFor(java.util.Set, com.sun.mirror.apt.AnnotationProcessorEnvironment) + */ + public AnnotationProcessor getProcessorFor( + Set decls, + AnnotationProcessorEnvironment env) { + return new PauseAnnotationProcessor(decls, env); + } + +} -- cgit v1.2.3