use of com.intellij.openapi.fileTypes.FileType in project intellij-community by JetBrains.
the class CustomRegexpFilter method createOpenFileHyperlink.
protected HyperlinkInfo createOpenFileHyperlink(String fileName, final int line, int column) {
if ((fileName == null || fileName.length() == 0)) {
if (myBase != null) {
fileName = myBase.getPresentableUrl();
} else {
return null;
}
}
fileName = fileName.replace(File.separatorChar, '/');
VirtualFile file;
// try to interpret the filename as URL
if (URLUtil.containsScheme(fileName)) {
try {
file = VfsUtil.findFileByURL(new URL(fileName));
} catch (MalformedURLException e) {
file = VirtualFileManager.getInstance().findFileByUrl(VfsUtil.pathToUrl(fileName));
}
} else {
file = VfsUtil.findRelativeFile(fileName, myBase);
}
if (file == null) {
//noinspection ConstantConditions
return null;
}
final FileType fileType = file.getFileType();
if (fileType != null && column > 0) {
final Document document = FileDocumentManager.getInstance().getDocument(file);
final int start = document.getLineStartOffset(line);
final int max = document.getLineEndOffset(line);
final int tabSize = CodeStyleSettingsManager.getInstance(myProject).getCurrentSettings().getTabSize(fileType);
column = EditorUtil.calcColumnNumber(null, document.getCharsSequence(), start, Math.min(start + column, max), tabSize);
}
return new OpenFileHyperlinkInfo(myProject, file, line, column);
}
use of com.intellij.openapi.fileTypes.FileType in project intellij-community by JetBrains.
the class JavaFxFileTypeFactory method createFileTypes.
@Override
public void createFileTypes(@NotNull FileTypeConsumer consumer) {
final FileType fileType = consumer.getStandardFileTypeByName("XML");
assert fileType != null;
consumer.consume(fileType, FXML_EXTENSION);
}
use of com.intellij.openapi.fileTypes.FileType in project intellij-community by JetBrains.
the class JavaFxLocationReferenceProvider method collectRefs.
private PsiReference[] collectRefs(@NotNull PsiElement element, String value, int startInElement) {
final int atSignIndex = value.indexOf('@');
if (atSignIndex >= 0 && (atSignIndex == 0 || StringUtil.trimLeading(value).startsWith("@"))) {
value = value.substring(atSignIndex + 1);
startInElement += atSignIndex + 1;
}
final FileReferenceSet set = new FileReferenceSet(value, element, startInElement, null, true) {
@Override
protected Condition<PsiFileSystemItem> getReferenceCompletionFilter() {
return item -> {
if (item instanceof PsiDirectory)
return true;
final VirtualFile virtualFile = item.getVirtualFile();
if (virtualFile == null)
return false;
final FileType fileType = virtualFile.getFileType();
return myAcceptedFileTypes.contains(fileType);
};
}
};
if (value.startsWith("/")) {
set.addCustomization(FileReferenceSet.DEFAULT_PATH_EVALUATOR_OPTION, FileReferenceSet.ABSOLUTE_TOP_LEVEL);
}
return set.getAllReferences();
}
use of com.intellij.openapi.fileTypes.FileType in project intellij-community by JetBrains.
the class XmlCompletionContributor method addEntityRefCompletions.
private static void addEntityRefCompletions(PsiElement context, CompletionResultSet resultSet) {
XmlFile containingFile = null;
XmlFile descriptorFile = null;
final XmlTag tag = PsiTreeUtil.getParentOfType(context, XmlTag.class);
if (tag != null) {
containingFile = (XmlFile) tag.getContainingFile();
descriptorFile = findDescriptorFile(tag, containingFile);
}
if (HtmlUtil.isHtml5Context(tag)) {
descriptorFile = XmlUtil.findXmlFile(containingFile, Html5SchemaProvider.getCharsDtdLocation());
} else if (tag == null) {
final XmlDocument document = PsiTreeUtil.getParentOfType(context, XmlDocument.class);
if (document != null) {
containingFile = (XmlFile) document.getContainingFile();
final FileType ft = containingFile.getFileType();
if (HtmlUtil.isHtml5Document(document)) {
descriptorFile = XmlUtil.findXmlFile(containingFile, Html5SchemaProvider.getCharsDtdLocation());
} else if (ft != StdFileTypes.XML) {
final String namespace = ft == StdFileTypes.XHTML || ft == StdFileTypes.JSPX ? XmlUtil.XHTML_URI : XmlUtil.HTML_URI;
final XmlNSDescriptor nsDescriptor = document.getDefaultNSDescriptor(namespace, true);
if (nsDescriptor != null) {
descriptorFile = nsDescriptor.getDescriptorFile();
}
}
}
}
if (descriptorFile != null && containingFile != null) {
final boolean acceptSystemEntities = containingFile.getFileType() == StdFileTypes.XML;
final PsiElementProcessor processor = new PsiElementProcessor() {
@Override
public boolean execute(@NotNull final PsiElement element) {
if (element instanceof XmlEntityDecl) {
final XmlEntityDecl xmlEntityDecl = (XmlEntityDecl) element;
if (xmlEntityDecl.isInternalReference() || acceptSystemEntities) {
final LookupElementBuilder _item = buildEntityLookupItem(xmlEntityDecl);
if (_item != null) {
resultSet.addElement(_item);
resultSet.stopHere();
}
}
}
return true;
}
};
XmlUtil.processXmlElements(descriptorFile, processor, true);
if (descriptorFile != containingFile && acceptSystemEntities) {
final XmlProlog element = containingFile.getDocument().getProlog();
if (element != null)
XmlUtil.processXmlElements(element, processor, true);
}
}
}
use of com.intellij.openapi.fileTypes.FileType in project intellij-community by JetBrains.
the class ToggleFieldBreakpointAction method getPlace.
@Nullable
public static SourcePosition getPlace(AnActionEvent event) {
final DataContext dataContext = event.getDataContext();
final Project project = event.getData(CommonDataKeys.PROJECT);
if (project == null) {
return null;
}
if (ActionPlaces.PROJECT_VIEW_POPUP.equals(event.getPlace()) || ActionPlaces.STRUCTURE_VIEW_POPUP.equals(event.getPlace()) || ActionPlaces.FAVORITES_VIEW_POPUP.equals(event.getPlace())) {
final PsiElement psiElement = event.getData(CommonDataKeys.PSI_ELEMENT);
if (psiElement instanceof PsiField) {
return SourcePosition.createFromElement(psiElement);
}
return null;
}
final DebuggerTreeNodeImpl selectedNode = DebuggerAction.getSelectedNode(dataContext);
if (selectedNode != null && selectedNode.getDescriptor() instanceof FieldDescriptorImpl) {
final DebuggerContextImpl debuggerContext = DebuggerAction.getDebuggerContext(dataContext);
final DebugProcessImpl debugProcess = debuggerContext.getDebugProcess();
if (debugProcess != null) {
// if there is an active debug session
final Ref<SourcePosition> positionRef = new Ref<>(null);
debugProcess.getManagerThread().invokeAndWait(new DebuggerContextCommandImpl(debuggerContext) {
@Override
public Priority getPriority() {
return Priority.HIGH;
}
@Override
public void threadAction() {
ApplicationManager.getApplication().runReadAction(() -> positionRef.set(SourcePositionProvider.getSourcePosition(selectedNode.getDescriptor(), project, debuggerContext)));
}
});
final SourcePosition sourcePosition = positionRef.get();
if (sourcePosition != null) {
return sourcePosition;
}
}
}
if (DebuggerAction.isContextView(event)) {
DebuggerTree tree = DebuggerTree.DATA_KEY.getData(dataContext);
if (tree != null && tree.getSelectionPath() != null) {
DebuggerTreeNodeImpl node = ((DebuggerTreeNodeImpl) tree.getSelectionPath().getLastPathComponent());
if (node != null && node.getDescriptor() instanceof FieldDescriptorImpl) {
Field field = ((FieldDescriptorImpl) node.getDescriptor()).getField();
DebuggerSession session = tree.getDebuggerContext().getDebuggerSession();
PsiClass psiClass = DebuggerUtils.findClass(field.declaringType().name(), project, (session != null) ? session.getSearchScope() : GlobalSearchScope.allScope(project));
if (psiClass != null) {
psiClass = (PsiClass) psiClass.getNavigationElement();
final PsiField psiField = psiClass.findFieldByName(field.name(), true);
if (psiField != null) {
return SourcePosition.createFromElement(psiField);
}
}
}
}
return null;
}
Editor editor = event.getData(CommonDataKeys.EDITOR);
if (editor == null) {
editor = FileEditorManager.getInstance(project).getSelectedTextEditor();
}
if (editor != null) {
final Document document = editor.getDocument();
PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(document);
if (file != null) {
final VirtualFile virtualFile = file.getVirtualFile();
FileType fileType = virtualFile != null ? virtualFile.getFileType() : null;
if (StdFileTypes.JAVA == fileType || StdFileTypes.CLASS == fileType) {
final PsiField field = FieldBreakpoint.findField(project, document, editor.getCaretModel().getOffset());
if (field != null) {
return SourcePosition.createFromElement(field);
}
}
}
}
return null;
}
Aggregations