Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSarika Sinha2020-01-07 10:50:42 +0000
committerSarika Sinha2020-01-07 10:52:34 +0000
commit7d5ca4d34c3267a0f49084b31147c12fd0922f53 (patch)
treefcf946f017128028a8bc4ce507411a7ed105cbb6
parentf414f843639cc270822cea65bcf5375caf28464b (diff)
downloadeclipse.jdt.core-7d5ca4d34c3267a0f49084b31147c12fd0922f53.tar.gz
eclipse.jdt.core-7d5ca4d34c3267a0f49084b31147c12fd0922f53.tar.xz
eclipse.jdt.core-7d5ca4d34c3267a0f49084b31147c12fd0922f53.zip
Bug 553154 - [14] Records - DOM AST SupportY20200108-0435
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/AbstractMethodDeclaration.java7
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/MethodDeclaration.java3
-rw-r--r--org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTConverter.java82
3 files changed, 89 insertions, 3 deletions
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/AbstractMethodDeclaration.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/AbstractMethodDeclaration.java
index 0648075a5b..2d41fd440b 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/AbstractMethodDeclaration.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/AbstractMethodDeclaration.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
@@ -76,6 +76,7 @@ public abstract class AbstractMethodDeclaration
public int bodyStart;
public int bodyEnd = -1;
public CompilationResult compilationResult;
+ protected boolean isImplicit; // used in Java 14 Records
AbstractMethodDeclaration(CompilationResult compilationResult){
this.compilationResult = compilationResult;
@@ -464,6 +465,10 @@ public abstract class AbstractMethodDeclaration
return (this.modifiers & ClassFileConstants.AccStatic) != 0;
}
+ public boolean isImplicit() {
+ return this.isImplicit;
+ }
+
/**
* Fill up the method body with statement
* @param parser
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/MethodDeclaration.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/MethodDeclaration.java
index a3d7db6f4b..62abff4d7a 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/MethodDeclaration.java
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/MethodDeclaration.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
@@ -61,7 +61,6 @@ public class MethodDeclaration extends AbstractMethodDeclaration {
public TypeReference returnType;
public TypeParameter[] typeParameters;
- public boolean isImplicit; // used in Java 14 Records
/**
* MethodDeclaration constructor comment.
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 3d9c559fc1..f1b0e529cc 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
@@ -224,6 +224,88 @@ class ASTConverter {
// Convert javadoc
convert(typeDeclaration.javadoc, typeDecl);
}
+
+ protected void buildBodyDeclarations(
+ org.eclipse.jdt.internal.compiler.ast.TypeDeclaration typeDeclaration,
+ RecordDeclaration recordDeclaration,
+ boolean isInterface) {
+ // add body declaration in the lexical order
+ org.eclipse.jdt.internal.compiler.ast.TypeDeclaration[] members = typeDeclaration.memberTypes;
+ org.eclipse.jdt.internal.compiler.ast.FieldDeclaration[] fields = typeDeclaration.fields;
+ org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration[] methods = typeDeclaration.methods;
+
+ int fieldsLength = fields == null? 0 : fields.length;
+ int methodsLength = methods == null? 0 : methods.length;
+ int membersLength = members == null ? 0 : members.length;
+ int fieldsIndex = 0;
+ int methodsIndex = 0;
+ int membersIndex = 0;
+
+ while ((fieldsIndex < fieldsLength)
+ || (membersIndex < membersLength)
+ || (methodsIndex < methodsLength)) {
+ org.eclipse.jdt.internal.compiler.ast.FieldDeclaration nextFieldDeclaration = null;
+ org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration nextMethodDeclaration = null;
+ org.eclipse.jdt.internal.compiler.ast.TypeDeclaration nextMemberDeclaration = null;
+
+ int position = Integer.MAX_VALUE;
+ int nextDeclarationType = -1;
+ if (fieldsIndex < fieldsLength) {
+ nextFieldDeclaration = fields[fieldsIndex];
+ if (!nextFieldDeclaration.isARecordComponent) {
+ if (nextFieldDeclaration.declarationSourceStart < position) {
+ position = nextFieldDeclaration.declarationSourceStart;
+ nextDeclarationType = 0; // FIELD
+ }
+ } else {
+ fieldsIndex++;
+ }
+
+ }
+ if (methodsIndex < methodsLength) {
+ nextMethodDeclaration = methods[methodsIndex];
+ if (!nextMethodDeclaration.isImplicit()) {
+ if (nextMethodDeclaration.declarationSourceStart < position) {
+ position = nextMethodDeclaration.declarationSourceStart;
+ nextDeclarationType = 1; // METHOD
+ }
+
+ } else {
+ methodsIndex++;
+ }
+
+ }
+ if (membersIndex < membersLength) {
+ nextMemberDeclaration = members[membersIndex];
+ if (nextMemberDeclaration.declarationSourceStart < position) {
+ position = nextMemberDeclaration.declarationSourceStart;
+ nextDeclarationType = 2; // MEMBER
+ }
+ }
+ switch (nextDeclarationType) {
+ case 0 :
+ checkAndAddMultipleFieldDeclaration(fields, fieldsIndex, recordDeclaration.bodyDeclarations());
+ fieldsIndex++;
+ break;
+ case 1 :
+ methodsIndex++;
+ if (!nextMethodDeclaration.isDefaultConstructor() && !nextMethodDeclaration.isClinit()) {
+ recordDeclaration.bodyDeclarations().add(convert(isInterface, nextMethodDeclaration));
+ }
+ break;
+ case 2 :
+ membersIndex++;
+ ASTNode node = convert(nextMemberDeclaration);
+ if (node == null) {
+ recordDeclaration.setFlags(recordDeclaration.getFlags() | ASTNode.MALFORMED);
+ } else {
+ recordDeclaration.bodyDeclarations().add(node);
+ }
+ }
+ }
+ // Convert javadoc
+ convert(typeDeclaration.javadoc, recordDeclaration);
+ }
protected void buildBodyDeclarations(org.eclipse.jdt.internal.compiler.ast.TypeDeclaration enumDeclaration2, EnumDeclaration enumDeclaration) {
// add body declaration in the lexical order

Back to the top