Copyright BEA 2005, made available under EPL 1.0 | 1 Using Java Annotations in Eclipse Gary Horen BEA Systems Tim Wagner BEA Systems.

Slides:



Advertisements
Similar presentations
Introduction to Java 2 Programming Lecture 3 Writing Java Applications, Java Development Tools.
Advertisements

AspectWerkz 2 - and the road to AspectJ 5 Jonas Bonér Senior Software Engineer BEA Systems.
Extending Eclipse CDT for Remote Target Debugging Thomas Fletcher Director, Automotive Engineering Services QNX Software Systems.
Introduction To Java Objectives For Today â Introduction To Java â The Java Platform & The (JVM) Java Virtual Machine â Core Java (API) Application Programming.
2005 JavaOne SM Conference | Session BOF-9161 Exploring Annotation-Based Programming through the APT and Mirror APIs Tim Wagner, Senior Manager Gary Horen,
Lab#1 (14/3/1431h) Introduction To java programming cs425
1 Web Services – Part II CS , Spring 2008/9.
Presented by IBM developer Works ibm.com/developerworks/ 2006 January – April © 2006 IBM Corporation. Making the most of The Eclipse Web Tools Platform.
Eclipse Architecture Dwight Deugo Nesa Matic
20-Jun-15 Eclipse. Most slides from: 2 About IDEs An IDE is an Integrated Development Environment.
Presented by IBM developer Works ibm.com/developerworks/ 2006 January – April © 2006 IBM Corporation. Making the most of Creating Eclipse plug-ins.
Views Dwight Deugo Nesa Matic
1 Plug-in Development Environment (PDE) Guide. 2 Introduction to PDE l What is PDE: »a tool designed to help you develop platform plug-ins while working.
Enhancing Developer Productivity using Eclipse Presented by: Tom Sausner.
PHY281Introduction to JavaSlide 1 Introduction to Java In this section we will learn how how to use Java and write our first Java Applet:  The Java Development.
Eclipse IDE. 2 IDE Overview An IDE is an Interactive Development Environment Different IDEs meet different needs BlueJ and DrJava are designed as teaching.
© 2006 by IBM 1 How to use Eclipse to Build Rich Internet Applications With PHP and AJAX Phil Berkland IBM Software Group Emerging.
Mobile Programming Lecture 1 Getting Started. Today's Agenda About the Eclipse IDE Hello, World! Project Android Project Structure Intro to Activities,
Pittsburgh Java User Group– Dec Java PureFaces: A JSF Framework Extension.
M1G Introduction to Programming 2 4. Enhancing a class:Room.
© 2005 by IBM; made available under the EPL v1.0 | March 1, 2005 Tim deBoer Gorkem Ercan Extend WTP Server Tools for your.
What’s new in Stack 3.2 Michael Youngstrom. Disclaimer This IS a presentation – So sit back and relax Please ask questions.
1 v1.6 08/02/2006 Overview of Eclipse Lectures 1.Overview 2.Installing and Running 3.Building and Running Java Classes 4.Refactoring 5.Debugging 6.Testing.
Java: Chapter 1 Computer Systems Computer Programming II.
© 2006 IBM Corporation IBM WebSphere Portlet Factory Architecture.
|Tecnologie Web L-A Anno Accademico Laboratorio di Tecnologie Web Introduzione ad Eclipse e Tomcat
© 2006 by BEA Systems Inc; made available under the EPL v1.0 | March 2006 | Java Annotation Processing (APT) in the Eclipse JDT Gary Horen BEA Systems.
© 2008 by BEA Systems Inc.; made available under the EPL v1.0 | 3/18/2008 | Java Annotations an introduction to Java Annotations Walter Harley BEA Systems.
The Basics of Javadoc Presented By: Wes Toland. Outline  Overview  Background  Environment  Features Javadoc Comment Format Javadoc Program HTML API.
1 Module Objective & Outline Module Objective: After completing this Module, you will be able to, appreciate java as a programming language, write java.
© 2005 by IBM; made available under the EPL v1.0 | May 19, 2005 Tim deBoer WTP Server Tools Open House.
© 2005 by IBM; made available under the EPL v1.0 | May 19, 2005 Tim deBoer WTP Server Tools Open House.
Fun with Java Annotations Brian McGinnis. Java Annotations Introduced in “Tiger” release (Java 1.5) Introduced in “Tiger” release (Java 1.5) One of most.
1162 JDK 5.0 Features Christian Kemper Principal Architect Borland.
Introduction to Eclipse CSC 216 Lecture 3 Ed Gehringer Using (with permission) slides developed by— Dwight Deugo Nesa Matic
C# D1 CSC 298 Elements of C# code (part 2). C# D2 Writing a class (or a struct)  Similarly to Java or C++  Fields: to hold the class data  Methods:
Copyright © Curt Hill Turtles The beginning of media computation.
Eclipse Eclipse An IDE is an Integrated Development Environment Different IDEs meet different needs – BlueJ, DrJava are designed as teaching.
© Keren Kalif Advanced Java Topics Written by Keren Kalif, Edited by Liron Blecher.
© 2002 IBM Corporation Confidential | Date | Other Information, if necessary June, 2011 Made available under the Eclipse Public License v Mobile.
Eclipse 24-Apr-17.
First Venture into the Android World Chapter 1 Part 2.
Core Java Introduction Byju Veedu Ness Technologies httpdownload.oracle.com/javase/tutorial/getStarted/intro/definition.html.
CS101: Introduction to Computer Science Slides adapted from Sedgewick and Wayne Copyright © Your First Java.
Spring and DWR Frameworks for Rich Web Enterprise Application Thomas Wiradikusuma Presentation to the 20 th.
 Programming - the process of creating computer programs.
Java Annotations. Annotations  Annotations are metadata or data about data. An annotation indicates that the declared element should be processed in.
introductory lecture on java programming
Modern Programming Language. Web Container & Web Applications Web applications are server side applications The most essential requirement.
© 2009 by IBM; made available under the EPL v1.0 | Feb 1, 2009 Seneca 2009 Tim deBoer Gorkem Ercan Extend WTP Server Tools.
Eclipse 27-Apr-17.
1 Example Uses of Java Reflection Explained Simply.
Customizing Share Document Previews Will Abson Senior Integrations Engineer and Share Extras Project Lead
Today Javadoc. Packages and static import. Viewing API source code. Upcoming Topics: –protected access modifier –Using the debugger in Eclipse –JUnit testing.
The Java API for XML-Based Web Services. A Web Service example in Java SOAP-awareServlet (e.g. Apache Axis2) SOAP-awareServlet Any class processing the.
Static SDO Proposal Main Points/ Next Steps. Goals of specification Not about the algorithm to generate Static SDOs Instead, about how Static SDOs map.
Java IDE Dwight Deugo Nesa Matic
SESSION 1 Introduction in Java. Objectives Introduce classes and objects Starting with Java Introduce JDK Writing a simple Java program Using comments.
Testing and Debugging.
Eclipse 20-Sep-18.
Embracing Java 9 and beyond with Eclipse JDT
The JSF Tools Project – WTP (internal) release review
Developing and testing enterprise Java applications
Java IDE Dwight Deugo Nesa Matic Portions of the notes for this lecture include excerpts from.
Review of Previous Lesson
The beginning of media computation Followed by a demo
Presentation transcript:

Copyright BEA 2005, made available under EPL 1.0 | 1 Using Java Annotations in Eclipse Gary Horen BEA Systems Tim Wagner BEA Systems

Copyright BEA 2005, made available under EPL 1.0. | 2 Agenda Background Simple Example Demo Mirror API and APT Pitfalls More Elaborate Example Futures

Copyright BEA 2005, made available under EPL 1.0. | 3 What are annotations? Metadata placed directly in your source code Standardized by JSR 175, added to Java in 1.5 Intended to replace “xdoclet”-style programming with a modern, type-checked str=“hi”) public class Foo { … }

Copyright BEA 2005, made available under EPL 1.0. | 4 What are annotations? Defined using Java – much like interfaces Can be used by both tools and runtimes Enable a simpler “POJO”-based programming model MyAnnotation { int num; String str; }

Copyright BEA 2005, made available under EPL 1.0. | 5 What can an annotation Public class Foo { } Endpoint Interface XML-Java Bindings Example: helping a POJO to become a web service Annotations on user code generate helper objects Endpoint interface: receives and parses XML message Bindings embody the message as parameters to the POJO method generates

Copyright BEA 2005, made available under EPL 1.0. | 6 Who uses annotations? J2SE – builtin annotations J2EE – EBJ 3.0, JSR 181, JSR 250, JAXB 2.0, JAX-WS rd party frameworks: Hibernate, Beehive, Spring …and eventually every major

Copyright BEA 2005, made available under EPL 1.0. | 7 Build-time uses Many annotations effects happen at build time, not run time “I need to create a stub/skeleton that matches this interface” “I need to inform my container that I need resource X” “I need to verify that this method meets some constraints” We need several things to make this useful Something to process a set of annotations – an annotation processor A build (compile) time container for these processors – a compiler with extra smarts Enhanced visual tools – make Eclipse aware of the special semantics of annotations

Copyright BEA 2005, made available under EPL 1.0. | 8 Process view Processor public class Foo {... } Annotated Source File apt tool in JDK 1.5 or Eclipse apt plugin processoranother processor calls

Copyright BEA 2005, made available under EPL 1.0. | 9 What can an annotation processor do? Can Claim a set of annotations Check annotations for semantic errors Generate new Java source files Generate arbitrary data files (e.g. deployment descriptor) Cannot Change the bytecode generated when the file is compiled in any way

Copyright BEA 2005, made available under EPL 1.0. | 10 Demo DemoAnnotation An Annotation contains elements Elements contain names and values An annotation processor can check element values for correctness TypeGeneratingAnnotation Generates a Java source file

Copyright BEA 2005, made available under EPL 1.0. | 11 Demo: processor finds invalid value

Copyright BEA 2005, made available under EPL 1.0. | 12 Demo: annotation generates type

Copyright BEA 2005, made available under EPL 1.0. | 13 Agenda Background Simple Example Demo The mirror API and APT Pitfalls More Elaborate Example Futures

Copyright BEA 2005, made available under EPL 1.0. | 14 What you need to provide Step 1: Locate or write your own annotation(s) MyAnnotation { int num; String str; }

Copyright BEA 2005, made available under EPL 1.0. | 15 What you need to provide Step 2: Write an annotation processor factory import com.sun.mirror.apt.*; public class MyAnnotationFactory implements AnnotationProcessorFactory { AnnotationProcessor getProcessorFor() … }

Copyright BEA 2005, made available under EPL 1.0. | 16 What you need to provide Step 3: Write an annotation processor import com.sun.mirror.apt.*; public class MyAnnotationProcessor implements AnnotationProcessor { void process() }

Copyright BEA 2005, made available under EPL 1.0. | 17 Packaging You provide The annotation declaration An implementation of AnnotationProcessorFactory An implementation of AnnotationProcessor These are packaged in a jar Processor runs inside a dispatching framework Command line APT org.eclipse.jdt.apt.core plugin

Copyright BEA 2005, made available under EPL 1.0. | 18 Environment APIs Annotation Processor Environment Type system exploration File generation Error messages Declarations @Baz... b a c d

Copyright BEA 2005, made available under EPL 1.0. | 19 Using AnnotationProcessorEnvironment AnnotationProcessorEnvironment getDeclarationsWith(annotation) Declaration AnnotationMirror Element map getAnnotationMirrors() getElementValues()

Copyright BEA 2005, made available under EPL 1.0. | 20 Processing rounds Round 1: Original source files Round 3: Types generated in round 2 Round 2: Types generated by processing original files in round 1

Copyright BEA 2005, made available under EPL 1.0. | 21 “Write once” – processor reuse apt tool in JDK 1.5 or Eclipse apt processor Eclipse apt plugin or apt tool in JDK 1.5

Copyright BEA 2005, made available under EPL 1.0. | 22 Dispatching: command line support apt Tool available in JDK 1.5 (along with javac, javadoc, javap, etc.) Works like javac, but with something extra: It runs 3 rd party annotation processors in addition to compiling source code Any generated types also get compiled Locates factories through META-INF/services/ com.sun.mirror.apt.AnnotationProcessorFactory file: Each line of file = fully qualified factory class name % apt –classpath Proc.jar MyProgram.java

Copyright BEA 2005, made available under EPL 1.0. | 23 Dispatching: inside Eclipse From a jar file external to the workspace Classpath variables provide indirection From a jar file inside a project Static jar only: jar file may not be rebuilt in same workspace that uses it Jar file must be available on the Eclipse Java compiler runtime classpath From a plugin Debugging must be done in plugin: Build in development workspace Run on annotated source in debugged workspace

Copyright BEA 2005, made available under EPL 1.0. | 24 Eclipse APT configuration UI

Copyright BEA 2005, made available under EPL 1.0. | 25 Agenda Background Simple Example Demo The mirror API and APT Pitfalls More Elaborate Example Futures

Copyright BEA 2005, made available under EPL 1.0. | 26 Pitfall: APT round class class Mumble Round class class class class GenMoo Round 2 All of round 1 runs first Then all of round 2

Copyright BEA 2005, made available under EPL 1.0. | 27 Pitfall: Eclipse round class class Mumble Round class class class class GenMoo Round 2 Dispatch all this Rounding in Eclipse must be file-at-a-time for performance reasons. Then this

Copyright BEA 2005, made available under EPL 1.0. | 28 Pitfall: gathering generated files Don’t do this. It depends on dispatcher implementation. Instead: gather generated files in a post-build class class class class GenX Foo.xml Roo.xml Goo.xml Round 1 generates Round 2 reads all

Copyright BEA 2005, made available under EPL 1.0. | 29 Pitfall: processor requests generated type Don’t do this. It depends on visibility of generated types. But: generated types can refer to other generated class class Moo class class GenFoo class GenGoo Round 1 generates Round 2 generates Generated type refers to: OK Anno processor requests: not OK

Copyright BEA 2005, made available under EPL 1.0. | 30 Pitfall: APT round class class Mumble Round class class class class GenMoo Round 2 All of round 1 runs first Then all of round 2

Copyright BEA 2005, made available under EPL 1.0. | 31 Pitfall: build vs. reconcile Interactive (as you type) compilation = reconcile Can’t put new files on disk File generation happens only during build Best practice: build your workspace before you edit Then reconcile can see generated types Less confusion for the user Set project autobuild (build on Save) to “on” Keep build current Hopefully reconcile limitation goes away in next release

Copyright BEA 2005, made available under EPL 1.0. | 32 Agenda Background Simple Example Demo The Mirror API and APT Pitfalls More Elaborate Example Futures

Copyright BEA 2005, made available under EPL 1.0. | 33 Example: the Chargeable annotation App developer annotates a class to use the accounting system: Class level Method level

Copyright BEA 2005, made available under EPL 1.0. | 34 What do? class executeRequest() start = currentTimeMillis(); _service.executeRequest(); AccountSystem.charge( currentTimeMillis() – start); class SomeServiceWrapper private SomeService _service; public executeRequest() Generates wrapper class with proxy method that posts charge Generates ISomeService interface; both wrapper and app class implement Generates factory that creates the wrapped SomeService class

Copyright BEA 2005, made available under EPL 1.0. | 35 Code public class AnalysisService public ResultSet executeQuery(String key) { … =.007) public int findMedianSalary(ResultSet res) { … public int findMeanSales(ResultSet res) { … }

Copyright BEA 2005, made available under EPL 1.0. | generates source files Generated source User’s code

Copyright BEA 2005, made available under EPL 1.0. | 37 Agenda Background Simple Example Demo The Mirror API and APT Pitfalls More Elaborate Example Futures JSR 269 UI Enhancements

Copyright BEA 2005, made available under EPL 1.0. | 38 JSR 269 Annotations already standard language feature (JSR 175) Standard annotations exist for specific applications (JSR 181, 220) The mirror API is a preview interface (com.sun.mirror) Sun has announced intention to open-source interfaces JSR 269 will standardize the processor API (in javax package space) Specification will wrap up soon, to be available in Java SE 6 Target Eclipse availablity: 3.2 Mirror support continues in Eclipse until 269 widely adopted

Copyright BEA 2005, made available under EPL 1.0. | 39 User Interface APIs Eclipse apt processor factory

Copyright BEA 2005, made available under EPL 1.0. | 40 Eclipse-specific functionality Code assistance inside annotation values Auto-completion Quick-fix Visual editing A special viewer/editor for annotations Refactoring Participation in rename operations Find-uses

Copyright BEA 2005, made available under EPL 1.0. | 41 Code assistance: auto-completion User presses Ctrl-space Annotation processor proposes content

Copyright BEA 2005, made available under EPL 1.0. | 42 Code assistance: quick-fix Annotation processor posts an error or warning User presses Ctrl-1 Annotation processor can propose fixes to the user

Copyright BEA 2005, made available under EPL 1.0. | 43 Visual Annotation buffer = true), conversation ) public boolean testVerifyFunds(Mumble m) { … } Show complex annotations in friendlier way Property pane-like UI Values in code in bold typeface Defaulted values in normal typeface Make nested annotations understandable

Copyright BEA 2005, made available under EPL 1.0. | 44 Release Timeline: APT in Eclipse JUNJULAUGSEPOCTNOVDECJANFEBMARAPRJUN Alpha (core) 3.1 Beta (UI Features) APT released as part of JDT

Copyright BEA 2005, made available under EPL 1.0. | 45 Q & A Try it out! Download and install at:

Copyright BEA 2005, made available under EPL 1.0 | 46 Using Java Annotations in Eclipse Gary Horen BEA Systems Tim Wagner BEA Systems