本文整理汇总了Java中org.eclipse.gmt.modisco.java.ASTNode类的典型用法代码示例。如果您正苦于以下问题:Java ASTNode类的具体用法?Java ASTNode怎么用?Java ASTNode使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ASTNode类属于org.eclipse.gmt.modisco.java包,在下文中一共展示了ASTNode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addComments
import org.eclipse.gmt.modisco.java.ASTNode; //导入依赖的package包/类
/**
* @param commentsBefore
* @param element
* @param enclosedByElement
* @param prefixOfElement
*/
private void addComments(final List<Comment> commentsBefore, final ASTNode element,
final boolean enclosedByElement, final boolean prefixOfElement,
final List<Comment> localCommentsList) {
for (Comment comment : commentsBefore) {
if (localCommentsList.contains(comment)) {
if (this.debug) {
System.out.println("added comment = " + comment.getContent()); //$NON-NLS-1$
}
comment.setEnclosedByParent(enclosedByElement);
comment.setPrefixOfParent(prefixOfElement);
element.getComments().add(comment);
localCommentsList.remove(comment);
}
}
}
示例2: attachComment
import org.eclipse.gmt.modisco.java.ASTNode; //导入依赖的package包/类
private static void attachComment(final Comment comment,
final org.eclipse.jdt.core.dom.ASTNode jdtComment, final ASTNode receiver,
final JDTVisitor visitor) {
if (receiver.getComments().contains(comment)) {
return;
}
int insertIndex = 0;
for (; insertIndex < receiver.getComments().size(); insertIndex++) {
org.eclipse.jdt.core.dom.ASTNode jdtOtherComment = visitor.getCommentsBinding().getKey(
receiver.getComments().get(insertIndex));
if (jdtOtherComment != null
&& jdtOtherComment.getStartPosition() > jdtComment.getStartPosition()) {
break;
}
}
receiver.getComments().add(insertIndex, comment);
}
示例3: completeVariableAccess
import org.eclipse.gmt.modisco.java.ASTNode; //导入依赖的package包/类
/**
* For unresolved items, <code>SingleVariableAccess</code> may not have been
* yet created (no kind of binding)
*
* @param node
* a variable access (<code>PendingElement</code> or resolved
* <code>SingleVariableAccess</code>)
* @param visitor
* the JDTVisitor
*/
public static SingleVariableAccess completeVariableAccess(final ASTNode node,
final JDTVisitor visitor) {
if (node instanceof SingleVariableAccess) {
return (SingleVariableAccess) node;
} else if (node instanceof UnresolvedItemAccess) {
// now we know that the unresolved item is a variable access -> we
// substitute UIA with VariableAccess
SingleVariableAccess varAcc = visitor.getFactory().createSingleVariableAccess();
if (((UnresolvedItemAccess) node).getQualifier() != null) {
varAcc.setQualifier((Expression) ((UnresolvedItemAccess) node).getQualifier());
}
JDTVisitorUtils.substitutePendingClientNode(node, varAcc,
"element", "variable", visitor); //$NON-NLS-1$ //$NON-NLS-2$
return varAcc;
} else {
SingleVariableAccess variableAccess = visitor.getFactory().createSingleVariableAccess();
((PendingElement) node).setClientNode(variableAccess);
((PendingElement) node).setLinkName("variable"); //$NON-NLS-1$
return variableAccess;
}
}
示例4: addJavadoc
import org.eclipse.gmt.modisco.java.ASTNode; //导入依赖的package包/类
public static Javadoc addJavadoc(ASTNode bodyDeclaration, String documentation, boolean addEmptyLine) {
Javadoc javadoc = JavaFactory.eINSTANCE.createJavadoc();
if(documentation != null) {
for(String documentationChunk : documentation.split("\\n")){
TagElement tagElement = JavaFactory.eINSTANCE.createTagElement();
tagElement.getFragments().add(createTextElement(documentationChunk));
if(addEmptyLine) {
tagElement.getFragments().add(createTextElement(""));
}
javadoc.getTags().add(tagElement);
}
}
javadoc.setPrefixOfParent(true);
if(bodyDeclaration != null) {
bodyDeclaration.getComments().add(javadoc);
}
return javadoc;
}
示例5: queryCommentsTagContent
import org.eclipse.gmt.modisco.java.ASTNode; //导入依赖的package包/类
public static Query<Integer> queryCommentsTagContent(Resource resource) {
return () -> {
Set<TextElement> result = new HashSet<>();
try {
Model model = (Model) resource.getContents().get(0);
if (model.getName().equals("org.eclipse.gmt.modisco.java.neoemf") || model.getName().equals("org.eclipse.jdt.core")) {
for (CompilationUnit cu : model.getCompilationUnits()) {
for (Comment comment : cu.getCommentList()) {
if (comment instanceof Javadoc) {
Javadoc javadoc = (Javadoc) comment;
for (TagElement te : javadoc.getTags()) {
for (ASTNode node : te.getFragments()) {
if (node instanceof TextElement) {
result.add((TextElement) node);
}
}
}
}
}
}
}
}
catch (NullPointerException e) {
log.error("Null pointer", e);
}
return result.size();
};
}
示例6: affectTarget
import org.eclipse.gmt.modisco.java.ASTNode; //导入依赖的package包/类
/**
* Affect the given {@code target} to the client node. This method use the
* EMF reflexive API.
*
* @param target
* the target.
*/
public void affectTarget(final ASTNode target) {
if (this.clientNode != null) {
EStructuralFeature feature = this.clientNode.eClass().getEStructuralFeature(
this.linkName);
affectTarget0(feature, target);
}
}
示例7: mayOwnComment
import org.eclipse.gmt.modisco.java.ASTNode; //导入依赖的package包/类
private static boolean mayOwnComment(final org.eclipse.jdt.core.dom.ASTNode element) {
return !(element instanceof org.eclipse.jdt.core.dom.Comment)
&& !(element instanceof org.eclipse.jdt.core.dom.TagElement)
&& !(element instanceof org.eclipse.jdt.core.dom.TextElement)
&& !(element instanceof org.eclipse.jdt.core.dom.MemberRef)
&& !(element instanceof org.eclipse.jdt.core.dom.MethodRef);
}
示例8: manageBindingRef
import org.eclipse.gmt.modisco.java.ASTNode; //导入依赖的package包/类
/**
* Resolves this JDT ParameterizedType <code>type</code> and creates the
* corresponding MoDisco {@link ParameterizedType} object (or returns a
* similar ParameterizedType if any).
*
* @param type
* the JDT ParameterizedType node.
* @param visitor
* the JDTVisitor.
* @return the MoDisco ParameterizedType object.
*/
public static ParameterizedType manageBindingRef(
final org.eclipse.jdt.core.dom.ParameterizedType type, final JDTVisitor visitor) {
Binding id = JDTDelegateBindingFactory.getInstance().getBindingForParameterizedType(type);
ParameterizedType parameterizedType = (ParameterizedType) visitor.getGlobalBindings()
.getTarget(id);
if (parameterizedType == null) {
parameterizedType = visitor.getFactory().createParameterizedType();
parameterizedType.setName(id.toString());
if (visitor.getBijectiveMap().get(type.getType()) != null) {
parameterizedType.setType(completeTypeAccess(
visitor.getBijectiveMap().get(type.getType()), visitor));
}
for (Iterator<?> i = type.typeArguments().iterator(); i.hasNext();) {
Object typeArgument = i.next();
ASTNode node = visitor.getBijectiveMap().get(typeArgument);
if (node == null) {
RuntimeException e = new RuntimeException(
"typeArgument not found in visitor bijective map: " + type.getParent().getParent().toString()); //$NON-NLS-1$
MoDiscoLogger.logWarning(e, JavaActivator.getDefault());
}
TypeAccess itElement = completeTypeAccess(node, visitor);
if (itElement != null) {
parameterizedType.getTypeArguments().add(itElement);
}
}
visitor.getJdtModel().getOrphanTypes().add(parameterizedType);
visitor.getGlobalBindings().addTarget(id, parameterizedType);
}
return parameterizedType;
}
示例9: substitutePendingClientNode
import org.eclipse.gmt.modisco.java.ASTNode; //导入依赖的package包/类
/**
*
* @param oldClientNode
* @param newClientNode
* @param oldClientLinkName
* @param newClientLinkName
* @param visitor
*/
public static void substitutePendingClientNode(final ASTNode oldClientNode,
final ASTNode newClientNode, final String oldClientLinkName,
final String newClientLinkName, final JDTVisitor visitor) {
PendingElement pe = visitor.getGlobalBindings()
.getPending(oldClientNode, oldClientLinkName);
if (pe != null) {
pe.setClientNode(newClientNode);
pe.setLinkName(newClientLinkName);
visitor.getBijectiveMap().put(visitor.getBijectiveMap().getKey(oldClientNode),
newClientNode);
EcoreUtil.remove(oldClientNode);
}
}
示例10: completeBinding
import org.eclipse.gmt.modisco.java.ASTNode; //导入依赖的package包/类
/**
* Complete <code>PendingElement</code> instances with client node and
* client link name.
*
* @param clientNode
* @param modiscoNode
* @param clientLinkName
*/
public static boolean completeBinding(final ASTNode clientNode, final ASTNode modiscoNode,
final String clientLinkName) {
if (modiscoNode != null) {
if (modiscoNode instanceof PendingElement) {
PendingElement pending = (PendingElement) modiscoNode;
pending.setLinkName(clientLinkName);
pending.setClientNode(clientNode);
} else {
return true;
}
}
return false;
}
示例11: computeListOfcommentsAfter
import org.eclipse.gmt.modisco.java.ASTNode; //导入依赖的package包/类
/**
* @param jdtNode
* @param cuJdtNode
* @param visitor
* @return
*/
private List<Comment> computeListOfcommentsAfter(
final org.eclipse.jdt.core.dom.ASTNode jdtNode, final CompilationUnit cuJdtNode,
final JDTVisitor visitor) {
List<Comment> result = new ArrayList<Comment>();
int index = cuJdtNode.lastTrailingCommentIndex(jdtNode);
if (index != -1) {
/*
* we have to retrieve all comments which start position is more
* than basic end position of jdt node. Or the opposite way, all
* comments which ended before the extended end position of jdt
* node.
*/
int endPosition = cuJdtNode.getExtendedStartPosition(jdtNode) + cuJdtNode.getExtendedLength(jdtNode);
for (int i = index; i > -1; i--) {
org.eclipse.jdt.core.dom.ASTNode jdtComment = (org.eclipse.jdt.core.dom.ASTNode) cuJdtNode
.getCommentList().get(i);
int commentEndPosition = (cuJdtNode.getExtendedStartPosition(jdtComment) + cuJdtNode
.getExtendedLength(jdtComment));
if (this.debug) {
System.out.println("end position = " + endPosition); //$NON-NLS-1$
System.out.println("comment end position = " + commentEndPosition); //$NON-NLS-1$
}
String whitespaces = null;
if (endPosition > commentEndPosition) {
try {
whitespaces = visitor.getJavaContent().substring(commentEndPosition, endPosition).trim();
} catch (Exception e) {
// markus, hub, sam, srcrepo
// this often throughs a sting out of bounds exception.
// will simply break the loop, and skip all further comments, when this happens.
break;
}
}
if ((whitespaces == null) || (whitespaces.length() == 0)) {
// shift the end position to manage further comments
endPosition = cuJdtNode.getExtendedStartPosition(jdtComment);
Comment comment = visitor.getCommentsBinding().get(jdtComment);
if (comment != null) {
result.add(0, comment);
}
} else {
// stop iteration (we are inside or before the jdt node)
i = -1;
}
}
}
if (this.debug) {
System.out.println("number of comments after the node = " + result.size()); //$NON-NLS-1$
}
return result;
}
示例12: computeListOfcommentsBefore
import org.eclipse.gmt.modisco.java.ASTNode; //导入依赖的package包/类
/**
* @param jdtNode
* @param cuJdtNode
* @return
*/
private List<Comment> computeListOfcommentsBefore(
final org.eclipse.jdt.core.dom.ASTNode jdtNode, final CompilationUnit cuJdtNode,
final JDTVisitor visitor) {
List<Comment> result = new ArrayList<Comment>();
int index = cuJdtNode.firstLeadingCommentIndex(jdtNode);
if (index != -1) {
/*
* we have to retrieve all comments which start position is less
* than start position of jdt node. shall we use the extended
* position and length ?
*/
int size = cuJdtNode.getCommentList().size();
int startPosition = cuJdtNode.getExtendedStartPosition(jdtNode);
for (int i = index; i < size; i++) {
org.eclipse.jdt.core.dom.ASTNode jdtComment = (org.eclipse.jdt.core.dom.ASTNode) cuJdtNode
.getCommentList().get(i);
int commentPosition = cuJdtNode.getExtendedStartPosition(jdtComment);
if (this.debug) {
System.out.println("start position = " + startPosition); //$NON-NLS-1$
System.out.println("comment position = " + commentPosition); //$NON-NLS-1$
}
String whitespaces = null;
if (commentPosition > startPosition) {
try {
whitespaces = visitor.getJavaContent().substring(startPosition, commentPosition).trim();
} catch (Exception e) {
// markus, hub, sam, srcrepo
// this often throughs a sting out of bounds exception.
// will simply break the loop, and skip all further comments, when this happens.
break;
}
}
if ((whitespaces == null) || (whitespaces.length() == 0)) {
/*
* shift the start position to manage further comments, to
* manage whitespace (space and tabulation).
*/
startPosition = commentPosition + cuJdtNode.getExtendedLength(jdtComment);
Comment comment = visitor.getCommentsBinding().get(jdtComment);
if (comment != null) {
result.add(comment);
}
} else {
// stop iteration (we are inside or after the jdt node)
i = size;
}
}
}
if (this.debug) {
System.out.println("number of comments before the node = " + result.size()); //$NON-NLS-1$
}
return result;
}
示例13: alternateLocationSearch
import org.eclipse.gmt.modisco.java.ASTNode; //导入依赖的package包/类
/**
* Some misc comments are not linked to any node in jdt AST : - comments in
* a block, with at least one blank line before next node and one blank line
* after last node - comments in a block, at the end and with at least one
* blank line after last node. Use another algorithm to link them.
*
* @param comment
* @param visitor
*/
private static boolean alternateLocationSearch(final Comment comment, final JDTVisitor visitor,
final org.eclipse.gmt.modisco.java.CompilationUnit moDiscoCuNode) {
ASTNode bestParent = null;
org.eclipse.jdt.core.dom.ASTNode jdtComment = visitor.getCommentsBinding().getKey(comment);
// We search the nearest element in default parent subtree
int bestFollowingNodeStart = Integer.MAX_VALUE;
int bestFollowingNodeEnd = Integer.MIN_VALUE;
int bestEnclosingNodeStart = Integer.MIN_VALUE;
int bestEnclosingNodeEnd = Integer.MAX_VALUE;
for (org.eclipse.jdt.core.dom.ASTNode jdtNode : visitor.getBijectiveMap().getKeys()) {
ASTNode modiscoNode = visitor.getBijectiveMap().get(jdtNode);
if (mayOwnComment(jdtNode) && !(modiscoNode instanceof PendingElement)) {
int sp = jdtNode.getStartPosition();
int ep = jdtNode.getStartPosition() + jdtNode.getLength();
// Does this node follow the comment more closely ?
if ((sp >= jdtComment.getStartPosition() + jdtComment.getLength())
&& (sp < bestFollowingNodeStart || (sp == bestFollowingNodeStart && ep > bestFollowingNodeEnd))
&& (sp < bestEnclosingNodeEnd)) {
bestFollowingNodeStart = sp;
bestFollowingNodeEnd = ep;
bestParent = modiscoNode;
comment.setEnclosedByParent(false);
comment.setPrefixOfParent(true);
}
// Does this node enclose the comment more closely ?
if ((sp <= jdtComment.getStartPosition()) && (ep > jdtComment.getStartPosition())
&& (ep < bestFollowingNodeStart) && (ep <= bestEnclosingNodeEnd)
&& (sp >= bestEnclosingNodeStart)) {
bestEnclosingNodeEnd = ep;
bestEnclosingNodeStart = sp;
bestParent = modiscoNode;
comment.setEnclosedByParent(true);
comment.setPrefixOfParent(false);
}
}
}
if (bestParent != null) {
// insert comment in parent comment list at the right position
if (bestParent instanceof Package) {
bestParent = moDiscoCuNode;
comment.setEnclosedByParent(false);
comment.setPrefixOfParent(true);
}
attachComment(comment, jdtComment, bestParent, visitor);
return true;
}
return false;
}
示例14: getPending
import org.eclipse.gmt.modisco.java.ASTNode; //导入依赖的package包/类
/**
* Returns the {@link PendingElement} contained in this
* {@code BindingManager} specified by the {@code clientNode} and the
* {@code linkName}.
*
* @param clientNode
* the client node
* @param linkName
* the name of the feature
* @return the {@code PendingElement} object specified by the
* {@code clientNode} and the {@code linkName}, or {@code null} if
* the object is not contained in this {@code BindingManager}
*/
public PendingElement getPending(final ASTNode clientNode, final String linkName) {
PendingElement result = null;
for (PendingElement pe : this.pendings) {
if (pe.getClientNode() != null && pe.getClientNode().equals(clientNode)
&& pe.getLinkName() != null && pe.getLinkName().equals(linkName)) {
result = pe;
}
}
return result;
}
示例15: completeExpression
import org.eclipse.gmt.modisco.java.ASTNode; //导入依赖的package包/类
/**
* For unresolved items as qualifiers, <code>UnresolvedItemAccess</code> may
* not have been yet created
*
* @param node
* an expression (<code>PendingElement</code> or resolved
* <code>Expression</code>)
* @param visitor
* the JDTVisitor
*/
public static Expression completeExpression(final ASTNode node, final JDTVisitor visitor) {
if (node instanceof Expression) {
return (Expression) node;
}
UnresolvedItemAccess unrAcc = visitor.getFactory().createUnresolvedItemAccess();
((PendingElement) node).setClientNode(unrAcc);
((PendingElement) node).setLinkName("element"); //$NON-NLS-1$
return unrAcc;
}