Java Code Examples for org.eclipse.jdt.core.dom.TryStatement#RESOURCES_PROPERTY

The following examples show how to use org.eclipse.jdt.core.dom.TryStatement#RESOURCES_PROPERTY . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InlineTempRefactoring.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private RefactoringStatus checkSelection(VariableDeclaration decl) {
	ASTNode parent= decl.getParent();
	if (parent instanceof MethodDeclaration) {
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.InlineTempRefactoring_method_parameter);
	}

	if (parent instanceof CatchClause) {
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.InlineTempRefactoring_exceptions_declared);
	}

	if (parent instanceof VariableDeclarationExpression && parent.getLocationInParent() == ForStatement.INITIALIZERS_PROPERTY) {
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.InlineTempRefactoring_for_initializers);
	}

	if (parent instanceof VariableDeclarationExpression && parent.getLocationInParent() == TryStatement.RESOURCES_PROPERTY) {
		return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.InlineTempRefactoring_resource_in_try_with_resources);
	}

	if (decl.getInitializer() == null) {
		String message= Messages.format(RefactoringCoreMessages.InlineTempRefactoring_not_initialized, BasicElementLabels.getJavaElementName(decl.getName().getIdentifier()));
		return RefactoringStatus.createFatalErrorStatus(message);
	}

	return checkAssignments(decl);
}
 
Example 2
Source File: ExtractMethodAnalyzer.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void endVisit(VariableDeclarationExpression node) {
	if (getSelection().getEndVisitSelectionMode(node) == Selection.SELECTED && getFirstSelectedNode() == node) {
		if (node.getLocationInParent() == TryStatement.RESOURCES_PROPERTY) {
			invalidSelection(RefactoringCoreMessages.ExtractMethodAnalyzer_resource_in_try_with_resources, JavaStatusContext.create(fCUnit, getSelection()));
		}
	}
	checkTypeInDeclaration(node.getType());
	super.endVisit(node);
}
 
Example 3
Source File: AbstractExceptionAnalyzer.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public boolean visit(VariableDeclarationExpression node) {
	if (node.getLocationInParent() == TryStatement.RESOURCES_PROPERTY) {
		Type type = node.getType();
		ITypeBinding resourceTypeBinding = type.resolveBinding();
		if (resourceTypeBinding != null) {
			IMethodBinding methodBinding = Bindings.findMethodInHierarchy(resourceTypeBinding, "close", new ITypeBinding[0]); //$NON-NLS-1$
			if (methodBinding != null) {
				addExceptions(methodBinding.getExceptionTypes(), node.getAST());
			}
		}
	}
	return super.visit(node);
}
 
Example 4
Source File: ExtractMethodAnalyzer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void endVisit(VariableDeclarationExpression node) {
	if (getSelection().getEndVisitSelectionMode(node) == Selection.SELECTED && getFirstSelectedNode() == node) {
		if (node.getLocationInParent() == TryStatement.RESOURCES_PROPERTY) {
			invalidSelection(RefactoringCoreMessages.ExtractMethodAnalyzer_resource_in_try_with_resources, JavaStatusContext.create(fCUnit, getSelection()));
		}
	}
	checkTypeInDeclaration(node.getType());
	super.endVisit(node);
}
 
Example 5
Source File: AbstractExceptionAnalyzer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public boolean visit(VariableDeclarationExpression node) {
	if (node.getLocationInParent() == TryStatement.RESOURCES_PROPERTY) {
		Type type= node.getType();
		ITypeBinding resourceTypeBinding= type.resolveBinding();
		if (resourceTypeBinding != null) {
			IMethodBinding methodBinding= Bindings.findMethodInHierarchy(resourceTypeBinding, "close", new ITypeBinding[0]); //$NON-NLS-1$
			if (methodBinding != null) {
				addExceptions(methodBinding.getExceptionTypes(), node.getAST());
			}
		}
	}
	return super.visit(node);
}