MCPcopy Create free account
hub / github.com/beanshell/beanshell / toLHS

Method toLHS

src/bsh/Name.java:668–753  ·  view source on GitHub ↗
( 
		CallStack callstack, Interpreter interpreter )

Source from the content-addressed store, hash-verified

666 /*
667 */
668 synchronized public LHS toLHS(
669 CallStack callstack, Interpreter interpreter )
670 throws UtilEvalError
671 {
672 // Should clean this up to a single return statement
673 reset();
674 LHS lhs;
675
676 // Simple (non-compound) variable assignment e.g. x=5;
677 if ( !isCompound(evalName) )
678 {
679 if ( evalName.equals("this") )
680 throw new UtilEvalError("Can't assign to 'this'." );
681
682 // Interpreter.debug("Simple var LHS...");
683 lhs = new LHS( namespace, evalName, false/*bubble up if allowed*/);
684 return lhs;
685 }
686
687 // Field e.g. foo.bar=5;
688 Object obj = null;
689 try {
690 while( evalName != null && isCompound( evalName ) )
691 {
692 obj = consumeNextObjectField( callstack, interpreter,
693 false/*forcclass*/, true/*autoallocthis*/ );
694 }
695 }
696 catch( UtilEvalError e ) {
697 throw new UtilEvalError( "LHS evaluation: " + e.getMessage() );
698 }
699
700 // Finished eval and its a class.
701 if ( evalName == null && obj instanceof ClassIdentifier )
702 throw new UtilEvalError("Can't assign to class: " + value );
703
704 if ( obj == null )
705 throw new UtilEvalError("Error in LHS: " + value );
706
707 // e.g. this.x=5; or someThisType.x=5;
708 if ( obj instanceof This )
709 {
710 // dissallow assignment to magic fields
711 if (
712 evalName.equals("namespace")
713 || evalName.equals("variables")
714 || evalName.equals("methods")
715 || evalName.equals("caller")
716 )
717 throw new UtilEvalError(
718 "Can't assign to special variable: "+evalName );
719
720 Interpreter.debug("found This reference evaluating LHS");
721 /*
722 If this was a literal "super" reference then we allow recursion
723 in setting the variable to get the normal effect of finding the
724 nearest definition starting at the super scope. On any other
725 resolution qualified by a 'this' type reference we want to set

Callers 3

evalMethod · 0.45
setMethod · 0.45
unsetMethod · 0.45

Calls 9

resetMethod · 0.95
isCompoundMethod · 0.95
debugMethod · 0.95
getLHSStaticFieldMethod · 0.95
getLHSObjectFieldMethod · 0.95
getTargetClassMethod · 0.80
equalsMethod · 0.45
getMessageMethod · 0.45

Tested by

no test coverage detected