/** * Creates the Javadoc tags for newly inserted comments. * * @param document the document * @param command the command * @param indentation the base indentation to use * @param lineDelimiter the line delimiter to use * @param unit the compilation unit shown in the editor * @return the tags to add to the document * @throws CoreException if accessing the Java model fails * @throws BadLocationException if accessing the document fails */ private String createJavaDocTags(IDocument document, DocumentCommand command, String indentation, String lineDelimiter, ICompilationUnit unit) throws CoreException, BadLocationException { IJavaElement element= unit.getElementAt(command.offset); if (element == null) return null; switch (element.getElementType()) { case IJavaElement.TYPE: return createTypeTags(document, command, indentation, lineDelimiter, (IType) element); case IJavaElement.METHOD: return createMethodTags(document, command, indentation, lineDelimiter, (IMethod) element); default: return null; } }
private String createMethodTags(IDocument document, DocumentCommand command, String indentation, String lineDelimiter, IMethod method) throws CoreException, BadLocationException { IRegion partition= TextUtilities.getPartition(document, fPartitioning, command.offset, false); IMethod inheritedMethod= getInheritedMethod(method); String comment= CodeGeneration.getMethodComment(method, inheritedMethod, lineDelimiter); if (comment != null) { comment= comment.trim(); boolean javadocComment= comment.startsWith("/**"); //$NON-NLS-1$ if (!isFirstComment(document, command, method, javadocComment)) return null; boolean isJavaDoc= partition.getLength() >= 3 && document.get(partition.getOffset(), 3).equals("/**"); //$NON-NLS-1$ if (javadocComment == isJavaDoc) { return prepareTemplateComment(comment, indentation, method.getJavaProject(), lineDelimiter); } } return null; }
@Override public void customizeDocumentCommand(IDocument document, DocumentCommand command) { if (!isSmartMode()) return; if (command.text != null) { if (command.length == 0) { String[] lineDelimiters= document.getLegalLineDelimiters(); int index= TextUtilities.endsWith(lineDelimiters, command.text); if (index > -1) { // ends with line delimiter if (lineDelimiters[index].equals(command.text)) // just the line delimiter indentAfterNewLine(document, command); return; } } if (command.text.equals("/")) { //$NON-NLS-1$ indentAfterCommentEnd(document, command); return; } } }
int firstNonWS= findEndOfWhiteSpace(d, lineOffset, offset); Assert.isTrue(firstNonWS >= lineOffset, "indentation must not be negative"); //$NON-NLS-1$ IRegion prefix= findPrefixRange(d, line); String indentation= d.get(prefix.getOffset(), prefix.getLength()); int lengthToAdd= Math.min(offset - prefix.getOffset(), prefix.getLength()); if (isPreferenceTrue(PreferenceConstants.EDITOR_CLOSE_JAVADOCS) && isNewComment(d, offset)) { c.shiftsCaret= false; c.caretOffset= c.offset + buf.length(); if (isPreferenceTrue(PreferenceConstants.EDITOR_ADD_JAVADOC_TAGS)) { ICompilationUnit unit= getCompilationUnit(); String string= createJavaDocTags(d, c, indentation, lineDelimiter, unit);
public IAutoEditStrategy[] getAutoEditStrategies(ISourceViewer sourceViewer, String contentType) { String partitioning= getConfiguredDocumentPartitioning(sourceViewer); if (IJavaPartitions.JAVA_DOC.equals(contentType) || IJavaPartitions.JAVA_MULTI_LINE_COMMENT.equals(contentType)) return new IAutoEditStrategy[] { new JavaDocAutoIndentStrategy(partitioning) }; else if (IJavaPartitions.JAVA_STRING.equals(contentType)) return new IAutoEditStrategy[] { new SmartSemicolonAutoEditStrategy(partitioning), new JavaStringAutoIndentStrategy(partitioning) }; else if (IJavaPartitions.JAVA_CHARACTER.equals(contentType) || IDocument.DEFAULT_CONTENT_TYPE.equals(contentType)) return new IAutoEditStrategy[] { new SmartSemicolonAutoEditStrategy(partitioning), new JavaAutoIndentStrategy(partitioning, getProject()) }; else return new IAutoEditStrategy[] { new JavaAutoIndentStrategy(partitioning, getProject()) }; }
/** * Returns the range of the Javadoc prefix on the given line in * <code>document</code>. The prefix greedily matches the following regex * pattern: <code>\w*\*\w*</code>, that is, any number of whitespace * characters, followed by an asterix ('*'), followed by any number of * whitespace characters. * * @param document the document to which <code>line</code> refers * @param line the line from which to extract the prefix range * @return an <code>IRegion</code> describing the range of the prefix on * the given line * @throws BadLocationException if accessing the document fails */ private IRegion findPrefixRange(IDocument document, IRegion line) throws BadLocationException { int lineOffset= line.getOffset(); int lineEnd= lineOffset + line.getLength(); int indentEnd= findEndOfWhiteSpace(document, lineOffset, lineEnd); if (indentEnd < lineEnd && document.getChar(indentEnd) == '*') { indentEnd++; while (indentEnd < lineEnd && document.getChar(indentEnd) == ' ') indentEnd++; } return new Region(lineOffset, indentEnd - lineOffset); }
int firstNonWS= findEndOfWhiteSpace(d, lineOffset, offset); Assert.isTrue(firstNonWS >= lineOffset, "indentation must not be negative"); //$NON-NLS-1$ IRegion prefix= findPrefixRange(d, line); String indentation= d.get(prefix.getOffset(), prefix.getLength()); int lengthToAdd= Math.min(offset - prefix.getOffset(), prefix.getLength()); if (isPreferenceTrue(PreferenceConstants.EDITOR_CLOSE_JAVADOCS) && isNewComment(d, offset)) { c.shiftsCaret= false; c.caretOffset= c.offset + buf.length(); String endTag= lineDelimiter + indentation + " */"; //$NON-NLS-1$ if (isPreferenceTrue(PreferenceConstants.EDITOR_ADD_JAVADOC_TAGS)) { ICompilationUnit unit= getCompilationUnit(); String string= createJavaDocTags(d, c, indentation, lineDelimiter, unit); buf.append(restOfLine);
@Override public IAutoEditStrategy[] getAutoEditStrategies(ISourceViewer sourceViewer, String contentType) { String partitioning= getConfiguredDocumentPartitioning(sourceViewer); if (IJavaPartitions.JAVA_DOC.equals(contentType) || IJavaPartitions.JAVA_MULTI_LINE_COMMENT.equals(contentType)) return new IAutoEditStrategy[] { new JavaDocAutoIndentStrategy(partitioning) }; else if (IJavaPartitions.JAVA_STRING.equals(contentType)) return new IAutoEditStrategy[] { new SmartSemicolonAutoEditStrategy(partitioning), new JavaStringAutoIndentStrategy(partitioning, getProject()) }; else if (IJavaPartitions.JAVA_CHARACTER.equals(contentType) || IDocument.DEFAULT_CONTENT_TYPE.equals(contentType)) return new IAutoEditStrategy[] { new SmartSemicolonAutoEditStrategy(partitioning), new JavaAutoIndentStrategy(partitioning, getProject(), sourceViewer) }; else return new IAutoEditStrategy[] { new JavaAutoIndentStrategy(partitioning, getProject(), sourceViewer) }; }
/** * Returns the range of the Javadoc prefix on the given line in * <code>document</code>. The prefix greedily matches the following regex * pattern: <code>\w*\*\w*</code>, that is, any number of whitespace * characters, followed by an asterisk ('*'), followed by any number of * whitespace characters. * * @param document the document to which <code>line</code> refers * @param line the line from which to extract the prefix range * @return an <code>IRegion</code> describing the range of the prefix on the given line * @throws BadLocationException if accessing the document fails */ private IRegion findPrefixRange(IDocument document, IRegion line) throws BadLocationException { int lineOffset= line.getOffset(); int lineEnd= lineOffset + line.getLength(); int indentEnd= findEndOfWhiteSpace(document, lineOffset, lineEnd); if (indentEnd < lineEnd && document.getChar(indentEnd) == '*') { indentEnd++; while (indentEnd < lineEnd && document.getChar(indentEnd) == ' ') indentEnd++; } return new Region(lineOffset, indentEnd - lineOffset); }
int firstNonWS= findEndOfWhiteSpace(d, lineOffset, offset); Assert.isTrue(firstNonWS >= lineOffset, "indentation must not be negative"); //$NON-NLS-1$ IRegion prefix= findPrefixRange(d, line); String indentation= d.get(prefix.getOffset(), prefix.getLength()); int lengthToAdd= Math.min(offset - prefix.getOffset(), prefix.getLength()); if (isPreferenceTrue(PreferenceConstants.EDITOR_CLOSE_JAVADOCS) && isNewComment(d, offset)) { c.shiftsCaret= false; c.caretOffset= c.offset + buf.length(); String endTag= lineDelimiter + indentation + " */"; //$NON-NLS-1$ if (isPreferenceTrue(PreferenceConstants.EDITOR_ADD_JAVADOC_TAGS)) { ICompilationUnit unit= getCompilationUnit(); String string= createJavaDocTags(d, c, indentation, lineDelimiter, unit); buf.append(restOfLine);
private String createMethodTags(IDocument document, DocumentCommand command, String indentation, String lineDelimiter, IMethod method) throws CoreException, BadLocationException { IRegion partition= TextUtilities.getPartition(document, fPartitioning, command.offset, false); IMethod inheritedMethod= getInheritedMethod(method); String comment= CodeGeneration.getMethodComment(method, inheritedMethod, lineDelimiter); if (comment != null) { comment= comment.trim(); boolean javadocComment= comment.startsWith("/**"); //$NON-NLS-1$ if (!isFirstComment(document, command, method, javadocComment)) return null; boolean isJavaDoc= partition.getLength() >= 3 && document.get(partition.getOffset(), 3).equals("/**"); //$NON-NLS-1$ if (javadocComment == isJavaDoc) { return prepareTemplateComment(comment, indentation, method.getJavaProject(), lineDelimiter); } } return null; }
public void customizeDocumentCommand(IDocument document, DocumentCommand command) { if (!isSmartMode()) return; if (command.text != null) { if (command.length == 0) { String[] lineDelimiters= document.getLegalLineDelimiters(); int index= TextUtilities.endsWith(lineDelimiters, command.text); if (index > -1) { // ends with line delimiter if (lineDelimiters[index].equals(command.text)) // just the line delimiter indentAfterNewLine(document, command); return; } } if (command.text.equals("/")) { //$NON-NLS-1$ indentAfterCommentEnd(document, command); return; } } }
/** * Creates the Javadoc tags for newly inserted comments. * * @param document the document * @param command the command * @param indentation the base indentation to use * @param lineDelimiter the line delimiter to use * @param unit the compilation unit shown in the editor * @return the tags to add to the document * @throws CoreException if accessing the Java model fails * @throws BadLocationException if accessing the document fails */ private String createJavaDocTags(IDocument document, DocumentCommand command, String indentation, String lineDelimiter, ICompilationUnit unit) throws CoreException, BadLocationException { IJavaElement element= unit.getElementAt(command.offset); if (element == null) return null; switch (element.getElementType()) { case IJavaElement.TYPE: return createTypeTags(document, command, indentation, lineDelimiter, (IType) element); case IJavaElement.METHOD: return createMethodTags(document, command, indentation, lineDelimiter, (IMethod) element); default: return null; } }
@Override public IAutoEditStrategy[] getAutoEditStrategies(ISourceViewer sourceViewer, String contentType) { String partitioning= getConfiguredDocumentPartitioning(sourceViewer); if (IJavaPartitions.JAVA_DOC.equals(contentType) || IJavaPartitions.JAVA_MULTI_LINE_COMMENT.equals(contentType)) return new IAutoEditStrategy[] { new JavaDocAutoIndentStrategy(partitioning) }; else if (IJavaPartitions.JAVA_STRING.equals(contentType)) return new IAutoEditStrategy[] { new SmartSemicolonAutoEditStrategy(partitioning), new JavaStringAutoIndentStrategy(partitioning, getProject()) }; else if (IJavaPartitions.JAVA_CHARACTER.equals(contentType) || IDocument.DEFAULT_CONTENT_TYPE.equals(contentType)) return new IAutoEditStrategy[] { new SmartSemicolonAutoEditStrategy(partitioning), new JavaAutoIndentStrategy(partitioning, getProject(), sourceViewer) }; else return new IAutoEditStrategy[] { new JavaAutoIndentStrategy(partitioning, getProject(), sourceViewer) }; }
/** * Returns the range of the Javadoc prefix on the given line in * <code>document</code>. The prefix greedily matches the following regex * pattern: <code>\w*\*\w*</code>, that is, any number of whitespace * characters, followed by an asterisk ('*'), followed by any number of * whitespace characters. * * @param document the document to which <code>line</code> refers * @param line the line from which to extract the prefix range * @return an <code>IRegion</code> describing the range of the prefix on the given line * @throws BadLocationException if accessing the document fails */ private IRegion findPrefixRange(IDocument document, IRegion line) throws BadLocationException { int lineOffset= line.getOffset(); int lineEnd= lineOffset + line.getLength(); int indentEnd= findEndOfWhiteSpace(document, lineOffset, lineEnd); if (indentEnd < lineEnd && document.getChar(indentEnd) == '*') { indentEnd++; while (indentEnd < lineEnd && document.getChar(indentEnd) == ' ') indentEnd++; } return new Region(lineOffset, indentEnd - lineOffset); }
private String createMethodTags(IDocument document, DocumentCommand command, String indentation, String lineDelimiter, IMethod method) throws CoreException, BadLocationException { IRegion partition= TextUtilities.getPartition(document, fPartitioning, command.offset, false); IMethod inheritedMethod= getInheritedMethod(method); String comment= CodeGeneration.getMethodComment(method, inheritedMethod, lineDelimiter); if (comment != null) { comment= comment.trim(); boolean javadocComment= comment.startsWith("/**"); //$NON-NLS-1$ if (!isFirstComment(document, command, method, javadocComment)) return null; boolean isJavaDoc= partition.getLength() >= 3 && document.get(partition.getOffset(), 3).equals("/**"); //$NON-NLS-1$ if (javadocComment == isJavaDoc) { return prepareTemplateComment(comment, indentation, method.getJavaProject(), lineDelimiter); } } return null; }
@Override public void customizeDocumentCommand(IDocument document, DocumentCommand command) { if (!isSmartMode()) return; if (command.text != null) { if (command.length == 0) { String[] lineDelimiters= document.getLegalLineDelimiters(); int index= TextUtilities.endsWith(lineDelimiters, command.text); if (index > -1) { // ends with line delimiter if (lineDelimiters[index].equals(command.text)) // just the line delimiter indentAfterNewLine(document, command); return; } } if (command.text.equals("/")) { //$NON-NLS-1$ indentAfterCommentEnd(document, command); return; } } }
/** * Creates the Javadoc tags for newly inserted comments. * * @param document the document * @param command the command * @param indentation the base indentation to use * @param lineDelimiter the line delimiter to use * @param unit the compilation unit shown in the editor * @return the tags to add to the document * @throws CoreException if accessing the java model fails * @throws BadLocationException if accessing the document fails */ private String createJavaDocTags(IDocument document, DocumentCommand command, String indentation, String lineDelimiter, ICompilationUnit unit) throws CoreException, BadLocationException { IJavaElement element= unit.getElementAt(command.offset); if (element == null) return null; switch (element.getElementType()) { case IJavaElement.TYPE: return createTypeTags(document, command, indentation, lineDelimiter, (IType) element); case IJavaElement.METHOD: return createMethodTags(document, command, indentation, lineDelimiter, (IMethod) element); default: return null; } }