Skip to content

Commit

Permalink
Merge pull request #1662 from noopur2507/merge-beta23-to-master
Browse files Browse the repository at this point in the history
Merge remote-tracking branch 'upstream/BETA_JAVA23'
  • Loading branch information
jarthana authored Sep 18, 2024
2 parents a531b37 + d034430 commit fee4f51
Show file tree
Hide file tree
Showing 43 changed files with 1,559 additions and 103 deletions.
2 changes: 1 addition & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pipeline {
sh """
mvn -U -e -DskipTests=false -Dmaven.repo.local=$WORKSPACE/.m2/repository \
clean verify --batch-mode --fail-at-end \
-Pbree-libs -Papi-check -Pjavadoc \
-Pbree-libs -Papi-check -Pjavadoc -Pbuild-individual-bundles \
-Dmaven.test.failure.ignore=true \
-Dcompare-version-with-baselines.skip=false
"""
Expand Down
2 changes: 1 addition & 1 deletion org.eclipse.jdt.astview.feature/feature.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<feature
id="org.eclipse.jdt.astview.feature"
label="Java AST View"
version="1.2.300.qualifier"
version="1.2.350.qualifier"
provider-name="Eclipse.org"
license-feature="org.eclipse.license"
license-feature-version="0.0.0">
Expand Down
2 changes: 1 addition & 1 deletion org.eclipse.jdt.astview/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Automatic-Module-Name: org.eclipse.jdt.astview
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.jdt.astview; singleton:=true
Bundle-Version: 1.6.200.qualifier
Bundle-Version: 1.6.250.qualifier
Bundle-Activator: org.eclipse.jdt.astview.ASTViewPlugin
Bundle-Vendor: %providerName
Bundle-Localization: plugin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@
public class ASTView extends ViewPart implements IShowInSource, IShowInTargetList {

static final int JLS_LATEST= AST.getJLSLatest();
private static final int JLS23= ASTHelper.JLS23;
private static final int JLS22= ASTHelper.JLS22;
private static final int JLS21= ASTHelper.JLS21;
private static final int JLS20= ASTHelper.JLS20;
Expand Down Expand Up @@ -522,6 +523,7 @@ public ASTView() {
case JLS20:
case JLS21:
case JLS22:
case JLS23:
fCurrentASTLevel= level;
}
} catch (NumberFormatException e) {
Expand Down Expand Up @@ -1150,6 +1152,7 @@ public void run() {
new ASTLevelToggle("AST Level 2&0 (20)", JLS20), //$NON-NLS-1$
new ASTLevelToggle("AST Level 2&1 (21)", JLS21), //$NON-NLS-1$
new ASTLevelToggle("AST Level 2&2 (22)", JLS22), //$NON-NLS-1$
new ASTLevelToggle("AST Level 2&3 (23)", JLS23), //$NON-NLS-1$
};

fAddToTrayAction= new Action() {
Expand Down
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>
4 changes: 3 additions & 1 deletion org.eclipse.jdt.core.manipulation/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.31.0,4.0.0)",
org.eclipse.jdt.launching;bundle-version="3.23.0",
org.eclipse.core.filesystem;bundle-version="1.10.0",
org.eclipse.core.filebuffers;bundle-version="3.8.0",
org.eclipse.search.core;bundle-version="3.16.0"
org.eclipse.search.core;bundle-version="3.16.0",
org.commonmark;bundle-version="0.22.0",
org.commonmark-gfm-tables;bundle-version="0.22.0"
Bundle-ActivationPolicy: lazy
Export-Package: org.eclipse.jdt.core.manipulation,
org.eclipse.jdt.core.refactoring,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
/*******************************************************************************
* Copyright (c) 2024 GK Software SE and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Stephan Herrmann - Initial API and implementation
*******************************************************************************/
package org.eclipse.jdt.core.manipulation.internal.javadoc;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.commonmark.Extension;
import org.commonmark.ext.gfm.tables.TablesExtension;
import org.commonmark.node.Document;
import org.commonmark.node.Node;
import org.commonmark.node.Paragraph;
import org.commonmark.parser.Parser;
import org.commonmark.renderer.html.HtmlRenderer;

import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.dom.ASTNode;
import org.eclipse.jdt.core.dom.Javadoc;
import org.eclipse.jdt.core.dom.TagElement;
import org.eclipse.jdt.core.dom.TextElement;

public class CoreMarkdownAccessImpl extends CoreJavadocAccessImpl {

private Parser fParser;
private HtmlRenderer fRenderer;
private int fBlockDepth= 0;

public CoreMarkdownAccessImpl(IJavaElement element, Javadoc javadoc, String source) {
super(element, javadoc, source);
init();
}
public CoreMarkdownAccessImpl(IJavaElement element, Javadoc javadoc, String source, JavadocLookup lookup) {
super(element, javadoc, source, lookup);
init();
}

private void init() {
List<Extension> extensions= List.of(TablesExtension.create());
fParser= Parser.builder().extensions(extensions).build();
fRenderer= HtmlRenderer.builder().extensions(extensions).build();
}

@Override
protected String removeDocLineIntros(String textWithSlashes) {
String lineBreakGroup= "(\\r\\n?|\\n)"; //$NON-NLS-1$
String noBreakSpace= "[^\r\n&&\\s]"; //$NON-NLS-1$
// in the markdown case relevant leading whitespace is contained in TextElements, no need to preserve blanks *between* elements
return textWithSlashes.replaceAll(lineBreakGroup + noBreakSpace + "*///" + noBreakSpace + '*', "$1"); //$NON-NLS-1$ //$NON-NLS-2$
}

@Override
protected void handleLink(List<? extends ASTNode> fragments) {
if (fragments.size() == 2 && fragments.get(0) instanceof TextElement) {
// super method expects the reference as first fragment, optional label as second fragment
fragments= Arrays.asList(fragments.get(1), fragments.get(0));
}
super.handleLink(fragments);
}

@Override
protected String getBlockTagStart() {
this.fBlockDepth++;
return "\n"+super.getBlockTagStart(); //$NON-NLS-1$
}

@Override
protected String getBlockTagEnd() {
if (this.fBlockDepth > 0)
this.fBlockDepth--;
return super.getBlockTagEnd();
}

@Override
protected void handleContentElements(List<? extends ASTNode> nodes, boolean skipLeadingWhitespace, TagElement tagElement) {
int start= fBuf.length();
super.handleContentElements(nodes, skipLeadingWhitespace, tagElement);
if (this.fBlockDepth > 0) {
// inside an HTML block the markdown content must be rendered now
String generated= fBuf.substring(start); // extract new part of fBuf
Node node= fParser.parse(generated);
if (node.getFirstChild() instanceof Paragraph para && para.getNext() == null) {
// inside block replace single paragraph with its children
node= eliminateContainerNode(para);
}
String rendered= fRenderer.render(node);
fBuf.replace(start, fBuf.length(), rendered); // replace new part with its rendered version
}
}

/** Return a new Document containing all children of the given container node. */
protected Node eliminateContainerNode(Node container) {
List<Node> children= new ArrayList<>();
for (Node child= container.getFirstChild(); child != null; child= child.getNext()) {
children.add(child);
}
Document doc= new Document();
for (Node child2 : children) {
doc.appendChild(child2);
}
return doc;
}

@Override
public String toHTML() {
String content= super.toHTML();
Node document= fParser.parse(content);
return fRenderer.render(document);
}
}
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 Down Expand Up @@ -33,6 +33,12 @@ public class JavadocLookup {
public static final IJavadocContentFactory DEFAULT_FACTORY= new IJavadocContentFactory() {
@Override
public IJavadocAccess createJavadocAccess(IJavaElement element, Javadoc javadoc, String source, JavadocLookup lookup) {
if (source.startsWith("///")) { //$NON-NLS-1$
if (lookup == null)
return new CoreMarkdownAccessImpl(element, javadoc, source);
else
return new CoreMarkdownAccessImpl(element, javadoc, source, lookup);
}
if (lookup == null)
return new CoreJavadocAccessImpl(element, javadoc, source);
else
Expand Down
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 Down Expand Up @@ -45,15 +45,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 +90,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 +153,7 @@ public IToken nextToken() {
} else {

switch (fState) {
case MARKDOWN_COMMENT:
case SINGLE_LINE_COMMENT:
case CHARACTER:
case STRING:
Expand Down Expand Up @@ -181,6 +186,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 +260,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 +332,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 +665,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 +728,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
Expand Up @@ -38,6 +38,7 @@ public class ASTHelper {
public static final int JLS20 = AST.JLS20;
public static final int JLS21 = AST.JLS21;
public static final int JLS22 = AST.JLS22;
public static final int JLS23 = AST.JLS23;

private static boolean isNodeTypeSupportedInAST(AST ast, int nodeType) {
switch (nodeType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -727,36 +727,6 @@ public void endVisit(StringLiteral node) {
endVisit((Expression)node);
}

@Override
public boolean visit(StringTemplateExpression node) {
return visit((Expression) node);
}

@Override
public boolean visit(StringTemplateComponent node) {
return visit((Expression) node);
}

@Override
public boolean visit(StringFragment node) {
return visit((Expression) node);
}

@Override
public void endVisit(StringTemplateExpression node) {
endVisit((Expression) node);
}

@Override
public void endVisit(StringTemplateComponent node) {
endVisit((Expression) node);
}

@Override
public void endVisit(StringFragment node) {
endVisit((Expression) node);
}

@Override
public boolean visit(SuperFieldAccess node) {
return visit((Expression)node);
Expand Down
Loading

0 comments on commit fee4f51

Please sign in to comment.