Java Code Examples for org.eclipse.core.runtime.Assert#isNotNull()
The following examples show how to use
org.eclipse.core.runtime.Assert#isNotNull() .
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: AccessAnalyzer.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
public AccessAnalyzer(SelfEncapsulateFieldRefactoring refactoring, ICompilationUnit unit, IVariableBinding field, ITypeBinding declaringClass, ASTRewrite rewriter, ImportRewrite importRewrite) { Assert.isNotNull(refactoring); Assert.isNotNull(unit); Assert.isNotNull(field); Assert.isNotNull(declaringClass); Assert.isNotNull(rewriter); Assert.isNotNull(importRewrite); fCUnit = unit; fFieldBinding = field.getVariableDeclaration(); fDeclaringClassBinding = declaringClass; fRewriter = rewriter; fImportRewriter = importRewrite; fGroupDescriptions = new ArrayList<>(); fGetter = refactoring.getGetterName(); fSetter = refactoring.getSetterName(); fEncapsulateDeclaringClass = refactoring.getEncapsulateDeclaringClass(); try { fIsFieldFinal = Flags.isFinal(refactoring.getField().getFlags()); } catch (JavaModelException e) { // assume non final field } fStatus = new RefactoringStatus(); }
Example 2
Source File: CoreSwtbotTools.java From dsl-devkit with Eclipse Public License 1.0 | 6 votes |
/** * Enforces the workbench focus policy. * <p> * <em>Note</em>: Depending on {@link CoreSwtbotTools#getWorkbenchFocusPolicy()}, this method waits until the window under test has focus before returning, or * else re-sets the focus on the window. * </p> * * @param bot * the {@link SwtWorkbenchBot} for which to check the focus, must not be {@code null} */ public static void enforceWorkbenchFocusPolicy(final SwtWorkbenchBot bot) { Assert.isNotNull(bot, ARGUMENT_BOT); if (bot.getFocusedWidget() == null) { if (WorkbenchFocusPolicy.WAIT == getWorkbenchFocusPolicy()) { bot.waitUntilFocused(); } else if (WorkbenchFocusPolicy.REFOCUS == getWorkbenchFocusPolicy()) { PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() { /** {@inheritDoc} */ @Override public void run() { final Shell[] shells = PlatformUI.getWorkbench().getDisplay().getShells(); if (shells.length > 0) { shells[0].forceActive(); } } }); } } }
Example 3
Source File: ModulaContextualCompletionProposal.java From xds-ide with Eclipse Public License 1.0 | 6 votes |
/** * Creates a new completion proposal. All fields are initialized based on the provided information. * * @param replacementString the actual string to be inserted into the document * @param replacementOffset the offset of the text to be replaced * @param replacementLength the length of the text to be replaced * @param cursorPosition the position of the cursor following the insert relative to replacementOffset * @param image the image to display for this proposal * @param displayString the string to be displayed for the proposal * @param contextInformation the context information associated with this proposal * @param additionalProposalInfo the additional information associated with this proposal */ public ModulaContextualCompletionProposal(String replacementString, int replacementOffset, int replacementLength, int cursorPosition, Image image, StyledString displaySString, IContextInformation contextInformation, String additionalProposalInfo) { Assert.isNotNull(replacementString); Assert.isTrue(replacementOffset >= 0); Assert.isTrue(replacementLength >= 0); Assert.isTrue(cursorPosition >= 0); fReplacementString= replacementString; fReplacementOffset= replacementOffset; fReplacementLength= replacementLength; fCursorPosition= cursorPosition; fImage= image; fDisplaySString= displaySString; fContextInformation= contextInformation; fAdditionalProposalInfo= additionalProposalInfo; }
Example 4
Source File: TLCModelFactory.java From tlaplus with MIT License | 6 votes |
public static Model getBy(final IFile aFile) { Assert.isNotNull(aFile); final ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager(); final ILaunchConfigurationType launchConfigurationType = launchManager .getLaunchConfigurationType(TLCModelLaunchDelegate.LAUNCH_CONFIGURATION_TYPE); try { final ILaunchConfiguration[] launchConfigurations = launchManager.getLaunchConfigurations(launchConfigurationType); for (int i = 0; i < launchConfigurations.length; i++) { final ILaunchConfiguration launchConfiguration = launchConfigurations[i]; if (aFile.equals(launchConfiguration.getFile())) { return launchConfiguration.getAdapter(Model.class); } } } catch (CoreException shouldNeverHappen) { shouldNeverHappen.printStackTrace(); } return null; }
Example 5
Source File: CoreSwtbotTools.java From dsl-devkit with Eclipse Public License 1.0 | 6 votes |
/** * Open view. * * @param bot * to work with, must not be {@code null} * @param category * the category, must not be {@code null} * @param view * the name of the view, must not be {@code null} */ public static void openView(final SWTWorkbenchBot bot, final String category, final String view) { Assert.isNotNull(bot, ARGUMENT_BOT); Assert.isNotNull(category, "category"); Assert.isNotNull(view, ARGUMENT_VIEW); bot.menu("Window").menu("Show View").menu("Other...").click(); bot.shell("Show View").activate(); final SWTBotTree tree = bot.tree(); for (SWTBotTreeItem item : tree.getAllItems()) { if (category.equals(item.getText())) { CoreSwtbotTools.waitForItem(bot, item); final SWTBotTreeItem[] node = item.getItems(); for (SWTBotTreeItem swtBotTreeItem : node) { if (view.equals(swtBotTreeItem.getText())) { swtBotTreeItem.select(); } } } } assertTrue("View or Category found", bot.button().isEnabled()); bot.button("OK").click(); }
Example 6
Source File: ChangePublicToProtectedResolution.java From spotbugs with GNU Lesser General Public License v2.1 | 5 votes |
@Override protected void repairBug(ASTRewrite rewrite, CompilationUnit workingUnit, BugInstance bug) throws BugResolutionException { Assert.isNotNull(rewrite); Assert.isNotNull(workingUnit); Assert.isNotNull(bug); TypeDeclaration type = getTypeDeclaration(workingUnit, bug.getPrimaryClass()); MethodDeclaration method = getMethodDeclaration(type, bug.getPrimaryMethod()); Modifier originalModifier = getPublicModifier(method); ListRewrite listRewrite = rewrite.getListRewrite(method, MethodDeclaration.MODIFIERS2_PROPERTY); Modifier protectedModifier = workingUnit.getAST().newModifier(PROTECTED_KEYWORD); listRewrite.replace(originalModifier, protectedModifier, null); }
Example 7
Source File: RenameTypeParameterProcessor.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
@Override public Change createChange(IProgressMonitor monitor) throws CoreException, OperationCanceledException { Assert.isNotNull(monitor); try { Change change= fChange; if (change != null) { String project= null; IJavaProject javaProject= fTypeParameter.getJavaProject(); if (javaProject != null) { project= javaProject.getElementName(); } String description= Messages.format(RefactoringCoreMessages.RenameTypeParameterProcessor_descriptor_description_short, BasicElementLabels.getJavaElementName(fTypeParameter.getElementName())); String header= Messages.format(RefactoringCoreMessages.RenameTypeParameterProcessor_descriptor_description, new String[] { BasicElementLabels.getJavaElementName(fTypeParameter.getElementName()), JavaElementLabels.getElementLabel(fTypeParameter.getDeclaringMember(), JavaElementLabels.ALL_FULLY_QUALIFIED), BasicElementLabels.getJavaElementName(getNewElementName())}); String comment= new JDTRefactoringDescriptorComment(project, this, header).asString(); RenameJavaElementDescriptor descriptor= RefactoringSignatureDescriptorFactory.createRenameJavaElementDescriptor(IJavaRefactorings.RENAME_TYPE_PARAMETER); descriptor.setProject(project); descriptor.setDescription(description); descriptor.setComment(comment); descriptor.setFlags(RefactoringDescriptor.NONE); descriptor.setJavaElement(fTypeParameter); descriptor.setNewName(getNewElementName()); descriptor.setUpdateReferences(fUpdateReferences); change= new DynamicValidationRefactoringChange(descriptor, RefactoringCoreMessages.RenameTypeParameterProcessor_change_name, new Change[] { change}); } return change; } finally { fChange= null; monitor.done(); } }
Example 8
Source File: RenameAnalyzeUtil.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
/** * This method analyzes a set of local variable renames inside one cu. It checks whether * any new compile errors have been introduced by the rename(s) and whether the correct * node(s) has/have been renamed. * * @param analyzePackages the LocalAnalyzePackages containing the information about the local renames * @param cuChange the TextChange containing all local variable changes to be applied. * @param oldCUNode the fully (incl. bindings) resolved AST node of the original compilation unit * @param recovery whether statements and bindings recovery should be performed when parsing the changed CU * @return a RefactoringStatus containing errors if compile errors or wrongly renamed nodes are found * @throws CoreException thrown if there was an error greating the preview content of the change */ public static RefactoringStatus analyzeLocalRenames(LocalAnalyzePackage[] analyzePackages, TextChange cuChange, CompilationUnit oldCUNode, boolean recovery) throws CoreException { RefactoringStatus result= new RefactoringStatus(); ICompilationUnit compilationUnit= (ICompilationUnit) oldCUNode.getJavaElement(); String newCuSource= cuChange.getPreviewContent(new NullProgressMonitor()); CompilationUnit newCUNode= new RefactoringASTParser(IASTSharedValues.SHARED_AST_LEVEL).parse(newCuSource, compilationUnit, true, recovery, null); result.merge(analyzeCompileErrors(newCuSource, newCUNode, oldCUNode)); if (result.hasError()) { return result; } for (int i= 0; i < analyzePackages.length; i++) { ASTNode enclosing= getEnclosingBlockOrMethodOrLambda(analyzePackages[i].fDeclarationEdit, cuChange, newCUNode); // get new declaration IRegion newRegion= RefactoringAnalyzeUtil.getNewTextRange(analyzePackages[i].fDeclarationEdit, cuChange); ASTNode newDeclaration= NodeFinder.perform(newCUNode, newRegion.getOffset(), newRegion.getLength()); Assert.isTrue(newDeclaration instanceof Name); VariableDeclaration declaration= getVariableDeclaration((Name) newDeclaration); Assert.isNotNull(declaration); SimpleName[] problemNodes= ProblemNodeFinder.getProblemNodes(enclosing, declaration, analyzePackages[i].fOccurenceEdits, cuChange); result.merge(RefactoringAnalyzeUtil.reportProblemNodes(newCuSource, problemNodes)); } return result; }
Example 9
Source File: DelegateCreator.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
/** * Prepares the delegate member. The delegate member will have the same * signature as the old member and contain a call to the new member and a * javadoc reference with a reference to the new member. * * All references to the new member will contain the new name of the member * and/or new declaring type, if any. * */ public void prepareDelegate() throws JavaModelException { Assert.isNotNull(fDelegateRewrite); Assert.isNotNull(fDeclaration); initialize(); // Moving to a new type? if (fDestinationTypeBinding != null) { fDestinationType= fOriginalRewrite.getImportRewrite().addImport(fDestinationTypeBinding, getAst()); fIsMoveToAnotherFile= true; } else { fIsMoveToAnotherFile= false; } fTrackedPosition= fDelegateRewrite.getASTRewrite().track(fDeclaration); ASTNode delegateBody= createBody(fDeclaration); if (delegateBody != null) { // is null for interface and abstract methods fDelegateRewrite.getASTRewrite().set(getBodyHead(fDeclaration), getBodyProperty(), delegateBody, null); } if (fDeclareDeprecated) { createJavadoc(); } }
Example 10
Source File: ASTUtil.java From spotbugs with GNU Lesser General Public License v2.1 | 5 votes |
@CheckForNull protected static Statement searchStatement(CompilationUnit compilationUnit, List<?> statements, int startLine, int endLine) { Assert.isNotNull(compilationUnit); Assert.isNotNull(statements); for (Object statementObj : statements) { Statement statement = (Statement) statementObj; int lineNumber = compilationUnit.getLineNumber(statement.getStartPosition()); if (startLine <= lineNumber && lineNumber <= endLine) { return statement; } } return null; }
Example 11
Source File: DelegateCreator.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
private TagElement createJavadocMemberReferenceTag(BodyDeclaration declaration, final AST ast) throws JavaModelException { Assert.isNotNull(ast); Assert.isNotNull(declaration); ASTNode javadocReference= createDocReference(declaration); final TagElement element= ast.newTagElement(); element.setTagName(TagElement.TAG_LINK); element.fragments().add(javadocReference); return element; }
Example 12
Source File: JDTUtils.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
/** * {@code true} if the element is deprecated. Otherwise, {@code false}. */ public static boolean isDeprecated(IJavaElement element) throws JavaModelException { Assert.isNotNull(element, "element"); if (element instanceof ITypeRoot) { return Flags.isDeprecated(((ITypeRoot) element).findPrimaryType().getFlags()); } else if (element instanceof IMember) { return Flags.isDeprecated(((IMember) element).getFlags()); } return false; }
Example 13
Source File: XdsProject.java From xds-ide with Eclipse Public License 1.0 | 5 votes |
@Override public synchronized void refreshExternalDependencies() { Assert.isNotNull(children); removeExternalDependenciesNode(); buildExternalDependenciesChildren(); }
Example 14
Source File: CoreSwtbotTools.java From dsl-devkit with Eclipse Public License 1.0 | 5 votes |
/** * Switching to a new Perspective. * * @param bot * to work with, must not be {@code null} * @param perspective * the new perspective to open, must not be {@code null} */ public static void switchPerspective(final SWTWorkbenchBot bot, final String perspective) { Assert.isNotNull(bot, ARGUMENT_BOT); Assert.isNotNull(perspective, "perspective"); // Change the perspective via the Open Perspective dialog bot.menu("Window").menu("Open Perspective").menu("Other...").click(); final SWTBotShell shell = bot.shell("Open Perspective"); shell.activate(); // select the dialog bot.table().select(perspective); bot.button("OK").click(); }
Example 15
Source File: CopyModifications.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
private void add(Object element, RefactoringArguments args, IParticipantDescriptorFilter filter) { Assert.isNotNull(element); Assert.isNotNull(args); fCopies.add(element); fCopyArguments.add(args); fParticipantDescriptorFilter.add(filter); }
Example 16
Source File: XtextSourceViewer.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
/** * copied from org.eclipse.jdt.internal.ui.javaeditor.JavaSourceViewer.prependTextPresentationListener(ITextPresentationListener) */ public void prependTextPresentationListener(ITextPresentationListener listener) { Assert.isNotNull(listener); if (fTextPresentationListeners == null) fTextPresentationListeners= new ArrayList<ITextPresentationListener>(); fTextPresentationListeners.remove(listener); fTextPresentationListeners.add(0, listener); }
Example 17
Source File: JavaMoveProcessor.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 4 votes |
public void setReorgQueries(IReorgQueries queries) { Assert.isNotNull(queries); fReorgQueries= queries; }
Example 18
Source File: RefactoringWizardOpenOperation_NonForking.java From xtext-eclipse with Eclipse Public License 2.0 | 4 votes |
/** * @see RefactoringWizardOpenOperation#RefactoringWizardOpenOperation */ public RefactoringWizardOpenOperation_NonForking(RefactoringWizard wizard) { Assert.isNotNull(wizard); fWizard = wizard; }
Example 19
Source File: RenameTypeParameterProcessor.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 3 votes |
/** * Creates a new rename type parameter visitor. * * @param rewrite * the compilation unit rewrite to use * @param range * the source range of the type parameter * @param status * the status to update */ public RenameTypeParameterVisitor(CompilationUnitRewrite rewrite, ISourceRange range, RefactoringStatus status) { Assert.isNotNull(rewrite); Assert.isNotNull(range); Assert.isNotNull(status); fRewrite= rewrite; fName= (SimpleName) NodeFinder.perform(rewrite.getRoot(), range); fBinding= fName.resolveBinding(); fStatus= status; }
Example 20
Source File: AbstractScopingTest.java From dsl-devkit with Eclipse Public License 1.0 | 2 votes |
/** * Checks if the given objects are in scope of the given reference for the given context. * * @param context * {@link EObject} element from which an element shall be referenced, must not be {@code null} * @param reference * the structural feature of {@code context} for which the scope should be asserted, must not be {@code null} and part of the context element * @param expectedObjects * for given scope, must not be {@code null} */ protected void assertScopedObjects(final EObject context, final EReference reference, final EObject... expectedObjects) { Assert.isNotNull(expectedObjects, PARAMETER_EXPECTED_OBJECTS); assertScopedObjects(context, reference, Lists.newArrayList(expectedObjects)); }