Skip to content

Commit

Permalink
Merge pull request #116 from jakejustus/Dev
Browse files Browse the repository at this point in the history
ClassDocumentation for 11.5+
  • Loading branch information
jakejustus committed Sep 21, 2015
2 parents 1ebdc01 + 22ab001 commit 2eef1d3
Show file tree
Hide file tree
Showing 13 changed files with 305 additions and 14 deletions.
2 changes: 2 additions & 0 deletions .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@
<classpathentry kind="lib" path="lib/guava.jar"/>
<classpathentry kind="lib" path="lib/gson-2.2.4.jar"/>
<classpathentry kind="lib" path="lib/profiler-parser-1.2.jar"/>
<classpathentry kind="lib" path="lib/ast.jar"/>
<classpathentry kind="lib" path="lib/ast-dependencies.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
6 changes: 4 additions & 2 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@
<pathelement location="lib/gson-2.2.4.jar" />
<pathelement location="lib/guava.jar" />
<pathelement location="lib/profiler-parser-1.2.jar" />
<pathelement location="lib/ast.jar" />
<pathelement location="lib/ast-dependencies.jar" />
</path>
<path id="pct.test.compil">
<path refid="pct.compil" />
Expand Down Expand Up @@ -328,7 +330,7 @@
<zipfileset src="lib/proparse.jar" includes="**/*.class" />
<zipfileset src="lib/profiler-parser-1.2.jar" includes="**/*.class" />
<zipfileset dir="${src.progress}/Consultingwerk/Studio/ClassDocumentation/Templates" prefix="templates" />
<zipfileset src="lib/parser.jar" includes="**/*.class,**/jaxb.index" />
<zipfileset src="lib/parser.jar" includes="eu/rssw/rcode/*.class,**/jaxb.index" />
<zipfileset src="lib/antlr-2.7.7.jar" includes="**/*.class" />
<manifest>
<attribute name="Built-By" value="${user.name}" />
Expand Down Expand Up @@ -393,7 +395,7 @@
<zipfileset dir="${build-test}" includes="**/*" prefix="build/test" />
<zipfileset dir="tests" includes="**/*" prefix="testbox" />
<zipfileset dir="${src.progress}" includes="Consultingwerk/**/*" prefix="testbox/ClassDocumentation/test3/src" />
<zipfileset dir="lib" includes="ant.jar,ant-apache-regexp.jar,ant-launcher.jar,antlr4-runtime-4.5.jar,ini4j-0.5.1.jar,guava.jar,jakarta-regexp-1.5.jar,testng-6.3.1.jar,oe_common_services.jar,jacocoant.jar,*.pl" prefix="lib" />
<zipfileset dir="lib" includes="ast.jar,ast-dependencies.jar,ant.jar,ant-apache-regexp.jar,ant-launcher.jar,antlr4-runtime-4.5.jar,ini4j-0.5.1.jar,guava.jar,jakarta-regexp-1.5.jar,testng-6.3.1.jar,jacocoant.jar,*.pl" prefix="lib" />
<zipfileset dir="${dist}" includes="PCT.jar" prefix="dist" />
</zip>
</target>
Expand Down
Binary file added lib/ast-dependencies.jar
Binary file not shown.
Binary file added lib/ast.jar
Binary file not shown.
31 changes: 26 additions & 5 deletions src/java/eu/rssw/pct/oedoc/ClassDocumentationVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@

import antlr.CommonHiddenStreamToken;

import com.openedge.pdt.core.ast.ASTNode;
import com.openedge.pdt.core.ast.ConstructorDeclaration;
import com.openedge.pdt.core.ast.EventDeclaration;
import com.openedge.pdt.core.ast.MethodDeclaration;
import com.openedge.pdt.core.ast.ProgressParserTokenTypes;
import com.openedge.pdt.core.ast.ProgressTokenTypes;
import com.openedge.pdt.core.ast.PropertyDeclaration;
import com.openedge.pdt.core.ast.PropertyMethod;
import com.openedge.pdt.core.ast.SimpleToken;
Expand All @@ -24,7 +26,6 @@
import com.openedge.pdt.core.ast.model.IParameter;
import com.openedge.pdt.core.ast.visitor.ASTVisitor;

import eu.rssw.parser.ParserUtils;
import eu.rssw.rcode.AccessModifier;
import eu.rssw.rcode.ClassCompilationUnit;
import eu.rssw.rcode.Constructor;
Expand Down Expand Up @@ -100,7 +101,7 @@ public boolean visit(PropertyDeclaration decl) {
prop.dataType = decl.getDataType().getName();
prop.extent = decl.getExtent();
prop.modifier = AccessModifier.from(decl.getAccessModifier());
prop.propertyComment = ParserUtils.findPreviousComment(decl);
prop.propertyComment = findPreviousComment(decl);
cu.properties.add(prop);

return true;
Expand Down Expand Up @@ -136,7 +137,7 @@ public boolean visit(ConstructorDeclaration decl) {
constr.modifier = AccessModifier.STATIC;
else
constr.modifier = AccessModifier.from(decl.getAccessModifier());
constr.constrComment = ParserUtils.findPreviousComment(decl);
constr.constrComment = findPreviousComment(decl);

if (decl.getParameters() != null) {
for (IParameter p : decl.getParameters()) {
Expand Down Expand Up @@ -165,7 +166,7 @@ public boolean visit(MethodDeclaration decl) {
method.isStatic = decl.isStatic();
method.isFinal = decl.isFinal();
method.isAbstract = decl.isAbstract();
method.methodComment = ParserUtils.findPreviousComment(decl);
method.methodComment = findPreviousComment(decl);
cu.methods.add(method);

if (decl.getParameters() != null) {
Expand Down Expand Up @@ -198,7 +199,7 @@ public boolean visit(EventDeclaration decl) {
event.isAbstract = decl.isAbstract();
if (decl.isDelegate())
event.delegateName = decl.getDelegateName();
event.eventComment = ParserUtils.findPreviousComment(decl);
event.eventComment = findPreviousComment(decl);
cu.events.add(event);

if (decl.getParameters() != null) {
Expand Down Expand Up @@ -233,4 +234,24 @@ else if (decl.getChild(ProgressParserTokenTypes.ASSEMBLY) != null)

return true;
}

/**
* Renvoie le *dernier* commentaire
*
* @param node
* @return
*/
public static String findPreviousComment(ASTNode node) {
if ((node.getHiddenPrevious() != null) && (node.getHiddenPrevious().getType() == ProgressTokenTypes.ML__COMMENT)) {
return node.getHiddenPrevious().getText();
}
IASTNode n = node.getPrevSibling();
while ((n != null) && (n.getType() == ProgressParserTokenTypes.ANNOTATION)) {
if ((n.getHiddenPrevious() != null) && (n.getHiddenPrevious().getType() == ProgressTokenTypes.ML__COMMENT))
return n.getHiddenPrevious().getText();
n = n.getPrevSibling();
}
return null;
}

}
241 changes: 241 additions & 0 deletions src/java/eu/rssw/pct/oedoc/OpenEdgeDocumentation115.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,241 @@
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "Ant" and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [email protected].
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package eu.rssw.pct.oedoc;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.xml.bind.JAXBException;

import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.types.FileSet;
import org.apache.tools.ant.types.Path;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;

import com.openedge.core.runtime.IPropath;
import com.openedge.core.runtime.Propath;
import com.openedge.pdt.core.ast.ASTManager;
import com.openedge.pdt.core.ast.ASTNode;
import com.openedge.pdt.core.ast.IASTManager;
import com.openedge.pdt.core.ast.PropathASTContext;
import com.openedge.pdt.core.ast.model.IASTContext;
import com.openedge.pdt.core.ast.model.IASTNode;
import com.openedge.pdt.core.ast.model.ICompilationUnit;
import com.phenix.pct.Messages;
import com.phenix.pct.PCT;

/**
* Class for generating XML documentation from OpenEdge classes
*
* @author <a href="mailto:[email protected]">Gilles QUERRET </a>
*/
public class OpenEdgeDocumentation115 extends PCT {
private File destDir = null;
private String encoding = null;
private List<FileSet> filesets = new ArrayList<FileSet>();
protected Path propath = null;

public OpenEdgeDocumentation115() {
super();
createPropath();
}

/**
* Adds a set of files to archive.
*
* @param set FileSet
*/
public void addFileset(FileSet set) {
filesets.add(set);
}

/**
* Build dir
*
* @param dir Directory
*/
public void setBuildDir(File dir) {

}

/**
* Destination directory
*
* @param destFile Directory
*/
public void setDestDir(File dir) {
this.destDir = dir;
}

/**
* Codepage to use when reading files
*
* @param encoding String
*/
public void setEncoding(String encoding) {
this.encoding = encoding;
}

/**
* Set the propath to be used when running the procedure
*
* @param propath an Ant Path object containing the propath
*/
public void addPropath(Path propath) {
createPropath().append(propath);
}

/**
* Creates a new Path instance
*
* @return Path
*/
public Path createPropath() {
if (this.propath == null) {
this.propath = new Path(this.getProject());
}

return this.propath;
}

/**
* Do the work
*
* @throws BuildException Something went wrong
*/
public void execute() throws BuildException {
checkDlcHome();

// Destination directory must exist
if (this.destDir == null) {
throw new BuildException(Messages.getString("OpenEdgeClassDocumentation.0"));
}
// There must be at least one fileset
if (this.filesets.size() == 0) {
throw new BuildException(Messages.getString("OpenEdgeClassDocumentation.1"));
}
IPropath pp = new Propath(new org.eclipse.core.runtime.Path(getProject().getBaseDir().getAbsolutePath()), propath.list());
IASTContext astContext = new PropathASTContext(pp);
IProgressMonitor monitor = new NullProgressMonitor();
IASTManager astMgr = ASTManager.getASTManager();

log("Generating XML documentation (11.5+ method)", Project.MSG_INFO);
try {
for (FileSet fs : filesets) {
// And get files from fileset
String[] dsfiles = fs.getDirectoryScanner(this.getProject()).getIncludedFiles();

for (int i = 0; i < dsfiles.length; i++) {
File file = new File(fs.getDir(this.getProject()), dsfiles[i]);
log("Generating AST for " + file.getAbsolutePath(), Project.MSG_VERBOSE);
int extPos = file.getName().lastIndexOf('.');
String ext = file.getName().substring(extPos);
boolean isClass = ".cls".equalsIgnoreCase(ext);

ICompilationUnit root = astMgr.createAST(file, astContext, monitor, IASTManager.EXPAND_ON, IASTManager.DLEVEL_FULL);
if (isClass) {
ClassDocumentationVisitor visitor = new ClassDocumentationVisitor();
log("Executing AST ClassVisitor " + file.getAbsolutePath(), Project.MSG_VERBOSE);
root.accept(visitor);
if (visitor.getPackageName().length() == 0)
visitor.toXML(new File(destDir, visitor.getClassName() + ".xml"));
else
visitor.toXML(new File(destDir, visitor.getPackageName() + "."
+ visitor.getClassName() + ".xml"));
} else {
ProcedureDocumentationVisitor visitor = new ProcedureDocumentationVisitor();
log("Executing AST ProcedureVisitor " + file.getAbsolutePath(), Project.MSG_VERBOSE);
root.accept(visitor);
File destFile = new File(destDir, dsfiles[i] + ".xml");
destFile.getParentFile().mkdirs();
visitor.toXML(destFile);
}
}
}
} catch (IOException caught) {
throw new BuildException(caught);
} catch (JAXBException caught) {
throw new BuildException(caught);
}
}

public static void setSourceRange(ASTNode node) {
if (node instanceof ICompilationUnit) {
node.setStartPosition(1);
}

if ((node.getFirstChild1() == null) || (node.getType() == 22)) {
node.setStartPosition(node.getTokenStart());
node.setLength(node.getTokenLength());
}

IASTNode prev = null;
for (IASTNode child = node.getFirstChild1(); child != null; child = child.getNextSibling1()) {
((ASTNode) child).setParent(node);
if (prev != null) {
((ASTNode) child).setPrevSibling(prev);
}
prev = child;

if (child.getType() != 22) {
setSourceRange((ASTNode) child);
}
}
}

}
Loading

0 comments on commit 2eef1d3

Please sign in to comment.