use of com.intellij.openapi.fileTypes.FileType in project intellij-community by JetBrains.
the class UnknownFileTypeDiffRequest method getComponent.
@NotNull
@Override
public JComponent getComponent(@NotNull final DiffContext context) {
final SimpleColoredComponent label = new SimpleColoredComponent();
label.setTextAlign(SwingConstants.CENTER);
label.append("Can't show diff for unknown file type. ", new SimpleTextAttributes(SimpleTextAttributes.STYLE_PLAIN, UIUtil.getInactiveTextColor()));
if (myFileName != null) {
label.append("Associate", SimpleTextAttributes.LINK_ATTRIBUTES, new Runnable() {
@Override
public void run() {
FileType type = FileTypeChooser.associateFileType(myFileName);
if (type != null)
onSuccess(context);
}
});
LinkMouseListenerBase.installSingleTagOn(label);
}
return new DiffUtil.CenteredPanel(label, JBUI.Borders.empty(5));
}
use of com.intellij.openapi.fileTypes.FileType in project intellij-community by JetBrains.
the class LangDiffIgnoredRangeProvider method getLanguage.
@Nullable
private static Language getLanguage(@NotNull Project project, @NotNull DiffContent content) {
Language language = content.getUserData(DiffUserDataKeys.LANGUAGE);
if (language != null)
return language;
FileType type = content.getContentType();
if (type instanceof LanguageFileType)
language = ((LanguageFileType) type).getLanguage();
if (language != null && content instanceof DocumentContent) {
VirtualFile highlightFile = ((DocumentContent) content).getHighlightFile();
if (highlightFile != null)
language = LanguageSubstitutors.INSTANCE.substituteLanguage(language, highlightFile, project);
}
return language;
}
use of com.intellij.openapi.fileTypes.FileType in project intellij-community by JetBrains.
the class UnifiedDiffViewer method performRediff.
@Override
@NotNull
protected Runnable performRediff(@NotNull final ProgressIndicator indicator) {
try {
indicator.checkCanceled();
final Document document1 = getContent1().getDocument();
final Document document2 = getContent2().getDocument();
final CharSequence[] texts = ReadAction.compute(() -> {
return new CharSequence[] { document1.getImmutableCharSequence(), document2.getImmutableCharSequence() };
});
final List<LineFragment> fragments = myTextDiffProvider.compare(texts[0], texts[1], indicator);
final DocumentContent content1 = getContent1();
final DocumentContent content2 = getContent2();
indicator.checkCanceled();
TwosideDocumentData data = ReadAction.compute(() -> {
indicator.checkCanceled();
UnifiedFragmentBuilder builder = new UnifiedFragmentBuilder(fragments, document1, document2, myMasterSide);
builder.exec();
indicator.checkCanceled();
EditorHighlighter highlighter = buildHighlighter(myProject, content1, content2, texts[0], texts[1], builder.getRanges(), builder.getText().length());
UnifiedEditorRangeHighlighter rangeHighlighter = new UnifiedEditorRangeHighlighter(myProject, document1, document2, builder.getRanges());
return new TwosideDocumentData(builder, highlighter, rangeHighlighter);
});
UnifiedFragmentBuilder builder = data.getBuilder();
FileType fileType = content2.getContentType() == null ? content1.getContentType() : content2.getContentType();
LineNumberConvertor convertor1 = builder.getConvertor1();
LineNumberConvertor convertor2 = builder.getConvertor2();
List<LineRange> changedLines = builder.getChangedLines();
boolean isContentsEqual = builder.isEqual();
CombinedEditorData editorData = new CombinedEditorData(builder.getText(), data.getHighlighter(), data.getRangeHighlighter(), fileType, convertor1.createConvertor(), convertor2.createConvertor());
return apply(editorData, builder.getBlocks(), convertor1, convertor2, changedLines, isContentsEqual);
} catch (DiffTooBigException e) {
return () -> {
clearDiffPresentation();
myPanel.setTooBigContent();
};
} catch (ProcessCanceledException e) {
throw e;
} catch (Throwable e) {
LOG.error(e);
return () -> {
clearDiffPresentation();
myPanel.setErrorContent();
};
}
}
use of com.intellij.openapi.fileTypes.FileType in project intellij-community by JetBrains.
the class OverrideImplementUtil method setupMethodBody.
public static void setupMethodBody(final PsiMethod result, final PsiMethod originalMethod, final PsiClass targetClass, final FileTemplate template) throws IncorrectOperationException {
if (targetClass.isInterface()) {
if (isImplementInterfaceInJava8Interface(targetClass) || originalMethod.hasModifierProperty(PsiModifier.DEFAULT)) {
PsiUtil.setModifierProperty(result, PsiModifier.DEFAULT, true);
} else {
final PsiCodeBlock body = result.getBody();
if (body != null)
body.delete();
}
}
FileType fileType = FileTypeManager.getInstance().getFileTypeByExtension(template.getExtension());
PsiType returnType = result.getReturnType();
if (returnType == null) {
returnType = PsiType.VOID;
}
Properties properties = FileTemplateManager.getInstance(targetClass.getProject()).getDefaultProperties();
properties.setProperty(FileTemplate.ATTRIBUTE_RETURN_TYPE, returnType.getPresentableText());
properties.setProperty(FileTemplate.ATTRIBUTE_DEFAULT_RETURN_VALUE, PsiTypesUtil.getDefaultValueOfType(returnType));
properties.setProperty(FileTemplate.ATTRIBUTE_CALL_SUPER, callSuper(originalMethod, result));
JavaTemplateUtil.setClassAndMethodNameProperties(properties, targetClass, result);
JVMElementFactory factory = JVMElementFactories.getFactory(targetClass.getLanguage(), originalMethod.getProject());
if (factory == null)
factory = JavaPsiFacade.getInstance(originalMethod.getProject()).getElementFactory();
@NonNls String methodText;
try {
methodText = "void foo () {\n" + template.getText(properties) + "\n}";
methodText = FileTemplateUtil.indent(methodText, result.getProject(), fileType);
} catch (Exception e) {
throw new IncorrectOperationException("Failed to parse file template", (Throwable) e);
}
if (methodText != null) {
PsiMethod m;
try {
m = factory.createMethodFromText(methodText, originalMethod);
} catch (IncorrectOperationException e) {
ApplicationManager.getApplication().invokeLater(() -> Messages.showErrorDialog(CodeInsightBundle.message("override.implement.broken.file.template.message"), CodeInsightBundle.message("override.implement.broken.file.template.title")));
return;
}
PsiCodeBlock oldBody = result.getBody();
if (oldBody != null) {
oldBody.replace(m.getBody());
}
}
}
use of com.intellij.openapi.fileTypes.FileType in project intellij-community by JetBrains.
the class LightStubBuilder method buildStubTree.
@Override
public StubElement buildStubTree(@NotNull PsiFile file) {
LighterAST tree = FORCED_AST.get();
if (tree == null) {
FileType fileType = file.getFileType();
if (!(fileType instanceof LanguageFileType)) {
LOG.error("File is not of LanguageFileType: " + fileType + ", " + file);
return null;
}
assert file instanceof PsiFileImpl;
final IFileElementType contentType = ((PsiFileImpl) file).getElementTypeForStubBuilder();
if (contentType == null) {
LOG.error("File is not of IStubFileElementType: " + file);
return null;
}
final FileASTNode node = file.getNode();
if (node.getElementType() instanceof ILightStubFileElementType) {
tree = node.getLighterAST();
} else {
tree = new TreeBackedLighterAST(node);
}
} else {
FORCED_AST.set(null);
}
if (tree == null)
return null;
final StubElement rootStub = createStubForFile(file, tree);
buildStubTree(tree, tree.getRoot(), rootStub);
return rootStub;
}
Aggregations