use of org.eclipse.jdt.core.dom.Initializer in project flux by eclipse.
the class ScopeAnalyzer method addLocalDeclarations.
private boolean addLocalDeclarations(ASTNode node, int offset, int flags, IBindingRequestor requestor) {
if (hasFlag(VARIABLES, flags) || hasFlag(TYPES, flags)) {
BodyDeclaration declaration = ASTResolving.findParentBodyDeclaration(node);
if (declaration instanceof MethodDeclaration || declaration instanceof Initializer || declaration instanceof FieldDeclaration) {
ScopeAnalyzerVisitor visitor = new ScopeAnalyzerVisitor(offset, flags, requestor);
declaration.accept(visitor);
return visitor.fBreak;
}
}
return false;
}
use of org.eclipse.jdt.core.dom.Initializer in project eclipse.jdt.ls by eclipse.
the class NavigateToDefinitionHandler method computeBreakContinue.
private Location computeBreakContinue(ITypeRoot typeRoot, int line, int column) throws CoreException {
int offset = JsonRpcHelpers.toOffset(typeRoot.getBuffer(), line, column);
if (offset >= 0) {
CompilationUnit unit = SharedASTProviderCore.getAST(typeRoot, SharedASTProviderCore.WAIT_YES, null);
if (unit == null) {
return null;
}
ASTNode selectedNode = NodeFinder.perform(unit, offset, 0);
ASTNode node = null;
SimpleName label = null;
if (selectedNode instanceof BreakStatement) {
node = selectedNode;
label = ((BreakStatement) node).getLabel();
} else if (selectedNode instanceof ContinueStatement) {
node = selectedNode;
label = ((ContinueStatement) node).getLabel();
} else if (selectedNode instanceof SimpleName && selectedNode.getParent() instanceof BreakStatement) {
node = selectedNode.getParent();
label = ((BreakStatement) node).getLabel();
} else if (selectedNode instanceof SimpleName && selectedNode.getParent() instanceof ContinueStatement) {
node = selectedNode.getParent();
label = ((ContinueStatement) node).getLabel();
}
if (node != null) {
ASTNode parent = node.getParent();
ASTNode target = null;
while (parent != null) {
if (parent instanceof MethodDeclaration || parent instanceof Initializer) {
break;
}
if (label == null) {
if (parent instanceof ForStatement || parent instanceof EnhancedForStatement || parent instanceof WhileStatement || parent instanceof DoStatement) {
target = parent;
break;
}
if (node instanceof BreakStatement) {
if (parent instanceof SwitchStatement || parent instanceof SwitchExpression) {
target = parent;
break;
}
}
if (node instanceof LabeledStatement) {
target = parent;
break;
}
} else if (LabeledStatement.class.isInstance(parent)) {
LabeledStatement ls = (LabeledStatement) parent;
if (ls.getLabel().getIdentifier().equals(label.getIdentifier())) {
target = ls;
break;
}
}
parent = parent.getParent();
}
if (target != null) {
int start = target.getStartPosition();
int end = new TokenScanner(unit.getTypeRoot()).getNextEndOffset(node.getStartPosition(), true) - start;
if (start >= 0 && end >= 0) {
return JDTUtils.toLocation((ICompilationUnit) typeRoot, start, end);
}
}
}
}
return null;
}
use of org.eclipse.jdt.core.dom.Initializer in project eclipse.jdt.ls by eclipse.
the class LocalCorrectionsSubProcessor method addConstructorFromSuperclassProposal.
public static void addConstructorFromSuperclassProposal(IInvocationContext context, IProblemLocationCore problem, Collection<ChangeCorrectionProposal> proposals) throws CoreException {
ASTNode selectedNode = problem.getCoveringNode(context.getASTRoot());
if (selectedNode == null) {
return;
}
TypeDeclaration typeDeclaration = null;
if (selectedNode.getLocationInParent() == TypeDeclaration.NAME_PROPERTY) {
typeDeclaration = (TypeDeclaration) selectedNode.getParent();
} else {
BodyDeclaration declaration = ASTResolving.findParentBodyDeclaration(selectedNode);
if (declaration instanceof Initializer && problem.getProblemId() == IProblem.UnhandledExceptionInDefaultConstructor) {
addUncaughtExceptionProposals(context, problem, proposals);
}
return;
}
ITypeBinding binding = typeDeclaration.resolveBinding();
if (binding == null || binding.getSuperclass() == null) {
return;
}
ICompilationUnit cu = context.getCompilationUnit();
IMethodBinding[] methods = binding.getSuperclass().getDeclaredMethods();
for (int i = 0; i < methods.length; i++) {
IMethodBinding curr = methods[i];
if (curr.isConstructor() && !Modifier.isPrivate(curr.getModifiers())) {
proposals.add(new ConstructorFromSuperclassProposal(cu, typeDeclaration, curr, IProposalRelevance.ADD_CONSTRUCTOR_FROM_SUPER_CLASS));
}
}
}
use of org.eclipse.jdt.core.dom.Initializer in project eclipse.jdt.ls by eclipse.
the class ExtractMethodAnalyzer method computeLastStatementSelected.
private void computeLastStatementSelected() {
ASTNode[] nodes = getSelectedNodes();
if (nodes.length == 0) {
fIsLastStatementSelected = false;
} else {
Block body = null;
LambdaExpression enclosingLambdaExpr = ASTResolving.findEnclosingLambdaExpression(getFirstSelectedNode());
if (enclosingLambdaExpr != null) {
ASTNode lambdaBody = enclosingLambdaExpr.getBody();
if (lambdaBody instanceof Block) {
body = (Block) lambdaBody;
} else {
fIsLastStatementSelected = true;
return;
}
} else {
if (fEnclosingBodyDeclaration instanceof MethodDeclaration) {
body = ((MethodDeclaration) fEnclosingBodyDeclaration).getBody();
} else if (fEnclosingBodyDeclaration instanceof Initializer) {
body = ((Initializer) fEnclosingBodyDeclaration).getBody();
}
}
if (body != null) {
List<Statement> statements = body.statements();
if (statements.size() > 0) {
fIsLastStatementSelected = nodes[nodes.length - 1] == statements.get(statements.size() - 1);
} else {
fIsLastStatementSelected = true;
}
}
}
}
use of org.eclipse.jdt.core.dom.Initializer in project eclipse.jdt.ls 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;
}
}
Aggregations