Skip to content

Commit

Permalink
[19] Update ASTFlattener
Browse files Browse the repository at this point in the history
Fixes #265
  • Loading branch information
noopur2507 committed Sep 15, 2022
1 parent b2e9961 commit 80ce98a
Show file tree
Hide file tree
Showing 3 changed files with 131 additions and 11 deletions.
21 changes: 21 additions & 0 deletions org.eclipse.jdt.core.manipulation/.settings/.api_filters
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,27 @@
<message_argument value="getPattern()"/>
</message_arguments>
</filter>
<filter id="640712815">
<message_arguments>
<message_argument value="RecordPattern"/>
<message_argument value="ASTFlattener"/>
<message_argument value="getPatternName()"/>
</message_arguments>
</filter>
<filter id="640712815">
<message_arguments>
<message_argument value="RecordPattern"/>
<message_argument value="ASTFlattener"/>
<message_argument value="getPatternType()"/>
</message_arguments>
</filter>
<filter id="640712815">
<message_arguments>
<message_argument value="RecordPattern"/>
<message_argument value="ASTFlattener"/>
<message_argument value="patterns()"/>
</message_arguments>
</filter>
<filter comment="Java preview feature API" id="640712815">
<message_arguments>
<message_argument value="TypePattern"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ private static boolean isNodeTypeSupportedInAST(AST ast, int nodeType) {
case ASTNode.RECORD_DECLARATION:
case ASTNode.INSTANCEOF_EXPRESSION:
return ast.apiLevel() >= JLS16;
case ASTNode.TAG_PROPERTY:
return ast.apiLevel() >= AST.JLS18;
case ASTNode.TYPE_PATTERN:
case ASTNode.RECORD_PATTERN:
return ast.isPreviewEnabled();
default:
break;
Expand Down Expand Up @@ -102,4 +105,11 @@ public static boolean isPatternSupported(AST ast) {
return isNodeTypeSupportedInAST(ast, ASTNode.TYPE_PATTERN);
}

public static boolean isRecordPatternSupported(AST ast) {
return isNodeTypeSupportedInAST(ast, ASTNode.RECORD_PATTERN);
}

public static boolean isJavaDocCodeSnippetSupported(AST ast) {
return isNodeTypeSupportedInAST(ast, ASTNode.TAG_PROPERTY);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2000, 2021 IBM Corporation and others.
* Copyright (c) 2000, 2022 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 @@ -739,7 +743,7 @@ public boolean visit(ForStatement node) {
public boolean visit(GuardedPattern node) {
if (ASTHelper.isPatternSupported(node.getAST())) {
node.getPattern().accept(this);
this.fBuffer.append(" && ");//$NON-NLS-1$
this.fBuffer.append(" when ");//$NON-NLS-1$
node.getExpression().accept(this);
}
return false;
Expand Down Expand Up @@ -864,6 +868,17 @@ public boolean visit(Javadoc node) {
return false;
}

@Override
public boolean visit(JavaDocRegion node) {
return false;
}

@Override
public boolean visit(JavaDocTextElement node) {
this.fBuffer.append(node.getText());
return false;
}

/*
* @see ASTVisitor#visit(LabeledStatement)
*/
Expand Down Expand Up @@ -1310,6 +1325,17 @@ public boolean visit(ProvidesDirective node) {
return false;
}

@Override
public boolean visit(ModuleQualifiedName node) {
node.getModuleQualifier().accept(this);
this.fBuffer.append("/");//$NON-NLS-1$
ASTNode cNode = node.getName();
if (cNode != null) {
cNode.accept(this);
}
return false;
}

/*
* @see ASTVisitor#visit(QualifiedName)
*/
Expand Down Expand Up @@ -1389,6 +1415,52 @@ public boolean visit(RecordDeclaration node) {
return false;
}

@Override
public boolean visit(RecordPattern node) {
if (ASTHelper.isRecordPatternSupported(node.getAST())) {

if (node.getPatternType() != null) {
node.getPatternType().accept(this);
}
boolean addBraces = node.patterns().size() >= 1;
if (addBraces) {
this.fBuffer.append("(");//$NON-NLS-1$
}
int size = 1;
for (Pattern pattern : node.patterns()) {
visitPattern(pattern);
if (addBraces && size < node.patterns().size()) {
this.fBuffer.append(", ");//$NON-NLS-1$
}
size++;
}
if (addBraces) {
this.fBuffer.append(")");//$NON-NLS-1$
}
if (node.getPatternName() != null) {
this.fBuffer.append(" ");//$NON-NLS-1$
node.getPatternName().accept(this);
}
}
return false;
}

private boolean visitPattern(Pattern node) {
if (!ASTHelper.isPatternSupported(node.getAST())) {
return false;
}
if (node instanceof RecordPattern) {
return visit((RecordPattern) node);
}
if (node instanceof GuardedPattern) {
return visit((GuardedPattern) node);
}
if (node instanceof TypePattern) {
return visit((TypePattern) node);
}
return false;
}

@Override
public boolean visit(RequiresDirective node) {
this.fBuffer.append("requires");//$NON-NLS-1$
Expand Down Expand Up @@ -1493,15 +1565,6 @@ public boolean visit(StringLiteral node) {
return false;
}

/*
* @see ASTVisitor#visit(StringLiteral)
*/
@Override
public boolean visit(TextBlock node) {
this.fBuffer.append(node.getEscapedValue());
return false;
}

/*
* @see ASTVisitor#visit(SuperConstructorInvocation)
*/
Expand Down Expand Up @@ -1731,12 +1794,38 @@ public boolean visit(TagElement node) {
e.accept(this);
previousRequiresWhiteSpace= !currentIncludesWhiteSpace && !(e instanceof TagElement);
}
if (ASTHelper.isJavaDocCodeSnippetSupported(node.getAST())) {
for (Iterator<TagProperty> it = node.tagProperties().iterator(); it.hasNext(); ) {
TagProperty tagProperty = it.next();
tagProperty.accept(this);
}

}
if (node.isNested()) {
this.fBuffer.append("}");//$NON-NLS-1$
}
return false;
}

@Override
public boolean visit(TagProperty node) {
this.fBuffer.append("\n{"); //$NON-NLS-1$
this.fBuffer.append(node.getName());
this.fBuffer.append(" = "); //$NON-NLS-1$
this.fBuffer.append(node.getStringValue());
node.getNodeValue().accept(this);
this.fBuffer.append("}"); //$NON-NLS-1$
return false;
}



@Override
public boolean visit(TextBlock node) {
this.fBuffer.append(node.getEscapedValue());
return false;
}

/*
* @see ASTVisitor#visit(TextElement)
* @since 3.0
Expand Down

0 comments on commit 80ce98a

Please sign in to comment.