List of usage examples for org.eclipse.jdt.core.dom TagElement getStartPosition
public final int getStartPosition()
From source file:at.bestsolution.fxide.jdt.text.javadoc.JavadocContentAccess2.java
License:Open Source License
private void handleInlineTagElement(TagElement node) { String name = node.getTagName(); if (TagElement.TAG_VALUE.equals(name) && handleValueTag(node)) return;/*from ww w . j a v a 2s. c o m*/ boolean isLink = TagElement.TAG_LINK.equals(name); boolean isLinkplain = TagElement.TAG_LINKPLAIN.equals(name); boolean isCode = TagElement.TAG_CODE.equals(name); boolean isLiteral = TagElement.TAG_LITERAL.equals(name); if (isLiteral || isCode) fLiteralContent++; if (isLink || isCode) fBuf.append("<code>"); //$NON-NLS-1$ if (isLink || isLinkplain) handleLink(node.fragments()); else if (isCode || isLiteral) handleContentElements(node.fragments(), true); else if (handleInheritDoc(node)) { // handled } else if (handleDocRoot(node)) { // handled } else { //print uninterpreted source {@tagname ...} for unknown tags int start = node.getStartPosition(); String text = fSource.substring(start, start + node.getLength()); fBuf.append(removeDocLineIntros(text)); } if (isLink || isCode) fBuf.append("</code>"); //$NON-NLS-1$ if (isLiteral || isCode) fLiteralContent--; }
From source file:com.bsiag.eclipse.jdt.java.formatter.CommentsPreparator.java
License:Open Source License
@Override public boolean visit(TagElement node) { String tagName = node.getTagName(); if (tagName == null || tagName.length() <= 1) return true; int startIndex = tokenStartingAt(node.getStartPosition()); int nodeEnd = node.getStartPosition() + node.getLength() - 1; while (ScannerHelper.isWhitespace(this.ctm.charAt(nodeEnd))) nodeEnd--;/* ww w . j av a 2s . c o m*/ int endIndex = tokenEndingAt(nodeEnd); this.ctm.get(startIndex + 1).setWrapPolicy(WrapPolicy.DISABLE_WRAP); if (node.getParent() instanceof Javadoc) { assert this.ctm.toString(startIndex).startsWith(tagName); boolean isParamTag = PARAM_TAGS.contains(tagName); if (isParamTag && this.options.comment_insert_new_line_for_parameter && startIndex < endIndex) { Token token = this.ctm.get(startIndex + 2); token.breakBefore(); } if (this.options.comment_indent_root_tags) { int indent = this.ctm.getLength(this.ctm.get(startIndex), 0) + 1; if (isParamTag && this.options.comment_indent_parameter_description) indent += this.options.indentation_size; for (int i = startIndex + 1; i <= endIndex; i++) { Token token = this.ctm.get(i); token.setIndent(indent); // indent is used temporarily, tokens that are actually first in line // will have this changed to align (indent is reserved for code inside <pre> tags) } } Token startTokeen = this.ctm.get(startIndex); if (startIndex > 1) startTokeen.breakBefore(); int firstTagIndex; if (this.firstTagToken == null || (firstTagIndex = this.ctm.indexOf(this.firstTagToken)) < 0 || startIndex < firstTagIndex) this.firstTagToken = startTokeen; handleHtml(node); } if (node.isNested()) { substituteWrapIfTouching(startIndex); substituteWrapIfTouching(endIndex + 1); if (IMMUTABLE_TAGS.contains(tagName) && startIndex < endIndex) disableFormatting(startIndex, endIndex); noSubstituteWrapping(node.getStartPosition(), nodeEnd); } return true; }
From source file:com.bsiag.eclipse.jdt.java.formatter.CommentsPreparator.java
License:Open Source License
@Override public void endVisit(TagElement node) { String tagName = node.getTagName(); if (tagName == null || tagName.length() <= 1) handleHtml(node);/* w w w . j av a 2s.c o m*/ handleStringLiterals(this.tm.toString(node), node.getStartPosition()); }
From source file:com.bsiag.eclipse.jdt.java.formatter.CommentsPreparator.java
License:Open Source License
private void handleHtml(TagElement node) { if (!this.options.comment_format_html && !this.options.comment_format_source) return;// www . j a v a2 s.c o m String text = this.tm.toString(node); Matcher matcher = HTML_TAG_PATTERN.matcher(text); while (matcher.find()) { int startPos = matcher.start() + node.getStartPosition(); int endPos = matcher.end() - 1 + node.getStartPosition(); boolean isOpeningTag = (matcher.start(1) == matcher.end(1)); if (this.options.comment_format_html) { // make sure tokens inside the tag are wrapped only as a substitute int firstTokenIndex = tokenStartingAt(startPos), lastTokenIndex = tokenEndingAt(endPos); for (int i = firstTokenIndex + 1; i <= lastTokenIndex; i++) { Token token = this.ctm.get(i); if (token.getWrapPolicy() == null) token.setWrapPolicy(WrapPolicy.SUBSTITUTE_ONLY); } // never break tags on special characters noSubstituteWrapping(startPos, endPos - 1); // ... except for equals sign in attributes String attributesText = matcher.group(8); Matcher attrMatcher = HTML_ATTRIBUTE_PATTERN.matcher(attributesText); final int commentStart = this.ctm.get(0).originalStart; while (attrMatcher.find()) { int equalPos = node.getStartPosition() + matcher.start(8) + attrMatcher.start(1); assert this.tm.charAt(equalPos) == '='; this.noSubstituteWrapping[equalPos - commentStart] = false; } } int matchedGroups = 0; for (int i = 2; i <= 7; i++) if (matcher.start(i) < matcher.end(i)) matchedGroups++; if (matchedGroups != 1) continue; if (matcher.start(2) < matcher.end(2)) { handleFormatCodeTag(startPos, endPos, isOpeningTag); } if (this.options.comment_format_html) { if (matcher.start(3) < matcher.end(3)) { handleSeparateLineTag(startPos, endPos); } else if (matcher.start(4) < matcher.end(4)) { handleBreakBeforeTag(startPos, endPos, isOpeningTag); } else if (matcher.start(5) < matcher.end(5)) { handleBreakAfterTag(startPos, endPos); } else if (matcher.start(6) < matcher.end(6)) { handleNoFormatTag(startPos, endPos, isOpeningTag); } else if (matcher.start(7) < matcher.end(7)) { handleOtherTag(startPos, endPos); } } } }
From source file:com.servoy.eclipse.docgenerator.parser.JavadocExtractor.java
License:Open Source License
@Override public void endVisit(TagElement node) { javadocsStack.pop();/* w w w . j a va2 s. c o m*/ if (node.isNested()) { lastNodeEnd = node.getStartPosition() + node.getLength() - 1; } }
From source file:org.autorefactor.refactoring.rules.CommentsRefactoring.java
License:Open Source License
private String addPeriodAtEndOfFirstLine(Javadoc node, String comment) { String beforeFirstTag = comment; String afterFirstTag = ""; final Matcher m = FIRST_JAVADOC_TAG.matcher(comment); if (m.find()) { if (m.start() == 0) { return null; }//from ww w . j a va 2 s. c o m beforeFirstTag = comment.substring(0, m.start()); afterFirstTag = comment.substring(m.start()); } final Matcher matcher = JAVADOC_WITHOUT_PUNCTUATION.matcher(beforeFirstTag); if (matcher.matches()) { final List<TagElement> tagElements = tags(node); if (tagElements.size() >= 2) { final TagElement firstLine = tagElements.get(0); final int relativeStart = firstLine.getStartPosition() - node.getStartPosition(); final int endOfFirstLine = relativeStart + firstLine.getLength(); return comment.substring(0, endOfFirstLine) + "." + comment.substring(endOfFirstLine); // TODO JNR do the replace here, not outside this method } return matcher.group(1) + "." + matcher.group(2) + afterFirstTag; } return null; }
From source file:org.eclipse.pde.api.tools.internal.builder.TagValidator.java
License:Open Source License
/** * Creates a new {@link IApiProblem} for the given tag and adds it to the * cache/*from w ww . ja v a2 s. c o m*/ * * @param tag * @param element * @param context */ private void createTagProblem(String typeName, TagElement tag, int element, int kind, int markerid, String context) { int charstart = tag.getStartPosition(); int charend = charstart + tag.getTagName().length(); int linenumber = -1; try { // unit cannot be null IDocument document = Util.getDocument(fCompilationUnit); linenumber = document.getLineOfOffset(charstart); } catch (BadLocationException e) { } catch (CoreException e) { } try { IApiProblem problem = ApiProblemFactory.newApiProblem( fCompilationUnit.getCorrespondingResource().getProjectRelativePath().toPortableString(), typeName, new String[] { tag.getTagName(), context }, new String[] { IApiMarkerConstants.API_MARKER_ATTR_ID, IApiMarkerConstants.MARKER_ATTR_HANDLE_ID }, new Object[] { new Integer(markerid), fCompilationUnit.getHandleIdentifier() }, linenumber, charstart, charend, IApiProblem.CATEGORY_USAGE, element, kind, IApiProblem.NO_FLAGS); addProblem(problem); } catch (JavaModelException e) { } }
From source file:org.eclipse.pde.api.tools.ui.internal.markers.RemoveUnsupportedTagOperation.java
License:Open Source License
@Override public IStatus runInUIThread(IProgressMonitor monitor) { SubMonitor localMonitor = SubMonitor.convert(monitor, MarkerMessages.RemoveUnsupportedTagOperation_removeing_unsupported_tag, this.markers.length + 6); HashMap<ICompilationUnit, Boolean> seen = new HashMap<ICompilationUnit, Boolean>(); for (int i = 0; i < this.markers.length; i++) { // retrieve the AST node compilation unit IResource resource = this.markers[i].getResource(); IJavaElement javaElement = JavaCore.create(resource); try {/*from w w w. j av a2 s . c o m*/ if (javaElement != null && javaElement.getElementType() == IJavaElement.COMPILATION_UNIT) { ICompilationUnit compilationUnit = (ICompilationUnit) javaElement; if (!seen.containsKey(compilationUnit)) { seen.put(compilationUnit, Boolean.valueOf(compilationUnit.hasUnsavedChanges())); } if (!compilationUnit.isWorkingCopy()) { // open an editor of the corresponding unit to "show" // the quick-fix change JavaUI.openInEditor(compilationUnit); } if (!compilationUnit.isConsistent()) { compilationUnit.reconcile(ICompilationUnit.NO_AST, false, null, null); Util.updateMonitor(localMonitor, 1); } Util.updateMonitor(localMonitor, 1); ASTParser parser = ASTParser.newParser(AST.JLS8); parser.setSource(compilationUnit); Integer charStartAttribute = null; charStartAttribute = (Integer) this.markers[i].getAttribute(IMarker.CHAR_START); int intValue = charStartAttribute.intValue(); parser.setFocalPosition(intValue); Map<String, String> options = compilationUnit.getJavaProject().getOptions(true); options.put(JavaCore.COMPILER_DOC_COMMENT_SUPPORT, JavaCore.ENABLED); parser.setCompilerOptions(options); final CompilationUnit unit = (CompilationUnit) parser.createAST(new NullProgressMonitor()); NodeFinder finder = new NodeFinder(intValue); unit.accept(finder); Util.updateMonitor(localMonitor, 1); BodyDeclaration node = finder.getNode(); if (node != null) { unit.recordModifications(); AST ast = unit.getAST(); ASTRewrite rewrite = ASTRewrite.create(ast); Javadoc docnode = node.getJavadoc(); if (docnode == null) { return Status.CANCEL_STATUS; } else { List<TagElement> tags = docnode.tags(); String arg = (String) this.markers[i] .getAttribute(IApiMarkerConstants.MARKER_ATTR_MESSAGE_ARGUMENTS); String[] args = arg.split("#"); //$NON-NLS-1$ TagElement tag = null; for (Iterator<TagElement> iterator = tags.iterator(); iterator.hasNext();) { tag = iterator.next(); if (args[0].equals(tag.getTagName()) && tag.getStartPosition() == intValue) { break; } } if (tag == null) { return Status.CANCEL_STATUS; } ListRewrite lrewrite = rewrite.getListRewrite(docnode, Javadoc.TAGS_PROPERTY); lrewrite.remove(tag, null); Util.updateMonitor(localMonitor, 1); } TextEdit edit = rewrite.rewriteAST(); compilationUnit.applyTextEdit(edit, monitor); Util.updateMonitor(localMonitor, 1); } } } catch (JavaModelException jme) { } catch (PartInitException e) { } catch (CoreException e) { } } // try saving the compilation units if they were in a saved state when // the quick-fix started for (Entry<ICompilationUnit, Boolean> entry : seen.entrySet()) { if (!entry.getValue().booleanValue()) { try { entry.getKey().commitWorkingCopy(true, null); } catch (JavaModelException jme) { } } } return Status.OK_STATUS; }
From source file:org.eclipse.xtext.xbase.ui.hover.XbaseHoverDocumentationProvider.java
License:Open Source License
protected void handleInlineTagElement(TagElement node) { String name = node.getTagName(); if (TagElement.TAG_VALUE.equals(name) && handleValueTag(node)) return;//w w w . j av a2s . c o m boolean isLink = TagElement.TAG_LINK.equals(name); boolean isLinkplain = TagElement.TAG_LINKPLAIN.equals(name); boolean isCode = TagElement.TAG_CODE.equals(name); boolean isLiteral = TagElement.TAG_LITERAL.equals(name); if (isLiteral || isCode) fLiteralContent++; if (isLink || isCode) buffer.append("<code>"); //$NON-NLS-1$ if (isLink || isLinkplain) handleLink(node.fragments()); else if (isCode || isLiteral) { @SuppressWarnings("unchecked") List<ASTNode> fragments = node.fragments(); handleContentElements(fragments, true); } else if (handleInheritDoc(node)) { // handled } else if (handleDocRoot(node)) { // handled } else { //print uninterpreted source {@tagname ...} for unknown tags int start = node.getStartPosition(); String text = rawJavaDoc.substring(start, start + node.getLength()); buffer.append(removeDocLineIntros(text)); } if (isLink || isCode) buffer.append("</code>"); //$NON-NLS-1$ if (isLiteral || isCode) fLiteralContent--; }
From source file:org.juniversal.translator.csharp.JavadocCommentWriter.java
License:Open Source License
@Override public void write(Javadoc javadoc) { int previousAdditionalIndentation = getTargetWriter() .setAdditionalIndentation(getTargetWriter().getCurrColumn()); boolean wroteSummary = false; for (Object tagObj : javadoc.tags()) { TagElement tag = (TagElement) tagObj; String tagName = tag.getTagName(); int position = tag.getStartPosition(); int lineNumber = getSourceFileWriter().getSourceLineNumber(position); //String prefix = tagCount++ == 0 ? "/// " : "\n/// "; if (tagName == null) { if (!wroteSummary) { writeSummaryTag(lineNumber, tag); wroteSummary = true;/*from w ww. ja va 2 s . com*/ } else writeRemarksTag(lineNumber, tag); } else { switch (tagName) { case "@param": writeParamTag(lineNumber, tag); break; case "@returns": writeReturnsTag(lineNumber, tag); break; case "@since": writeSinceTag(lineNumber, tag); break; case "@author": writeAuthorTag(lineNumber, tag); break; default: writeRemarksTag(lineNumber, tag); break; } } } getTargetWriter().setAdditionalIndentation(previousAdditionalIndentation); setPositionToEndOfNode(javadoc); }