-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce basic DOM models and converter code to avoid errors in editor.
- Loading branch information
Showing
8 changed files
with
559 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
167 changes: 167 additions & 0 deletions
167
org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/StringTemplate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,167 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2023 IBM Corporation 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: | ||
* IBM Corporation - initial API and implementation | ||
*******************************************************************************/ | ||
|
||
package org.eclipse.jdt.core.dom; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.eclipse.jdt.internal.core.dom.util.DOMASTUtil; | ||
|
||
/** | ||
* StringTemplateExpression AST node type. | ||
* | ||
* @since 3.36 | ||
* @noreference This class is not intended to be referenced by clients. | ||
*/ | ||
@SuppressWarnings("rawtypes") | ||
public class StringTemplate extends Expression { | ||
/** | ||
* A list of property descriptors (element type: | ||
* {@link StructuralPropertyDescriptor}), | ||
* or null if uninitialized. | ||
*/ | ||
private static final List PROPERTY_DESCRIPTORS; | ||
/** | ||
* The "patterns" structural property of this node type (child type: {@link Pattern}). | ||
*/ | ||
public static final ChildListPropertyDescriptor STRING_TEMPLATE_FRAGMENTS = | ||
new ChildListPropertyDescriptor(StringTemplate.class, "fragments", Expression.class, CYCLE_RISK); //$NON-NLS-1$ | ||
|
||
/** | ||
* The "patternType" structural property of this node type (child type: {@link Type}). | ||
*/ | ||
public static final ChildListPropertyDescriptor STRING_TEMPLATE_VALUES = | ||
new ChildListPropertyDescriptor(StringTemplate.class, "expressions", Expression.class, CYCLE_RISK); //$NON-NLS-1$ | ||
|
||
static { | ||
List propertyList = new ArrayList(2); | ||
createPropertyList(StringTemplate.class, propertyList); | ||
addProperty(STRING_TEMPLATE_FRAGMENTS, propertyList); | ||
addProperty(STRING_TEMPLATE_VALUES, propertyList); | ||
PROPERTY_DESCRIPTORS = reapPropertyList(propertyList); | ||
} | ||
|
||
/** | ||
*/ | ||
private final ASTNode.NodeList fragments = | ||
new ASTNode.NodeList(STRING_TEMPLATE_FRAGMENTS); | ||
/** | ||
*/ | ||
private final ASTNode.NodeList expressions = | ||
new ASTNode.NodeList(STRING_TEMPLATE_VALUES); | ||
|
||
StringTemplate(AST ast) { | ||
super(ast); | ||
supportedOnlyIn21(); | ||
} | ||
|
||
/** | ||
* Returns a list of structural property descriptors for this node type. | ||
* Clients must not modify the result. | ||
* | ||
* @param apiLevel the API level; one of the | ||
* <code>AST.JLS*</code> constants | ||
* @return a list of property descriptors (element type: | ||
* {@link StructuralPropertyDescriptor}) | ||
* @since 3.24 | ||
*/ | ||
public static List propertyDescriptors(int apiLevel) { | ||
return PROPERTY_DESCRIPTORS; | ||
} | ||
public static List propertyDescriptors(int apiLevel, boolean previewEnabled) { | ||
if (DOMASTUtil.isStringTemplateSupported(apiLevel, previewEnabled)) { | ||
return PROPERTY_DESCRIPTORS; | ||
} | ||
return null; | ||
} | ||
@Override | ||
final List internalStructuralPropertiesForType(int apiLevel) { | ||
return propertyDescriptors(apiLevel); | ||
} | ||
|
||
@Override | ||
final List internalStructuralPropertiesForType(int apiLevel, boolean previewEnabled) { | ||
return propertyDescriptors(apiLevel, previewEnabled); | ||
} | ||
/** | ||
* @noreference This method is not intended to be referenced by clients as it is a part of Java preview feature. | ||
*/ | ||
@SuppressWarnings("unchecked") | ||
public List<Expression> fragments() { | ||
supportedOnlyIn21(); | ||
return this.fragments; | ||
} | ||
@SuppressWarnings("unchecked") | ||
public List<Expression> expressions() { | ||
supportedOnlyIn21(); | ||
return this.expressions; | ||
} | ||
@Override | ||
int getNodeType0() { | ||
return STRING_TEMPLATE; | ||
} | ||
|
||
@Override | ||
final List internalGetChildListProperty(ChildListPropertyDescriptor property) { | ||
if (property == STRING_TEMPLATE_FRAGMENTS) { | ||
return fragments(); | ||
} | ||
if (property == STRING_TEMPLATE_VALUES) { | ||
return expressions(); | ||
} | ||
// allow default implementation to flag the error | ||
return super.internalGetChildListProperty(property); | ||
} | ||
|
||
@Override | ||
boolean subtreeMatch0(ASTMatcher matcher, Object other) { | ||
return matcher.match(this, other); | ||
} | ||
|
||
@Override | ||
ASTNode clone0(AST target) { | ||
StringTemplate result = new StringTemplate(target); | ||
result.fragments().addAll(ASTNode.copySubtrees(target, fragments())); | ||
result.expressions().addAll(ASTNode.copySubtrees(target, expressions())); | ||
result.setSourceRange(getStartPosition(), getLength()); | ||
return result; | ||
} | ||
|
||
@Override | ||
void accept0(ASTVisitor visitor) { | ||
boolean visitChildren = visitor.visit(this); | ||
if (visitChildren) { | ||
// visit children in normal left to right reading order | ||
acceptChildren(visitor, this.fragments); | ||
acceptChildren(visitor, this.expressions); | ||
} | ||
visitor.endVisit(this); | ||
|
||
} | ||
|
||
@Override | ||
int memSize() { | ||
return BASE_NODE_SIZE + 2 * 4; | ||
} | ||
|
||
@Override | ||
int treeSize() { | ||
return | ||
memSize() | ||
+ this.fragments.listSize() | ||
+ this.expressions.listSize(); | ||
} | ||
} |
Oops, something went wrong.