if (document.getLength() == 0) return 0;
	private static int getPeerPosition(IDocument document, DocumentCommand command) {    	/*    	 * Search for scope closers in the pasted text and find their opening peers    	 * in the document.     	 */    	Document pasted= new Document(command.text);    	installJavaStuff(pasted);    	int firstPeer= command.offset;    	    	JavaHeuristicScanner pScanner= new JavaHeuristicScanner(pasted);    	JavaHeuristicScanner dScanner= new JavaHeuristicScanner(document);    	    	// add scope relevant after context to peer search    	int afterToken= dScanner.nextToken(command.offset + command.length, JavaHeuristicScanner.UNBOUND);    	try {			switch (afterToken) {			case Symbols.TokenRBRACE:				pasted.replace(pasted.getLength(), 0, "}"); //$NON-NLS-1$				break;			case Symbols.TokenRPAREN:				pasted.replace(pasted.getLength(), 0, ")"); //$NON-NLS-1$				break;			case Symbols.TokenRBRACKET:				pasted.replace(pasted.getLength(), 0, "]"); //$NON-NLS-1$				break;			}		} catch (BadLocationException e) {			// cannot happen			Assert.isTrue(false);		}    	    	int pPos= 0; // paste text position (increasing from 0)    	int dPos= Math.max(0, command.offset - 1); // document position (decreasing from paste offset)    	while (true) {    		int token= pScanner.nextToken(pPos, JavaHeuristicScanner.UNBOUND);   			pPos= pScanner.getPosition();    		switch (token) {    			case Symbols.TokenLBRACE:    			case Symbols.TokenLBRACKET:    			case Symbols.TokenLPAREN:    				pPos= skipScope(pScanner, pPos, token);    				if (pPos == JavaHeuristicScanner.NOT_FOUND)    					return firstPeer;    				break; // closed scope -> keep searching    			case Symbols.TokenRBRACE:    				int peer= dScanner.findOpeningPeer(dPos, '{', '}');    				dPos= peer - 1;     				if (peer == JavaHeuristicScanner.NOT_FOUND)    					return firstPeer;    				firstPeer= peer;    				break; // keep searching    			case Symbols.TokenRBRACKET:    				peer= dScanner.findOpeningPeer(dPos, '[', ']');    				dPos= peer - 1;     				if (peer == JavaHeuristicScanner.NOT_FOUND)    					return firstPeer;    				firstPeer= peer;    				break; // keep searching    			case Symbols.TokenRPAREN:    				peer= dScanner.findOpeningPeer(dPos, '(', ')');    				dPos= peer - 1;     				if (peer == JavaHeuristicScanner.NOT_FOUND)    					return firstPeer;    				firstPeer= peer;    				break; // keep searching    			case Symbols.TokenCASE:    			case Symbols.TokenDEFAULT:    				JavaIndenter indenter= new JavaIndenter(document, dScanner);    				peer= indenter.findReferencePosition(dPos, false, false, false, true);    				if (peer == JavaHeuristicScanner.NOT_FOUND)    					return firstPeer;    				firstPeer= peer;    				break; // keep searching    				    			case Symbols.TokenEOF:    				return firstPeer;    			default:    				// keep searching    		}    	}    }