alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

What this is

This file is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Other links

The source code

/*
 *                 Sun Public License Notice
 *
 * The contents of this file are subject to the Sun Public License
 * Version 1.0 (the "License"). You may not use this file except in
 * compliance with the License. A copy of the License is available at
 * http://www.sun.com/
 *
 * The Original Code is NetBeans. The Initial Developer of the Original
 * Code is Sun Microsystems, Inc. Portions Copyright 1997-2003 Sun
 * Microsystems, Inc. All Rights Reserved.
 */
package org.netbeans.modules.javacore.parser;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import org.netbeans.jmi.javamodel.Feature;
import org.netbeans.jmi.javamodel.Resource;
import org.netbeans.lib.java.parser.ASTree;
import org.netbeans.lib.java.parser.ASTreeTypes;
import org.netbeans.modules.javacore.internalapi.JavaMetamodel;
import org.netbeans.modules.javacore.jmiimpl.javamodel.FeatureImpl;
import org.netbeans.modules.javacore.jmiimpl.javamodel.SemiPersistentElement;

/**
 *
 * @author Martin Matula
 */
public final class ResourceInfo extends ElementInfo {
    public static final int RESOURCE_TYPE = ASTreeTypes.COMPILATION_UNIT;

    public final ClassInfo[] classes;
    public final ElementInfo[] imports;
    public final String sourceText;
    public final boolean isFromDoc;
    
    private MDRParser hardRef;
    private Set attributed;

    public ResourceInfo(ASTree tree, int infoType, Resource resource, ClassInfo[] classes, ElementInfo[] imports) {
        super(tree, infoType, resource == null ? null : resource.getName());
        MDRParser parser = tree == null ? null : (MDRParser) tree.getASTContext();
        this.sourceText = parser != null ? parser.getSourceText() : null;
        this.isFromDoc = parser != null && parser.isFromDocument();
        this.classes = classes == null ? EMPTY_FEATURES : classes;
        this.imports = imports == null ? EMPTY_FEATURES : imports;
    }

    public void hardRefAST() {
        hardRef = resource.getParser();
    }

    public void doAttribution(FeatureImpl parent) {
        ASTree tree = parent.getASTree();
        if (tree != null) {
            MDRParser parser = (MDRParser) tree.getASTContext();
            parser.prepareForAttribution((Feature) parent, tree);
            if (attributed == null) {
                attributed = new HashSet();
            }
            attributed.add(parent);
        }
    }

    public ASTree refreshASTree() {
        //System.out.println("recollecting garbagecollected AST: " + name);
        MDRParser mdrParser = new MDRParser(resource, JavaMetamodel.getManager().getDataObject(resource), sourceText, isFromDoc);
//        System.err.println("Recreating AST for: " + mdrParser);
//        CachedReference.dumpCache();
        ResourceInfo resInfo = mdrParser.enterMembers();
        this.tree = resInfo.tree;
        
        if (attributed != null) {
            for (Iterator it = attributed.iterator(); it.hasNext();) {
                FeatureImpl entry = (FeatureImpl) it.next();
                mdrParser.prepareForAttribution((Feature) entry, entry.getASTree());
            }
        }
        
        return mdrParser.getASTree();
    }

    public ASTree getTypeAST(SemiPersistentElement owner) {
        ASTree tree = owner.getASTree();
        if (tree != null) {
            ASTree pkg = tree.getSubTrees()[0];
            return pkg == null ? null : pkg.getSubTrees()[0];
        }
        return null;
    }

    public String getSourceText() {
        return sourceText;
    }
}
... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.