Skip to content

Commit

Permalink
[23] Partition support for markdown comments #1542
Browse files Browse the repository at this point in the history
  • Loading branch information
jarthana committed Jul 26, 2024
1 parent 52e334a commit c659493
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 16 deletions.
8 changes: 8 additions & 0 deletions org.eclipse.jdt.core.manipulation/.settings/.api_filters
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,12 @@
</message_arguments>
</filter>
</resource>
<resource path="proposals/org/eclipse/jdt/ui/text/IJavaPartitions.java" type="org.eclipse.jdt.ui.text.IJavaPartitions">
<filter id="403767336">
<message_arguments>
<message_argument value="org.eclipse.jdt.ui.text.IJavaPartitions"/>
<message_argument value="JAVA_MARKDOWN_COMMENT"/>
</message_arguments>
</filter>
</resource>
</component>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2023 IBM Corporation and others.
* Copyright (c) 2023, 2024 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand All @@ -8,6 +8,10 @@
*
* SPDX-License-Identifier: EPL-2.0
*
* This is an implementation of an early-draft specification developed under the Java
* Community Process (JCP) and is made available for testing and evaluation purposes
* only. The code is not compatible with any specification of the JCP.
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
Expand Down Expand Up @@ -45,15 +49,18 @@ public abstract class AbstractFastJavaPartitionScanner implements IPartitionToke
private static final int CHARACTER= 4;
private static final int STRING= 5;
private static final int MULTI_LINE_STRING= 6;
private static final int MARKDOWN_COMMENT = 7;

// beginning of prefixes and postfixes
private static final int NONE= 0;
private static final int BACKSLASH= 1; // postfix for STRING and CHARACTER
private static final int SLASH= 2; // prefix for SINGLE_LINE or MULTI_LINE or JAVADOC
private static final int SLASH_STAR= 3; // prefix for MULTI_LINE_COMMENT or JAVADOC
private static final int SLASH_STAR_STAR= 4; // prefix for MULTI_LINE_COMMENT or JAVADOC
private static final int STAR= 5; // postfix for MULTI_LINE_COMMENT or JAVADOC
private static final int CARRIAGE_RETURN=6; // postfix for STRING, CHARACTER and SINGLE_LINE_COMMENT
private static final int SLASH_SLASH = 3; // prefix for MARKDOWN
private static final int SLASH_STAR= 4; // prefix for MULTI_LINE_COMMENT or JAVADOC
private static final int SLASH_STAR_STAR= 5; // prefix for MULTI_LINE_COMMENT or JAVADOC
private static final int SLASH_SLASH_SLASH= 6; // prefix for MULTI_LINE_COMMENT or JAVADOC
private static final int STAR= 7; // postfix for MULTI_LINE_COMMENT or JAVADOC
private static final int CARRIAGE_RETURN=8; // postfix for STRING, CHARACTER and SINGLE_LINE_COMMENT
private static final int TRIPLE_QUOTE= 9; // prefix for TextBlock.

/** The scanner. */
Expand Down Expand Up @@ -87,7 +94,8 @@ public abstract class AbstractFastJavaPartitionScanner implements IPartitionToke
new Token(JAVA_DOC),
new Token(JAVA_CHARACTER),
new Token(JAVA_STRING),
new Token(JAVA_MULTI_LINE_STRING)
new Token(JAVA_MULTI_LINE_STRING),
new Token(JAVA_MARKDOWN_COMMENT)
};

public AbstractFastJavaPartitionScanner(boolean emulate) {
Expand Down Expand Up @@ -149,6 +157,7 @@ public IToken nextToken() {
} else {

switch (fState) {
case MARKDOWN_COMMENT:
case SINGLE_LINE_COMMENT:
case CHARACTER:
case STRING:
Expand Down Expand Up @@ -181,6 +190,7 @@ public IToken nextToken() {

case '\n':
switch (fState) {
case MARKDOWN_COMMENT:
case SINGLE_LINE_COMMENT:
case CHARACTER:
case STRING:
Expand Down Expand Up @@ -254,9 +264,9 @@ public IToken nextToken() {
case '/':
if (fLast == SLASH) {
if (fTokenLength - getLastLength(fLast) > 0) {
return preFix(JAVA, SINGLE_LINE_COMMENT, NONE, 2);
return preFix(JAVA, SINGLE_LINE_COMMENT, SLASH_SLASH, 2);
} else {
preFix(JAVA, SINGLE_LINE_COMMENT, NONE, 2);
preFix(JAVA, SINGLE_LINE_COMMENT, SLASH_SLASH, 2);
fTokenOffset += fTokenLength;
fTokenLength= fPrefixLength;
break;
Expand Down Expand Up @@ -326,9 +336,36 @@ public IToken nextToken() {
break;

case SINGLE_LINE_COMMENT:
consume();
switch (ch) {
case '/':
if (fLast == SLASH_SLASH) {
fLast= SLASH_SLASH_SLASH;
fTokenLength++;
fState= MARKDOWN_COMMENT;
} else {
fTokenLength++;
fLast= SLASH;
}
break;
default:
consume();
break;
}
break;
case MARKDOWN_COMMENT:
switch (ch) {
case '\r':
case '\n':
return postFix(MARKDOWN_COMMENT);
case '/':
fTokenLength++;
fLast= SLASH_SLASH_SLASH;
break;
default:
consume();
break;
}
break;

case JAVADOC:
switch (ch) {
case '/':
Expand Down Expand Up @@ -632,10 +669,10 @@ private static final int getLastLength(int last) {
case SLASH:
case STAR:
return 1;

case SLASH_SLASH:
case SLASH_STAR:
return 2;

case SLASH_SLASH_SLASH:
case SLASH_STAR_STAR:
case TRIPLE_QUOTE:
return 3;
Expand Down Expand Up @@ -695,6 +732,8 @@ private static int getState(String contentType) {
return CHARACTER;
case JAVA_MULTI_LINE_STRING:
return MULTI_LINE_STRING;
case JAVA_MARKDOWN_COMMENT:
return MARKDOWN_COMMENT;
default:
return JAVA;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2019 IBM Corporation and others.
* Copyright (c) 2000, 2024 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand All @@ -8,6 +8,10 @@
*
* SPDX-License-Identifier: EPL-2.0
*
* This is an implementation of an early-draft specification developed under the Java
* Community Process (JCP) and is made available for testing and evaluation purposes
* only. The code is not compatible with any specification of the JCP.
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
Expand Down Expand Up @@ -57,4 +61,8 @@ public interface IJavaPartitions {
* @since 3.20
*/
String JAVA_MULTI_LINE_STRING= "__java_multiline_string"; //$NON-NLS-1$
/**
* @since 1.21
*/
String JAVA_MARKDOWN_COMMENT = "__java_markdown_comment"; //$NON-NLS-1$
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2019 IBM Corporation and others.
* Copyright (c) 2019, 2024 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand All @@ -8,6 +8,10 @@
*
* SPDX-License-Identifier: EPL-2.0
*
* This is an implementation of an early-draft specification developed under the Java
* Community Process (JCP) and is made available for testing and evaluation purposes
* only. The code is not compatible with any specification of the JCP.
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
Expand All @@ -31,7 +35,8 @@ public class JavaPartitionerManager implements IJavaPartitionerManager {
IJavaPartitions.JAVA_SINGLE_LINE_COMMENT,
IJavaPartitions.JAVA_STRING,
IJavaPartitions.JAVA_CHARACTER,
IJavaPartitions.JAVA_MULTI_LINE_STRING
IJavaPartitions.JAVA_MULTI_LINE_STRING,
IJavaPartitions.JAVA_MARKDOWN_COMMENT
};

private static ITextEditor fEditor;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2019 IBM Corporation and others.
* Copyright (c) 2000, 2024 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand All @@ -8,6 +8,10 @@
*
* SPDX-License-Identifier: EPL-2.0
*
* This is an implementation of an early-draft specification developed under the Java
* Community Process (JCP) and is made available for testing and evaluation purposes
* only. The code is not compatible with any specification of the JCP.
*
* Contributors:
* IBM Corporation - initial API and implementation
* Tom Eicher (Avaloq Evolution AG) - block selection mode
Expand Down Expand Up @@ -457,6 +461,9 @@ public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) {
ContentAssistProcessor javadocProcessor= new JavadocCompletionProcessor(getEditor(), assistant);
assistant.setContentAssistProcessor(javadocProcessor, IJavaPartitions.JAVA_DOC);

ContentAssistProcessor markdownProcessor= new JavadocCompletionProcessor(getEditor(), assistant);

Check warning on line 464 in org.eclipse.jdt.ui/ui/org/eclipse/jdt/ui/text/JavaSourceViewerConfiguration.java

View check run for this annotation

Jenkins - Eclipse JDT / Compiler and API Tools

Unnecessary Code

NORMAL: The value of the local variable markdownProcessor is not used
assistant.setContentAssistProcessor(javadocProcessor, IJavaPartitions.JAVA_MARKDOWN_COMMENT);

ContentAssistProcessor multiLineStringProcessor= new JavaCompletionProcessor(getEditor(), assistant, IJavaPartitions.JAVA_MULTI_LINE_STRING);
assistant.setContentAssistProcessor(multiLineStringProcessor, IJavaPartitions.JAVA_MULTI_LINE_STRING);

Expand Down

0 comments on commit c659493

Please sign in to comment.