@Override
	public boolean applyTo(Program program) {
		SymbolTable st = program.getSymbolTable();
		Symbol oldSymbol = st.getPrimarySymbol(addr);

		if (oldSymbol == null) {
			errorMsg = "No Symbols at address: " + addr;
			return false;
		}

		if (namespace == null) {
			namespace = program.getGlobalNamespace();
		}
		symbol = st.getSymbol(name, addr, namespace);
		if (symbol == null) {
			// no new symbol - not an error condition if the previous symbol was dynamic.  The
			// assumption here is that the user has performed an operation that did not actually
			// change the state of the symbol, like changing the namespace of a default symbol, 
			// which has no effect
			if (!oldSymbol.isDynamic()) {
				errorMsg = "Symbol " + name + " does not exist in namespace " + namespace +
					" at address " + addr;
				return false;
			}
			return true;
		}
		if (oldSymbol.getSymbolType() == SymbolType.FUNCTION) {
			if (oldSymbol == symbol) {
				return true; // function symbol is already primary
			}
			// keep the function symbol and rename it to the new symbol name;
			// (first have to delete the new symbol).
			String oldName = oldSymbol.getName();
			SourceType oldSource = oldSymbol.getSource();
			Namespace oldParent = oldSymbol.getParentNamespace();
			if (namespace == oldSymbol.getObject()) {
				// local label promotion - switch names but not namespaces
				oldParent = namespace;
				namespace = oldSymbol.getParentNamespace();
			}
			SourceType symbolSource = symbol.getSource();
			symbol.delete();
			try {
				oldSymbol.setNameAndNamespace(name, namespace, symbolSource);
				symbol = oldSymbol;
				// If renamed oldSymbol is now Default source don't keep old name (handles special Thunk rename case)
				if (oldSource != SourceType.DEFAULT &&
					oldSymbol.getSource() != SourceType.DEFAULT) {
					// put the other symbol back using the old namespace and old source
					st.createLabel(addr, oldName, oldParent, oldSource);
				}
				return true;
			}
			catch (DuplicateNameException e) {
				errorMsg = "Duplicate name should not have happened for " + name;
			}
			catch (InvalidInputException e) {
				errorMsg = "InvalidInputException: " + e.getMessage();
			}
			catch (CircularDependencyException e) {
				errorMsg = "CircularDependencyException: " + e.getMessage();
			}
			return false;
		}
		if (!symbol.setPrimary()) {
			errorMsg = "Set primary not permitted for " + symbol.getName(true);
			return false;
		}
		return true;
	}
Constructs a new command for setting the primary state of a label.
@param addr the address of the label to make primary.
@param name the name of the label to make primary.
@param namespace the parent namespace of the label to make primary.
Ghidra/Features/Base/src/main/java/ghidra/app/cmd/label/SetLabelPrimaryCmd.java