|
What this is
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-2004 Sun * Microsystems, Inc. All Rights Reserved. */ package org.netbeans.modules.javacore.jmiimpl.javamodel; import java.util.*; import org.netbeans.jmi.javamodel.Element; import org.netbeans.jmi.javamodel.StatementBlock; import org.netbeans.lib.java.parser.ASTree; import org.netbeans.mdr.storagemodel.StorableObject; import org.netbeans.modules.javacore.parser.ASTProvider; /** * * @author Martin Matula */ public abstract class StatementBlockImpl extends StatementImpl implements StatementBlock { private LightAttrList statements = null; /** Creates a new instance of StatementBlockImpl */ public StatementBlockImpl(StorableObject o) { super(o); } /** * Returns the value of attribute statements. * @return Value of attribute statements. */ public List getStatements() { if (!childrenInited) { initChildren(); } return statements; } void setStatements(List statements) { this.statements = createChildrenList("statements", statements, CHANGED_STATEMENTS); // NOI18N } protected void _delete() { // --- delete components ------------------------------------------- if (childrenInited) { deleteChildren(statements); } // --- delete links ----------------------------------------------- // no links to delete // --- call super --------------------------------------- super._delete(); } public void replaceChild(Element oldElement,Element newElement) { if (childrenInited) { replaceObject(getStatements(),oldElement,newElement); } } public List getChildren() { return new ArrayList(getStatements()); } protected void initChildren() { childrenInited = false; statements = createChildrenList(statements, "statements", getASTree().getSubTrees(), CHANGED_STATEMENTS, false); // NOI18N childrenInited = true; } public String getSourceText() { String origElem; if ((origElem = checkChange()) != null) return origElem; StringBuffer buf = new StringBuffer(); List statements = getStatements(); formatElementPart(BLOCK_OPEN_CURLY, buf); for (Iterator iter = statements.iterator(); iter.hasNext();) { StatementImpl stat = (StatementImpl) iter.next(); buf.append("\n"); // NOI18N buf.append(getIndentation()); if (!stat.isNew() && !stat.isChanged()) { buf.append(INDENTATION); //NOI18N buf.append(stat.getSourceText().trim()); } else { buf.append(stat.getSourceText()); } } formatElementPart(BLOCK_CLOSE_CURLY, buf); return buf.toString(); } protected String getIndentation() { Object comp = refImmediateComposite(); // for method or for statement block which is not part of another // statement block do not increment the indentation if (comp instanceof SemiPersistentElement) { return ((SemiPersistentElement) comp).getIndentation(); } else if (!(comp instanceof StatementBlock)) { return ((TransientElement) comp).getIndentation(); } else { return ((TransientElement) comp).getIndentation().concat(INDENTATION); } } public void getDiff(List diff) { ASTProvider parser = getParser(); ASTree tree = getASTree(); ASTree[] children = tree.getSubTrees(); if (children == null) children = new ASTree[0]; int pos = parser.getToken(tree.getLastToken()).getStartOffset(); getCollectionDiff(diff, parser, CHANGED_STATEMENTS, children, getStatements(), pos, "\n"); // NOI18N } } |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
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.