From 01723d7ee608163b2faeae2e6e5890c473ab7bb2 Mon Sep 17 00:00:00 2001 From: Alexander Lobas Date: Sun, 27 May 2012 18:25:58 +0400 Subject: [PATCH] Inspections --- .../designer/AndroidDesignerEditor.java | 8 +++- .../AndroidDesignerEditorPanel.java | 18 ++++++++ .../AndroidBackgroundEditorHighlighter.java | 44 +++++++++++++++++++ .../inspection/AndroidHighlightingPass.java | 42 ++++++++++++++++++ .../android/inspections/lint/ProblemData.java | 2 +- .../android/inspections/lint/State.java | 2 +- 6 files changed, 113 insertions(+), 3 deletions(-) create mode 100644 plugins/android-designer/src/com/intellij/android/designer/inspection/AndroidBackgroundEditorHighlighter.java create mode 100644 plugins/android-designer/src/com/intellij/android/designer/inspection/AndroidHighlightingPass.java diff --git a/plugins/android-designer/src/com/intellij/android/designer/AndroidDesignerEditor.java b/plugins/android-designer/src/com/intellij/android/designer/AndroidDesignerEditor.java index abd7c40b34dc..4d8e19066cbe 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/AndroidDesignerEditor.java +++ b/plugins/android-designer/src/com/intellij/android/designer/AndroidDesignerEditor.java @@ -16,6 +16,7 @@ package com.intellij.android.designer; import com.intellij.android.designer.designSurface.AndroidDesignerEditorPanel; +import com.intellij.android.designer.inspection.AndroidBackgroundEditorHighlighter; import com.intellij.codeHighlighting.BackgroundEditorHighlighter; import com.intellij.designer.DesignerEditor; import com.intellij.designer.designSurface.DesignerEditorPanel; @@ -28,6 +29,8 @@ import org.jetbrains.annotations.NotNull; * @author Alexander Lobas */ public final class AndroidDesignerEditor extends DesignerEditor { + private BackgroundEditorHighlighter myHighlighter; + public AndroidDesignerEditor(Project project, VirtualFile file) { super(project, file); } @@ -46,6 +49,9 @@ public final class AndroidDesignerEditor extends DesignerEditor { @Override public BackgroundEditorHighlighter getBackgroundHighlighter() { - return null; // TODO: Auto-generated method stub + if (myHighlighter == null) { + myHighlighter = new AndroidBackgroundEditorHighlighter((AndroidDesignerEditorPanel)getDesignerPanel()); + } + return myHighlighter; } } \ No newline at end of file diff --git a/plugins/android-designer/src/com/intellij/android/designer/designSurface/AndroidDesignerEditorPanel.java b/plugins/android-designer/src/com/intellij/android/designer/designSurface/AndroidDesignerEditorPanel.java index eeac4342a475..29a9abb11c4e 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/designSurface/AndroidDesignerEditorPanel.java +++ b/plugins/android-designer/src/com/intellij/android/designer/designSurface/AndroidDesignerEditorPanel.java @@ -45,6 +45,9 @@ import com.intellij.psi.xml.XmlFile; import com.intellij.util.Alarm; import com.intellij.util.ThrowableRunnable; import org.jetbrains.android.facet.AndroidFacet; +import org.jetbrains.android.inspections.lint.AndroidLintExternalAnnotator; +import org.jetbrains.android.inspections.lint.ProblemData; +import org.jetbrains.android.inspections.lint.State; import org.jetbrains.android.maven.AndroidMavenUtil; import org.jetbrains.android.sdk.AndroidPlatform; import org.jetbrains.android.sdk.AndroidSdkUtils; @@ -112,6 +115,21 @@ public final class AndroidDesignerEditorPanel extends DesignerEditorPanel { }); } + public void loadInspections() { + AndroidLintExternalAnnotator annotator = new AndroidLintExternalAnnotator(); + State state = annotator.collectionInformation(myXmlFile); + if (state == null) { + System.out.println("No inspections"); + } + else { + state = annotator.doAnnotate(state); + System.out.println("==== Problems ===="); + for (ProblemData problem : state.getProblems()) { + System.out.println(problem.getIssue() + " | " + problem.getMessage() + " | " + problem.getTextRange()); + } + } + } + private void reparseFile() { try { storeState(); diff --git a/plugins/android-designer/src/com/intellij/android/designer/inspection/AndroidBackgroundEditorHighlighter.java b/plugins/android-designer/src/com/intellij/android/designer/inspection/AndroidBackgroundEditorHighlighter.java new file mode 100644 index 000000000000..37b8cfdb9ade --- /dev/null +++ b/plugins/android-designer/src/com/intellij/android/designer/inspection/AndroidBackgroundEditorHighlighter.java @@ -0,0 +1,44 @@ +/* + * Copyright 2000-2012 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 com.intellij.android.designer.inspection; + +import com.intellij.android.designer.designSurface.AndroidDesignerEditorPanel; +import com.intellij.codeHighlighting.BackgroundEditorHighlighter; +import com.intellij.codeHighlighting.HighlightingPass; +import org.jetbrains.annotations.NotNull; + +/** + * @author Alexander Lobas + */ +public class AndroidBackgroundEditorHighlighter implements BackgroundEditorHighlighter { + private final HighlightingPass[] myHighlightingPasses; + + public AndroidBackgroundEditorHighlighter(AndroidDesignerEditorPanel designer) { + myHighlightingPasses = new HighlightingPass[]{new AndroidHighlightingPass(designer)}; + } + + @NotNull + @Override + public HighlightingPass[] createPassesForEditor() { + return myHighlightingPasses; + } + + @NotNull + @Override + public HighlightingPass[] createPassesForVisibleArea() { + return HighlightingPass.EMPTY_ARRAY; + } +} \ No newline at end of file diff --git a/plugins/android-designer/src/com/intellij/android/designer/inspection/AndroidHighlightingPass.java b/plugins/android-designer/src/com/intellij/android/designer/inspection/AndroidHighlightingPass.java new file mode 100644 index 000000000000..b08c9da07dfc --- /dev/null +++ b/plugins/android-designer/src/com/intellij/android/designer/inspection/AndroidHighlightingPass.java @@ -0,0 +1,42 @@ +/* + * Copyright 2000-2012 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 com.intellij.android.designer.inspection; + +import com.intellij.android.designer.designSurface.AndroidDesignerEditorPanel; +import com.intellij.codeHighlighting.HighlightingPass; +import com.intellij.openapi.progress.ProgressIndicator; + +/** + * @author Alexander Lobas + */ +public class AndroidHighlightingPass implements HighlightingPass { + private final AndroidDesignerEditorPanel myDesigner; + + public AndroidHighlightingPass(AndroidDesignerEditorPanel designer) { + myDesigner = designer; + } + + @Override + public void collectInformation(ProgressIndicator progress) { + myDesigner.loadInspections(); + // TODO: Auto-generated method stub + } + + @Override + public void applyInformationToEditor() { + // TODO: Auto-generated method stub + } +} \ No newline at end of file diff --git a/plugins/android/src/org/jetbrains/android/inspections/lint/ProblemData.java b/plugins/android/src/org/jetbrains/android/inspections/lint/ProblemData.java index 72805b19ae45..a4ab9a846116 100644 --- a/plugins/android/src/org/jetbrains/android/inspections/lint/ProblemData.java +++ b/plugins/android/src/org/jetbrains/android/inspections/lint/ProblemData.java @@ -7,7 +7,7 @@ import org.jetbrains.annotations.NotNull; /** * @author Eugene.Kudelevsky */ -class ProblemData { +public class ProblemData { private final Issue myIssue; private final String myMessage; private final TextRange myTextRange; diff --git a/plugins/android/src/org/jetbrains/android/inspections/lint/State.java b/plugins/android/src/org/jetbrains/android/inspections/lint/State.java index 9793e507d201..9b27e0e163a0 100644 --- a/plugins/android/src/org/jetbrains/android/inspections/lint/State.java +++ b/plugins/android/src/org/jetbrains/android/inspections/lint/State.java @@ -11,7 +11,7 @@ import java.util.List; /** * @author Eugene.Kudelevsky */ -class State { +public class State { private final Module myModule; private final VirtualFile myMainFile;