]> git.uio.no Git - ifi-stolz-refaktor.git/blame - case-study/jdt-after/core extension/org/eclipse/jdt/internal/corext/dom/fragments/SimpleFragment.java
Some talks, mostly identical.
[ifi-stolz-refaktor.git] / case-study / jdt-after / core extension / org / eclipse / jdt / internal / corext / dom / fragments / SimpleFragment.java
CommitLineData
1b2798f6
EK
1/*******************************************************************************
2 * Copyright (c) 2000, 2011 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11package org.eclipse.jdt.internal.corext.dom.fragments;
12
13import org.eclipse.core.runtime.Assert;
14
15import org.eclipse.text.edits.TextEditGroup;
16
17import org.eclipse.jdt.core.dom.ASTNode;
18import org.eclipse.jdt.core.dom.Name;
19import org.eclipse.jdt.core.dom.ParenthesizedExpression;
20import org.eclipse.jdt.core.dom.rewrite.ASTRewrite;
21
22import org.eclipse.jdt.internal.corext.dom.JdtASTMatcher;
23
24class SimpleFragment extends ASTFragment {
25 private final ASTNode fNode;
26
27 SimpleFragment(ASTNode node) {
28 Assert.isNotNull(node);
29 fNode= node;
30 }
31
32 @Override
33 public IASTFragment[] getMatchingFragmentsWithNode(ASTNode node) {
34 if (! JdtASTMatcher.doNodesMatch(getAssociatedNode(), node))
35 return new IASTFragment[0];
36
37 IASTFragment match= ASTFragmentFactory.createFragmentForFullSubtree(node);
38 Assert.isTrue(match.matches(this) || this.matches(match));
39 return new IASTFragment[] { match };
40 }
41
42 public boolean matches(IASTFragment other) {
43 return other.getClass().equals(getClass()) && JdtASTMatcher.doNodesMatch(other.getAssociatedNode(), getAssociatedNode());
44 }
45
46 public IASTFragment[] getSubFragmentsMatching(IASTFragment toMatch) {
47 return ASTMatchingFragmentFinder.findMatchingFragments(getAssociatedNode(), (ASTFragment) toMatch);
48 }
49
50 public int getStartPosition() {
51 return fNode.getStartPosition();
52 }
53
54 public int getLength() {
55 return fNode.getLength();
56 }
57
58 public ASTNode getAssociatedNode() {
59 return fNode;
60 }
61
62 public void replace(ASTRewrite rewrite, ASTNode replacement, TextEditGroup textEditGroup) {
63 if (replacement instanceof Name && fNode.getParent() instanceof ParenthesizedExpression) {
64 // replace including the parenthesized expression around it
65 rewrite.replace(fNode.getParent(), replacement, textEditGroup);
66 } else {
67 rewrite.replace(fNode, replacement, textEditGroup);
68 }
69 }
70
71 @Override
72 public int hashCode() {
73 return fNode.hashCode();
74 }
75
76 @Override
77 public boolean equals(Object obj) {
78 if (this == obj)
79 return true;
80 if (obj == null)
81 return false;
82 if (getClass() != obj.getClass())
83 return false;
84 SimpleFragment other= (SimpleFragment) obj;
85 return other.generated_7872377811361121460(this);
86 }
87
88 public boolean generated_7872377811361121460(SimpleFragment simplefragment) {
89 return simplefragment.fNode.equals(fNode);
90 }
91
92}