001    /*
002     * mesopotamia-java @mesopotamia.version@
003     * Multilingual parser and repository. 
004     * Copyright (C) 2005  Hammurapi Group
005     *
006     * This program is free software; you can redistribute it and/or
007     * modify it under the terms of the GNU Lesser General Public
008     * License as published by the Free Software Foundation; either
009     * version 2 of the License, or (at your option) any later version.
010     *
011     * This program is distributed in the hope that it will be useful,
012     * but WITHOUT ANY WARRANTY; without even the implied warranty of
013     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014     * Lesser General Public License for more details.
015     *
016     * You should have received a copy of the GNU Lesser General Public
017     * License along with this library; if not, write to the Free Software
018     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
019     *
020     * URL: http://http://www.hammurapi.biz
021     * e-Mail: support@hammurapi.biz
022     */
023    package org.mesopotamia.lang.java;
024    
025    import java.util.List;
026    
027    import org.mesopotamia.LanguageElement;
028    import org.mesopotamia.LanguageElementHandle;
029    import org.mesopotamia.NodeData;
030    import org.mesopotamia.RepositoryLanguage;
031    import org.mesopotamia.Scan;
032    
033    import biz.hammurapi.util.VisitableBase;
034    import biz.hammurapi.util.Visitor;
035    
036    /**
037     * Base class for all language elements for Java language
038     * @author Pavel Vlasov
039     * @revision $Revision$
040     */
041    public class JavaLanguageElement extends LanguageElement {
042    
043            public static final String JAVA_LANG_OBJECT = "java.lang.Object";
044    
045            public JavaLanguageElement(
046                            NodeData xData, 
047                            Class<?> context, 
048                            Scan scan,
049                            RepositoryLanguage language, 
050                            Object environment) {
051                    super(xData, context, scan, language, environment);
052                    if (xData instanceof MesopotamiaJavaNode) {
053                            comments = ((MesopotamiaJavaNode) xData).getComments();
054                    }
055            }
056            
057            private List<Comment> comments;
058            
059            /**
060             * @return Comments before this element, if any.
061             */
062            public List<Comment> getComments() {
063                    return comments;
064            }
065    
066            protected LanguageElementHandle providerHandle;
067            
068            public void setProviderHandle(LanguageElementHandle providerHandle) {
069                    this.providerHandle = providerHandle;
070            }
071            
072            protected void acceptChildren(Visitor visitor) {
073                    super.acceptChildren(visitor);
074                    VisitableBase.object2visitor(getProvider(), visitor);
075            }       
076            
077            /**
078             * Provider for this language element, i.e. what comes before DOT.
079             * @return
080             */
081            public LanguageElement getProvider() {
082                    return (LanguageElement) (providerHandle == null ? null : getScan().getLanguageElement(providerHandle));
083            }
084            
085            protected String fcn;
086            protected boolean fcnCalculated;
087                    
088            /**
089             * Helper method for giving FCN's to anonymous and local classes.
090             * @return
091             */
092            protected String getFcn() {
093                    if (!fcnCalculated) {
094                            LanguageElement parent = getParent();
095                            if (parent instanceof JavaLanguageElement) {
096                                    fcn = ((JavaLanguageElement) parent).getFcn()+"."+getId();
097                            } else {
098                                    fcn = String.valueOf(getId());
099                            }
100                            fcnCalculated = true;
101                    }
102                    return fcn;
103            }
104    }