Skip to content

Commit

Permalink
#18 added file listener to reload data of changed files
Browse files Browse the repository at this point in the history
  • Loading branch information
aschuler84 committed Apr 9, 2022
1 parent 5bc5c8b commit 73af61b
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 4 deletions.
7 changes: 7 additions & 0 deletions src/main/java/at/mana/idea/ManaPluginStartup.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,13 @@
import com.intellij.openapi.project.ProjectManagerListener;
import com.intellij.openapi.startup.StartupActivity;
import com.intellij.openapi.util.Key;
import com.intellij.openapi.vfs.VirtualFileManager;
import com.intellij.openapi.vfs.newvfs.BulkFileListener;
import com.intellij.openapi.vfs.newvfs.events.VFileEvent;
import org.jetbrains.annotations.NotNull;

import java.util.List;

import static at.mana.idea.util.I18nUtil.i18n;
/**
* @author Andreas Schuler
Expand All @@ -36,6 +41,8 @@ public class ManaPluginStartup implements StartupActivity
@Override
public void runActivity(@NotNull Project project) {
HibernateUtil.getSessionFactory();


if( !ManaSettingsState.getInstance().initialVerification ) {
// TODO: extract to configuration util
Notification notification = NotificationGroupManager.getInstance().getNotificationGroup("ManaNotificationGroup")
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/at/mana/idea/editor/ManaLineEditorPainter.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ public class ManaLineEditorPainter extends EditorLinePainter implements UpdateIn
//double total = statistics.getMethodEnergyStatistics().values().stream().flatMap(Collection::stream)
// .mapToDouble( value -> value.getEnergyConsumption().getAverage() ).sum();
statistics.getMethodEnergyStatistics().forEach((k, v) -> {
if (doc.getLineNumber(k.getTextOffset()) == lineNumber) {
if ( k.getTextOffset() < doc.getTextLength()
&& doc.getLineNumber(k.getTextOffset()) == lineNumber) {

// TODO: change model to store method hash and include linenumber in methodDescriptor

// compute max consumption in this class
// print relative contribution per each method as chart -> color coded
List<LineExtensionInfo> histogram = createHistogram( v );
Expand Down
32 changes: 29 additions & 3 deletions src/main/java/at/mana/idea/service/impl/StorageServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,12 @@
import com.intellij.openapi.components.Service;
import com.intellij.openapi.project.DumbAware;
import com.intellij.openapi.project.DumbService;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiJavaFile;
import com.intellij.psi.PsiMethod;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.VirtualFileManager;
import com.intellij.openapi.vfs.newvfs.BulkFileListener;
import com.intellij.openapi.vfs.newvfs.events.VFileEvent;
import com.intellij.psi.*;
import com.intellij.psi.util.ClassUtil;

import org.jetbrains.annotations.NotNull;
Expand All @@ -60,7 +63,30 @@ public class StorageServiceImpl implements StorageService
{

private final Map<PsiJavaFile, ManaEnergyExperimentModel> model = new HashMap<>();
private Project project;

public StorageServiceImpl(Project project) {
this.project = project;
initFileChangeListener();
}

private void initFileChangeListener() {
project.getMessageBus().connect().subscribe(VirtualFileManager.VFS_CHANGES,
new BulkFileListener() {
@Override
public void after(@NotNull List<? extends VFileEvent> events) {
for( VFileEvent event : events ) {
VirtualFile file = event.getFile();
PsiFile psiFile = PsiManager.getInstance(project).findFile( file );
if( psiFile instanceof PsiJavaFile
&& !psiFile.getFileType().getDefaultExtension().endsWith("class") ) {
PsiJavaFile javaFile = (PsiJavaFile) psiFile;
model.remove(javaFile);
}
}
}
});
}

@Override
public ManaEnergyExperimentModel findDataFor(PsiJavaFile file) {
Expand Down

0 comments on commit 73af61b

Please sign in to comment.