com.intellij.psi.util.PsiUtilCore Java Examples

The following examples show how to use com.intellij.psi.util.PsiUtilCore. 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: ProjectViewImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void deleteElement(@Nonnull DataContext dataContext) {
  List<PsiElement> allElements = Arrays.asList(getElementsToDelete());
  List<PsiElement> validElements = new ArrayList<>();
  for (PsiElement psiElement : allElements) {
    if (psiElement != null && psiElement.isValid()) validElements.add(psiElement);
  }
  final PsiElement[] elements = PsiUtilCore.toPsiElementArray(validElements);

  LocalHistoryAction a = LocalHistory.getInstance().startAction(IdeBundle.message("progress.deleting"));
  try {
    DeleteHandler.deletePsiElement(elements, myProject);
  }
  finally {
    a.finish();
  }
}
 
Example #2
Source File: RTMergerTreeStructureProvider.java    From react-templates-plugin with MIT License 6 votes vote down vote up
private static PsiElement[] collectFormPsiElements(Collection<AbstractTreeNode> selected) {
    Set<PsiElement> result = new HashSet<PsiElement>();
    for (AbstractTreeNode node : selected) {
        if (node.getValue() instanceof RTFile) {
            RTFile form = (RTFile) node.getValue();
            result.add(form.getRtjsFile());
            if (form.getController() != null) {
                result.add(form.getController());
            }
            ContainerUtil.addAll(result, form.getRtFile());
        } else if (node.getValue() instanceof PsiElement) {
            result.add((PsiElement) node.getValue());
        }
    }
    return PsiUtilCore.toPsiElementArray(result);
}
 
Example #3
Source File: PsiElementRenameHandler.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static void invoke(PsiElement element, Project project, PsiElement nameSuggestionContext, @Nullable Editor editor) {
  if (element != null && !canRename(project, editor, element)) {
    return;
  }

  VirtualFile contextFile = PsiUtilCore.getVirtualFile(nameSuggestionContext);

  if (nameSuggestionContext != null &&
      nameSuggestionContext.isPhysical() &&
      (contextFile == null || !ScratchUtil.isScratch(contextFile) && !PsiManager.getInstance(project).isInProject(nameSuggestionContext))) {
    final String message = "Selected element is used from non-project files. These usages won't be renamed. Proceed anyway?";
    if (ApplicationManager.getApplication().isUnitTestMode()) throw new CommonRefactoringUtil.RefactoringErrorHintException(message);
    if (Messages.showYesNoDialog(project, message, RefactoringBundle.getCannotRefactorMessage(null), Messages.getWarningIcon()) != Messages.YES) {
      return;
    }
  }

  FeatureUsageTracker.getInstance().triggerFeatureUsed("refactoring.rename");

  rename(element, project, nameSuggestionContext, editor);
}
 
Example #4
Source File: LocalSearchScope.java    From consulo with Apache License 2.0 6 votes vote down vote up
public LocalSearchScope(@Nonnull PsiElement[] scope, @Nullable final String displayName, final boolean ignoreInjectedPsi) {
  myIgnoreInjectedPsi = ignoreInjectedPsi;
  myDisplayName = displayName;
  Set<PsiElement> localScope = new LinkedHashSet<PsiElement>(scope.length);

  for (final PsiElement element : scope) {
    LOG.assertTrue(element != null, "null element");
    LOG.assertTrue(element.getContainingFile() != null, element.getClass().getName());
    if (element instanceof PsiFile) {
      List<PsiFile> files = ((PsiFile)element).getViewProvider().getAllFiles();
      ContainerUtil.addAll(localScope, files);
    }
    else {
      localScope.add(element);
    }
  }
  myScope = PsiUtilCore.toPsiElementArray(localScope);
}
 
Example #5
Source File: RTMergerTreeStructureProvider.java    From react-templates-plugin with MIT License 6 votes vote down vote up
private static PsiElement[] collectFormPsiElements(Collection<AbstractTreeNode> selected) {
    Set<PsiElement> result = new HashSet<PsiElement>();
    for (AbstractTreeNode node : selected) {
        if (node.getValue() instanceof RTFile) {
            RTFile form = (RTFile) node.getValue();
            result.add(form.getRtjsFile());
            if (form.getController() != null) {
                result.add(form.getController());
            }
            ContainerUtil.addAll(result, form.getRtFile());
        } else if (node.getValue() instanceof PsiElement) {
            result.add((PsiElement) node.getValue());
        }
    }
    return PsiUtilCore.toPsiElementArray(result);
}
 
Example #6
Source File: CustomTemplateCallback.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
public static PsiElement getContext(@Nonnull PsiFile file, int offset, boolean searchInInjectedFragment) {
  PsiElement element = null;
  if (searchInInjectedFragment && !InjectedLanguageManager.getInstance(file.getProject()).isInjectedFragment(file)) {
    PsiDocumentManager documentManager = PsiDocumentManager.getInstance(file.getProject());
    Document document = documentManager.getDocument(file);
    if (document != null && !documentManager.isCommitted(document)) {
      LOGGER.error("Trying to access to injected template context on uncommited document, offset = " + offset, AttachmentFactory.createAttachment(file.getVirtualFile()));
    }
    else {
      element = InjectedLanguageManager.getInstance(file.getProject()).findInjectedElementAt(file, offset);
    }
  }
  if (element == null) {
    element = PsiUtilCore.getElementAtOffset(file, offset);
  }
  return element;
}
 
Example #7
Source File: RTMergerTreeStructureProvider.java    From react-templates-plugin with MIT License 6 votes vote down vote up
private static PsiElement[] collectFormPsiElements(Collection<AbstractTreeNode> selected) {
    Set<PsiElement> result = new HashSet<PsiElement>();
    for (AbstractTreeNode node : selected) {
        if (node.getValue() instanceof RTFile) {
            RTFile form = (RTFile) node.getValue();
            result.add(form.getRtjsFile());
            if (form.getController() != null) {
                result.add(form.getController());
            }
            ContainerUtil.addAll(result, form.getRtFile());
        } else if (node.getValue() instanceof PsiElement) {
            result.add((PsiElement) node.getValue());
        }
    }
    return PsiUtilCore.toPsiElementArray(result);
}
 
Example #8
Source File: ErrorFilter.java    From intellij-latte with MIT License 6 votes vote down vote up
public boolean shouldHighlightErrorElement(@NotNull PsiErrorElement element) {
	PsiFile templateLanguageFile = PsiUtilCore.getTemplateLanguageFile(element.getContainingFile());
	if (templateLanguageFile == null) {
		return true;
	}
	Language language = templateLanguageFile.getLanguage();
	if (language != LatteLanguage.INSTANCE) {
		return true;
	}
	if (element.getParent() instanceof XmlElement || element.getParent() instanceof CssElement) {
		return false;
	}
	if (element.getParent().getLanguage() == LatteLanguage.INSTANCE) {
		return true;
	}
	PsiElement nextSibling;
	for (nextSibling = PsiTreeUtil.nextLeaf(element); nextSibling instanceof PsiWhiteSpace; nextSibling = nextSibling.getNextSibling());

	PsiElement psiElement = nextSibling == null ? null : PsiTreeUtil.findCommonParent(nextSibling, element);
	boolean nextIsOuterLanguageElement = nextSibling instanceof OuterLanguageElement || nextSibling instanceof LatteMacroClassic;
	return !nextIsOuterLanguageElement || psiElement == null || psiElement instanceof PsiFile;
}
 
Example #9
Source File: BashPsiUtils.java    From BashSupport with Apache License 2.0 6 votes vote down vote up
public static PsiElement findPreviousSibling(PsiElement start, IElementType ignoreType) {
    if (start == null) {
        return null;
    }

    PsiElement current = start.getPrevSibling();
    while (current != null) {
        if (ignoreType != PsiUtilCore.getElementType(current)) {
            return current;
        }

        current = current.getPrevSibling();
    }

    return null;
}
 
Example #10
Source File: BashPsiUtils.java    From BashSupport with Apache License 2.0 6 votes vote down vote up
public static PsiElement findNextSibling(PsiElement start, IElementType ignoreType) {
    if (start == null) {
        return null;
    }

    PsiElement current = start.getNextSibling();
    while (current != null) {
        if (ignoreType != PsiUtilCore.getElementType(current)) {
            return current;
        }

        current = current.getNextSibling();
    }

    return null;
}
 
Example #11
Source File: EditSourceUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nullable
public static Navigatable getDescriptor(final PsiElement element) {
  if (!canNavigate(element)) {
    return null;
  }
  if (element instanceof PomTargetPsiElement) {
    return ((PomTargetPsiElement)element).getTarget();
  }
  final PsiElement navigationElement = element.getNavigationElement();
  if (navigationElement instanceof PomTargetPsiElement) {
    return ((PomTargetPsiElement)navigationElement).getTarget();
  }
  final int offset = navigationElement instanceof PsiFile ? -1 : navigationElement.getTextOffset();
  final VirtualFile virtualFile = PsiUtilCore.getVirtualFile(navigationElement);
  if (virtualFile == null || !virtualFile.isValid()) {
    return null;
  }
  OpenFileDescriptor desc = new OpenFileDescriptor(navigationElement.getProject(), virtualFile, offset);
  desc.setUseCurrentWindow(FileEditorManager.USE_CURRENT_WINDOW.isIn(navigationElement));
  return desc;
}
 
Example #12
Source File: Trees.java    From antlr4-intellij-adaptor with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/** Get all non-WS, non-Comment children of t */
@NotNull
public static PsiElement[] getChildren(PsiElement t) {
	if ( t==null ) return PsiElement.EMPTY_ARRAY;

	PsiElement psiChild = t.getFirstChild();
	if (psiChild == null) return PsiElement.EMPTY_ARRAY;

	List<PsiElement> result = new ArrayList<>();
	while (psiChild != null) {
		if ( !(psiChild instanceof PsiComment) &&
			 !(psiChild instanceof PsiWhiteSpace) )
		{
			result.add(psiChild);
		}
		psiChild = psiChild.getNextSibling();
	}
	return PsiUtilCore.toPsiElementArray(result);
}
 
Example #13
Source File: PsiDirectoryImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
@Nonnull
public PsiElement[] getChildren() {
  checkValid();

  VirtualFile[] files = myFile.getChildren();
  final ArrayList<PsiElement> children = new ArrayList<PsiElement>(files.length);
  processChildren(new PsiElementProcessor<PsiFileSystemItem>() {
    @Override
    public boolean execute(@Nonnull final PsiFileSystemItem element) {
      children.add(element);
      return true;
    }
  });

  return PsiUtilCore.toPsiElementArray(children);
}
 
Example #14
Source File: FavoritesTreeViewPanel.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void deleteElement(@Nonnull DataContext dataContext) {
  List<PsiElement> allElements = Arrays.asList(getElementsToDelete());
  List<PsiElement> validElements = new ArrayList<>();
  for (PsiElement psiElement : allElements) {
    if (psiElement != null && psiElement.isValid()) validElements.add(psiElement);
  }
  final PsiElement[] elements = PsiUtilCore.toPsiElementArray(validElements);

  LocalHistoryAction a = LocalHistory.getInstance().startAction(IdeBundle.message("progress.deleting"));
  try {
    DeleteHandler.deletePsiElement(elements, myProject);
  }
  finally {
    a.finish();
  }
}
 
Example #15
Source File: CSharpCatchStatementImpl.java    From consulo-csharp with Apache License 2.0 6 votes vote down vote up
@RequiredReadAction
public void deleteVariable()
{
	CSharpLocalVariable variable = getVariable();
	if(variable == null)
	{
		return;
	}

	PsiElement lparElement = variable.getPrevSibling();
	PsiElement rparElement = variable.getNextSibling();

	((CSharpLocalVariableImpl) variable).deleteInternal();

	if(PsiUtilCore.getElementType(lparElement) == CSharpTokens.LPAR)
	{
		lparElement.delete();
	}

	if(PsiUtilCore.getElementType(rparElement) == CSharpTokens.RPAR)
	{
		rparElement.delete();
	}
}
 
Example #16
Source File: PsiInvalidElementAccessException.java    From consulo with Apache License 2.0 6 votes vote down vote up
public PsiInvalidElementAccessException(@Nullable PsiElement element, @Nullable String message, @Nullable Throwable cause) {
  super(null, cause);
  myElementReference = new SoftReference<PsiElement>(element);

  if (element == null) {
    myMessage = message;
    myDiagnostic = Attachment.EMPTY_ARRAY;
  }
  else if (element == PsiUtilCore.NULL_PSI_ELEMENT) {
    myMessage = "NULL_PSI_ELEMENT ;" + message;
    myDiagnostic = Attachment.EMPTY_ARRAY;
  }
  else {
    boolean recursiveInvocation = Boolean.TRUE.equals(element.getUserData(REPORTING_EXCEPTION));
    element.putUserData(REPORTING_EXCEPTION, Boolean.TRUE);

    try {
      Object trace = recursiveInvocation ? null : getPsiInvalidationTrace(element);
      myMessage = getMessageWithReason(element, message, recursiveInvocation, trace);
      myDiagnostic = createAttachments(trace);
    }
    finally {
      element.putUserData(REPORTING_EXCEPTION, null);
    }
  }
}
 
Example #17
Source File: GeneralHighlightingPass.java    From consulo with Apache License 2.0 6 votes vote down vote up
public GeneralHighlightingPass(@Nonnull Project project,
                               @Nonnull PsiFile file,
                               @Nonnull Document document,
                               int startOffset,
                               int endOffset,
                               boolean updateAll,
                               @Nonnull ProperTextRange priorityRange,
                               @Nullable Editor editor,
                               @Nonnull HighlightInfoProcessor highlightInfoProcessor) {
  super(project, document, PRESENTABLE_NAME, file, editor, TextRange.create(startOffset, endOffset), true, highlightInfoProcessor);
  myUpdateAll = updateAll;
  myPriorityRange = priorityRange;

  PsiUtilCore.ensureValid(file);
  boolean wholeFileHighlighting = isWholeFileHighlighting();
  myHasErrorElement = !wholeFileHighlighting && Boolean.TRUE.equals(getFile().getUserData(HAS_ERROR_ELEMENT));
  final DaemonCodeAnalyzerEx daemonCodeAnalyzer = DaemonCodeAnalyzerEx.getInstanceEx(myProject);
  FileStatusMap fileStatusMap = daemonCodeAnalyzer.getFileStatusMap();
  myErrorFound = !wholeFileHighlighting && fileStatusMap.wasErrorFound(getDocument());

  // initial guess to show correct progress in the traffic light icon
  setProgressLimit(document.getTextLength() / 2); // approx number of PSI elements = file length/2
  myGlobalScheme = editor != null ? editor.getColorsScheme() : EditorColorsManager.getInstance().getGlobalScheme();
}
 
Example #18
Source File: CompletionPhase.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static boolean shouldSkipAutoPopup(Editor editor, PsiFile psiFile) {
  int offset = editor.getCaretModel().getOffset();
  int psiOffset = Math.max(0, offset - 1);

  PsiElement elementAt = psiFile.findElementAt(psiOffset);
  if (elementAt == null) return true;

  Language language = PsiUtilCore.findLanguageFromElement(elementAt);

  for (CompletionConfidence confidence : CompletionConfidenceEP.forLanguage(language)) {
    final ThreeState result = confidence.shouldSkipAutopopup(elementAt, psiFile, offset);
    if (result != ThreeState.UNSURE) {
      LOG.debug(confidence + " has returned shouldSkipAutopopup=" + result);
      return result == ThreeState.YES;
    }
  }
  return false;
}
 
Example #19
Source File: CoverageListNode.java    From consulo with Apache License 2.0 6 votes vote down vote up
public boolean contains(VirtualFile file) {
  final Object value = getValue();
  if (value instanceof PsiElement) {
    final boolean equalContainingFile = Comparing.equal(PsiUtilCore.getVirtualFile((PsiElement)value), file);
    if (equalContainingFile) return true;
  }
  if (value instanceof PsiDirectory) {
    return contains(file, (PsiDirectory)value);
  }
  else if (value instanceof PsiDirectoryContainer) {
    final PsiDirectory[] directories = ((PsiDirectoryContainer)value).getDirectories();
    for (PsiDirectory directory : directories) {
      if (contains(file, directory)) return true;
    }
  }
  return false;
}
 
Example #20
Source File: ARRelationReferenceProvider.java    From yiistorm with MIT License 6 votes vote down vote up
/**
 * Search file by Class name
 *
 * @param className Name of class
 * @return VirtualFile
 */
protected static VirtualFile getClassFile(String className) {
    String namespacedName = CommonHelper.prepareClassName(className);
    String cleanName = CommonHelper.getCleanClassName(className);
    List<PsiElement> elements = PsiPhpHelper.getPsiElementsFromClassName(cleanName, YiiPsiReferenceProvider.project);
    if (elements.size() > 0) {
        for (PsiElement element : elements) {
            String elementName = "";
            PsiElement namespaceElement = ExtendedPsiPhpHelper.getNamespaceElement(element);
            if (namespaceElement != null) {
                elementName = ExtendedPsiPhpHelper.getNamespaceFullName(namespaceElement) + "\\";
            }
            elementName += PsiPhpHelper.getClassIdentifierName(element);
            PsiElement navElement = element.getNavigationElement();
            if (namespacedName.equals(elementName)) {
                navElement = TargetElementUtilBase.getInstance().getGotoDeclarationTarget(element, navElement);
                if (navElement != null) {
                    VirtualFile virtualFile = PsiUtilCore.getVirtualFile(navElement);
                    return virtualFile;
                }
            }
        }
    }
    return null;
}
 
Example #21
Source File: HTMLComposerImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void appendElementReference(final StringBuffer buf, RefElement refElement, boolean isPackageIncluded) {
  final HTMLComposerExtension extension = getLanguageExtension(refElement);

  if (extension != null) {
    extension.appendReferencePresentation(refElement, buf, isPackageIncluded);
  }
  else if (refElement instanceof RefFile) {
    buf.append(A_HREF_OPENING);

    buf.append(((RefElementImpl)refElement).getURL());

    buf.append("\">");
    String refElementName = refElement.getName();
    final PsiElement element = refElement.getPsiElement();
    if (element != null) {
      VirtualFile file = PsiUtilCore.getVirtualFile(element);
      if (file != null) {
        refElementName = ProjectUtilCore.displayUrlRelativeToProject(file, file.getPresentableUrl(), element.getProject(), true, false);
      }
    }
    buf.append(refElementName);
    buf.append(A_CLOSING);
  }
}
 
Example #22
Source File: NavBarModelBuilderImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void traverseToRoot(@Nonnull PsiElement psiElement, @Nonnull Set<VirtualFile> roots, @Nonnull List<Object> model, @Nullable NavBarModelExtension ownerExtension) {

  List<NavBarModelExtension> extensions = NavBarModelExtension.EP_NAME.getExtensionList();

  for (PsiElement e = normalize(psiElement, ownerExtension), next = null; e != null; e = normalize(next, ownerExtension), next = null) {
    // check if we're running circles due to getParent()->normalize/adjust()
    if (model.contains(e)) break;
    model.add(e);

    // check if a root is reached
    VirtualFile vFile = PsiUtilCore.getVirtualFile(e);
    if (roots.contains(vFile)) break;

    for (NavBarModelExtension ext : extensions) {
      PsiElement parent = ext.getParent(e);
      if (parent != null && parent != e) {
        //noinspection AssignmentToForLoopParameter
        next = parent;
        break;
      }
    }
  }
}
 
Example #23
Source File: ParameterInfoController.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nullable
public static <E extends PsiElement> E findArgumentList(PsiFile file, int offset, int lbraceOffset) {
  if (file == null) return null;
  ParameterInfoHandler[] handlers = ShowParameterInfoHandler.getHandlers(file.getProject(), PsiUtilCore.getLanguageAtOffset(file, offset), file.getViewProvider().getBaseLanguage());

  if (handlers != null) {
    for (ParameterInfoHandler handler : handlers) {
      if (handler instanceof ParameterInfoHandlerWithTabActionSupport) {
        final ParameterInfoHandlerWithTabActionSupport parameterInfoHandler2 = (ParameterInfoHandlerWithTabActionSupport)handler;

        // please don't remove typecast in the following line; it's required to compile the code under old JDK 6 versions
        final E e = ParameterInfoUtils.findArgumentList(file, offset, lbraceOffset, parameterInfoHandler2);
        if (e != null) return e;
      }
    }
  }

  return null;
}
 
Example #24
Source File: Evaluator.java    From consulo-csharp with Apache License 2.0 6 votes vote down vote up
@Nullable
@RequiredReadAction
public static DotNetTypeProxy findTypeMirror(@Nonnull CSharpEvaluateContext context, @Nullable PsiElement element)
{
	if(element instanceof CSharpTypeDeclaration)
	{
		DotNetDebugContext debuggerContext = context.getDebuggerContext();

		VirtualFile virtualFile = PsiUtilCore.getVirtualFile(element);
		if(virtualFile == null)
		{
			return null;
		}
		return debuggerContext.getVirtualMachine().findType(element.getProject(), ((CSharpTypeDeclaration) element).getVmQName(), virtualFile);
	}
	return null;
}
 
Example #25
Source File: AnnotationUseImporter.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
public static void insertUse(InsertionContext context, String fqnAnnotation) {
    PsiElement element = PsiUtilCore.getElementAtOffset(context.getFile(), context.getStartOffset());
    PhpPsiElement scopeForUseOperator = PhpCodeInsightUtil.findScopeForUseOperator(element);

    if(null == scopeForUseOperator) {
        return;
    }

    // PhpCodeInsightUtil.canImport:
    // copied from PhpReferenceInsertHandler; throws an error on PhpContractUtil because of "fully qualified names only"
    // but that is catch on phpstorm side already; looks fixed now so use fqn

    if(!fqnAnnotation.startsWith("\\")) {
        fqnAnnotation = "\\" + fqnAnnotation;
    }

    // this looks suitable! :)
    if(PhpCodeInsightUtil.alreadyImported(scopeForUseOperator, fqnAnnotation) == null) {
        PsiDocumentManager.getInstance(context.getProject()).commitDocument(context.getDocument());
        PhpAliasImporter.insertUseStatement(fqnAnnotation, scopeForUseOperator);
        PsiDocumentManager.getInstance(context.getProject()).doPostponedOperationsAndUnblockDocument(context.getDocument());
    }
}
 
Example #26
Source File: DefaultNavBarExtension.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static boolean processChildren(final PsiDirectory object, final Object rootElement, final Processor<Object> processor) {
  return ApplicationManager.getApplication().runReadAction(new Computable<Boolean>() {
    @Override
    public Boolean compute() {
      final ModuleFileIndex moduleFileIndex = rootElement instanceof Module ? ModuleRootManager.getInstance((Module)rootElement).getFileIndex() : null;
      final PsiElement[] children = object.getChildren();
      for (PsiElement child : children) {
        if (child != null && child.isValid()) {
          if (moduleFileIndex != null) {
            final VirtualFile virtualFile = PsiUtilCore.getVirtualFile(child);
            if (virtualFile != null && !moduleFileIndex.isInContent(virtualFile)) continue;
          }
          if (!processor.process(child)) return false;
        }
      }
      return true;
    }
  });
}
 
Example #27
Source File: FavoritesTreeViewPanel.java    From consulo with Apache License 2.0 6 votes vote down vote up
private PsiElement[] getElementsToDelete() {
  ArrayList<PsiElement> result = new ArrayList<>();
  Object[] elements = getSelectedNodeElements();
  for (int idx = 0; elements != null && idx < elements.length; idx++) {
    if (elements[idx] instanceof PsiElement) {
      final PsiElement element = (PsiElement)elements[idx];
      result.add(element);
      if (element instanceof PsiDirectory) {
        final VirtualFile virtualFile = ((PsiDirectory)element).getVirtualFile();
        final String path = virtualFile.getPath();
        if (path.endsWith(ArchiveFileSystem.ARCHIVE_SEPARATOR)) { // if is jar-file root
          final VirtualFile vFile =
            LocalFileSystem.getInstance().findFileByPath(path.substring(0, path.length() - ArchiveFileSystem.ARCHIVE_SEPARATOR.length()));
          if (vFile != null) {
            final PsiFile psiFile = PsiManager.getInstance(myProject).findFile(vFile);
            if (psiFile != null) {
              elements[idx] = psiFile;
            }
          }
        }
      }
    }
  }

  return PsiUtilCore.toPsiElementArray(result);
}
 
Example #28
Source File: CS0509.java    From consulo-csharp with Apache License 2.0 6 votes vote down vote up
@RequiredReadAction
@Nullable
@Override
public HighlightInfoFactory checkImpl(@Nonnull CSharpLanguageVersion languageVersion, @Nonnull CSharpHighlightContext highlightContext, @Nonnull DotNetType element)
{
	PsiElement parent = element.getParent();
	if(parent instanceof DotNetTypeList && PsiUtilCore.getElementType(parent) == CSharpElements.EXTENDS_LIST)
	{
		PsiElement superParent = parent.getParent();
		if(superParent instanceof CSharpTypeDeclaration && ((CSharpTypeDeclaration) superParent).isEnum())
		{
			return null;
		}
		PsiElement psiElement = element.toTypeRef().resolve().getElement();
		if(psiElement instanceof CSharpTypeDeclaration)
		{
			if(((CSharpTypeDeclaration) psiElement).hasModifier(DotNetModifier.SEALED))
			{
				return newBuilder(element, formatElement(parent.getParent()), ((CSharpTypeDeclaration) psiElement).getVmQName());
			}
		}
	}
	return null;
}
 
Example #29
Source File: CS1008.java    From consulo-csharp with Apache License 2.0 6 votes vote down vote up
@RequiredReadAction
@Nullable
@Override
public HighlightInfoFactory checkImpl(@Nonnull CSharpLanguageVersion languageVersion, @Nonnull CSharpHighlightContext highlightContext, @Nonnull DotNetType element)
{
	PsiElement parent = element.getParent();
	if(parent instanceof DotNetTypeList && PsiUtilCore.getElementType(parent) == CSharpElements.EXTENDS_LIST)
	{
		PsiElement superParent = parent.getParent();
		if(superParent instanceof CSharpTypeDeclaration && ((CSharpTypeDeclaration) superParent).isEnum())
		{
			PsiElement psiElement = element.toTypeRef().resolve().getElement();
			if(psiElement instanceof CSharpTypeDeclaration)
			{
				if(!ArrayUtil.contains(((CSharpTypeDeclaration) psiElement).getVmQName(), ourEnumSuperTypes))
				{
					return newBuilder(element);
				}
			}
		}
	}
	return null;
}
 
Example #30
Source File: CS0709.java    From consulo-csharp with Apache License 2.0 6 votes vote down vote up
@RequiredReadAction
@Nullable
@Override
public HighlightInfoFactory checkImpl(@Nonnull CSharpLanguageVersion languageVersion, @Nonnull CSharpHighlightContext highlightContext, @Nonnull DotNetType element)
{
	PsiElement parent = element.getParent();
	if(parent instanceof DotNetTypeList && PsiUtilCore.getElementType(parent) == CSharpElements.EXTENDS_LIST)
	{
		PsiElement psiElement = element.toTypeRef().resolve().getElement();
		if(psiElement instanceof CSharpTypeDeclaration)
		{
			if(((CSharpTypeDeclaration) psiElement).hasModifier(DotNetModifier.STATIC))
			{
				return newBuilder(element, formatElement(parent.getParent()), ((CSharpTypeDeclaration) psiElement).getVmQName());
			}
		}
	}
	return super.checkImpl(languageVersion, highlightContext, element);
}