mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -535,7 +535,9 @@ public class AndroidFacet extends Facet<AndroidFacetConfiguration> {
|
||||
final String sdkHomePath = FileUtil.toSystemIndependentName(platform.getSdkData().getLocation());
|
||||
final VirtualFile annotationsJar = JarFileSystem.getInstance().findFileByPath(
|
||||
sdkHomePath + AndroidSdkUtils.ANNOTATIONS_JAR_RELATIVE_PATH + JarFileSystem.JAR_SEPARATOR);
|
||||
filesToAdd.add(annotationsJar);
|
||||
if (annotationsJar != null) {
|
||||
filesToAdd.add(annotationsJar);
|
||||
}
|
||||
}
|
||||
|
||||
addFilesToSdkIfNecessary(sdk, filesToAdd);
|
||||
|
||||
+13
-6
@@ -9,6 +9,7 @@ import com.intellij.codeInsight.daemon.HighlightDisplayKey;
|
||||
import com.intellij.codeInsight.intention.HighPriorityAction;
|
||||
import com.intellij.codeInsight.intention.IntentionAction;
|
||||
import com.intellij.codeInspection.InspectionProfile;
|
||||
import com.intellij.codeInspection.SuppressIntentionAction;
|
||||
import com.intellij.codeInspection.ex.CustomEditInspectionToolsSettingsAction;
|
||||
import com.intellij.codeInspection.ex.DisableInspectionToolAction;
|
||||
import com.intellij.lang.annotation.Annotation;
|
||||
@@ -155,8 +156,6 @@ public class AndroidLintExternalAnnotator extends ExternalAnnotator<State, State
|
||||
final AndroidLintInspectionBase inspection = pair.getFirst();
|
||||
final HighlightDisplayLevel displayLevel = pair.getSecond();
|
||||
|
||||
final Annotation annotation = createAnnotation(holder, message, range, displayLevel);
|
||||
|
||||
if (inspection != null) {
|
||||
final HighlightDisplayKey key = HighlightDisplayKey.find(inspection.getShortName());
|
||||
|
||||
@@ -164,7 +163,9 @@ public class AndroidLintExternalAnnotator extends ExternalAnnotator<State, State
|
||||
final PsiElement startElement = file.findElementAt(range.getStartOffset());
|
||||
final PsiElement endElement = file.findElementAt(range.getEndOffset() - 1);
|
||||
|
||||
if (startElement != null && endElement != null) {
|
||||
if (startElement != null && endElement != null && !inspection.isSuppressedFor(startElement)) {
|
||||
final Annotation annotation = createAnnotation(holder, message, range, displayLevel);
|
||||
|
||||
for (AndroidLintQuickFix fix : inspection.getQuickFixes(message)) {
|
||||
if (fix.isApplicable(startElement, endElement, false)) {
|
||||
annotation.registerFix(new MyFixingIntention(fix, startElement, endElement));
|
||||
@@ -174,10 +175,16 @@ public class AndroidLintExternalAnnotator extends ExternalAnnotator<State, State
|
||||
for (IntentionAction intention : inspection.getIntentions(startElement, endElement)) {
|
||||
annotation.registerFix(intention);
|
||||
}
|
||||
}
|
||||
annotation.registerFix(new MyDisableInspectionFix(key));
|
||||
annotation.registerFix(new MyEditInspectionToolsSettingsAction(key, inspection));
|
||||
|
||||
annotation.registerFix(new MyDisableInspectionFix(key));
|
||||
annotation.registerFix(new MyEditInspectionToolsSettingsAction(key, inspection));
|
||||
final SuppressIntentionAction[] suppressActions = inspection.getSuppressActions(startElement);
|
||||
if (suppressActions != null) {
|
||||
for (SuppressIntentionAction action : suppressActions) {
|
||||
annotation.registerFix(action);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+30
-7
@@ -6,8 +6,11 @@ import com.android.tools.lint.detector.api.Scope;
|
||||
import com.android.tools.lint.detector.api.Severity;
|
||||
import com.intellij.analysis.AnalysisScope;
|
||||
import com.intellij.codeHighlighting.HighlightDisplayLevel;
|
||||
import com.intellij.codeInsight.daemon.HighlightDisplayKey;
|
||||
import com.intellij.codeInsight.intention.IntentionAction;
|
||||
import com.intellij.codeInspection.*;
|
||||
import com.intellij.lang.java.JavaLanguage;
|
||||
import com.intellij.lang.xml.XMLLanguage;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.module.Module;
|
||||
@@ -32,15 +35,12 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author Eugene.Kudelevsky
|
||||
*/
|
||||
public abstract class AndroidLintInspectionBase extends GlobalInspectionTool {
|
||||
public abstract class AndroidLintInspectionBase extends GlobalInspectionTool implements CustomSuppressableInspectionTool {
|
||||
private static final Logger LOG = Logger.getInstance("#org.jetbrains.android.inspections.lint.AndroidLintInspectionBase");
|
||||
|
||||
private static final Map<Issue, String> ourIssue2InspectionShortName = new HashMap<Issue, String>();
|
||||
@@ -160,7 +160,7 @@ public abstract class AndroidLintInspectionBase extends GlobalInspectionTool {
|
||||
}
|
||||
}
|
||||
|
||||
if (f != null) {
|
||||
if (f != null && !isSuppressedFor(f)) {
|
||||
result.add(manager.createProblemDescriptor(f, message, false, getLocalQuickFixes(f, f, message),
|
||||
ProblemHighlightType.GENERIC_ERROR_OR_WARNING));
|
||||
}
|
||||
@@ -169,7 +169,7 @@ public abstract class AndroidLintInspectionBase extends GlobalInspectionTool {
|
||||
final PsiElement startElement = psiFile.findElementAt(range.getStartOffset());
|
||||
final PsiElement endElement = psiFile.findElementAt(range.getEndOffset() - 1);
|
||||
|
||||
if (startElement != null && endElement != null) {
|
||||
if (startElement != null && endElement != null && !isSuppressedFor(startElement)) {
|
||||
result.add(manager.createProblemDescriptor(startElement, endElement, message,
|
||||
ProblemHighlightType.GENERIC_ERROR_OR_WARNING, false,
|
||||
getLocalQuickFixes(startElement, endElement, message)));
|
||||
@@ -179,6 +179,29 @@ public abstract class AndroidLintInspectionBase extends GlobalInspectionTool {
|
||||
return result.toArray(new ProblemDescriptor[result.size()]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SuppressIntentionAction[] getSuppressActions(@Nullable PsiElement element) {
|
||||
final List<SuppressIntentionAction> result = new ArrayList<SuppressIntentionAction>();
|
||||
result.addAll(Arrays.asList(SuppressManager.getInstance().createSuppressActions(HighlightDisplayKey.find(getShortName()))));
|
||||
result.addAll(Arrays.asList(new XmlSuppressableInspectionTool.SuppressTagStatic(getShortName()),
|
||||
new XmlSuppressableInspectionTool.SuppressForFile(getShortName())));
|
||||
return result.toArray(new SuppressIntentionAction[result.size()]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSuppressedFor(PsiElement element) {
|
||||
if (element == null) {
|
||||
return false;
|
||||
}
|
||||
else if (element.getLanguage() == JavaLanguage.INSTANCE) {
|
||||
return SuppressManager.getInstance().isSuppressedFor(element, getShortName());
|
||||
}
|
||||
else if (element.getLanguage() == XMLLanguage.INSTANCE) {
|
||||
return XmlSuppressionProvider.isSuppressed(element, getShortName());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private synchronized static void addIssue(@NotNull Issue issue, @NotNull String shortName) {
|
||||
ourIssue2InspectionShortName.put(issue, shortName);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package p1.p2;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import java.lang.Integer;
|
||||
|
||||
public class MyActivity extends Activity
|
||||
{
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
Integer n = new Integer(3);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<problems>
|
||||
<problem>
|
||||
<file>MyActivity.java</file>
|
||||
<line>15</line>
|
||||
<description>Use Integer.valueOf(3) instead</description>
|
||||
</problem>
|
||||
</problems>
|
||||
@@ -0,0 +1,18 @@
|
||||
package p1.p2;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import java.lang.Integer;
|
||||
|
||||
public class MyActivity extends Activity
|
||||
{
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
@SuppressWarnings("AndroidLintUseValueOf")
|
||||
Integer n = new Integer(3);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<problems>
|
||||
</problems>
|
||||
@@ -0,0 +1,3 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<problems>
|
||||
</problems>
|
||||
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
>
|
||||
<!--suppress AndroidLintHardcodedText -->
|
||||
<TextView
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:t<caret>ext="Hello World, MyActivity"
|
||||
/>
|
||||
</LinearLayout>
|
||||
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
>
|
||||
<!--suppress AndroidLintHardcodedText -->
|
||||
<TextView
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:t<caret>ext="Hello World, MyActivity"
|
||||
/>
|
||||
</LinearLayout>
|
||||
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--suppress AndroidLintHardcodedText -->
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
>
|
||||
<TextView
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:t<caret>ext="Hello World, MyActivity"
|
||||
/>
|
||||
</LinearLayout>
|
||||
@@ -195,6 +195,34 @@ public class AndroidLintTest extends AndroidTestCase {
|
||||
doGlobalInspectionTest(new AndroidLintInspectionToolProvider.AndroidLintIconDuplicatesInspection());
|
||||
}
|
||||
|
||||
public void testSuppressingInXml1() throws Exception {
|
||||
doTestNoFix(new AndroidLintInspectionToolProvider.AndroidLintHardcodedTextInspection(),
|
||||
"/res/layout/layout.xml", "xml");
|
||||
}
|
||||
|
||||
public void testSuppressingInXml2() throws Exception {
|
||||
doTestNoFix(new AndroidLintInspectionToolProvider.AndroidLintHardcodedTextInspection(),
|
||||
"/res/layout/layout.xml", "xml");
|
||||
}
|
||||
|
||||
public void testSuppressingInXml3() throws Exception {
|
||||
createManifest();
|
||||
myFixture.copyFileToProject(getGlobalTestDir() + "/layout.xml", "res/layout/layout.xml");
|
||||
doGlobalInspectionTest(new AndroidLintInspectionToolProvider.AndroidLintHardcodedTextInspection());
|
||||
}
|
||||
|
||||
public void testSuppressingInJava() throws Exception {
|
||||
createManifest();
|
||||
myFixture.copyFileToProject(getGlobalTestDir() + "/MyActivity.java", "src/p1/p2/MyActivity.java");
|
||||
doGlobalInspectionTest(new AndroidLintInspectionToolProvider.AndroidLintUseValueOfInspection());
|
||||
}
|
||||
|
||||
public void testLintInJavaFile() throws Exception {
|
||||
createManifest();
|
||||
myFixture.copyFileToProject(getGlobalTestDir() + "/MyActivity.java", "src/p1/p2/MyActivity.java");
|
||||
doGlobalInspectionTest(new AndroidLintInspectionToolProvider.AndroidLintUseValueOfInspection());
|
||||
}
|
||||
|
||||
private void doGlobalInspectionTest(@NotNull AndroidLintInspectionBase inspection) {
|
||||
final GlobalInspectionToolWrapper wrapper = new GlobalInspectionToolWrapper(inspection);
|
||||
myFixture.enableInspections(wrapper);
|
||||
|
||||
Reference in New Issue
Block a user