/* -*- Mode: JDE; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* This file is part of the debugger and core tools for the AspectJ(tm)
* programming language; see http://aspectj.org
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* either http://www.mozilla.org/MPL/ or http://aspectj.org/MPL/.
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is AspectJ.
*
* The Initial Developer of the Original Code is Xerox Corporation. Portions
* created by Xerox Corporation are Copyright (C) 1999-2002 Xerox Corporation.
* All Rights Reserved.
*/
package org.aspectj.tools.doclets.standard;
import org.aspectj.ajdoc.AdviceDoc;
import org.aspectj.ajdoc.AspectDoc;
import com.sun.javadoc.ClassDoc;
import com.sun.javadoc.ProgramElementDoc;
import com.sun.tools.doclets.Util;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
/**
* A splattering of misc. functionality.
*
* @author Jeff Palm
*/
public class Statics {
/**
* Returns a aspectj-world type String of cd
.
*
* @return either aspect interface or class depending
* on the type of cd
.
*/
public static String type(ClassDoc cd) {
return cd instanceof AspectDoc
? "aspect" : cd.isInterface()
? "interface" : "class";
}
/**
* Returns the link target for member
.
*
* @param member the ProgramElementDoc in question.
* @return the link target for member
.
*/
public static String where(ProgramElementDoc member) {
return member.name();
}
/**
* Returns the link label for member
.
*
* @param member the ProgramElementDoc in question.
* @return the link label for member
.
*/
public static String label(ProgramElementDoc member) {
return member.name();
}
/**
* Returns the link target for member
from
* cd
.
*
* @param cd the class from which we're linking.
* @param member the ProgramElementDoc in question.
* @return the link target for member
.
*/
public static String where(ClassDoc cd, ProgramElementDoc member) {
if (member instanceof AdviceDoc) {
return name(cd, (AdviceDoc)member).replace(' ','_').replace('#','-');
}
return member.name();
}
/**
* Returns the link label for member
from
* cd
.
*
* @param cd the class from which we're linking.
* @param member the ProgramElementDoc in question.
* @return the link target for member
.
*/
public static String label(ClassDoc cd, ProgramElementDoc member) {
return name(cd, member);
}
/**
* Returns the name for member
from
* cd
. This is here because we don't
* want really print the name of advice.
*
* @param cd the class from which we're printing.
* @param member the ProgramElementDoc in question.
* @return the name for member
.
*/
public static String name(ClassDoc cd, ProgramElementDoc member) {
if (member instanceof AdviceDoc) {
return name(cd, (AdviceDoc)member);
}
return member.name();
}
/**
* Returns the String that should be printed for
* an advice's name.
*
* @param cd the ClassDoc from where we're printing.
* @param advice the member in question.
* @return correct printing name for advice
.
*/
public static String name(ClassDoc cd, AdviceDoc advice) {
String name = advice.name();
int num = 1;
for (Iterator i = advice(cd).iterator(); i.hasNext();) {
AdviceDoc ad = (AdviceDoc)i.next();
if (ad.equals(advice)) {
break;
}
if (ad.name().equals(name)) {
num++;
}
}
return name + " #" + num;
}
/**
* Returns the advice contained in classdoc
.
*
* @param cd ClassDoc in question.
* @return a List with the {@link AdviceDoc}s
* contained in cd
.
*/
public static List advice(ClassDoc classdoc) {
if (!(classdoc instanceof AspectDoc)) return Collections.EMPTY_LIST;
AdviceDoc[] advice = ((AspectDoc)classdoc).advice();
return advice == null ? Collections.EMPTY_LIST : Util.asList(advice);
}
/**
* Returns an array of classes only.
*
* @param arr source array from where the ClassDocs in
* the result will come.
* @return an array of ClassDoc containing only
* classes, no aspects.
*/
public static ClassDoc[] classes(ClassDoc[] arr) {
List list = new ArrayList();
for (int i = 0; i < arr.length; i++) {
if (!(arr[i] instanceof AspectDoc)) {
list.add(arr[i]);
}
}
return (ClassDoc[])list.toArray(new ClassDoc[list.size()]);
}
/**
* Returns a list of the classes found in the
* passed in list of types.
*
* @param types List of ClassDocs.
* @return a List containing those ClassDocs in
* types
that are not aspects.
* @see #types(List,boolean)
*/
public static List classes(List types) {
return types(types, false);
}
/**
* Returns a list of the classes found in the
* passed in list of types.
*
* @param types List of ClassDocs.
* @return a List containing those ClassDocs in
* types
that are aspects.
* @see #types(List,boolean)
*/
public static List aspects(List types) {
return types(types, true);
}
/**
* Returns a list of ClassDocs taken from types
* that are aspects iff wantAspects
.
*
* @param types source List of ClassDocs.
* @param wantAspects ClassDocs cin the resulting List will
* conform to the test:
* c instanceof AspectDoc) == wantAspects.
* @return a List of ClassDocs all who conform to the test:
* c instanceof AspectDoc) == wantAspects.
*/
public static List types(List types, boolean wantAspects) {
List list = new ArrayList();
for (Iterator i = types.iterator(); i.hasNext();) {
ClassDoc cd = (ClassDoc)i.next();
if ((cd instanceof AspectDoc) == wantAspects) {
list.add(cd);
}
}
return list;
}
/**
* Returns a prequalified class link to cd
using
* the link target where
.
*
* @param writer base writer to use.
* @param cd class to where we're linking.
* @param where link target.
* @return prequalified class link using
* cd
and where
.
*/
public static String getPreQualifiedClassLink
(com.sun.tools.doclets.standard.SubWriterHolderWriter writer,
ClassDoc cd,
String where) {
return writer.getPkgName(cd) + writer.getClassLink(cd, where, cd.name());
}
/**
* Returns a prequalified class link to cd
using
* the link target where
returned by
* calling getPreQualifiedClassLink
.
*
* @param writer base writer to use.
* @param cd class to where we're linking.
* @param where link target.
* @see #getPreQualifiedClassLink
*/
public static void printPreQualifiedClassLink
(com.sun.tools.doclets.standard.SubWriterHolderWriter writer,
ClassDoc cd,
String where) {
writer.print(getPreQualifiedClassLink(writer, cd, where));
}
}