use of org.eclipse.jdt.core.dom.AbstractTypeDeclaration in project che by eclipse.
the class ExtractConstantRefactoring method getReplacementScope.
/*
* Elements returned by next() are BodyDeclaration or Annotation instances.
*/
private Iterator<ASTNode> getReplacementScope() throws JavaModelException {
boolean declPredecessorReached = false;
Collection<ASTNode> scope = new ArrayList<ASTNode>();
AbstractTypeDeclaration containingType = getContainingTypeDeclarationNode();
if (containingType instanceof EnumDeclaration) {
// replace in all enum constants bodies
EnumDeclaration enumDeclaration = (EnumDeclaration) containingType;
scope.addAll(enumDeclaration.enumConstants());
}
for (Iterator<IExtendedModifier> iter = containingType.modifiers().iterator(); iter.hasNext(); ) {
IExtendedModifier modifier = iter.next();
if (modifier instanceof Annotation) {
scope.add((ASTNode) modifier);
}
}
for (Iterator<BodyDeclaration> bodyDeclarations = containingType.bodyDeclarations().iterator(); bodyDeclarations.hasNext(); ) {
BodyDeclaration bodyDeclaration = bodyDeclarations.next();
if (bodyDeclaration == getNodeToInsertConstantDeclarationAfter())
declPredecessorReached = true;
if (insertFirst() || declPredecessorReached || !isStaticFieldOrStaticInitializer(bodyDeclaration))
scope.add(bodyDeclaration);
}
return scope.iterator();
}
use of org.eclipse.jdt.core.dom.AbstractTypeDeclaration in project che by eclipse.
the class PromoteTempToFieldRefactoring method getNamesOfFieldsInDeclaringType.
private String[] getNamesOfFieldsInDeclaringType() {
final AbstractTypeDeclaration type = getEnclosingType();
if (type instanceof TypeDeclaration) {
FieldDeclaration[] fields = ((TypeDeclaration) type).getFields();
List<String> result = new ArrayList<String>(fields.length);
for (int i = 0; i < fields.length; i++) {
for (Iterator<VariableDeclarationFragment> iter = fields[i].fragments().iterator(); iter.hasNext(); ) {
VariableDeclarationFragment field = iter.next();
result.add(field.getName().getIdentifier());
}
}
return result.toArray(new String[result.size()]);
}
return new String[] {};
}
use of org.eclipse.jdt.core.dom.AbstractTypeDeclaration in project che by eclipse.
the class JavaTextSelection method resolveInClassInitializer.
public boolean resolveInClassInitializer() {
if (fInClassInitializerRequested)
return fInClassInitializer;
fInClassInitializerRequested = true;
resolveSelectedNodes();
ASTNode node = getStartNode();
if (node == null) {
fInClassInitializer = true;
} else {
while (node != null) {
int nodeType = node.getNodeType();
if (node instanceof AbstractTypeDeclaration) {
fInClassInitializer = false;
break;
} else if (nodeType == ASTNode.ANONYMOUS_CLASS_DECLARATION) {
fInClassInitializer = false;
break;
} else if (nodeType == ASTNode.INITIALIZER) {
fInClassInitializer = true;
break;
}
node = node.getParent();
}
}
return fInClassInitializer;
}
use of org.eclipse.jdt.core.dom.AbstractTypeDeclaration in project che by eclipse.
the class JavaTextSelection method resolveInVariableInitializer.
public boolean resolveInVariableInitializer() {
if (fInVariableInitializerRequested)
return fInVariableInitializer;
fInVariableInitializerRequested = true;
resolveSelectedNodes();
ASTNode node = getStartNode();
ASTNode last = null;
while (node != null) {
int nodeType = node.getNodeType();
if (node instanceof AbstractTypeDeclaration) {
fInVariableInitializer = false;
break;
} else if (nodeType == ASTNode.ANONYMOUS_CLASS_DECLARATION) {
fInVariableInitializer = false;
break;
} else if (nodeType == ASTNode.VARIABLE_DECLARATION_FRAGMENT && ((VariableDeclarationFragment) node).getInitializer() == last) {
fInVariableInitializer = true;
break;
} else if (nodeType == ASTNode.SINGLE_VARIABLE_DECLARATION && ((SingleVariableDeclaration) node).getInitializer() == last) {
fInVariableInitializer = true;
break;
} else if (nodeType == ASTNode.ANNOTATION_TYPE_MEMBER_DECLARATION && ((AnnotationTypeMemberDeclaration) node).getDefault() == last) {
fInVariableInitializer = true;
break;
}
last = node;
node = node.getParent();
}
return fInVariableInitializer;
}
use of org.eclipse.jdt.core.dom.AbstractTypeDeclaration in project AutoRefactor by JnRouvignac.
the class RemoveUnneededThisExpressionRefactoring method thisExpressionRefersToEnclosingType.
private static boolean thisExpressionRefersToEnclosingType(Name thisQualifierName, ASTNode node) {
if (thisQualifierName == null) {
return true;
}
final ASTNode enclosingType = getEnclosingType(node);
if (enclosingType instanceof AnonymousClassDeclaration) {
return false;
}
final AbstractTypeDeclaration ancestor = (AbstractTypeDeclaration) enclosingType;
if (thisQualifierName instanceof SimpleName) {
return isEqual((SimpleName) thisQualifierName, ancestor.getName());
} else if (thisQualifierName instanceof QualifiedName) {
final QualifiedName qn = (QualifiedName) thisQualifierName;
return isEqual(qn.getName(), ancestor.getName()) && thisExpressionRefersToEnclosingType(qn.getQualifier(), ancestor);
}
throw new NotImplementedException(thisQualifierName);
}
Aggregations