Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Javadoc formatting issues #31

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
Manifest-Version: 1.0
Bundle-SymbolicName: OldJavaFormatter;singleton:=true
Bundle-Name: OldJavaFormatter
Bundle-Version: 1.12.0
Require-Bundle: org.eclipse.jdt.core;bundle-version="[3.27.0,4.0.0)",
org.eclipse.jface.text;bundle-version="[3.18.100,4.0.0)",
org.eclipse.core.runtime;bundle-version="[3.23.0,4.0.0)"
Bundle-Version: 2024.06.0
Require-Bundle: org.eclipse.jdt.core;bundle-version="[3.36.0,4.0.0)",
org.eclipse.jface.text;bundle-version="[3.24.200,4.0.0)",
org.eclipse.core.runtime;bundle-version="[3.30.0,4.0.0)"
Bundle-ManifestVersion: 2
Bundle-RequiredExecutionEnvironment: JavaSE-1.8,
JavaSE-11
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,8 +368,10 @@ public boolean visit(StringLiteralConcatenation stringLiteral, BlockScope scope)
if (((stringLiteral.bits & ASTNode.ParenthesizedMASK) >> ASTNode.ParenthesizedSHIFT) != 0) {
addRealFragment(stringLiteral);
} else {
for (int i = 0, max = stringLiteral.counter; i < max; i++) {
addRealFragment(stringLiteral.literals[i]);
StringLiteral[] literals;
literals= stringLiteral.getLiterals();
for (int i = 0, max = literals.length; i < max; i++) {
addRealFragment(literals[i]);
if (i < max - 1) {
this.operatorsList.add(Integer.valueOf(TerminalTokens.TokenNamePLUS));
}
Expand Down
4 changes: 2 additions & 2 deletions src/org/eclipse/jdt/luna/formatter/CodeFormatterVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -5404,8 +5404,8 @@ public boolean visit(StringLiteralConcatenation stringLiteral, BlockScope scope)
}

this.scribe.printComment(Scribe.PRESERVE_EMPTY_LINES_IN_STRING_LITERAL_CONCATENATION);
ASTNode[] fragments = stringLiteral.literals;
int fragmentsSize = stringLiteral.counter;
ASTNode[] fragments = stringLiteral.getLiterals();
int fragmentsSize = fragments.length;

final LegacyBinaryOperatorFormatOption binopt = this.legacy.getFormatOptionForStringConcat();

Expand Down
40 changes: 34 additions & 6 deletions src/org/eclipse/jdt/luna/formatter/FormatterCommentParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

import org.eclipse.jdt.core.compiler.CharOperation;
import org.eclipse.jdt.core.compiler.InvalidInputException;
import org.eclipse.jdt.internal.compiler.ast.JavadocQualifiedTypeReference;
import org.eclipse.jdt.internal.compiler.ast.JavadocSingleTypeReference;
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
import org.eclipse.jdt.internal.compiler.parser.JavadocParser;
import org.eclipse.jdt.internal.compiler.parser.ScannerHelper;
Expand Down Expand Up @@ -60,14 +62,31 @@ public boolean parse(int start, int end) {
* @see org.eclipse.jdt.internal.compiler.parser.JavadocParser#createArgumentReference(char[], int, boolean, java.lang.Object, long[], long)
*/
protected Object createArgumentReference(char[] name, int dim, boolean isVarargs, Object ref, long[] dimPositions, long argNamePos) throws InvalidInputException {
FormatJavadocReference typeRef = (FormatJavadocReference) ref;
FormatJavadocReference typeRef = toFormatJavadocReference(ref);
if (dim > 0) {
typeRef.sourceEnd = (int) dimPositions[dim-1];
}
if (argNamePos >= 0) typeRef.sourceEnd = (int) argNamePos;
return ref;
}

private FormatJavadocReference toFormatJavadocReference(Object ref)
{
FormatJavadocReference typeRef;
if(ref instanceof JavadocSingleTypeReference) {
JavadocSingleTypeReference j;
j = (JavadocSingleTypeReference)ref;
typeRef = new FormatJavadocReference(j.sourceStart, j.sourceEnd, this.scanner.getLineNumber(this.tagSourceStart));
}
else if(ref instanceof JavadocQualifiedTypeReference) {
JavadocQualifiedTypeReference j;
j = (JavadocQualifiedTypeReference)ref;
typeRef = new FormatJavadocReference(j.sourceStart, j.sourceEnd, this.scanner.getLineNumber(this.tagSourceStart));
}
else { typeRef = (FormatJavadocReference) ref;}
return typeRef;
}

/* (non-Javadoc)
* @see org.eclipse.jdt.internal.compiler.parser.AbstractCommentParser#createFakeReference(int)
*/
Expand All @@ -84,16 +103,25 @@ protected boolean createFakeReference(int start) {
* @see org.eclipse.jdt.internal.compiler.parser.JavadocParser#createFieldReference(java.lang.Object)
*/
protected Object createFieldReference(Object receiver) throws InvalidInputException {
int start = receiver == null ? this.memberStart : ((FormatJavadocReference)receiver).sourceStart;
int start = receiver == null ? this.memberStart : getSourceStart(receiver);
int lineStart = this.scanner.getLineNumber(start);
return new FormatJavadocReference(start, (int) this.identifierPositionStack[0], lineStart);
}

private int getSourceStart(Object receiver) {
if(receiver instanceof JavadocQualifiedTypeReference)
return ((JavadocQualifiedTypeReference)receiver).sourceStart;
else if(receiver instanceof JavadocSingleTypeReference) {
return ((JavadocSingleTypeReference)receiver).sourceStart;
}
return -1;
}

/* (non-Javadoc)
* @see org.eclipse.jdt.internal.compiler.parser.JavadocParser#createMethodReference(java.lang.Object, java.util.List)
*/
protected Object createMethodReference(Object receiver, @SuppressWarnings("rawtypes") List arguments) throws InvalidInputException {
int start = receiver == null ? this.memberStart : ((FormatJavadocReference) receiver).sourceStart;
int start = receiver == null ? this.memberStart : getSourceStart(receiver);
int lineStart = this.scanner.getLineNumber(start);
return new FormatJavadocReference(start, this.scanner.getCurrentTokenEndPosition(), lineStart);
}
Expand Down Expand Up @@ -649,8 +677,8 @@ protected boolean pushParamName(boolean isTypeParam) {
* @see org.eclipse.jdt.internal.compiler.parser.JavadocParser#pushSeeRef(java.lang.Object)
*/
protected boolean pushSeeRef(Object statement) {
FormatJavadocReference reference = (FormatJavadocReference) statement;
int lineTagStart = this.scanner.getLineNumber(this.tagSourceStart);
FormatJavadocReference reference = toFormatJavadocReference(statement);
int lineTagStart = this.scanner.getLineNumber(this.tagSourceStart);
FormatJavadocBlock block = new FormatJavadocBlock(this.tagSourceStart, this.tagSourceEnd, lineTagStart, this.tagValue);
block.reference = reference;
block.sourceEnd = reference.sourceEnd;
Expand Down Expand Up @@ -730,7 +758,7 @@ private void pushText(int start, int end, int htmlIndex, int htmlDepth) {
protected boolean pushThrowName(Object typeRef) {
int lineStart = this.scanner.getLineNumber(this.tagSourceStart);
FormatJavadocBlock block = new FormatJavadocBlock(this.tagSourceStart, this.tagSourceEnd, lineStart, this.tagValue);
block.reference = (FormatJavadocReference) typeRef;
block.reference = toFormatJavadocReference(typeRef);
block.sourceEnd = block.reference.sourceEnd;
pushOnAstStack(block, true);
return true;
Expand Down