Author: scabanovich
Date: 2007-07-13 02:41:45 -0400 (Fri, 13 Jul 2007)
New Revision: 2418
Added:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/Util.java
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/ISeamComponentMethod.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/SeamComponentMethodType.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamComponentMethod.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/java/ASTVisitorImpl.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/java/ComponentBuilder.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/java/SeamAnnotations.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/lib/ClassScanner.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/lib/TypeScanner.java
Log:
EXIN-217 Annotation @Remove processed.
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/ISeamComponentMethod.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/ISeamComponentMethod.java 2007-07-13
06:16:10 UTC (rev 2417)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/ISeamComponentMethod.java 2007-07-13
06:41:45 UTC (rev 2418)
@@ -10,6 +10,8 @@
******************************************************************************/
package org.jboss.tools.seam.core;
+import java.util.Set;
+
/**
* Represents method of seam component.
* This interface represents only methods with types enumerated in
SeamComponentMethodType
@@ -18,16 +20,11 @@
public interface ISeamComponentMethod extends ISeamJavaSourceReference, ISeamElement {
/**
- * @return is @ Create method
+ * @return is types of the method
*/
- public boolean isCreate();
+ public Set<SeamComponentMethodType> getTypes();
/**
- * @return is @ Destroy method
- */
- public boolean isDestroy();
-
- /**
* Returns create or destroy depending on type
* @param type
* @return
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/SeamComponentMethodType.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/SeamComponentMethodType.java 2007-07-13
06:16:10 UTC (rev 2417)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/core/SeamComponentMethodType.java 2007-07-13
06:41:45 UTC (rev 2418)
@@ -10,11 +10,24 @@
******************************************************************************/
package org.jboss.tools.seam.core;
+import org.jboss.tools.seam.internal.core.scanner.java.SeamAnnotations;
+
/**
* @author Alexey Kazakov
*/
-public enum SeamComponentMethodType {
- CREATE,
- DESTROY,
- REMOVE
-}
\ No newline at end of file
+public enum SeamComponentMethodType implements SeamAnnotations {
+ CREATE(CREATE_ANNOTATION_TYPE),
+ DESTROY(DESTROY_ANNOTATION_TYPE),
+ REMOVE(REMOVE_ANNOTATION_TYPE);
+
+ String annotationType;
+
+ SeamComponentMethodType(String annotationType) {
+ this.annotationType = annotationType;
+ }
+
+ public String getAnnotationType() {
+ return annotationType;
+ }
+
+}
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamComponentMethod.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamComponentMethod.java 2007-07-13
06:16:10 UTC (rev 2417)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/SeamComponentMethod.java 2007-07-13
06:41:45 UTC (rev 2418)
@@ -1,38 +1,47 @@
+ /*******************************************************************************
+ * Copyright (c) 2007 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
package org.jboss.tools.seam.internal.core;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
import org.eclipse.core.resources.IResource;
import org.eclipse.jdt.core.IMember;
+import org.eclipse.jdt.core.JavaModelException;
import org.jboss.tools.seam.core.ISeamComponentMethod;
import org.jboss.tools.seam.core.SeamComponentMethodType;
+import org.jboss.tools.seam.core.event.Change;
+/**
+ * @author Viacheslav Kabanovich
+ */
public class SeamComponentMethod extends SeamObject implements ISeamComponentMethod {
- boolean create = false;
- boolean destroy = false;
+ Set<SeamComponentMethodType> types = new
HashSet<SeamComponentMethodType>();
IMember javaSource = null;
+
+ public SeamComponentMethod() {}
- public boolean isCreate() {
- return create;
+ /**
+ * @return is types of the method
+ */
+ public Set<SeamComponentMethodType> getTypes() {
+ return types;
}
-
- public void setCreate(boolean b) {
- create = b;
- }
public boolean isOfType(SeamComponentMethodType type) {
- if(type == SeamComponentMethodType.CREATE) return isCreate();
- if(type == SeamComponentMethodType.DESTROY) return isDestroy();
- return false;
+ return types.contains(type);
}
- public boolean isDestroy() {
- return destroy;
- }
-
- public void setDestroy(boolean b) {
- destroy = b;
- }
-
public IMember getSourceMember() {
return javaSource;
}
@@ -42,7 +51,14 @@
}
public int getLength() {
- return 0;
+ if(javaSource == null) return 0;
+ try {
+ if(javaSource.getSourceRange() == null) return 0;
+ return javaSource.getSourceRange().getLength();
+ } catch (JavaModelException e) {
+ //ignore
+ return 0;
+ }
}
public IResource getResource() {
@@ -54,7 +70,34 @@
}
public int getStartPosition() {
- return 0;
+ if(javaSource == null) return 0;
+ try {
+ if(javaSource.getSourceRange() == null) return 0;
+ return javaSource.getSourceRange().getOffset();
+ } catch (JavaModelException e) {
+ //ignore
+ return 0;
+ }
}
+ public List<Change> merge(SeamObject s) {
+ List<Change> changes = super.merge(s);
+ SeamComponentMethod m = (SeamComponentMethod)s;
+ if(!typesAreEqual(types, m.types)) {
+ changes = Change.addChange(changes, new Change(this, "types", types,
m.types));
+ this.types = m.types;
+ }
+ return changes;
+ }
+
+ boolean typesAreEqual(Set<SeamComponentMethodType> types1,
Set<SeamComponentMethodType> types2) {
+ if(types1 == null || types2 == null) return types2 == types1;
+ if(types1.size() != types2.size()) return false;
+ for (SeamComponentMethodType t : types2) {
+ if(!types1.contains(t)) return false;
+ }
+ return true;
+
+ }
+
}
Added:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/Util.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/Util.java
(rev 0)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/Util.java 2007-07-13
06:41:45 UTC (rev 2418)
@@ -0,0 +1,43 @@
+ /*******************************************************************************
+ * Copyright (c) 2007 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.seam.internal.core.scanner;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.jboss.tools.seam.internal.core.scanner.java.SeamAnnotations;
+
+/**
+ * @author Viacheslav Kabanovich
+ */
+public class Util implements SeamAnnotations {
+
+ static Set<String> EJB_ANNOTATION_TYPES = new HashSet<String>();
+
+ static {
+ EJB_ANNOTATION_TYPES.add(STATEFUL_ANNOTATION_TYPE);
+ EJB_ANNOTATION_TYPES.add(ENTITY_ANNOTATION_TYPE);
+ EJB_ANNOTATION_TYPES.add(REMOVE_ANNOTATION_TYPE);
+ }
+
+ /**
+ * Returns true if parameter is qualified name of annotation type
+ * used to build seam model.
+ * @param qualifiedTypeName
+ * @return
+ */
+ public static boolean isSeamAnnotationType(String qualifiedTypeName) {
+ return qualifiedTypeName != null
+ && (qualifiedTypeName.startsWith(SEAM_ANNOTATION_TYPE_PREFIX)
+ || EJB_ANNOTATION_TYPES.contains(qualifiedTypeName));
+ }
+
+}
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/java/ASTVisitorImpl.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/java/ASTVisitorImpl.java 2007-07-13
06:16:10 UTC (rev 2417)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/java/ASTVisitorImpl.java 2007-07-13
06:41:45 UTC (rev 2418)
@@ -28,6 +28,7 @@
import org.eclipse.jdt.core.dom.SingleMemberAnnotation;
import org.eclipse.jdt.core.dom.TypeDeclaration;
import org.eclipse.jdt.core.dom.VariableDeclaration;
+import org.jboss.tools.seam.internal.core.scanner.Util;
/**
* Processes AST tree to find annotated type, fields and methods.
@@ -54,7 +55,7 @@
public boolean visit(SingleMemberAnnotation node) {
String type = resolveType(node);
- if(isSeamAnnotationType(type) && currentAnnotatedNode != null) {
+ if(Util.isSeamAnnotationType(type) && currentAnnotatedNode != null) {
currentAnnotatedNode.addAnnotation(new ResolvedAnnotation(type, node));
}
return false;
@@ -62,7 +63,7 @@
public boolean visit(NormalAnnotation node) {
String type = resolveType(node);
- if(isSeamAnnotationType(type) && currentAnnotatedNode != null) {
+ if(Util.isSeamAnnotationType(type) && currentAnnotatedNode != null) {
currentAnnotatedNode.addAnnotation(new ResolvedAnnotation(type, node));
}
return false;
@@ -70,7 +71,7 @@
public boolean visit(MarkerAnnotation node) {
String type = resolveType(node);
- if(isSeamAnnotationType(type) && currentAnnotatedNode != null) {
+ if(Util.isSeamAnnotationType(type) && currentAnnotatedNode != null) {
currentAnnotatedNode.addAnnotation(new ResolvedAnnotation(type, node));
}
return true;
@@ -100,11 +101,6 @@
return null;
}
- static boolean isSeamAnnotationType(String n) {
- return n != null && (n.startsWith(SEAM_ANNOTATION_TYPE_PREFIX)
- || n.equals(STATEFUL_ANNOTATION_TYPE));
- }
-
public boolean visit(Block node) {
return false;
}
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/java/ComponentBuilder.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/java/ComponentBuilder.java 2007-07-13
06:16:10 UTC (rev 2417)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/java/ComponentBuilder.java 2007-07-13
06:41:45 UTC (rev 2418)
@@ -30,6 +30,7 @@
import org.eclipse.jdt.core.dom.VariableDeclaration;
import org.jboss.tools.seam.core.BijectedAttributeType;
import org.jboss.tools.seam.core.ISeamXmlComponentDeclaration;
+import org.jboss.tools.seam.core.SeamComponentMethodType;
import org.jboss.tools.seam.internal.core.BijectedAttribute;
import org.jboss.tools.seam.internal.core.Role;
import org.jboss.tools.seam.internal.core.SeamAnnotatedFactory;
@@ -202,18 +203,20 @@
void processComponentMethods() {
for (AnnotatedASTNode<MethodDeclaration> n: annotatedMethods) {
- Annotation aCreate = findAnnotation(n, CREATE_ANNOTATION_TYPE);
- Annotation aDestroy = findAnnotation(n, DESTROY_ANNOTATION_TYPE);
- if(aCreate == null || aDestroy == null) continue;
- MethodDeclaration m = n.getNode();
-
- SeamComponentMethod cm = new SeamComponentMethod();
- component.addMethod(cm);
-
- if(aCreate != null) cm.setCreate(true);
- if(aDestroy != null) cm.setDestroy(true);
-
- cm.setSourceMember(findMethod(m));
+ SeamComponentMethod cm = null;
+ for (int i = 0; i < SeamComponentMethodType.values().length; i++) {
+ SeamComponentMethodType type = SeamComponentMethodType.values()[i];
+ Annotation a = findAnnotation(n, type.getAnnotationType());
+ if(a == null) continue;
+ if(cm == null) {
+ cm = new SeamComponentMethod();
+ component.addMethod(cm);
+ MethodDeclaration m = n.getNode();
+ component.addMethod(cm);
+ cm.setSourceMember(findMethod(m));
+ }
+ cm.getTypes().add(type);
+ }
}
}
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/java/SeamAnnotations.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/java/SeamAnnotations.java 2007-07-13
06:16:10 UTC (rev 2417)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/java/SeamAnnotations.java 2007-07-13
06:41:45 UTC (rev 2418)
@@ -1,5 +1,20 @@
+ /*******************************************************************************
+ * Copyright (c) 2007 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
package org.jboss.tools.seam.internal.core.scanner.java;
+/**
+ * Java annotations processed in building seam model
+ *
+ * @author Viacheslav Kabanovich
+ */
public interface SeamAnnotations {
public static String SEAM_ANNOTATION_TYPE_PREFIX =
"org.jboss.seam.annotations.";
@@ -15,12 +30,14 @@
public static String CREATE_ANNOTATION_TYPE = SEAM_ANNOTATION_TYPE_PREFIX +
"Create";
public static String DESTROY_ANNOTATION_TYPE = SEAM_ANNOTATION_TYPE_PREFIX +
"Destroy";
+ public static String REMOVE_ANNOTATION_TYPE = "javax.ejb.Remove";
public static String FACTORY_ANNOTATION_TYPE = SEAM_ANNOTATION_TYPE_PREFIX +
"Factory";
public static String ROLES_ANNOTATION_TYPE = SEAM_ANNOTATION_TYPE_PREFIX +
"Roles";
public static String ROLE_ANNOTATION_TYPE = SEAM_ANNOTATION_TYPE_PREFIX +
"Role";
+ public static String ENTITY_ANNOTATION_TYPE = "javax.persistence.Entity";
public static String STATEFUL_ANNOTATION_TYPE = "javax.ejb.Stateful";
}
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/lib/ClassScanner.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/lib/ClassScanner.java 2007-07-13
06:16:10 UTC (rev 2417)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/lib/ClassScanner.java 2007-07-13
06:41:45 UTC (rev 2418)
@@ -29,6 +29,7 @@
import org.jboss.tools.seam.internal.core.SeamAnnotatedFactory;
import org.jboss.tools.seam.internal.core.SeamJavaComponentDeclaration;
import org.jboss.tools.seam.internal.core.scanner.LoadedDeclarations;
+import org.jboss.tools.seam.internal.core.scanner.Util;
import org.jboss.tools.seam.internal.core.scanner.java.SeamAnnotations;
/**
@@ -85,7 +86,7 @@
Annotation[] as = cls.getAnnotations();
for (int i = 0; i < as.length; i++) {
Class<?> acls = as[i].annotationType();
- if(acls.getName().startsWith(SEAM_ANNOTATION_TYPE_PREFIX)) {
+ if(Util.isSeamAnnotationType(acls.getName())) {
return true;
}
}
@@ -97,9 +98,7 @@
Map<String,Annotation> map = null;
for (int i = 0; i < as.length; i++) {
Class<?> acls = as[i].annotationType();
- if(acls.getName().startsWith(SEAM_ANNOTATION_TYPE_PREFIX) ||
- //TODO put all non-seam relevant annotations to set
- acls.getName().equals(STATEFUL_ANNOTATION_TYPE)) {
+ if(Util.isSeamAnnotationType(acls.getName())) {
if(map == null) map = new HashMap<String, Annotation>();
map.put(acls.getName(), as[i]);
}
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/lib/TypeScanner.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/lib/TypeScanner.java 2007-07-13
06:16:10 UTC (rev 2417)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/lib/TypeScanner.java 2007-07-13
06:41:45 UTC (rev 2418)
@@ -29,6 +29,7 @@
import org.jboss.tools.seam.internal.core.SeamAnnotatedFactory;
import org.jboss.tools.seam.internal.core.SeamJavaComponentDeclaration;
import org.jboss.tools.seam.internal.core.scanner.LoadedDeclarations;
+import org.jboss.tools.seam.internal.core.scanner.Util;
import org.jboss.tools.seam.internal.core.scanner.java.SeamAnnotations;
public class TypeScanner implements SeamAnnotations {
@@ -80,7 +81,7 @@
IBinaryAnnotation[] as = cls.getAnnotations();
if(as != null) for (int i = 0; i < as.length; i++) {
String type = getTypeName(as[i]);
- if(type.startsWith(SEAM_ANNOTATION_TYPE_PREFIX)) {
+ if(Util.isSeamAnnotationType(type)) {
return true;
}
}
@@ -103,9 +104,7 @@
Map<String,IBinaryAnnotation> map = null;
for (int i = 0; i < as.length; i++) {
String type = getTypeName(as[i]);
- if(type.startsWith(SEAM_ANNOTATION_TYPE_PREFIX) ||
- //TODO put all non-seam relevant annotations to set
- type.equals(STATEFUL_ANNOTATION_TYPE)) {
+ if(Util.isSeamAnnotationType(type)) {
if(map == null) map = new HashMap<String, IBinaryAnnotation>();
map.put(type, as[i]);
}