Bug 553154 - [14] Records - DOM AST Support
Change-Id: I500593046929f480d2b4bf8338a4ab9593268217
diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTConverter.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTConverter.java
index 083bbeb..24fa499 100644
--- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTConverter.java
+++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTConverter.java
@@ -252,14 +252,10 @@
int nextDeclarationType = -1;
if (fieldsIndex < fieldsLength) {
nextFieldDeclaration = fields[fieldsIndex];
- if (!nextFieldDeclaration.isARecordComponent) {
- if (nextFieldDeclaration.declarationSourceStart < position) {
+ if (nextFieldDeclaration.declarationSourceStart < position) {
position = nextFieldDeclaration.declarationSourceStart;
nextDeclarationType = 0; // FIELD
- }
- } else {
- fieldsIndex++;
- }
+ }
}
if (methodsIndex < methodsLength) {
@@ -609,15 +605,18 @@
setModifiers(methodDecl, methodDeclaration);
boolean isConstructor = methodDeclaration.isConstructor();
methodDecl.setConstructor(isConstructor);
- if (DOMASTUtil.isRecordDeclarationSupported(this.ast)) {
- methodDecl.setCompactConstructor(methodDeclaration instanceof CompactConstructorDeclaration);
- }
final SimpleName methodName = new SimpleName(this.ast);
methodName.internalSetIdentifier(new String(methodDeclaration.selector));
int start = methodDeclaration.sourceStart;
- int end = retrieveIdentifierEndPosition(start, methodDeclaration.sourceEnd);
- if (end < start)
- end = start + methodDeclaration.selector.length;// naive recovery with method name
+ int end;
+ if (DOMASTUtil.isRecordDeclarationSupported(this.ast) && methodDeclaration instanceof CompactConstructorDeclaration) {
+ methodDecl.setCompactConstructor(true);
+ end = start + methodDeclaration.selector.length -1;
+ }else {
+ end = retrieveIdentifierEndPosition(start, methodDeclaration.sourceEnd);
+ if (end < start)
+ end = start + methodDeclaration.selector.length;// naive recovery with method name
+ }
methodName.setSourceRange(start, end - start + 1);
methodDecl.setName(methodName);
org.eclipse.jdt.internal.compiler.ast.TypeReference[] thrownExceptions = methodDeclaration.thrownExceptions;
@@ -3523,8 +3522,9 @@
recordNodes(variableDeclarationFragment, fieldDecl);
variableDeclarationFragment.resolveBinding();
}
- if (!fieldDecl.isARecordComponent)
- fieldDeclaration.setSourceRange(fieldDecl.declarationSourceStart, fieldDecl.declarationEnd - fieldDecl.declarationSourceStart + 1);
+ if (!fieldDecl.isARecordComponent) {
+ fieldDeclaration.setSourceRange(fieldDecl.declarationSourceStart, fieldDecl.declarationEnd - fieldDecl.declarationSourceStart + 1);
+ }
Type type = convertType(fieldDecl.type);
setTypeForField(fieldDeclaration, type, variableDeclarationFragment.getExtraDimensions());
setModifiers(fieldDeclaration, fieldDecl);
diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/NaiveASTFlattener.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/NaiveASTFlattener.java
index ccecdfb..9100aed 100644
--- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/NaiveASTFlattener.java
+++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/NaiveASTFlattener.java
@@ -22,6 +22,7 @@
import org.eclipse.jdt.core.dom.*;
import org.eclipse.jdt.internal.compiler.parser.ScannerHelper;
+import org.eclipse.jdt.internal.core.dom.util.DOMASTUtil;
/**
* Internal AST visitor for serializing an AST in a quick and dirty fashion.
@@ -973,7 +974,7 @@
this.buffer.append(">");//$NON-NLS-1$
}
}
- if (!node.isConstructor()) {
+ if (!node.isConstructor()){
if (node.getAST().apiLevel() == JLS2) {
getReturnType(node).accept(this);
} else {
@@ -987,31 +988,33 @@
this.buffer.append(" ");//$NON-NLS-1$
}
node.getName().accept(this);
- this.buffer.append("(");//$NON-NLS-1$
- if (node.getAST().apiLevel() >= JLS8) {
- Type receiverType = node.getReceiverType();
- if (receiverType != null) {
- receiverType.accept(this);
- this.buffer.append(' ');
- SimpleName qualifier = node.getReceiverQualifier();
- if (qualifier != null) {
- qualifier.accept(this);
- this.buffer.append('.');
- }
- this.buffer.append("this"); //$NON-NLS-1$
- if (node.parameters().size() > 0) {
- this.buffer.append(',');
+ if (!(DOMASTUtil.isRecordDeclarationSupported(node.getAST()) && node.isCompactConstructor())) {
+ this.buffer.append("(");//$NON-NLS-1$
+ if (node.getAST().apiLevel() >= JLS8) {
+ Type receiverType = node.getReceiverType();
+ if (receiverType != null) {
+ receiverType.accept(this);
+ this.buffer.append(' ');
+ SimpleName qualifier = node.getReceiverQualifier();
+ if (qualifier != null) {
+ qualifier.accept(this);
+ this.buffer.append('.');
+ }
+ this.buffer.append("this"); //$NON-NLS-1$
+ if (node.parameters().size() > 0) {
+ this.buffer.append(',');
+ }
}
}
- }
- for (Iterator it = node.parameters().iterator(); it.hasNext(); ) {
- SingleVariableDeclaration v = (SingleVariableDeclaration) it.next();
- v.accept(this);
- if (it.hasNext()) {
- this.buffer.append(",");//$NON-NLS-1$
+ for (Iterator it = node.parameters().iterator(); it.hasNext(); ) {
+ SingleVariableDeclaration v = (SingleVariableDeclaration) it.next();
+ v.accept(this);
+ if (it.hasNext()) {
+ this.buffer.append(",");//$NON-NLS-1$
+ }
}
+ this.buffer.append(")");//$NON-NLS-1$
}
- this.buffer.append(")");//$NON-NLS-1$
int size = node.getExtraDimensions();
if (node.getAST().apiLevel() >= JLS8) {
List dimensions = node.extraDimensions();
diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/rewrite/ASTRewriteFlattener.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/rewrite/ASTRewriteFlattener.java
index 028a889..8c9ba56 100644
--- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/rewrite/ASTRewriteFlattener.java
+++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/internal/core/dom/rewrite/ASTRewriteFlattener.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2019 IBM Corporation and others.
+ * Copyright (c) 2000, 2020 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -22,6 +22,7 @@
import org.eclipse.jdt.core.dom.*;
import org.eclipse.jdt.internal.compiler.util.Util;
+import org.eclipse.jdt.internal.core.dom.util.DOMASTUtil;
@SuppressWarnings("rawtypes")
public class ASTRewriteFlattener extends ASTVisitor {
@@ -702,27 +703,29 @@
this.result.append(' ');
}
getChildNode(node, MethodDeclaration.NAME_PROPERTY).accept(this);
- this.result.append('(');
- // receiver parameter
- if (node.getAST().apiLevel() >= JLS8_INTERNAL) {
- ASTNode receiverType = getChildNode(node, MethodDeclaration.RECEIVER_TYPE_PROPERTY);
- if (receiverType != null) {
- receiverType.accept(this);
- this.result.append(' ');
- ASTNode qualifier = getChildNode(node, MethodDeclaration.RECEIVER_QUALIFIER_PROPERTY);
- if (qualifier != null) {
- qualifier.accept(this);
- this.result.append('.');
- }
- this.result.append("this"); //$NON-NLS-1$
- if (getChildList(node, MethodDeclaration.PARAMETERS_PROPERTY).size() > 0) {
- this.result.append(',');
+ if (!(DOMASTUtil.isRecordDeclarationSupported(node.getAST()) && getBooleanAttribute(node, MethodDeclaration.COMPACT_CONSTRUCTOR_PROPERTY))) {
+ this.result.append('(');
+ // receiver parameter
+ if (node.getAST().apiLevel() >= JLS8_INTERNAL) {
+ ASTNode receiverType = getChildNode(node, MethodDeclaration.RECEIVER_TYPE_PROPERTY);
+ if (receiverType != null) {
+ receiverType.accept(this);
+ this.result.append(' ');
+ ASTNode qualifier = getChildNode(node, MethodDeclaration.RECEIVER_QUALIFIER_PROPERTY);
+ if (qualifier != null) {
+ qualifier.accept(this);
+ this.result.append('.');
+ }
+ this.result.append("this"); //$NON-NLS-1$
+ if (getChildList(node, MethodDeclaration.PARAMETERS_PROPERTY).size() > 0) {
+ this.result.append(',');
+ }
}
}
+
+ visitList(node, MethodDeclaration.PARAMETERS_PROPERTY, String.valueOf(','));
+ this.result.append(')');
}
-
- visitList(node, MethodDeclaration.PARAMETERS_PROPERTY, String.valueOf(','));
- this.result.append(')');
visitExtraDimensions(node, INTERNAL_METHOD_EXTRA_DIMENSIONS_PROPERTY, MethodDeclaration.EXTRA_DIMENSIONS2_PROPERTY);
ChildListPropertyDescriptor exceptionsProperty = node.getAST().apiLevel() < JLS8_INTERNAL ?