/* * [Definable.java] * * Summary: Describes one variable name token for display. Base for tokens with definition and reference variants. e.g. * * Copyright: (c) 2004-2017 Roedy Green, Canadian Mind Products, http://mindprod.com * * Licence: This software may be copied and used freely for any purpose but military. * http://mindprod.com/contact/nonmil.html * * Requires: JDK 1.8+ * * Created with: JetBrains IntelliJ IDEA IDE http://www.jetbrains.com/idea/ * * Version History: * 2.0 2009-04-19 tidy comments, more accurate colour names */ package com.mindprod.jtokens.java; import com.mindprod.jtokens.Token; /** * Describes one variable name token for display. Base for tokens with definition and reference variants. e.g. *

* JavaClassName Var Method * * @author Roedy Green, Canadian Mind Products * @version 2.0 2009-04-19 tidy comments, more accurate colour names * @since 2004-04-24 */ public abstract class Definable extends Token { /** * version number for the class */ static final long serialVersionUID = 1L; /** * true if this where the variable is defined. false if it is a reference to the variable. */ public boolean defining; /** * Constructor * * @param identifierName the name of an identifier e.g. i, temp. * @param defining true if this where the variable is defined. false if it is a reference to the variable. */ public Definable( String identifierName, boolean defining ) { super( identifierName ); this.defining = defining; if ( identifierName == null || identifierName.length() == 0 ) { throw new IllegalArgumentException( "missing identifierName for Definable" ); } } /** * Is this a the place where this thing is defined? * * @return true if this token represents a variable name where it was defined, which is shown bolder. */ private boolean isDefining() { return defining; } /** * Set whether this this the place where this is defined. * * @param defining true if this is the defining place. */ public void setDefining( boolean defining ) { this.defining = defining; } /** * Can this token be collapsed with following space or with a following identical token? * * @return true if can be collapsed simply by combining text */ public boolean isCollapsible() { // would confuse defined and ref return true; } /** * Can this token been collapse with the following given token * * @param t following token considered for merge * * @return true if the token in considered identical enough for merge. */ public boolean isCollapsible( Token t ) { // Definables will have a more stringent condition return isCollapsible() && t.getClass() == this.getClass() && ( ( Definable ) t ).defining == this.defining; } }