Java Code Examples for spoon.reflect.declaration.CtElement#getRoleInParent()
The following examples show how to use
spoon.reflect.declaration.CtElement#getRoleInParent() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TreeScanner.java From gumtree-spoon-ast-diff with Apache License 2.0 | 5 votes |
/** * Ignore some element from the AST * * @param element * @return */ private boolean isToIgnore(CtElement element) { if (element instanceof CtStatementList && !(element instanceof CtCase)) { if (element.getRoleInParent() == CtRole.ELSE || element.getRoleInParent() == CtRole.THEN) { return false; } return true; } if (element instanceof CtReference && element.getRoleInParent() == CtRole.SUPER_TYPE) { return false; } return element.isImplicit() || element instanceof CtReference; }
Example 2
Source File: DetectorChangePatternInstanceEngine.java From coming with MIT License | 4 votes |
/** * Match the element affected by an operation from the diff and the elements in * the pattern specification * * @param affectedOperation * @param affectedEntity * @return */ private List<MatchingEntity> matchElements(Operation affectedOperation, PatternEntity affectedEntity) { List<MatchingEntity> matching = new ArrayList<>(); int parentLevel = 1; PatternEntity parentEntity = affectedEntity; // Let's get the parent of the affected CtElement currentNodeFromAction = null; boolean matchnewvalue = false; // Search the node to select according to the type of operation and the pattern if (affectedOperation.getDstNode() != null && affectedEntity.getNewValue() != null) { currentNodeFromAction = affectedOperation.getDstNode(); matchnewvalue = true; } else if (affectedOperation instanceof UpdateOperation && (affectedEntity.getOldValue() != null)) { currentNodeFromAction = affectedOperation.getSrcNode(); matchnewvalue = false; } else { matchnewvalue = true; currentNodeFromAction = affectedOperation.getNode(); } int i_levels = 1; // Scale the parent hierarchy and check types. while (currentNodeFromAction != null && i_levels <= parentLevel) { String typeOfNode = EntityTypesInfoResolver.getNodeLabelFromCtElement(currentNodeFromAction); String valueOfNode = currentNodeFromAction.toString(); String roleInParent = (currentNodeFromAction.getRoleInParent() != null) ? currentNodeFromAction.getRoleInParent().toString().toLowerCase() : ""; String patternEntityValue = (matchnewvalue) ? parentEntity.getNewValue() : parentEntity.getOldValue(); if ( // type of element ("*".equals(parentEntity.getEntityType()) // || (typeOfNode != null && typeOfNode.equals(parentEntity.getEntityType()))) || (typeOfNode != null && EntityTypesInfoResolver.getInstance().isAChildOf(typeOfNode, parentEntity.getEntityType()))) /// && // value of element ("*".equals(patternEntityValue) || (valueOfNode != null && valueOfNode.equals(patternEntityValue))) // && // role ("*".equals(parentEntity.getRoleInParent()) || (roleInParent != null && roleInParent.equals(parentEntity.getRoleInParent().toLowerCase())))) { MatchingEntity match = new MatchingEntity(currentNodeFromAction, parentEntity); matching.add(match); ParentPatternEntity parentEntityFromPattern = parentEntity.getParentPatternEntity(); if (parentEntityFromPattern == null) { return matching; } i_levels = 1; parentLevel = parentEntityFromPattern.getParentLevel(); parentEntity = parentEntityFromPattern.getParent(); } else { // Not match i_levels++; } currentNodeFromAction = currentNodeFromAction.getParent(); } // Not all matched return null; }
Example 3
Source File: ExpressionReplaceOperator.java From astor with GNU General Public License v2.0 | 3 votes |
public boolean isStatement(CtElement toModif) { if (!(toModif instanceof CtStatement)) return false; if (toModif.getParent() instanceof CtBlock) return true; CtRole roleInParent = toModif.getRoleInParent(); if (CtRole.BODY.equals(roleInParent) || CtRole.THEN.equals(roleInParent) || CtRole.ELSE.equals(roleInParent)) return true; return false; }