public static IType getSingleSelectedType(IStructuredSelection selection) throws JavaModelException { Object first= selection.getFirstElement(); if (first instanceof IType) return (IType) first; if (first instanceof ICompilationUnit) { final ICompilationUnit unit= (ICompilationUnit) first; if (unit.exists()) return JavaElementUtil.getMainType(unit); } return null; }
public static IType getSingleSelectedType(IStructuredSelection selection) throws JavaModelException { Object first= selection.getFirstElement(); if (first instanceof IType) return (IType) first; if (first instanceof ICompilationUnit) { final ICompilationUnit unit= (ICompilationUnit) first; if (unit.exists()) return JavaElementUtil.getMainType(unit); } return null; }
private IType getDestinationAsType() throws JavaModelException { IJavaElement destination= getJavaElementDestination(); IType enclosingType= getEnclosingType(destination); if (enclosingType != null) return enclosingType; ICompilationUnit enclosingCu= getEnclosingCu(destination); Assert.isNotNull(enclosingCu); IType mainType= JavaElementUtil.getMainType(enclosingCu); Assert.isNotNull(mainType); return mainType; }
public static IType getSingleSelectedType(IStructuredSelection selection) throws JavaModelException { Object first= selection.getFirstElement(); if (first instanceof IType) return (IType) first; if (first instanceof ICompilationUnit) { final ICompilationUnit unit= (ICompilationUnit) first; if (unit.exists()) return JavaElementUtil.getMainType(unit); } return null; }
private static IType getSingleSelectedType(IStructuredSelection selection) throws JavaModelException { if (selection.isEmpty() || selection.size() != 1) return null; Object first= selection.getFirstElement(); if (first instanceof IType) return (IType)first; if (first instanceof ICompilationUnit) return JavaElementUtil.getMainType((ICompilationUnit)first); return null; }
private static IType getSingleSelectedType(IStructuredSelection selection) throws JavaModelException{ if (selection.isEmpty() || selection.size() != 1) return null; Object first= selection.getFirstElement(); if (first instanceof IType) return (IType)first; if (first instanceof ICompilationUnit) return JavaElementUtil.getMainType((ICompilationUnit)first); return null; }
private static IType getSingleSelectedType(IStructuredSelection selection) throws JavaModelException{ if (selection.isEmpty() || selection.size() != 1) return null; Object first= selection.getFirstElement(); if (first instanceof IType) return (IType)first; if (first instanceof ICompilationUnit) return JavaElementUtil.getMainType((ICompilationUnit)first); return null; }
private static IType getSingleSelectedType(IStructuredSelection selection) throws JavaModelException { if (selection.isEmpty() || selection.size() != 1) return null; Object first= selection.getFirstElement(); if (first instanceof IType) return (IType)first; if (first instanceof ICompilationUnit) return JavaElementUtil.getMainType((ICompilationUnit)first); return null; }
private static IType getSingleSelectedType(IStructuredSelection selection) throws JavaModelException { if (selection.isEmpty() || selection.size() != 1) return null; Object first= selection.getFirstElement(); if (first instanceof IType) return (IType)first; if (first instanceof ICompilationUnit) return JavaElementUtil.getMainType((ICompilationUnit)first); return null; }
private static IType getSingleSelectedType(IStructuredSelection selection) throws JavaModelException{ if (selection.isEmpty() || selection.size() != 1) return null; Object first= selection.getFirstElement(); if (first instanceof IType) return (IType)first; if (first instanceof ICompilationUnit) return JavaElementUtil.getMainType((ICompilationUnit)first); return null; }
private ASTNode getDestinationNode(IJavaElement destination, CompilationUnit target) throws JavaModelException { switch (destination.getElementType()) { case IJavaElement.INITIALIZER: return ASTNodeSearchUtil.getInitializerNode((IInitializer) destination, target); case IJavaElement.FIELD: return ASTNodeSearchUtil.getFieldOrEnumConstantDeclaration((IField) destination, target); case IJavaElement.METHOD: return ASTNodeSearchUtil.getMethodOrAnnotationTypeMemberDeclarationNode((IMethod) destination, target); case IJavaElement.TYPE: IType typeDestination= (IType) destination; if (typeDestination.isAnonymous()) { return ASTNodeSearchUtil.getClassInstanceCreationNode(typeDestination, target).getAnonymousClassDeclaration(); } else { return ASTNodeSearchUtil.getAbstractTypeDeclarationNode(typeDestination, target); } case IJavaElement.COMPILATION_UNIT: IType mainType= JavaElementUtil.getMainType((ICompilationUnit) destination); if (mainType != null) { return ASTNodeSearchUtil.getAbstractTypeDeclarationNode(mainType, target); } //$FALL-THROUGH$ default: return null; } }
private ASTNode getDestinationNode(IJavaElement destination, CompilationUnit target) throws JavaModelException { switch (destination.getElementType()) { case IJavaElement.INITIALIZER: return ASTNodeSearchUtil.getInitializerNode((IInitializer) destination, target); case IJavaElement.FIELD: return ASTNodeSearchUtil.getFieldOrEnumConstantDeclaration((IField) destination, target); case IJavaElement.METHOD: return ASTNodeSearchUtil.getMethodOrAnnotationTypeMemberDeclarationNode((IMethod) destination, target); case IJavaElement.TYPE: IType typeDestination= (IType) destination; if (typeDestination.isAnonymous()) { return ASTNodeSearchUtil.getClassInstanceCreationNode(typeDestination, target).getAnonymousClassDeclaration(); } else { return ASTNodeSearchUtil.getAbstractTypeDeclarationNode(typeDestination, target); } case IJavaElement.COMPILATION_UNIT: IType mainType= JavaElementUtil.getMainType((ICompilationUnit) destination); if (mainType != null) { return ASTNodeSearchUtil.getAbstractTypeDeclarationNode(mainType, target); } //$FALL-THROUGH$ default: return null; } }
@Override public void run(IStructuredSelection selection) { try { IField[] selectedFields= getSelectedFields(selection); if (canRunOn(selectedFields)) { run(selectedFields[0].getDeclaringType(), selectedFields, false); return; } Object firstElement= selection.getFirstElement(); if (firstElement instanceof IType) run((IType) firstElement, new IField[0], false); else if (firstElement instanceof ICompilationUnit) run(JavaElementUtil.getMainType((ICompilationUnit) firstElement), new IField[0], false); else if (!(firstElement instanceof IField)) MessageDialog.openInformation(getShell(), DIALOG_TITLE, ActionMessages.AddDelegateMethodsAction_not_applicable); } catch (CoreException e) { ExceptionHandler.handle(e, getShell(), DIALOG_TITLE, ActionMessages.AddDelegateMethodsAction_error_actionfailed); } }
public void run(IStructuredSelection selection) { try { IField[] selectedFields= getSelectedFields(selection); if (canRunOn(selectedFields)) { run(selectedFields[0].getDeclaringType(), selectedFields, false); return; } Object firstElement= selection.getFirstElement(); if (firstElement instanceof IType) run((IType) firstElement, new IField[0], false); else if (firstElement instanceof ICompilationUnit) run(JavaElementUtil.getMainType((ICompilationUnit) firstElement), new IField[0], false); else if (!(firstElement instanceof IField)) MessageDialog.openInformation(getShell(), DIALOG_TITLE, ActionMessages.AddDelegateMethodsAction_not_applicable); } catch (CoreException e) { ExceptionHandler.handle(e, getShell(), DIALOG_TITLE, ActionMessages.AddDelegateMethodsAction_error_actionfailed); } }
@Override public void run(IStructuredSelection selection) { try { IField[] selectedFields= getSelectedFields(selection); if (canRunOn(selectedFields)) { run(selectedFields[0].getDeclaringType(), selectedFields, false); return; } Object firstElement= selection.getFirstElement(); if (firstElement instanceof IType) run((IType) firstElement, new IField[0], false); else if (firstElement instanceof ICompilationUnit) run(JavaElementUtil.getMainType((ICompilationUnit) firstElement), new IField[0], false); else if (!(firstElement instanceof IField)) MessageDialog.openInformation(getShell(), DIALOG_TITLE, ActionMessages.AddDelegateMethodsAction_not_applicable); } catch (CoreException e) { ExceptionHandler.handle(e, getShell(), DIALOG_TITLE, ActionMessages.AddDelegateMethodsAction_error_actionfailed); } }
if (JavaElementUtil.getMainType(destinationCu) == null || !ReorgUtils.hasOnlyElementsOfType(getJavaElements(), new int[] {IJavaElement.FIELD, IJavaElement.INITIALIZER, IJavaElement.METHOD, IJavaElement.TYPE})) return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_cannot);
if (JavaElementUtil.getMainType(destinationCu) == null || !ReorgUtils.hasOnlyElementsOfType(getJavaElements(), new int[] {IJavaElement.FIELD, IJavaElement.INITIALIZER, IJavaElement.METHOD, IJavaElement.TYPE})) return RefactoringStatus.createFatalErrorStatus(RefactoringCoreMessages.ReorgPolicyFactory_cannot);