int firstLine= 1;
	private static void smartPaste(IDocument document, DocumentCommand command) {		try {			JavaHeuristicScanner scanner= new JavaHeuristicScanner(document);			JavaIndenter indenter= new JavaIndenter(document, scanner);			int offset= command.offset;						// reference position to get the indent from			int refOffset= indenter.findReferencePosition(offset);			if (refOffset == JavaHeuristicScanner.NOT_FOUND)				return;			int peerOffset= getPeerPosition(document, command);			peerOffset= indenter.findReferencePosition(peerOffset);			refOffset= Math.min(refOffset, peerOffset);						// eat any WS before the insertion to the beginning of the line 			IRegion line= document.getLineInformationOfOffset(offset);			String notSelected= document.get(line.getOffset(), offset - line.getOffset());			if (notSelected.trim().length() == 0) {				command.length += notSelected.length();				command.offset= line.getOffset();			}						// prefix: the part we need for formatting but won't paste			IRegion refLine= document.getLineInformationOfOffset(refOffset);			String prefix= document.get(refLine.getOffset(), command.offset - refLine.getOffset());						// handle the indentation computation inside a temporary document			Document temp= new Document(prefix + command.text);			scanner= new JavaHeuristicScanner(temp);			indenter= new JavaIndenter(temp, scanner);			installJavaStuff(temp);						// indent the first and second line			// compute the relative indentation difference from the second line			// (as the first might be partially selected) and use the value to			// indent all other lines.			boolean isIndentDetected= false;			StringBuffer addition= new StringBuffer();			int insertLength= 0;			int first= document.computeNumberOfLines(prefix);			int lines= temp.getNumberOfLines();			for (int l= first; l < lines; l++) { // we don't change the number of lines while adding indents								IRegion r= temp.getLineInformation(l);				int lineOffset= r.getOffset();				int lineLength= r.getLength();								if (lineLength == 0) // don't modify empty lines					continue;								if (!isIndentDetected){										// indent the first pasted line					String current= getCurrentIndent(temp, l);					StringBuffer correct= indenter.computeIndentation(lineOffset);					if (correct == null)						return; // bail out										insertLength= subtractIndent(correct, current, addition);					if (l != first)						isIndentDetected= true;				}								// relatively indent all pasted lines 				if (insertLength > 0)					addIndent(temp, l, addition);				else if (insertLength < 0)					cutIndent(temp, l, -insertLength);							}						// modify the command			command.text= temp.get(prefix.length(), temp.getLength() - prefix.length());					} catch (BadLocationException e) {			JavaPlugin.log(e);		}	}