Author: scabanovich
Date: 2007-07-05 13:41:12 -0400 (Thu, 05 Jul 2007)
New Revision: 2331
Added:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/lib/ClassScanner.java
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/IFileScanner.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/LoadedDeclarations.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/lib/LibraryScanner.java
Log:
EXIN-217
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/IFileScanner.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/IFileScanner.java 2007-07-05
17:12:54 UTC (rev 2330)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/IFileScanner.java 2007-07-05
17:41:12 UTC (rev 2331)
@@ -11,8 +11,6 @@
package org.jboss.tools.seam.internal.core.scanner;
import org.eclipse.core.resources.IFile;
-import org.jboss.tools.seam.internal.core.SeamComponent;
-import org.jboss.tools.seam.internal.core.SeamComponentDeclaration;
public interface IFileScanner {
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/LoadedDeclarations.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/LoadedDeclarations.java 2007-07-05
17:12:54 UTC (rev 2330)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/LoadedDeclarations.java 2007-07-05
17:41:12 UTC (rev 2331)
@@ -32,5 +32,11 @@
public List<SeamFactory> getFactories() {
return factories;
}
+
+ public void add(LoadedDeclarations ds) {
+ if(ds == null) return;
+ components.addAll(ds.components);
+ factories.addAll(ds.factories);
+ }
}
Added:
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
(rev 0)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/lib/ClassScanner.java 2007-07-05
17:41:12 UTC (rev 2331)
@@ -0,0 +1,68 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Exadel, Inc. and 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
+ *
+ * Contributors:
+ * Exadel, Inc. and Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.seam.internal.core.scanner.lib;
+
+import java.lang.annotation.Annotation;
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.jdt.core.IType;
+import org.jboss.tools.seam.internal.core.scanner.LoadedDeclarations;
+import org.jboss.tools.seam.internal.core.scanner.java.ASTVisitorImpl;
+
+/**
+ * Loads seam components from Class object.
+ *
+ * @author Viacheslav Kabanovich
+ */
+public class ClassScanner {
+
+ /**
+ * Checks if class may be a source of seam components.
+ * @param f
+ * @return
+ */
+ public boolean isLikelyComponentSource(Class<?> cls) {
+ return cls != null && isSeamAnnotatedClass(cls);
+ }
+
+ /**
+ * Loads seam components from class.
+ * Returns object that contains loaded components or null;
+ * @param type
+ * @param cls
+ * @param path
+ * @return
+ */
+ public LoadedDeclarations parse(IType type, Class<?> cls, IPath path) {
+ if(!isLikelyComponentSource(cls)) return null;
+ LoadedDeclarations ds = new LoadedDeclarations();
+
+ return ds;
+ }
+
+ /**
+ * Check if class has at least one seam annotation.
+ * @param cls
+ * @return
+ */
+ boolean isSeamAnnotatedClass(Class<?> cls) {
+ if(cls == null || cls.isInterface()) return false;
+ Annotation[] as = cls.getAnnotations();
+ for (int i = 0; i < as.length; i++) {
+ Class<?> acls = as[i].annotationType();
+ if(acls.getName().startsWith(ASTVisitorImpl.SEAM_ANNOTATION_TYPE_PREFIX)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+}
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/lib/LibraryScanner.java
===================================================================
---
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/lib/LibraryScanner.java 2007-07-05
17:12:54 UTC (rev 2330)
+++
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/scanner/lib/LibraryScanner.java 2007-07-05
17:41:12 UTC (rev 2331)
@@ -32,6 +32,7 @@
import org.jboss.tools.common.model.plugin.ModelPlugin;
import org.jboss.tools.common.model.util.EclipseResourceUtil;
import org.jboss.tools.common.model.util.XModelObjectUtil;
+import org.jboss.tools.seam.core.SeamCorePlugin;
import org.jboss.tools.seam.internal.core.SeamPropertiesDeclaration;
import org.jboss.tools.seam.internal.core.scanner.IFileScanner;
import org.jboss.tools.seam.internal.core.scanner.LoadedDeclarations;
@@ -41,6 +42,7 @@
* @author Viacheslav Kabanovich
*/
public class LibraryScanner implements IFileScanner {
+ static ClassScanner CLASS_SCANNER = new ClassScanner();
ClassPath classPath = null;
//Now it is absolute file on disk
@@ -167,10 +169,22 @@
} catch (ClassNotFoundException e) {
//ignore
}
- String result = cls == null ? "not found " + className : className;
- System.out.println(result);
+ if(cls == null) continue;
+ if(!CLASS_SCANNER.isLikelyComponentSource(cls)) continue;
+ LoadedDeclarations ds1 = null;
+ try {
+ ds1 = CLASS_SCANNER.parse(type, cls, sourcePath);
+ } catch (Exception e) {
+ SeamCorePlugin.getPluginLog().logError(e);
+ }
+ if(ds1 != null) {
+ ds.add(ds1);
+ }
+ System.out.println(className);
}
}
}
+
+
}