private static void fillJsTestFileStructure( @NotNull JstdTestFileStructure jsTestFileStructure, @NotNull JSStatement statement) { if (statement instanceof JSExpressionStatement) { JSExpressionStatement jsExpressionStatement = (JSExpressionStatement) statement; JSExpression expressionOfStatement = jsExpressionStatement.getExpression(); if (expressionOfStatement instanceof JSCallExpression) { // TestCase("testCaseName", { test1: function() {} }); JSCallExpression callExpression = (JSCallExpression) expressionOfStatement; createTestCaseStructure(jsTestFileStructure, callExpression); } else if (expressionOfStatement instanceof JSAssignmentExpression) { // testCase = TestCase("testCaseName"); JSAssignmentExpression jsAssignmentExpression = (JSAssignmentExpression) expressionOfStatement; JSCallExpression rOperandCallExpression = ObjectUtils.tryCast(jsAssignmentExpression.getROperand(), JSCallExpression.class); if (rOperandCallExpression != null) { JstdTestCaseStructure testCaseStructure = createTestCaseStructure(jsTestFileStructure, rOperandCallExpression); if (testCaseStructure != null) { JSDefinitionExpression jsDefinitionExpression = ObjectUtils.tryCast( jsAssignmentExpression.getLOperand(), JSDefinitionExpression.class); if (jsDefinitionExpression != null) { JSReferenceExpression jsReferenceExpression = ObjectUtils.tryCast( jsDefinitionExpression.getExpression(), JSReferenceExpression.class); if (jsReferenceExpression != null) { String refName = jsReferenceExpression.getReferencedName(); if (refName != null) { addPrototypeTests(testCaseStructure, refName, jsExpressionStatement); } } } } } } } if (statement instanceof JSVarStatement) { // var testCase = TestCase("testCaseName"); JSVarStatement jsVarStatement = (JSVarStatement) statement; JSVariable[] jsVariables = ObjectUtils.notNull(jsVarStatement.getVariables(), JSVariable.EMPTY_ARRAY); for (JSVariable jsVariable : jsVariables) { JSCallExpression jsCallExpression = ObjectUtils.tryCast(jsVariable.getInitializer(), JSCallExpression.class); if (jsCallExpression != null) { JstdTestCaseStructure testCaseStructure = createTestCaseStructure(jsTestFileStructure, jsCallExpression); if (testCaseStructure != null) { String refName = jsVariable.getQualifiedName(); if (refName != null) { addPrototypeTests(testCaseStructure, refName, jsVarStatement); } } } } } }
@Nullable private static JstdTestCaseStructure createTestCaseStructure( @NotNull JstdTestFileStructure jsTestFileStructure, @NotNull JSCallExpression testCaseCallExpression) { JSReferenceExpression referenceExpression = ObjectUtils.tryCast( testCaseCallExpression.getMethodExpression(), JSReferenceExpression.class); if (referenceExpression != null) { String referenceName = referenceExpression.getReferencedName(); if (TEST_CASE_NAME.equals(referenceName) || ASYNC_TEST_CASE_NAME.equals(referenceName)) { JSExpression[] arguments = JsPsiUtils.getArguments(testCaseCallExpression); if (arguments.length >= 1) { String testCaseName = JsPsiUtils.extractStringValue(arguments[0]); if (testCaseName != null) { JSObjectLiteralExpression testsObjectLiteral = null; if (arguments.length >= 2) { testsObjectLiteral = JsPsiUtils.extractObjectLiteralExpression(arguments[1]); } JstdTestCaseStructure testCaseStructure = new JstdTestCaseStructure( jsTestFileStructure, testCaseName, testCaseCallExpression, testsObjectLiteral); jsTestFileStructure.addTestCaseStructure(testCaseStructure); if (testsObjectLiteral != null) { fillTestCaseStructureByObjectLiteral(testCaseStructure, testsObjectLiteral); } return testCaseStructure; } } } } return null; }
public void setSelected(AnActionEvent e, boolean state) { T change = ObjectUtils.tryCast(e.getData(VcsDataKeys.CURRENT_CHANGE), myClass); if (change == null) return; if (state) { myViewer.includeChange(change); } else { myViewer.excludeChange(change); } }
@Override public void applyTo(@NotNull JstdRunSettings.Builder runSettingsBuilder) { BrowsersConfiguration.BrowserFamily selectedBrowser = ObjectUtils.tryCast( myPreferredDebugBrowserComboBox.getSelectedItem(), BrowsersConfiguration.BrowserFamily.class); if (selectedBrowser != null) { runSettingsBuilder.setPreferredDebugBrowser(selectedBrowser); } }
@Nullable private static BasePathInfo newBasePathInfo(@NotNull CompletionParameters parameters) { YAMLFile yamlFile = ObjectUtils.tryCast(parameters.getOriginalFile(), YAMLFile.class); if (yamlFile != null) { List<YAMLDocument> yamlDocuments = yamlFile.getDocuments(); if (!yamlDocuments.isEmpty()) { return new BasePathInfo(yamlDocuments.get(0)); } } return null; }
private static void addPrototypeTest( @NotNull JstdTestCaseStructure testCaseStructure, @Nullable JSExpression rightAssignmentOperand, @NotNull JSDefinitionExpression wholeLeftDefExpr) { JSReferenceExpression wholeLeftRefExpr = ObjectUtils.tryCast(wholeLeftDefExpr.getExpression(), JSReferenceExpression.class); LeafPsiElement testMethodLeafPsiElement = null; if (wholeLeftRefExpr != null) { testMethodLeafPsiElement = ObjectUtils.tryCast(wholeLeftRefExpr.getReferenceNameElement(), LeafPsiElement.class); } if (testMethodLeafPsiElement != null && testMethodLeafPsiElement.getElementType() == JSTokenTypes.IDENTIFIER) { JSFunctionExpression jsFunctionExpression = JsPsiUtils.extractFunctionExpression(rightAssignmentOperand); JstdTestStructure jstdTestStructure = JstdTestStructure.newPrototypeBasedTestStructure( wholeLeftDefExpr, testMethodLeafPsiElement, jsFunctionExpression); if (jstdTestStructure != null) { testCaseStructure.addTestStructure(jstdTestStructure); } } }
private static void assertResolvesTo( @Nullable PsiReference reference, @NotNull String file, @NotNull String function, int arity) { assertNotNull(reference); ErlangFunction resolvedFunction = ObjectUtils.tryCast(reference.resolve(), ErlangFunction.class); assertNotNull(resolvedFunction); String actualFile = resolvedFunction.getContainingFile().getName(); assertEquals(file, actualFile); assertEquals(function, resolvedFunction.getName()); assertEquals(arity, resolvedFunction.getArity()); }
private static void addBasePathCompletionsIfNeeded( @NotNull CompletionParameters parameters, @NotNull CompletionResultSet result, @NotNull BipartiteString caretBipartiteElementText) { YAMLKeyValue keyValue = ObjectUtils.tryCast(parameters.getPosition().getParent(), YAMLKeyValue.class); if (keyValue != null) { if (keyValue.getParent() instanceof YAMLDocument && BasePathInfo.isBasePathKey(keyValue)) { BasePathInfo basePathInfo = newBasePathInfo(parameters); if (basePathInfo != null) { VirtualFile configDir = basePathInfo.getConfigDir(); if (configDir != null) { addPathCompletions(result, caretBipartiteElementText, configDir, true); } } } } }
private void paintOnComponentUnderViewport(Component component, Graphics g) { JBViewport viewport = ObjectUtils.tryCast(myOwner, JBViewport.class); if (viewport == null || viewport.getView() != component || viewport.isPaintingNow()) return; // We're painting a component which has a viewport as it's ancestor. // As the viewport paints status text, we'll erase it, so we need to schedule a repaint for the // viewport with status text's bounds. // But it causes flicker, so we paint status text over the component first and then schedule the // viewport repaint. Rectangle textBoundsInViewport = getTextComponentBound(); int xInOwner = textBoundsInViewport.x - component.getX(); int yInOwner = textBoundsInViewport.y - component.getY(); Rectangle textBoundsInOwner = new Rectangle(xInOwner, yInOwner, textBoundsInViewport.width, textBoundsInViewport.height); doPaintStatusText(g, textBoundsInOwner); viewport.repaint(textBoundsInViewport); }
private static void addTopLevelKeysCompletionIfNeeded( @NotNull CompletionParameters parameters, @NotNull CompletionResultSet result, @NotNull BipartiteString caretBipartiteElementText) { PsiElement element = parameters.getPosition(); YAMLDocument yamlDocument = ObjectUtils.tryCast(element.getParent(), YAMLDocument.class); if (yamlDocument == null) { yamlDocument = JstdConfigFileUtils.getVerifiedHierarchyHead( element.getParent(), new Class[] {YAMLKeyValue.class}, YAMLDocument.class); } if (yamlDocument != null) { String prefix = caretBipartiteElementText.getPrefix(); result = result.withPrefixMatcher(prefix); for (String key : JstdConfigFileUtils.VALID_TOP_LEVEL_KEYS) { if (key.startsWith(prefix)) { result.addElement(LookupItem.fromString(key + ":")); } } } }
@NotNull protected ChangesSelection getChangesSelection() { final Change leadSelection = ObjectUtils.tryCast(myViewer.getLeadSelection(), Change.class); List<Change> changes = getSelectedChanges(); if (changes.size() < 2) { List<Change> allChanges = getAllChanges(); if (allChanges.size() > 1 || changes.isEmpty()) { changes = allChanges; } } if (leadSelection != null) { int indexInSelection = changes.indexOf(leadSelection); if (indexInSelection == -1) { return new ChangesSelection(Collections.singletonList(leadSelection), 0); } else { return new ChangesSelection(changes, indexInSelection); } } else { return new ChangesSelection(changes, 0); } }
public void calcData(DataKey key, DataSink sink) { if (key == VcsDataKeys.CHANGES) { List<Change> list = getSelectedChanges(); if (list.isEmpty()) list = getAllChanges(); sink.put(VcsDataKeys.CHANGES, list.toArray(new Change[list.size()])); } else if (key == VcsDataKeys.CHANGES_SELECTION) { sink.put(VcsDataKeys.CHANGES_SELECTION, getChangesSelection()); } else if (key == VcsDataKeys.CHANGE_LISTS) { sink.put(VcsDataKeys.CHANGE_LISTS, getSelectedChangeLists()); } else if (key == VcsDataKeys.CHANGE_LEAD_SELECTION) { final Change highestSelection = ObjectUtils.tryCast(myViewer.getHighestLeadSelection(), Change.class); sink.put( VcsDataKeys.CHANGE_LEAD_SELECTION, (highestSelection == null) ? new Change[] {} : new Change[] {highestSelection}); } else if (key == CommonDataKeys.VIRTUAL_FILE_ARRAY) { sink.put(CommonDataKeys.VIRTUAL_FILE_ARRAY, getSelectedFiles().toArray(VirtualFile[]::new)); } else if (key == CommonDataKeys.NAVIGATABLE_ARRAY) { sink.put( CommonDataKeys.NAVIGATABLE_ARRAY, getNavigatableArray(myProject, getSelectedFiles())); } else if (VcsDataKeys.IO_FILE_ARRAY.equals(key)) { sink.put(VcsDataKeys.IO_FILE_ARRAY, getSelectedIoFiles()); } else if (key == DATA_KEY) { sink.put(DATA_KEY, this); } else if (VcsDataKeys.SELECTED_CHANGES_IN_DETAILS.equals(key)) { final List<Change> selectedChanges = getSelectedChanges(); sink.put( VcsDataKeys.SELECTED_CHANGES_IN_DETAILS, selectedChanges.toArray(new Change[selectedChanges.size()])); } else if (UNVERSIONED_FILES_DATA_KEY.equals(key)) { sink.put( UNVERSIONED_FILES_DATA_KEY, getVirtualFiles(myViewer.getSelectionPaths(), UNVERSIONED_FILES_TAG)); } else if (PlatformDataKeys.DELETE_ELEMENT_PROVIDER.equals(key)) { sink.put(PlatformDataKeys.DELETE_ELEMENT_PROVIDER, myDeleteProvider); } }
private static void addPrototypeTests( @NotNull JstdTestCaseStructure testCaseStructure, @NotNull String referenceName, @NotNull JSStatement refStatement) { List<JSStatement> statements = JsPsiUtils.listStatementsInExecutionOrderNextTo(refStatement); for (JSStatement statement : statements) { JSExpressionStatement expressionStatement = ObjectUtils.tryCast(statement, JSExpressionStatement.class); if (expressionStatement != null) { JSAssignmentExpression assignmentExpr = ObjectUtils.tryCast(expressionStatement.getExpression(), JSAssignmentExpression.class); if (assignmentExpr != null) { JSDefinitionExpression wholeLeftDefExpr = ObjectUtils.tryCast(assignmentExpr.getLOperand(), JSDefinitionExpression.class); if (wholeLeftDefExpr != null) { JSReferenceExpression wholeLeftRefExpr = ObjectUtils.tryCast(wholeLeftDefExpr.getExpression(), JSReferenceExpression.class); if (wholeLeftRefExpr != null) { JSReferenceExpression testCaseAndPrototypeRefExpr = ObjectUtils.tryCast(wholeLeftRefExpr.getQualifier(), JSReferenceExpression.class); if (testCaseAndPrototypeRefExpr != null) { if ("prototype".equals(testCaseAndPrototypeRefExpr.getReferencedName())) { JSReferenceExpression testCaseRefExpr = ObjectUtils.tryCast( testCaseAndPrototypeRefExpr.getQualifier(), JSReferenceExpression.class); if (testCaseRefExpr != null && testCaseRefExpr.getQualifier() == null) { if (referenceName.equals(testCaseRefExpr.getReferencedName())) { addPrototypeTest( testCaseStructure, assignmentExpr.getROperand(), wholeLeftDefExpr); } } } } } } } } } }
@Nullable private Point createToolTipImage(@NotNull KeyType key) { UIUtil.putClientProperty(myComponent, EXPANDED_RENDERER, true); Pair<Component, Rectangle> rendererAndBounds = getCellRendererAndBounds(key); UIUtil.putClientProperty(myComponent, EXPANDED_RENDERER, null); if (rendererAndBounds == null) return null; JComponent renderer = ObjectUtils.tryCast(rendererAndBounds.first, JComponent.class); if (renderer == null) return null; if (renderer.getClientProperty(DISABLE_EXPANDABLE_HANDLER) != null) return null; if (UIUtil.getClientProperty((JComponent) rendererAndBounds.getFirst(), USE_RENDERER_BOUNDS) == Boolean.TRUE) { rendererAndBounds.getSecond().translate(renderer.getX(), renderer.getY()); rendererAndBounds.getSecond().setSize(renderer.getSize()); } myKeyItemBounds = rendererAndBounds.second; Rectangle cellBounds = myKeyItemBounds; Rectangle visibleRect = getVisibleRect(key); if (cellBounds.y < visibleRect.y) return null; int cellMaxY = cellBounds.y + cellBounds.height; int visMaxY = visibleRect.y + visibleRect.height; if (cellMaxY > visMaxY) return null; int cellMaxX = cellBounds.x + cellBounds.width; int visMaxX = visibleRect.x + visibleRect.width; Point location = new Point(visMaxX, cellBounds.y); SwingUtilities.convertPointToScreen(location, myComponent); Rectangle screen = !Registry.is("ide.expansion.hints.on.all.screens") ? ScreenUtil.getScreenRectangle(location) : ScreenUtil.getAllScreensRectangle(); int borderWidth = isPaintBorder() ? 1 : 0; int width = Math.min(screen.width + screen.x - location.x - borderWidth, cellMaxX - visMaxX); int height = cellBounds.height; if (width <= 0 || height <= 0) return null; Dimension size = getImageSize(width, height); myImage = UIUtil.createImage(size.width, size.height, BufferedImage.TYPE_INT_RGB); Graphics2D g = myImage.createGraphics(); g.setClip(null); doFillBackground(height, width, g); g.translate(cellBounds.x - visMaxX, 0); doPaintTooltipImage(renderer, cellBounds, g, key); CustomLineBorder border = null; if (borderWidth > 0) { border = new CustomLineBorder(getBorderColor(), borderWidth, 0, borderWidth, borderWidth); location.y -= borderWidth; size.width += borderWidth; size.height += borderWidth + borderWidth; } g.dispose(); myRendererPane.remove(renderer); myTipComponent.setBorder(border); myTipComponent.setPreferredSize(size); return location; }
public boolean isSelected(AnActionEvent e) { T change = ObjectUtils.tryCast(e.getData(VcsDataKeys.CURRENT_CHANGE), myClass); if (change == null) return false; return myViewer.isIncluded(change); }