Extract attachment helper to a separate file
Improve logic for a nonphysical file
This commit is contained in:
+4
-8
@@ -20,21 +20,18 @@ import com.intellij.codeHighlighting.Pass;
|
||||
import com.intellij.codeInsight.daemon.GutterIconNavigationHandler;
|
||||
import com.intellij.codeInsight.daemon.LineMarkerInfo;
|
||||
import com.intellij.codeInsight.daemon.LineMarkerProvider;
|
||||
import com.intellij.diagnostic.AttachmentFactory;
|
||||
import com.intellij.diagnostic.LogMessageEx;
|
||||
import com.intellij.icons.AllIcons;
|
||||
import com.intellij.ide.DataManager;
|
||||
import com.intellij.ide.util.PropertiesComponent;
|
||||
import com.intellij.openapi.actionSystem.ActionGroup;
|
||||
import com.intellij.openapi.actionSystem.DefaultActionGroup;
|
||||
import com.intellij.openapi.diagnostic.Attachment;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.markup.GutterIconRenderer;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.ModuleUtilCore;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.util.ExceptionUtil;
|
||||
import com.intellij.util.Function;
|
||||
@@ -52,6 +49,7 @@ import org.jetbrains.jet.lang.resolve.java.structure.impl.JavaMethodImpl;
|
||||
import org.jetbrains.jet.plugin.JetIcons;
|
||||
import org.jetbrains.jet.plugin.caches.resolve.JavaResolveExtension;
|
||||
import org.jetbrains.jet.plugin.project.ProjectStructureUtil;
|
||||
import org.jetbrains.jet.plugin.util.attachment.AttachmentPackage;
|
||||
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.Collection;
|
||||
@@ -111,12 +109,10 @@ public class KotlinSignatureInJavaMarkerProvider implements LineMarkerProvider {
|
||||
}
|
||||
}
|
||||
catch (AssertionError error) {
|
||||
VirtualFile virtualFile = psiFile.getVirtualFile();
|
||||
Attachment[] attachments = virtualFile != null
|
||||
? new Attachment[] {AttachmentFactory.createAttachment(virtualFile)}
|
||||
: new Attachment[] {};
|
||||
LOG.error(LogMessageEx.createEvent(
|
||||
"Exception while collecting KotlinSignature markers", ExceptionUtil.getThrowableText(error), attachments
|
||||
"Exception while collecting KotlinSignature markers",
|
||||
ExceptionUtil.getThrowableText(error),
|
||||
AttachmentPackage.attachmentsByPsiFile(psiFile)
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright 2010-2014 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.plugin.util.attachment
|
||||
|
||||
import com.intellij.psi.PsiFile
|
||||
import com.intellij.openapi.diagnostic.Attachment
|
||||
import com.intellij.diagnostic.AttachmentFactory
|
||||
|
||||
public fun attachmentsByPsiFile(file: PsiFile?): Array<Attachment> {
|
||||
if (file == null) return array()
|
||||
|
||||
val virtualFile = file.getVirtualFile()
|
||||
if (virtualFile != null) return array(AttachmentFactory.createAttachment(virtualFile))
|
||||
|
||||
val text = try { file.getText() } catch(e: Exception) { null }
|
||||
val name = try { file.getName() } catch(e: Exception) { null }
|
||||
|
||||
if (text != null && name != null) return array(Attachment(name, text))
|
||||
|
||||
return array()
|
||||
}
|
||||
Reference in New Issue
Block a user