oberhack 2004/03/29 10:29:34 Modified: ide/org.apache.avalon.ide.eclipse.core/src/org/apache/avalon/ide/eclipse/core/resource Test.java EclipseResource.java ClassResourceManager.java JavaDocResource.java Added: ide/org.apache.avalon.ide.eclipse.core/lib commons-lang.jar commons-logging.jar commons-collections-2.0.jar Log: Revision Changes Path 1.1 avalon-sandbox/ide/org.apache.avalon.ide.eclipse.core/lib/commons-lang.jar <<Binary file>> 1.1 avalon-sandbox/ide/org.apache.avalon.ide.eclipse.core/lib/commons-logging.jar <<Binary file>> 1.1 avalon-sandbox/ide/org.apache.avalon.ide.eclipse.core/lib/commons-collections-2.0.jar <<Binary file>> 1.3 +2 -2 avalon-sandbox/ide/org.apache.avalon.ide.eclipse.core/src/org/apache/avalon/ide/eclipse/core/resource/Test.java Index: Test.java =================================================================== RCS file: /home/cvs/avalon-sandbox/ide/org.apache.avalon.ide.eclipse.core/src/org/apache/avalon/ide/eclipse/core/resource/Test.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- Test.java 2 Mar 2004 12:07:44 -0000 1.2 +++ Test.java 29 Mar 2004 18:29:34 -0000 1.3 @@ -27,7 +27,7 @@ public static void main(String[] args) { - String str = SystemResource.replaceAll("hallo %test% gg %test% o", "%test%", "neu"); - Object obj = str; + SystemResource.replaceAll("hallo %test% gg %test% o", "%test%", "neu"); + } } 1.3 +79 -28 avalon-sandbox/ide/org.apache.avalon.ide.eclipse.core/src/org/apache/avalon/ide/eclipse/core/resource/EclipseResource.java Index: EclipseResource.java =================================================================== RCS file: /home/cvs/avalon-sandbox/ide/org.apache.avalon.ide.eclipse.core/src/org/apache/avalon/ide/eclipse/core/resource/EclipseResource.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- EclipseResource.java 2 Mar 2004 12:07:44 -0000 1.2 +++ EclipseResource.java 29 Mar 2004 18:29:34 -0000 1.3 @@ -48,22 +48,22 @@ { /** - * @uml property=project associationEnd={multiplicity={(0 -1)} - * elementType=java.lang.String} - * - */ + * @uml property=project associationEnd={multiplicity={(0 -1)} + * elementType=java.lang.String} + * + */ private IProject project; /** - * @uml property=classpathEntries associationEnd={multiplicity={(0 -1)} - * elementType=org.eclipse.jdt.core.IClasspathEntry} - * - */ + * @uml property=classpathEntries associationEnd={multiplicity={(0 -1)} + * elementType=org.eclipse.jdt.core.IClasspathEntry} + * + */ private Vector classpathEntries = new Vector(); /** - * - */ + * + */ public EclipseResource(IProject project) { super(); @@ -71,9 +71,63 @@ } /** - * @param element - * @return - */ + * extracts the fully qualified class name from a given filePathName + * + * @param pProject + * @param pFilePathName + * @return the fully qualified className + */ + public static String getQualifiedClassName(IResource pResource) + { + + String qualifiedClassName = null; + IProject project = pResource.getProject(); + + try + { + IJavaProject proj = JavaCore.create(project); + String filePathName = pResource.getLocation().toString(); + + if (pResource.getFileExtension().toLowerCase().equals("class")) + { + String outputPath = proj.getOutputLocation().toString(); + String projectPath = project.getLocation().toString(); + outputPath = projectPath + outputPath.substring(project.getName().length()); + qualifiedClassName = + filePathName.substring(outputPath.length(), filePathName.length() - 6); + return qualifiedClassName = qualifiedClassName.replace('/', '.'); + } + + IPackageFragmentRoot roots[] = proj.getPackageFragmentRoots(); + String projectPath = project.getLocation().toString(); + String sourcePath = null; + + for (int i = 0; roots.length > i; i++) + { + if (roots[i].isArchive()) + continue; + sourcePath = projectPath + "/" + roots[i].getElementName(); + if (sourcePath.equals(filePathName.substring(0, sourcePath.length()))) + { + break; + } + } + qualifiedClassName = + filePathName.substring(sourcePath.length() + 1, filePathName.length() - 5); + qualifiedClassName = qualifiedClassName.replace('/', '.'); + + } catch (JavaModelException e) + { + e.printStackTrace(); + } + + return qualifiedClassName; + } + + /** + * @param element + * @return + */ public String[] getSourcePaths() throws Exception { @@ -113,8 +167,8 @@ } } /** - * @param b - */ + * @param b + */ private void addUuidAccessor(IType type, boolean b) throws Exception { @@ -169,8 +223,8 @@ return buf.toString(); } /** - * @param b - */ + * @param b + */ private void addUuidField(IType type, boolean b) throws Exception { @@ -196,9 +250,9 @@ } /** - * @param file - * @return - */ + * @param file + * @return + */ public static URLClassLoader getProjectClassLoader(IResource file) { @@ -219,11 +273,11 @@ } /** - * Create a new Project with a given name and nature - * - * @param pFile - * @return - */ + * Create a new Project with a given name and nature + * + * @param pFile + * @return + */ public static IProject createMerlinProject(String projectName, String nature) throws InvocationTargetException, InterruptedException { @@ -253,9 +307,6 @@ description.setLocation(null); description.setNatureIds(natureIds); project.setDescription(description, null); - - //project.refreshLocal(IProject.DEPTH_INFINITE, new - // SubProgressMonitor(monitor, 1)); } catch (CoreException e) { 1.3 +1 -1 avalon-sandbox/ide/org.apache.avalon.ide.eclipse.core/src/org/apache/avalon/ide/eclipse/core/resource/ClassResourceManager.java Index: ClassResourceManager.java =================================================================== RCS file: /home/cvs/avalon-sandbox/ide/org.apache.avalon.ide.eclipse.core/src/org/apache/avalon/ide/eclipse/core/resource/ClassResourceManager.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- ClassResourceManager.java 2 Mar 2004 12:07:44 -0000 1.2 +++ ClassResourceManager.java 29 Mar 2004 18:29:34 -0000 1.3 @@ -41,7 +41,7 @@ public String getFullyQualifiedName() { - return getJavaDocResource().getFullQualifiedName(); + return getJavaDocResource().getQualifiedName(); } /** 1.3 +146 -27 avalon-sandbox/ide/org.apache.avalon.ide.eclipse.core/src/org/apache/avalon/ide/eclipse/core/resource/JavaDocResource.java Index: JavaDocResource.java =================================================================== RCS file: /home/cvs/avalon-sandbox/ide/org.apache.avalon.ide.eclipse.core/src/org/apache/avalon/ide/eclipse/core/resource/JavaDocResource.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- JavaDocResource.java 2 Mar 2004 12:07:44 -0000 1.2 +++ JavaDocResource.java 29 Mar 2004 18:29:34 -0000 1.3 @@ -19,9 +19,11 @@ import java.io.File; import java.io.IOException; +import java.io.StringBufferInputStream; import java.util.ArrayList; import java.util.Iterator; import java.util.List; +import java.util.Properties; import org.eclipse.core.resources.IProject; @@ -30,6 +32,7 @@ import xjavadoc.XJavaDoc; import xjavadoc.XTag; import xjavadoc.filesystem.FileSourceSet; +import xjavadoc.filesystem.XJavadocFile; /** * @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a> @@ -39,13 +42,23 @@ { /** - * @uml property=xClass associationEnd={multiplicity={(1 1)}} - */ + * @uml property=xClass associationEnd={multiplicity={(1 1)}} + */ private XClass xClass; + private static JavaDocResource[] docCache; + public JavaDocResource(String qualifiedClassName, String filePathName) + { + XJavaDoc xDoc; + xDoc = new XJavaDoc(); + xDoc.setUseNodeParser(true); + xDoc.addAbstractFile(qualifiedClassName, new XJavadocFile(new File(filePathName))); + + xClass = xDoc.getXClass(qualifiedClassName); + } /** - * - */ + * + */ public JavaDocResource(XClass clazz) { @@ -53,13 +66,13 @@ } /** - * Collects all java source files of a project. If it is not possible to - * retrieve the corresponding project of 'element' throw an exception. - * @TODO Change, so that no ref to EclipseResource - * - * @param IProject - * project - */ + * Collects all java source files of a project. If it is not possible to + * retrieve the corresponding project of 'element' throw an exception. + * @TODO Change, so that no ref to EclipseResource + * + * @param IProject + * project + */ public static JavaDocResource[] getJavaDocResources(IProject project) { XJavaDoc xDoc; @@ -89,9 +102,24 @@ // TODO Auto-generated catch block e.printStackTrace(); } - return (JavaDocResource[]) infoList.toArray(new JavaDocResource[infoList.size()]); + docCache = (JavaDocResource[]) infoList.toArray(new JavaDocResource[infoList.size()]); + return docCache; } - + + public static JavaDocResource getJavaDocResource(String qualifiedClassName) + { + if (docCache==null) return null; + + for(int i=0; docCache.length>i; i++){ + if(docCache[i].getQualifiedName().equals(qualifiedClassName)) + { + return docCache[i]; + } + } + return null; + } + + public void setPersistent(boolean b) { XTag tag = xClass.getDoc().getTag("persistent"); @@ -106,25 +134,114 @@ } /** - * @return - */ + * @param string + * @return + */ public boolean isPersistent() { - return (xClass.getDoc().getTag("persistent") != null); + + XClass sClass; + XClass clazz = xClass; + + if(isClassPersistent(clazz)) return true; + + while (!(sClass = clazz.getSuperclass()).getName().equals("Object")) + { + if (isClassPersistent(sClass)) + { + return isClassPersistent(sClass); + } + clazz = sClass; + } + return isClassPersistent(clazz); + } + + /** + * @return + */ + public boolean isClassPersistent(XClass xClazz) + { + XTag tag; + + if (xClazz.getDoc().getTag("persistent") != null) + return true; + + try + { + if ((tag = xClazz.getDoc().getTag("uml")) != null) + { + String stereotype = tag.getValue(); + Properties prop = new Properties(); + prop.load(new StringBufferInputStream(stereotype)); + if ((stereotype = (String) prop.get("stereotypes")) == null) + return false; + String array[] = stringToArray(stereotype); + for (int j = 0; array.length > j; j++) + { + if (array[j].equals("persistent")) + return true; + } + } + + } catch (IOException e) + { + e.printStackTrace(); + } + return false; } /** - * @return - */ - public String getFullQualifiedName() + * @param pStereotype + * @return + */ + private String[] stringToArray(String pStereotype) + { + List result = new ArrayList(); + StringBuffer buf = new StringBuffer(pStereotype); + char ch; + boolean open = false; + StringBuffer out = new StringBuffer(); + + for (int i = 0; buf.length() > i; i++) + { + ch = buf.charAt(i); + if (ch == '{') + continue; + if (ch == '}') + continue; + if (ch == '"' && !open) + { + open = true; + out = new StringBuffer(); + continue; + } + if (ch == '"' && open) + { + open = false; + result.add(out.toString()); + continue; + } + + if (open) + out.append(ch); + + } + + return (String[]) result.toArray(new String[result.size()]); + } + + /** + * @return + */ + public String getQualifiedName() { return xClass.getQualifiedName(); } /** - * - */ + * + */ public void save() { @@ -139,22 +256,24 @@ } /** - * @param string - * @return - */ + * @param string + * @return + */ public Object getAttribute(String string) { XClass sClass; - sClass = xClass; - while (!(sClass = sClass.getSuperclass()).getName().equals("Object")) + XClass clazz = xClass; + + while (!(sClass = clazz.getSuperclass()).getName().equals("Object")) { if (sClass.getField(string) != null) { return sClass.getField(string); } + clazz = sClass; } - return null; + return clazz.getField(string); } }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]