@SuppressWarnings("unchecked") @Override public <T, U> U getValue(T element) { return ((U) ((Object) (castTarget(element).isImplicit()))); }
/** * @return last implicit parent of element */ private ParameterElementPair getLastImplicitParent(ParameterElementPair pep) { CtElement element = pep.element; while (element.isParentInitialized()) { CtElement parent = element.getParent(); if ((parent instanceof CtBlock) == false || parent.isImplicit() == false) { break; } element = parent; } return pep.copyAndSet(element); } }
@SuppressWarnings("unchecked") void enter(CtElement e, ASTNode node) { stack.push(new ASTPair(e, node)); if (!(e instanceof CtPackage) || (compilationUnitSpoon.getFile() != null && compilationUnitSpoon.getFile().getName().equals(DefaultJavaPrettyPrinter.JAVA_PACKAGE_DECLARATION))) { if (compilationunitdeclaration != null && !e.isImplicit()) { e.setPosition(this.jdtTreeBuilder.getPositionBuilder().buildPositionCtElement(e, node)); } } ASTPair pair = stack.peek(); CtElement current = pair.element; if (current instanceof CtExpression) { while (!casts.isEmpty()) { ((CtExpression<?>) current).addTypeCast(casts.remove(0).typeRef); } } try { if (e instanceof CtTypedElement && !(e instanceof CtConstructorCall) && !(e instanceof CtCatchVariable) && node instanceof Expression) { if (((CtTypedElement<?>) e).getType() == null) { ((CtTypedElement<Object>) e).setType(this.jdtTreeBuilder.getReferencesBuilder().getTypeReference(((Expression) node).resolvedType)); } } } catch (UnsupportedOperationException ignore) { // For some element, we throw an UnsupportedOperationException when we call setType(). } }
/** * Scans an abstract element. */ // auto-generated, see spoon.generating.CloneVisitorGenerator public void scanCtElement(spoon.reflect.declaration.CtElement e) { ((spoon.reflect.declaration.CtElement) (other)).setPosition(e.getPosition()); ((spoon.reflect.declaration.CtElement) (other)).setAllMetadata(e.getAllMetadata()); ((spoon.reflect.declaration.CtElement) (other)).setImplicit(e.isImplicit()); super.scanCtElement(e); }
/** writes as many newlines as needed to align the line number again between the element position and the current line number */ public PrinterHelper adjustStartPosition(CtElement e) { if (!e.isImplicit() && e.getPosition().isValidPosition()) { // we should add some lines while (line < e.getPosition().getLine()) { writeln(); } // trying to remove some lines while (line > e.getPosition().getLine()) { if (!removeLine()) { break; } } } return this; }
boolean parentIsImplicit = parent.isImplicit();
continue; if (element.isImplicit()) { continue;
@Override public <T> void visitCtInvocation(CtInvocation<T> invocation) { if (childJDT instanceof TypeReference && child instanceof CtTypeAccess) { invocation.getExecutable().addActualTypeArgument(((CtTypeAccess) child).getAccessedType()); return; } else if (child instanceof CtExpression) { if (hasChildEqualsToReceiver(invocation) || hasChildEqualsToQualification(invocation)) { if (child instanceof CtThisAccess) { final CtTypeReference<?> declaringType = invocation.getExecutable().getDeclaringType(); if (declaringType != null && invocation.getExecutable().isStatic() && child.isImplicit()) { invocation.setTarget(jdtTreeBuilder.getFactory().Code().createTypeAccess(declaringType, declaringType.isAnonymous())); } else { invocation.setTarget((CtThisAccess<?>) child); } } else { invocation.setTarget((CtExpression<?>) child); } } else { invocation.addArgument((CtExpression<?>) child); } return; } super.visitCtInvocation(invocation); }
/** * 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; } return element.isImplicit() || element instanceof CtReference; }
/** * 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; } return element.isImplicit() || element instanceof CtReference; }
@Override protected void enter(CtElement e) { if (e.getPosition() instanceof NoSourcePosition) { return; } if (e.getPosition().getSourceStart() == patch.getSourceLocation().getBeginSource() && e.getPosition().getSourceEnd() == patch.getSourceLocation().getEndSource() && e.isImplicit() == false) { if (patch.getType() == RepairType.CONDITIONAL && e instanceof CtIf) { setResult(((CtIf) e).getCondition()); } else { setResult(e); } terminate(); return; } if (e.getPosition().getSourceStart() <= patch.getSourceLocation().getBeginSource() && e.getPosition().getSourceEnd() >= patch.getSourceLocation().getEndSource()) { super.enter(e); } } };