use of org.eclipse.jdt.core.dom.FieldDeclaration in project che by eclipse.
the class ExtractMethodRefactoring method initializeDestinations.
private void initializeDestinations() {
List<ASTNode> result = new ArrayList<ASTNode>();
BodyDeclaration decl = fAnalyzer.getEnclosingBodyDeclaration();
ASTNode current = ASTResolving.findParentType(decl.getParent());
if (fAnalyzer.isValidDestination(current)) {
result.add(current);
}
if (current != null && (decl instanceof MethodDeclaration || decl instanceof Initializer || decl instanceof FieldDeclaration)) {
ITypeBinding binding = ASTNodes.getEnclosingType(current);
ASTNode next = ASTResolving.findParentType(current.getParent());
while (next != null && binding != null && binding.isNested()) {
if (fAnalyzer.isValidDestination(next)) {
result.add(next);
}
current = next;
binding = ASTNodes.getEnclosingType(current);
next = ASTResolving.findParentType(next.getParent());
}
}
fDestinations = result.toArray(new ASTNode[result.size()]);
fDestination = fDestinations[fDestinationIndex];
}
use of org.eclipse.jdt.core.dom.FieldDeclaration in project che by eclipse.
the class ExtractConstantRefactoring method depends.
/* bd is a static field declaration or static initializer */
private static boolean depends(IExpressionFragment selected, BodyDeclaration bd) {
if (bd instanceof FieldDeclaration) {
FieldDeclaration fieldDecl = (FieldDeclaration) bd;
for (Iterator<VariableDeclarationFragment> fragments = fieldDecl.fragments().iterator(); fragments.hasNext(); ) {
VariableDeclarationFragment fragment = fragments.next();
SimpleName staticFieldName = fragment.getName();
if (selected.getSubFragmentsMatching(ASTFragmentFactory.createFragmentForFullSubtree(staticFieldName)).length != 0)
return true;
}
}
return false;
}
use of org.eclipse.jdt.core.dom.FieldDeclaration in project che by eclipse.
the class ExtractConstantRefactoring method computeConstantDeclarationLocation.
private void computeConstantDeclarationLocation() throws JavaModelException {
if (isDeclarationLocationComputed())
return;
BodyDeclaration lastStaticDependency = null;
Iterator<BodyDeclaration> decls = getContainingTypeDeclarationNode().bodyDeclarations().iterator();
while (decls.hasNext()) {
BodyDeclaration decl = decls.next();
int modifiers;
if (decl instanceof FieldDeclaration)
modifiers = ((FieldDeclaration) decl).getModifiers();
else if (decl instanceof Initializer)
modifiers = ((Initializer) decl).getModifiers();
else {
continue;
/* this declaration is not a field declaration
or initializer, so the placement of the constant
declaration relative to it does not matter */
}
if (Modifier.isStatic(modifiers) && depends(getSelectedExpression(), decl))
lastStaticDependency = decl;
}
if (lastStaticDependency == null)
fInsertFirst = true;
else
fToInsertAfter = lastStaticDependency;
}
use of org.eclipse.jdt.core.dom.FieldDeclaration in project che by eclipse.
the class CallInliner method initializeRewriteState.
private void initializeRewriteState() {
fFieldInitializer = false;
ASTNode parent = fInvocation.getParent();
do {
if (parent instanceof FieldDeclaration) {
fFieldInitializer = true;
return;
} else if (parent instanceof Block) {
return;
}
parent = parent.getParent();
} while (parent != null);
}
use of org.eclipse.jdt.core.dom.FieldDeclaration in project che by eclipse.
the class ConvertAnonymousToNestedRefactoring method mustInnerClassBeStatic.
public boolean mustInnerClassBeStatic() {
ITypeBinding typeBinding = ((AbstractTypeDeclaration) ASTNodes.getParent(fAnonymousInnerClassNode, AbstractTypeDeclaration.class)).resolveBinding();
ASTNode current = fAnonymousInnerClassNode.getParent();
boolean ans = false;
while (current != null) {
switch(current.getNodeType()) {
case ASTNode.SUPER_CONSTRUCTOR_INVOCATION:
case ASTNode.CONSTRUCTOR_INVOCATION:
return true;
case ASTNode.ANONYMOUS_CLASS_DECLARATION:
{
AnonymousClassDeclaration enclosingAnonymousClassDeclaration = (AnonymousClassDeclaration) current;
ITypeBinding binding = enclosingAnonymousClassDeclaration.resolveBinding();
if (binding != null && Bindings.isSuperType(typeBinding, binding.getSuperclass())) {
return false;
}
break;
}
case ASTNode.FIELD_DECLARATION:
{
FieldDeclaration enclosingFieldDeclaration = (FieldDeclaration) current;
if (Modifier.isStatic(enclosingFieldDeclaration.getModifiers())) {
ans = true;
}
break;
}
case ASTNode.METHOD_DECLARATION:
{
MethodDeclaration enclosingMethodDeclaration = (MethodDeclaration) current;
if (Modifier.isStatic(enclosingMethodDeclaration.getModifiers())) {
ans = true;
}
break;
}
case ASTNode.TYPE_DECLARATION:
{
return ans;
}
}
current = current.getParent();
}
return ans;
}
Aggregations