Merge branch 'master' of git.labs.intellij.net:idea/community

This commit is contained in:
Bas Leijdekkers
2011-02-18 09:29:36 +01:00
237 changed files with 4160 additions and 1722 deletions
@@ -15,10 +15,7 @@
*/
package com.intellij.compiler.ant.artifacts;
import com.intellij.compiler.ant.BuildProperties;
import com.intellij.compiler.ant.Comment;
import com.intellij.compiler.ant.GenerationOptions;
import com.intellij.compiler.ant.Generator;
import com.intellij.compiler.ant.*;
import com.intellij.compiler.ant.taskdefs.*;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.project.Project;
@@ -158,6 +155,7 @@ public class ArtifactsGenerator {
final String outputPath = BuildProperties.propertyRef(myContext.getArtifactOutputProperty(artifact));
artifactTarget.add(new Mkdir(outputPath));
generateTasksForArtifacts(artifact, artifactTarget, true);
final DirectoryAntCopyInstructionCreator creator = new DirectoryAntCopyInstructionCreator(outputPath);
@@ -170,9 +168,16 @@ public class ArtifactsGenerator {
for (Generator tag : copyInstructions) {
artifactTarget.add(tag);
}
generateTasksForArtifacts(artifact, artifactTarget, false);
return artifactTarget;
}
private void generateTasksForArtifacts(Artifact artifact, Target artifactTarget, final boolean preprocessing) {
for (ChunkBuildExtension extension : ChunkBuildExtension.EP_NAME.getExtensions()) {
extension.generateTasksForArtifact(myResolvingContext.getProject(), artifact, preprocessing, artifactTarget);
}
}
public List<String> getCleanTargetNames() {
final List<String> targets = new ArrayList<String>();
for (Artifact artifact : myAllArtifacts) {
@@ -27,6 +27,8 @@ import com.intellij.util.StringBuilderSpinAllocator;
import org.jetbrains.annotations.NonNls;
import java.io.*;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
/**
* @author Eugene Zhuravlev
@@ -47,6 +49,8 @@ public class CompilerParsingThread implements Runnable, OutputParser.Callback {
private String myPushBackLine = null;
private volatile boolean myProcessExited = false;
private final CompileContext myContext;
private final BlockingQueue<String> myLines = new LinkedBlockingQueue<String>();
public CompilerParsingThread(Process process, OutputParser outputParser, final boolean readErrorStream, boolean trimLines, CompileContext context) {
myProcess = process;
@@ -60,6 +64,24 @@ public class CompilerParsingThread implements Runnable, OutputParser.Callback {
volatile boolean processing;
public void run() {
if (CompileDriver.ourDebugMode) {
ApplicationManager.getApplication().executeOnPooledThread(new Runnable() {
@Override
public void run() {
while (true) {
final String line = readLine(myCompilerOutStreamReader);
if (CompileDriver.ourDebugMode) {
System.out.println("RAW_LIne read: #" + line + "#");
}
if (line == null) {
myLines.offer(TERMINATION_STRING);
break;
}
myLines.offer(line);
}
}
});
}
processing = true;
try {
while (true) {
@@ -111,7 +133,7 @@ public class CompilerParsingThread implements Runnable, OutputParser.Callback {
myLastReadLine = pushBack;
return pushBack;
}
final String line = readLine(myCompilerOutStreamReader);
final String line = getNextUnprocessedLine();
if (LOG.isDebugEnabled()) {
LOG.debug("LIne read: #" + line + "#");
}
@@ -127,6 +149,28 @@ public class CompilerParsingThread implements Runnable, OutputParser.Callback {
return myLastReadLine;
}
private String getNextUnprocessedLine() {
if (CompileDriver.ourDebugMode) {
try {
if (TERMINATION_STRING.equals(myLines.peek())) {
return TERMINATION_STRING;
}
final String line = myLines.take();
if (TERMINATION_STRING.equals(line)) {
myLines.offer(TERMINATION_STRING); // pushback
}
return line;
}
catch (InterruptedException e) {
e.printStackTrace();
return TERMINATION_STRING;
}
}
else {
return readLine(myCompilerOutStreamReader);
}
}
@Override
public void pushBack(String line) {
myLastReadLine = null;
@@ -144,6 +188,9 @@ public class CompilerParsingThread implements Runnable, OutputParser.Callback {
processCompiledClass(previousPath);
}
catch (CacheCorruptedException e) {
if (CompileDriver.ourDebugMode) {
e.printStackTrace();
}
myError = e;
LOG.info(e);
killProcess();
@@ -177,6 +224,9 @@ public class CompilerParsingThread implements Runnable, OutputParser.Callback {
buffer = StringBuilderSpinAllocator.alloc();
}
catch (SpinAllocator.AllocatorExhaustedException e) {
if (CompileDriver.ourDebugMode) {
e.printStackTrace();
}
LOG.info(e);
buffer = new StringBuilder();
releaseBuffer = false;
@@ -220,6 +270,9 @@ public class CompilerParsingThread implements Runnable, OutputParser.Callback {
try {
while(!reader.ready()) {
if (isProcessTerminated()) {
if (reader.ready()) {
break;
}
return -1;
}
try {
@@ -231,7 +284,16 @@ public class CompilerParsingThread implements Runnable, OutputParser.Callback {
return reader.read();
}
catch (IOException e) {
return -1; // When process terminated Process.getInputStream()'s underlaying stream becomes closed on Linux.
if (CompileDriver.ourDebugMode) {
e.printStackTrace();
}
return -1; // When process terminated Process.getInputStream()'s underlying stream becomes closed on Linux.
}
catch (Throwable t) {
if (CompileDriver.ourDebugMode) {
t.printStackTrace();
}
return -1;
}
}
@@ -20,6 +20,7 @@ import com.intellij.ExtensionPoints;
import com.intellij.openapi.extensions.ExtensionPointName;
import com.intellij.openapi.extensions.Extensions;
import com.intellij.openapi.project.Project;
import com.intellij.packaging.artifacts.Artifact;
import com.intellij.util.ArrayUtil;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NonNls;
@@ -44,6 +45,9 @@ public abstract class ChunkBuildExtension {
public void generateProperties(final PropertyFileGenerator generator, final Project project, final GenerationOptions options) {
}
public void generateTasksForArtifact(Project project, Artifact artifact, boolean preprocessing, CompositeGenerator generator) {
}
public List<String> getCleanTargetNames(Project project, GenerationOptions genOptions) {
return Collections.emptyList();
}
@@ -1,94 +0,0 @@
/*
* Copyright 2000-2009 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.
*/
/**
* @author cdr
*/
package com.intellij.openapi.roots.ui.configuration;
import com.intellij.ide.util.ElementsChooser;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.ProjectBundle;
import com.intellij.openapi.roots.LibraryOrderEntry;
import com.intellij.openapi.roots.libraries.Library;
import com.intellij.util.Icons;
import javax.swing.*;
import java.awt.*;
public class LibraryChooserElement {
private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.roots.ui.configuration.LibraryChooserElement");
private final String myName;
private final Library myLibrary;
private LibraryOrderEntry myOrderEntry;
public static final ElementsChooser.ElementProperties VALID_LIBRARY_ELEMENT_PROPERTIES = new ElementsChooser.ElementProperties() {
public Icon getIcon() {
return Icons.LIBRARY_ICON;
}
public Color getColor() {
return null;
}
};
public static final ElementsChooser.ElementProperties INVALID_LIBRARY_ELEMENT_PROPERTIES = new ElementsChooser.ElementProperties() {
public Icon getIcon() {
return Icons.LIBRARY_ICON;
}
public Color getColor() {
return Color.RED;
}
};
public LibraryChooserElement(Library library, final LibraryOrderEntry orderEntry) {
myLibrary = library;
myOrderEntry = orderEntry;
if (myLibrary == null && myOrderEntry == null) {
LOG.error("Both library and order entry are null");
myName = ProjectBundle.message("module.libraries.unknown.item");
}
else {
myName = myLibrary != null? myLibrary.getName() : myOrderEntry.getLibraryName();
}
}
public String toString() {
return myName;
}
public String getName() {
return myName;
}
public Library getLibrary() {
return myLibrary;
}
public LibraryOrderEntry getOrderEntry() {
return myOrderEntry;
}
public void setOrderEntry(LibraryOrderEntry orderEntry) {
myOrderEntry = orderEntry;
}
public boolean isAttachedToProject() {
return myOrderEntry != null;
}
public boolean isValid() {
return myLibrary != null;
}
}
@@ -1,87 +0,0 @@
/*
* Copyright 2000-2009 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.openapi.roots.ui.configuration;
import com.intellij.ide.util.ElementsChooser;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.roots.ModuleOrderEntry;
import com.intellij.openapi.roots.ui.util.CellAppearanceUtils;
import javax.swing.*;
import java.awt.*;
/**
* TODO: remove it together witrh DependenciesEditor
*/
public class ModuleChooserElement implements ElementsChooser.ElementProperties{
private final String myName;
private final Module myModule;
private ModuleOrderEntry myOrderEntry;
public ModuleChooserElement(Module module, ModuleOrderEntry orderEntry) {
myModule = module;
myOrderEntry = orderEntry;
myName = module != null? module.getName() : orderEntry.getModuleName();
}
public Module getModule() {
return myModule;
}
public ModuleOrderEntry getOrderEntry() {
return myOrderEntry;
}
public void setOrderEntry(ModuleOrderEntry orderEntry) {
myOrderEntry = orderEntry;
}
public String getName() {
return myName;
}
public Icon getIcon() {
if (myModule != null) {
return myModule.getModuleType().getNodeIcon(false);
}
else {
return CellAppearanceUtils.INVALID_ICON;
}
}
public Color getColor() {
return myModule == null ? Color.RED : null;
}
public String toString() {
return getName();
}
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof ModuleChooserElement)) return false;
final ModuleChooserElement chooserElement = (ModuleChooserElement)o;
if (!myName.equals(chooserElement.myName)) return false;
return true;
}
public int hashCode() {
return myName.hashCode();
}
}
@@ -169,10 +169,7 @@ public class ArtifactEditorContextImpl implements ArtifactEditorContext {
}
public List<Module> chooseModules(final List<Module> modules, final String title) {
ChooseModulesDialog dialog = new ChooseModulesDialog(getProject(), modules, title, null);
dialog.show();
List<Module> selected = dialog.getChosenElements();
return dialog.isOK() ? selected : Collections.<Module>emptyList();
return new ChooseModulesDialog(getProject(), modules, title, null).showAndGetResult();
}
public List<Library> chooseLibraries(final String title) {
@@ -4,6 +4,7 @@ import com.intellij.codeInsight.generation.GenerateMembersUtil;
import com.intellij.codeInsight.generation.OverrideImplementUtil;
import com.intellij.codeInsight.generation.PsiGenerationInfo;
import com.intellij.codeInsight.generation.PsiMethodMember;
import com.intellij.codeInsight.lookup.Lookup;
import com.intellij.codeInsight.lookup.LookupElementDecorator;
import com.intellij.codeInsight.lookup.LookupItem;
import com.intellij.featureStatistics.FeatureUsageTracker;
@@ -34,6 +35,8 @@ class ConstructorInsertHandler implements InsertHandler<LookupElementDecorator<L
private static final Logger LOG = Logger.getInstance("#com.intellij.codeInsight.completion.ConstructorInsertHandler");
public static final ConstructorInsertHandler SMART_INSTANCE = new ConstructorInsertHandler(true);
public static final ConstructorInsertHandler BASIC_INSTANCE = new ConstructorInsertHandler(false);
static final OffsetKey PARAM_LIST_START = OffsetKey.create("paramListStart");
static final OffsetKey PARAM_LIST_END = OffsetKey.create("paramListEnd");
private final boolean mySmart;
private ConstructorInsertHandler(boolean smart) {
@@ -51,6 +54,15 @@ class ConstructorInsertHandler implements InsertHandler<LookupElementDecorator<L
boolean withTail = item.getUserData(LookupItem.BRACKETS_COUNT_ATTR) == null && !inAnonymous;
boolean isAbstract = ((PsiClass)item.getObject()).hasModifierProperty(PsiModifier.ABSTRACT);
if (Lookup.REPLACE_SELECT_CHAR == context.getCompletionChar()) {
final int plStart = context.getOffset(PARAM_LIST_START);
final int plEnd = context.getOffset(PARAM_LIST_END);
if (plStart >= 0 && plEnd >= 0) {
context.getDocument().deleteString(plStart, plEnd);
PsiDocumentManager.getInstance(context.getProject()).commitAllDocuments();
}
}
insertParentheses(context, delegate, delegate.getObject(), withTail && isAbstract);
DefaultInsertHandler.addImportForItem(context, delegate);
@@ -79,13 +79,7 @@ class JavaClassNameInsertHandler implements InsertHandler<JavaPsiClassReferenceE
PsiElement parent = position.getParent();
if (parent instanceof PsiJavaCodeReferenceElement) {
final PsiJavaCodeReferenceElement ref = (PsiJavaCodeReferenceElement)parent;
if (PsiTreeUtil.getParentOfType(position, PsiDocTag.class) != null) {
if (ref.isReferenceTo(psiClass)) {
return;
}
}
final PsiReferenceParameterList parameterList = ref.getParameterList();
if (parameterList != null && parameterList.getTextLength() > 0) {
if (PsiTreeUtil.getParentOfType(position, PsiDocTag.class) != null && ref.isReferenceTo(psiClass)) {
return;
}
}
@@ -132,6 +126,15 @@ class JavaClassNameInsertHandler implements InsertHandler<JavaPsiClassReferenceE
private static boolean shouldInsertParentheses(PsiClass psiClass, PsiElement position) {
final PsiJavaCodeReferenceElement ref = PsiTreeUtil.getParentOfType(position, PsiJavaCodeReferenceElement.class);
if (ref == null) {
return false;
}
final PsiReferenceParameterList parameterList = ref.getParameterList();
if (parameterList != null && parameterList.getTextLength() > 0) {
return false;
}
final PsiElement prevElement = FilterPositionUtil.searchNonSpaceNonCommentBack(ref);
if (prevElement != null && prevElement.getParent() instanceof PsiNewExpression) {
@@ -177,6 +177,7 @@ public class JavaCompletionContributor extends CompletionContributor {
}
if (AFTER_NUMBER_LITERAL.accepts(position)) {
_result.stopHere();
return;
}
@@ -535,6 +536,15 @@ public class JavaCompletionContributor extends CompletionContributor {
final PsiJavaCodeReferenceElement ref = PsiTreeUtil.findElementOfClassAtOffset(file, context.getStartOffset(), PsiJavaCodeReferenceElement.class, false);
if (ref != null && !(ref instanceof PsiReferenceExpression)) {
context.setDummyIdentifier(CompletionInitializationContext.DUMMY_IDENTIFIER.trim() + ";");
if (JavaSmartCompletionContributor.AFTER_NEW.accepts(ref)) {
final PsiReferenceParameterList paramList = ref.getParameterList();
if (paramList != null && paramList.getTextLength() > 0) {
context.getOffsetMap().addOffset(ConstructorInsertHandler.PARAM_LIST_START, paramList.getTextRange().getStartOffset());
context.getOffsetMap().addOffset(ConstructorInsertHandler.PARAM_LIST_END, paramList.getTextRange().getEndOffset());
}
}
return;
}
@@ -23,13 +23,11 @@ import com.intellij.psi.*;
import com.intellij.psi.statistics.JavaStatisticsManager;
import com.intellij.psi.statistics.StatisticsInfo;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NonNls;
/**
* @author peter
*/
public class JavaCompletionStatistician extends CompletionStatistician{
@NonNls public static final String CLASS_NAME_COMPLETION_PREFIX = "classNameCompletion#";
public StatisticsInfo serialize(final LookupElement element, final CompletionLocation location) {
final Object o = element.getObject();
@@ -76,6 +74,10 @@ public class JavaCompletionStatistician extends CompletionStatistician{
if (!isClass && type == CompletionType.BASIC) return JavaStatisticsManager.createInfo(qualifierType, (PsiMember)o);
return StatisticsInfo.EMPTY;
}
if (isClass) {
return JavaStatisticsManager.createInfo(qualifierType, (PsiMember)o);
}
}
if (qualifierType != null) return StatisticsInfo.EMPTY;
@@ -25,6 +25,7 @@ import org.jetbrains.annotations.NotNull;
public class PreferLocalVariablesLiteralsAndAnnoMethodsWeigher extends CompletionWeigher {
enum MyResult {
className,
classLiteral,
normal,
superMethodParameters,
@@ -54,6 +55,10 @@ public class PreferLocalVariablesLiteralsAndAnnoMethodsWeigher extends Completio
if (object instanceof PsiAnnotationMethod && ((PsiAnnotationMethod)object).getContainingClass().isAnnotationType()) {
return MyResult.annoMethod;
}
if (object instanceof PsiClass) {
return MyResult.className;
}
}
return MyResult.normal;
@@ -16,29 +16,18 @@
package com.intellij.codeInsight.daemon.impl.analysis;
import com.intellij.codeInsight.AnnotationUtil;
import com.intellij.codeInsight.daemon.HighlightDisplayKey;
import com.intellij.codeInsight.daemon.JavaErrorMessages;
import com.intellij.codeInsight.daemon.impl.HighlightInfo;
import com.intellij.codeInsight.daemon.impl.HighlightInfoType;
import com.intellij.codeInsight.daemon.impl.JavaHightlightInfoTypes;
import com.intellij.codeInsight.daemon.impl.actions.SuppressFix;
import com.intellij.codeInsight.daemon.impl.quickfix.*;
import com.intellij.codeInsight.intention.EmptyIntentionAction;
import com.intellij.codeInsight.intention.IntentionAction;
import com.intellij.codeInsight.intention.QuickFixFactory;
import com.intellij.codeInspection.InspectionProfile;
import com.intellij.codeInspection.LocalInspectionTool;
import com.intellij.codeInspection.SuppressManager;
import com.intellij.codeInspection.ex.InspectionManagerEx;
import com.intellij.codeInspection.ex.LocalInspectionToolWrapper;
import com.intellij.codeInspection.uncheckedWarnings.UncheckedWarningLocalInspection;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.IndexNotReadyException;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.TextRange;
import com.intellij.pom.java.LanguageLevel;
import com.intellij.profile.codeInspection.InspectionProjectProfileManager;
import com.intellij.psi.*;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.search.searches.ReferencesSearch;
@@ -48,7 +37,6 @@ import com.intellij.util.containers.HashMap;
import com.intellij.util.containers.HashSet;
import gnu.trove.THashMap;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.*;
@@ -529,21 +517,7 @@ public class GenericsHighlightUtil {
return null;
}
//precondition: TypeConversionUtil.isAssignable(lType, rType) || expressionAssignable
public static HighlightInfo checkRawToGenericAssignment(PsiType lType, PsiType rType, @NotNull final PsiElement elementToHighlight) {
if (!PsiUtil.isLanguageLevel5OrHigher(elementToHighlight)) return null;
final HighlightDisplayKey key = HighlightDisplayKey.find(UncheckedWarningLocalInspection.SHORT_NAME);
if (!InspectionProjectProfileManager.getInstance(elementToHighlight.getProject()).getInspectionProfile().isToolEnabled(key,
elementToHighlight)) return null;
if (!isRawToGeneric(lType, rType)) return null;
String description = JavaErrorMessages.message("generics.unchecked.assignment",
HighlightUtil.formatType(rType),
HighlightUtil.formatType(lType));
return createUncheckedWarning(elementToHighlight, key, description, elementToHighlight);
}
private static boolean isRawToGeneric(PsiType lType, PsiType rType) {
public static boolean isRawToGeneric(PsiType lType, PsiType rType) {
if (lType instanceof PsiPrimitiveType || rType instanceof PsiPrimitiveType) return false;
if (lType.equals(rType)) return false;
if (lType instanceof PsiArrayType && rType instanceof PsiArrayType) {
@@ -628,27 +602,7 @@ public class GenericsHighlightUtil {
return false;
}
public static HighlightInfo checkUncheckedTypeCast(PsiTypeCastExpression typeCast) {
if (!PsiUtil.isLanguageLevel5OrHigher(typeCast)) return null;
final HighlightDisplayKey key = HighlightDisplayKey.find(UncheckedWarningLocalInspection.SHORT_NAME);
if (!InspectionProjectProfileManager.getInstance(typeCast.getProject()).getInspectionProfile().isToolEnabled(key, typeCast)) return null;
final PsiTypeElement typeElement = typeCast.getCastType();
if (typeElement == null) return null;
final PsiType castType = typeElement.getType();
final PsiExpression expression = typeCast.getOperand();
if (expression == null) return null;
final PsiType exprType = expression.getType();
if (exprType == null) return null;
if (isUncheckedCast(castType, exprType)) {
String description = JavaErrorMessages.message("generics.unchecked.cast",
HighlightUtil.formatType(exprType),
HighlightUtil.formatType(castType));
return createUncheckedWarning(expression, key, description, typeCast);
}
return null;
}
private static boolean isUncheckedCast(PsiType castType, PsiType operandType) {
public static boolean isUncheckedCast(PsiType castType, PsiType operandType) {
if (TypeConversionUtil.isAssignable(castType, operandType, false)) return false;
castType = castType.getDeepComponentType();
@@ -727,74 +681,7 @@ public class GenericsHighlightUtil {
((PsiClassType)rTypeArg).resolve() instanceof PsiTypeParameter;
}
public static HighlightInfo checkUncheckedCall(JavaResolveResult resolveResult, PsiCall call) {
if (!PsiUtil.isLanguageLevel5OrHigher(call)) return null;
final HighlightDisplayKey key = HighlightDisplayKey.find(UncheckedWarningLocalInspection.SHORT_NAME);
if (!InspectionProjectProfileManager.getInstance(call.getProject()).getInspectionProfile().isToolEnabled(key, call)) return null;
final PsiMethod method = (PsiMethod)resolveResult.getElement();
if (method == null) return null;
final PsiSubstitutor substitutor = resolveResult.getSubstitutor();
final PsiParameter[] parameters = method.getParameterList().getParameters();
for (final PsiParameter parameter : parameters) {
final PsiType parameterType = parameter.getType();
if (parameterType.accept(new PsiTypeVisitor<Boolean>() {
public Boolean visitPrimitiveType(PsiPrimitiveType primitiveType) {
return Boolean.FALSE;
}
public Boolean visitArrayType(PsiArrayType arrayType) {
return arrayType.getComponentType().accept(this);
}
public Boolean visitClassType(PsiClassType classType) {
PsiClass psiClass = classType.resolve();
if (psiClass instanceof PsiTypeParameter) {
return substitutor.substitute((PsiTypeParameter)psiClass) == null ? Boolean.TRUE : Boolean.FALSE;
}
PsiType[] parameters = classType.getParameters();
for (PsiType parameter : parameters) {
if (parameter.accept(this).booleanValue()) return Boolean.TRUE;
}
return Boolean.FALSE;
}
public Boolean visitWildcardType(PsiWildcardType wildcardType) {
PsiType bound = wildcardType.getBound();
if (bound != null) return bound.accept(this);
return Boolean.FALSE;
}
public Boolean visitEllipsisType(PsiEllipsisType ellipsisType) {
return ellipsisType.getComponentType().accept(this);
}
}).booleanValue()) {
final PsiElementFactory elementFactory = JavaPsiFacade.getInstance(method.getProject()).getElementFactory();
PsiType type = elementFactory.createType(method.getContainingClass(), substitutor);
String description = JavaErrorMessages.message("generics.unchecked.call.to.member.of.raw.type",
HighlightUtil.formatMethod(method),
HighlightUtil.formatType(type));
PsiElement element = call instanceof PsiMethodCallExpression
? ((PsiMethodCallExpression)call).getMethodExpression()
: call;
return createUncheckedWarning(call, key, description, element);
}
}
return null;
}
private static HighlightInfo createUncheckedWarning(PsiElement context, HighlightDisplayKey key, String description, PsiElement elementToHighlight) {
final InspectionProfile inspectionProfile =
InspectionProjectProfileManager.getInstance(context.getProject()).getInspectionProfile();
final LocalInspectionTool tool =
((LocalInspectionToolWrapper)inspectionProfile.getInspectionTool(UncheckedWarningLocalInspection.SHORT_NAME, elementToHighlight)).getTool();
if (InspectionManagerEx.inspectionResultSuppressed(context, tool)) return null;
HighlightInfo highlightInfo = HighlightInfo.createHighlightInfo(JavaHightlightInfoTypes.UNCHECKED_WARNING, elementToHighlight, description);
QuickFixAction.registerQuickFixAction(highlightInfo, new GenerifyFileFix(elementToHighlight.getContainingFile()), key);
return highlightInfo;
}
@Nullable
public static HighlightInfo checkForeachLoopParameterType(PsiForeachStatement statement) {
final PsiParameter parameter = statement.getIterationParameter();
final PsiExpression expression = statement.getIteratedValue();
@@ -811,14 +698,12 @@ public class GenericsHighlightUtil {
HighlightInfo highlightInfo = HighlightUtil.checkAssignability(parameterType, itemType, null, new TextRange(start, end));
if (highlightInfo != null) {
HighlightUtil.registerChangeVariableTypeFixes(parameter, itemType, highlightInfo);
} else {
highlightInfo = checkRawToGenericAssignment(parameterType, itemType, statement.getIterationParameter());
}
return highlightInfo;
}
@Nullable
private static PsiType getCollectionItemType(PsiExpression expression) {
public static PsiType getCollectionItemType(PsiExpression expression) {
final PsiType type = expression.getType();
if (type == null) return null;
if (type instanceof PsiArrayType) {
@@ -1112,25 +997,11 @@ public class GenericsHighlightUtil {
}
}
@Nullable
public static HighlightInfo checkUncheckedGenericsArrayCreation(PsiReferenceExpression referenceExpression, PsiElement resolved){
if (isUncheckedWarning(referenceExpression, resolved, false)) {
final HighlightInfo highlightInfo =
HighlightInfo.createHighlightInfo(HighlightInfoType.WARNING, referenceExpression, "Unchecked generics array creation for varargs parameter");
QuickFixAction.registerQuickFixAction(highlightInfo, new SuppressFix("unchecked"));
return highlightInfo;
}
return null;
}
public static boolean isUncheckedWarning(PsiReferenceExpression expression, PsiElement resolve, boolean ignoreSuppressed) {
public static boolean isUncheckedWarning(PsiJavaCodeReferenceElement expression, PsiElement resolve) {
if (resolve instanceof PsiMethod) {
final PsiMethod psiMethod = (PsiMethod)resolve;
final LanguageLevel languageLevel = PsiUtil.getLanguageLevel(expression);
if (!ignoreSuppressed) {
if (SuppressManager.getInstance().isSuppressedFor(expression, "unchecked")) return false;
}
if (psiMethod.isVarArgs()) {
if (!languageLevel.isAtLeast(LanguageLevel.JDK_1_7) || !AnnotationUtil.isAnnotated(psiMethod, "java.lang.SafeVarargs", false)) {
@@ -1140,12 +1011,31 @@ public class GenericsHighlightUtil {
final PsiType componentType = ((PsiEllipsisType)varargParameter.getType()).getComponentType();
if (!isReifiableType(componentType)) {
final PsiElement parent = expression.getParent();
if (parent instanceof PsiMethodCallExpression) {
final PsiExpression[] args = ((PsiMethodCallExpression)parent).getArgumentList().getExpressions();
for (int i = parametersCount - 1; i < args.length; i++) {
if (!isReifiableType(args[i].getType())){
return true;
if (parent instanceof PsiCall) {
final PsiExpressionList argumentList = ((PsiCall)parent).getArgumentList();
if (argumentList != null) {
final PsiExpression[] args = argumentList.getExpressions();
if (args.length == parametersCount) {
final PsiExpression lastArg = args[args.length - 1];
if (lastArg instanceof PsiReferenceExpression) {
final PsiElement lastArgsResolve = ((PsiReferenceExpression)lastArg).resolve();
if (lastArgsResolve instanceof PsiParameter) {
if (((PsiParameter)lastArgsResolve).getType() instanceof PsiArrayType) {
return false;
}
}
} else if (lastArg instanceof PsiMethodCallExpression) {
if (lastArg.getType() instanceof PsiArrayType) {
return false;
}
}
}
for (int i = parametersCount - 1; i < args.length; i++) {
if (!isReifiableType(args[i].getType())){
return true;
}
}
return args.length < parametersCount;
}
}
}
@@ -1169,14 +1059,22 @@ public class GenericsHighlightUtil {
}
if (type instanceof PsiClassType) {
final PsiClassType classType = (PsiClassType)type;
final PsiClassType classType = (PsiClassType)PsiUtil.convertAnonymousToBaseType(type);
if (classType.isRaw()) {
return true;
}
if (!classType.hasParameters()) {
return true;
PsiType[] parameters = classType.getParameters();
for (PsiType parameter : parameters) {
if (parameter instanceof PsiWildcardType && ((PsiWildcardType)parameter).getBound() == null) {
return true;
}
}
return !classType.hasNonTrivialParameters();
final PsiClass resolved = ((PsiClassType)PsiUtil.convertAnonymousToBaseType(classType)).resolve();
if (resolved instanceof PsiTypeParameter) {
return false;
}
return parameters.length == 0;
}
return false;
@@ -1253,29 +1151,6 @@ public class GenericsHighlightUtil {
return list;
}
public static HighlightInfo checkGenericCallWithRawArguments(JavaResolveResult resolveResult, PsiCallExpression callExpression) {
final PsiMethod method = (PsiMethod)resolveResult.getElement();
if (method == null) return null;
final PsiSubstitutor substitutor = resolveResult.getSubstitutor();
final PsiExpressionList argumentList = callExpression.getArgumentList();
if (argumentList == null) return null;
final PsiExpression[] expressions = argumentList.getExpressions();
final PsiParameter[] parameters = method.getParameterList().getParameters();
if (parameters.length != 0) {
for (int i = 0; i < expressions.length; i++) {
PsiParameter parameter = parameters[Math.min(i, parameters.length - 1)];
final PsiExpression expression = expressions[i];
final PsiType parameterType = substitutor.substitute(parameter.getType());
final PsiType expressionType = substitutor.substitute(expression.getType());
if (expressionType != null) {
final HighlightInfo highlightInfo = checkRawToGenericAssignment(parameterType, expressionType, expression);
if (highlightInfo != null) return highlightInfo;
}
}
}
return null;
}
public static HighlightInfo checkParametersOnRaw(PsiReferenceParameterList refParamList) {
if (refParamList.getTypeArguments().length == 0) return null;
JavaResolveResult resolveResult = null;
@@ -1334,42 +1209,6 @@ public class GenericsHighlightUtil {
return null;
}
public static HighlightInfo checkUncheckedOverriding (PsiMethod overrider, final List<HierarchicalMethodSignature> superMethodSignatures) {
if (!PsiUtil.isLanguageLevel5OrHigher(overrider)) return null;
final HighlightDisplayKey key = HighlightDisplayKey.find(UncheckedWarningLocalInspection.SHORT_NAME);
final InspectionProfile inspectionProfile =
InspectionProjectProfileManager.getInstance(overrider.getProject()).getInspectionProfile();
if (!inspectionProfile.isToolEnabled(key, overrider)) return null;
final LocalInspectionTool tool =
((LocalInspectionToolWrapper)inspectionProfile.getInspectionTool(UncheckedWarningLocalInspection.SHORT_NAME, overrider)).getTool();
if (InspectionManagerEx.inspectionResultSuppressed(overrider, tool)) return null;
final MethodSignature signature = overrider.getSignature(PsiSubstitutor.EMPTY);
for (MethodSignatureBackedByPsiMethod superSignature : superMethodSignatures) {
PsiMethod baseMethod = superSignature.getMethod();
PsiSubstitutor substitutor = MethodSignatureUtil.getSuperMethodSignatureSubstitutor(signature, superSignature);
if (substitutor == null) substitutor = superSignature.getSubstitutor();
if (PsiUtil.isRawSubstitutor(baseMethod, superSignature.getSubstitutor())) continue;
final PsiType baseReturnType = substitutor.substitute(baseMethod.getReturnType());
final PsiType overriderReturnType = overrider.getReturnType();
if (baseReturnType == null || overriderReturnType == null) return null;
if (isRawToGeneric(baseReturnType, overriderReturnType)) {
final String message = JavaErrorMessages.message("unchecked.overriding.incompatible.return.type",
HighlightUtil.formatType(overriderReturnType),
HighlightUtil.formatType(baseReturnType));
final PsiTypeElement returnTypeElement = overrider.getReturnTypeElement();
LOG.assertTrue(returnTypeElement != null);
final HighlightInfo highlightInfo = HighlightInfo.createHighlightInfo(JavaHightlightInfoTypes.UNCHECKED_WARNING, returnTypeElement, message);
QuickFixAction.registerQuickFixAction(highlightInfo,
new EmptyIntentionAction(JavaErrorMessages.message("unchecked.overriding")),
key);
return highlightInfo;
}
}
return null;
}
public static HighlightInfo checkEnumMustNotBeLocal(final PsiClass aClass) {
if (!aClass.isEnum()) return null;
PsiElement parent = aClass.getParent();
@@ -317,13 +317,6 @@ public class HighlightMethodUtil {
if (element instanceof PsiMethod && resolveResult.isValidResult()) {
TextRange fixRange = getFixRange(methodCall);
highlightInfo = HighlightUtil.checkUnhandledExceptions(methodCall, fixRange);
if (highlightInfo == null) {
highlightInfo = GenericsHighlightUtil.checkUncheckedCall(resolveResult, methodCall);
}
if (highlightInfo == null) {
highlightInfo = GenericsHighlightUtil.checkGenericCallWithRawArguments(resolveResult, methodCall);
}
}
else {
PsiMethod resolvedMethod = null;
@@ -1271,11 +1264,7 @@ public class HighlightMethodUtil {
ChangeStringLiteralToCharInMethodCallFix.registerFixes(constructors, constructorCall, info);
}
else {
HighlightInfo highlightInfo = GenericsHighlightUtil.checkUncheckedCall(result, constructorCall);
if (highlightInfo != null) {
holder.add(highlightInfo);
return;
}
HighlightInfo highlightInfo;
if (constructorCall instanceof PsiNewExpression) {
highlightInfo = GenericsHighlightUtil.checkReferenceTypeArgumentList(constructor,
((PsiNewExpression)constructorCall).getTypeArgumentList(),
@@ -1284,13 +1273,7 @@ public class HighlightMethodUtil {
holder.add(highlightInfo);
return;
}
highlightInfo = GenericsHighlightUtil.checkGenericCallWithRawArguments(result, (PsiCallExpression)constructorCall);
if (highlightInfo != null) {
holder.add(highlightInfo);
}
//if (PsiUtil.isLanguageLevel7OrHigher(constructorCall)) {
// // todo[anna] check if not diamond - apply corresponding fix
//}
}
}
}
@@ -459,8 +459,7 @@ public class HighlightUtil {
if (rType == null || lType == null || TypeConversionUtil.isAssignable(lType, rType)) return null;
}
else if (TypeConversionUtil.areTypesAssignmentCompatible(lType, expression)) {
if (lType == null || rType == null) return null;
return GenericsHighlightUtil.checkRawToGenericAssignment(lType, rType, expression);
return null;
}
if (rType == null) {
rType = expression.getType();
@@ -1131,7 +1130,7 @@ public class HighlightUtil {
return null;
}
private static PsiType sameType(PsiExpression[] expressions) {
public static PsiType sameType(PsiExpression[] expressions) {
PsiType type = null;
for (PsiExpression expression : expressions) {
final PsiType currentType;
@@ -635,7 +635,6 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh
if (!myHolder.hasErrorResults()) myHolder.add(HighlightMethodUtil.checkMethodIncompatibleThrows(methodSignature, superMethodSignatures, true, method.getContainingClass()));
if (!method.hasModifierProperty(PsiModifier.STATIC)) {
if (!myHolder.hasErrorResults()) myHolder.add(HighlightMethodUtil.checkMethodWeakerPrivileges(methodSignature, superMethodSignatures, true));
if (!myHolder.hasErrorResults()) myHolder.add(GenericsHighlightUtil.checkUncheckedOverriding(method, superMethodSignatures));
if (!myHolder.hasErrorResults()) myHolder.add(HighlightMethodUtil.checkMethodOverridesFinal(methodSignature, superMethodSignatures));
}
}
@@ -836,7 +835,6 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh
if (!myHolder.hasErrorResults()) myHolder.add(HighlightMethodUtil.checkConstructorCallMustBeFirstStatement(expression));
if (!myHolder.hasErrorResults()) myHolder.add(GenericsHighlightUtil.checkAccessStaticFieldFromEnumConstructor(expression, result));
if (!myHolder.hasErrorResults()) myHolder.add(HighlightUtil.checkClassReferenceAfterQualifier(expression, resolved));
if (!myHolder.hasErrorResults()) myHolder.add(GenericsHighlightUtil.checkUncheckedGenericsArrayCreation(expression, resolved));
}
@Override public void visitReferenceList(PsiReferenceList list) {
@@ -917,7 +915,6 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh
@Override public void visitTypeCastExpression(PsiTypeCastExpression typeCast) {
super.visitTypeCastExpression(typeCast);
if (!myHolder.hasErrorResults()) myHolder.add(HighlightUtil.checkInconvertibleTypeCast(typeCast));
if (!myHolder.hasErrorResults()) myHolder.add(GenericsHighlightUtil.checkUncheckedTypeCast(typeCast));
}
@Override public void visitTypeParameterList(PsiTypeParameterList list) {
@@ -18,14 +18,19 @@ package com.intellij.codeInsight.daemon.impl.quickfix;
import com.intellij.codeInsight.daemon.QuickFixBundle;
import com.intellij.codeInsight.intention.IntentionAction;
import com.intellij.codeInsight.CodeInsightUtilBase;
import com.intellij.codeInspection.LocalQuickFix;
import com.intellij.codeInspection.ProblemDescriptor;
import com.intellij.openapi.application.Result;
import com.intellij.openapi.command.WriteCommandAction;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.fileEditor.FileEditorManager;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiManager;
import com.intellij.refactoring.actions.TypeCookAction;
import org.jetbrains.annotations.NotNull;
public class GenerifyFileFix implements IntentionAction {
public class GenerifyFileFix implements IntentionAction, LocalQuickFix {
private final PsiFile myFile;
public GenerifyFileFix(PsiFile file) {
@@ -37,11 +42,28 @@ public class GenerifyFileFix implements IntentionAction {
return QuickFixBundle.message("generify.text", myFile.getName());
}
@NotNull
@Override
public String getName() {
return getText();
}
@NotNull
public String getFamilyName() {
return QuickFixBundle.message("generify.family");
}
@Override
public void applyFix(@NotNull final Project project, @NotNull final ProblemDescriptor descriptor) {
if (isAvailable(project, null, null)) {
new WriteCommandAction(project) {
protected void run(Result result) throws Throwable {
invoke(project, FileEditorManager.getInstance(project).getSelectedTextEditor(), descriptor.getPsiElement().getContainingFile());
}
}.execute();
}
}
public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
return myFile.isValid() && PsiManager.getInstance(project).isInProject(myFile);
}
@@ -18,6 +18,7 @@ package com.intellij.codeInsight.daemon.impl.quickfix;
import com.intellij.codeInsight.CodeInsightUtilBase;
import com.intellij.codeInsight.daemon.QuickFixBundle;
import com.intellij.codeInsight.intention.IntentionAction;
import com.intellij.codeInspection.IntentionAndQuickFixAction;
import com.intellij.openapi.command.undo.UndoUtil;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.Editor;
@@ -29,7 +30,7 @@ import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class VariableArrayTypeFix implements IntentionAction {
public class VariableArrayTypeFix extends IntentionAndQuickFixAction {
private static final Logger LOG = Logger.getInstance("#com.intellij.codeInsight.daemon.impl.quickfix.VariableArrayTypeFix");
private final PsiVariable myVariable;
@@ -93,12 +94,15 @@ public class VariableArrayTypeFix implements IntentionAction {
}
@NotNull
public String getText() {
@Override
public String getName() {
return myTargetType.equals(myVariable.getType()) && myNewExpression != null ?
QuickFixBundle.message("change.new.operator.type.text", getNewText(), myTargetType.getCanonicalText(), "") :
QuickFixBundle.message("fix.variable.type.text", myVariable.getName(), myTargetType.getCanonicalText());
}
@NotNull
public String getFamilyName() {
return myTargetType.equals(myVariable.getType()) && myNewExpression != null ?
@@ -113,7 +117,8 @@ public class VariableArrayTypeFix implements IntentionAction {
&& myInitializer.isValid();
}
public void invoke(@NotNull final Project project, final Editor editor, final PsiFile file) throws IncorrectOperationException {
@Override
public void applyFix(Project project, PsiFile file, @Nullable Editor editor) {
if (!CodeInsightUtilBase.prepareFileForWrite(myVariable.getContainingFile())) return;
try {
final PsiElementFactory factory = JavaPsiFacade.getInstance(file.getProject()).getElementFactory();
@@ -18,6 +18,7 @@ package com.intellij.codeInsight.daemon.impl.quickfix;
import com.intellij.codeInsight.CodeInsightUtilBase;
import com.intellij.codeInsight.daemon.QuickFixBundle;
import com.intellij.codeInsight.intention.IntentionAction;
import com.intellij.codeInspection.IntentionAndQuickFixAction;
import com.intellij.openapi.command.undo.UndoUtil;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.Editor;
@@ -27,8 +28,9 @@ import com.intellij.psi.codeStyle.JavaCodeStyleManager;
import com.intellij.psi.util.TypeConversionUtil;
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class VariableTypeFix implements IntentionAction {
public class VariableTypeFix extends IntentionAndQuickFixAction {
static final Logger LOG = Logger.getInstance("#com.intellij.codeInsight.daemon.impl.quickfix.VariableTypeFix");
private final PsiVariable myVariable;
@@ -39,8 +41,10 @@ public class VariableTypeFix implements IntentionAction {
myReturnType = toReturn != null ? GenericsUtil.getVariableTypeByExpressionType(toReturn) : null;
}
@NotNull
public String getText() {
@Override
public String getName() {
return QuickFixBundle.message("fix.variable.type.text",
getVariable().getName(),
getReturnType().getCanonicalText());
@@ -61,7 +65,8 @@ public class VariableTypeFix implements IntentionAction {
&& !TypeConversionUtil.isVoidType(getReturnType());
}
public void invoke(@NotNull Project project, Editor editor, PsiFile file) {
@Override
public void applyFix(Project project, PsiFile file, @Nullable Editor editor) {
if (!CodeInsightUtilBase.prepareFileForWrite(getVariable().getContainingFile())) return;
try {
getVariable().normalizeDeclaration();
@@ -39,7 +39,10 @@ public class InsertLiteralUnderscoresAction extends PsiElementBaseIntentionActio
!PsiType.FLOAT.equals(type) && !PsiType.DOUBLE.equals(type)) return false;
final String text = literalExpression.getText();
return text != null && !text.contains("_");
if (text == null || text.contains("_")) return false;
final String converted = LiteralFormatUtil.format(text, type);
return converted.length() != text.length();
}
@Override
@@ -16,6 +16,7 @@
package com.intellij.codeInspection;
import com.intellij.codeInsight.daemon.GroupNames;
import com.intellij.codeInsight.intention.HighPriorityAction;
import com.intellij.openapi.project.Project;
import com.intellij.pom.java.LanguageLevel;
import com.intellij.psi.*;
@@ -71,29 +72,8 @@ public class ExplicitTypeCanBeDiamondInspection extends BaseJavaLocalInspectionT
final PsiTypeElement[] typeElements = parameterList.getTypeParameterElements();
if (typeElements.length > 0) {
if (typeElements.length == 1 && typeElements[0].getType() instanceof PsiDiamondType) return;
holder.registerProblem(parameterList, "Redundant type argument #ref #loc",
new LocalQuickFix() {
@NotNull
@Override
public String getName() {
return "Replace with <>";
}
@NotNull
@Override
public String getFamilyName() {
return getName();
}
@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
final PsiElement psiElement = descriptor.getPsiElement();
if (psiElement instanceof PsiReferenceParameterList) {
final PsiTypeElement[] parameterElements = ((PsiReferenceParameterList)psiElement).getTypeParameterElements();
psiElement.deleteChildRange(parameterElements[0], parameterElements[parameterElements.length - 1]);
}
}
});
holder.registerProblem(parameterList, "Redundant type argument #ref #loc",
ProblemHighlightType.LIKE_UNUSED_SYMBOL, new ReplaceWithDiamondFix());
}
}
}
@@ -101,4 +81,27 @@ public class ExplicitTypeCanBeDiamondInspection extends BaseJavaLocalInspectionT
}
};
}
private static class ReplaceWithDiamondFix implements LocalQuickFix, HighPriorityAction {
@NotNull
@Override
public String getName() {
return "Replace with <>";
}
@NotNull
@Override
public String getFamilyName() {
return getName();
}
@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
final PsiElement psiElement = descriptor.getPsiElement();
if (psiElement instanceof PsiReferenceParameterList) {
final PsiTypeElement[] parameterElements = ((PsiReferenceParameterList)psiElement).getTypeParameterElements();
psiElement.deleteChildRange(parameterElements[0], parameterElements[parameterElements.length - 1]);
}
}
}
}
@@ -17,7 +17,9 @@ package com.intellij.codeInspection;
import com.intellij.codeInsight.AnnotationUtil;
import com.intellij.codeInsight.daemon.GroupNames;
import com.intellij.codeInsight.daemon.impl.HighlightInfo;
import com.intellij.codeInsight.daemon.impl.analysis.GenericsHighlightUtil;
import com.intellij.codeInspection.uncheckedWarnings.UncheckedWarningLocalInspection;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.TextRange;
@@ -105,8 +107,8 @@ public class RedundantUncheckedSuppressWarningsInspection extends BaseJavaLocalI
}
private static void checkIfSafeToRemoveWarning(PsiElement suppressElement, PsiElement placeToCheckWarningsIn, ProblemsHolder holder) {
final HashSet<PsiReferenceExpression> warningsElements = new HashSet<PsiReferenceExpression>();
collectUncheckedWarnings(placeToCheckWarningsIn, true, warningsElements);
final HashSet<PsiElement> warningsElements = new HashSet<PsiElement>();
collectUncheckedWarnings(placeToCheckWarningsIn, warningsElements);
if (warningsElements.isEmpty()) {
final int uncheckedIdx = suppressElement.getText().indexOf(RemoveUncheckedWarningFix.UNCHECKED);
holder.registerProblem(suppressElement,
@@ -115,14 +117,19 @@ public class RedundantUncheckedSuppressWarningsInspection extends BaseJavaLocalI
}
}
public static void collectUncheckedWarnings(final PsiElement place, final boolean ignoreSuppressed, final Collection<PsiReferenceExpression> warningsElements) {
place.accept(new JavaRecursiveElementVisitor() {
@Override
public void visitReferenceExpression(PsiReferenceExpression expression) {
super.visitReferenceExpression(expression);
if (GenericsHighlightUtil.isUncheckedWarning(expression, expression.resolve(), ignoreSuppressed)) {
warningsElements.add(expression);
public static void collectUncheckedWarnings(final PsiElement place, final Collection<PsiElement> warningsElements) {
final UncheckedWarningLocalInspection.UncheckedWarningsVisitor visitor =
new UncheckedWarningLocalInspection.UncheckedWarningsVisitor(false) {
@Override
protected void registerProblem(String message, PsiElement psiElement, LocalQuickFix... quickFix) {
warningsElements.add(psiElement);
}
};
place.accept(new JavaRecursiveElementVisitor(){
@Override
public void visitElement(PsiElement element) {
super.visitElement(element);
element.accept(visitor);
}
});
}
@@ -68,43 +68,22 @@ public class SafeVarargsCanBeUsedInspection extends BaseJavaLocalInspectionTool
if (!PsiUtil.getLanguageLevel(method).isAtLeast(LanguageLevel.JDK_1_7)) return;
if (AnnotationUtil.isAnnotated(method, "java.lang.SafeVarargs", false)) return;
if (!method.isVarArgs()) return;
if (method.hasModifierProperty(PsiModifier.STATIC) || method.hasModifierProperty(PsiModifier.FINAL)) {
final PsiParameter psiParameter = method.getParameterList().getParameters()[method.getParameterList().getParametersCount() - 1];
final PsiType componentType = ((PsiEllipsisType)psiParameter.getType()).getComponentType();
if (GenericsHighlightUtil.isReifiableType(componentType)) {
final PsiParameter psiParameter = method.getParameterList().getParameters()[method.getParameterList().getParametersCount() - 1];
final PsiType componentType = ((PsiEllipsisType)psiParameter.getType()).getComponentType();
if (GenericsHighlightUtil.isReifiableType(componentType)) {
return;
}
for (PsiReference reference : ReferencesSearch.search(psiParameter)) {
final PsiElement element = reference.getElement();
if (element instanceof PsiExpression && !PsiUtil.isAccessedForReading((PsiExpression)element)) {
return;
}
for (PsiReference reference : ReferencesSearch.search(psiParameter)) {
final PsiElement element = reference.getElement();
if (element instanceof PsiExpression && !PsiUtil.isAccessedForReading((PsiExpression)element)) {
return;
}
}
final PsiIdentifier nameIdentifier = method.getNameIdentifier();
if (nameIdentifier != null) {
holder.registerProblem(nameIdentifier, "Possible heap pollution from parametrized vararg type #loc", new LocalQuickFix() {
@NotNull
@Override
public String getName() {
return "Annotate as @SafeVarargs";
}
@NotNull
@Override
public String getFamilyName() {
return getName();
}
@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
final PsiElement psiElement = descriptor.getPsiElement();
if (psiElement instanceof PsiIdentifier) {
final PsiMethod psiMethod = (PsiMethod)psiElement.getParent();
new AddAnnotationFix("java.lang.SafeVarargs", psiMethod).applyFix(project, descriptor);
}
}
});
}
}
final PsiIdentifier nameIdentifier = method.getNameIdentifier();
if (nameIdentifier != null) {
holder.registerProblem(nameIdentifier, "Possible heap pollution from parameterized vararg type #loc",
//todo check if can be final or static
method.hasModifierProperty(PsiModifier.FINAL) || method.hasModifierProperty(PsiModifier.STATIC) ? new AnnotateAsSafeVarargsQuickFix() : null);
}
}
@@ -113,4 +92,27 @@ public class SafeVarargsCanBeUsedInspection extends BaseJavaLocalInspectionTool
}
};
}
private static class AnnotateAsSafeVarargsQuickFix implements LocalQuickFix {
@NotNull
@Override
public String getName() {
return "Annotate as @SafeVarargs";
}
@NotNull
@Override
public String getFamilyName() {
return getName();
}
@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
final PsiElement psiElement = descriptor.getPsiElement();
if (psiElement instanceof PsiIdentifier) {
final PsiMethod psiMethod = (PsiMethod)psiElement.getParent();
new AddAnnotationFix("java.lang.SafeVarargs", psiMethod).applyFix(project, descriptor);
}
}
}
}
@@ -16,20 +16,38 @@
package com.intellij.codeInspection.uncheckedWarnings;
import com.intellij.codeInspection.BaseJavaLocalInspectionTool;
import com.intellij.codeInspection.InspectionsBundle;
import com.intellij.codeInsight.daemon.JavaErrorMessages;
import com.intellij.codeInsight.daemon.impl.HighlightInfo;
import com.intellij.codeInsight.daemon.impl.analysis.GenericsHighlightUtil;
import com.intellij.codeInsight.daemon.impl.analysis.HighlightUtil;
import com.intellij.codeInsight.daemon.impl.quickfix.GenerifyFileFix;
import com.intellij.codeInsight.daemon.impl.quickfix.QuickFixAction;
import com.intellij.codeInsight.daemon.impl.quickfix.VariableArrayTypeFix;
import com.intellij.codeInsight.intention.IntentionAction;
import com.intellij.codeInsight.intention.QuickFixFactory;
import com.intellij.codeInsight.quickfix.ChangeVariableTypeQuickFixProvider;
import com.intellij.codeInspection.*;
import com.intellij.codeInspection.ex.UnfairLocalInspectionTool;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.extensions.Extensions;
import com.intellij.psi.*;
import com.intellij.psi.util.*;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.List;
/**
* User: anna
* Date: 17-Feb-2006
*/
public class UncheckedWarningLocalInspection extends BaseJavaLocalInspectionTool implements UnfairLocalInspectionTool {
public class UncheckedWarningLocalInspection extends BaseJavaLocalInspectionTool {
@NonNls public static final String SHORT_NAME = "UNCHECKED_WARNING";
public static final String DISPLAY_NAME = InspectionsBundle.message("unchecked.warning");
@NonNls public static final String ID = "unchecked";
private static final Logger LOG = Logger.getInstance("#" + UncheckedWarningLocalInspection.class);
@NotNull
public String getGroupDisplayName() {
@@ -56,4 +74,303 @@ public class UncheckedWarningLocalInspection extends BaseJavaLocalInspectionTool
public boolean isEnabledByDefault() {
return true;
}
@NotNull
@Override
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, final boolean isOnTheFly) {
return new UncheckedWarningsVisitor(isOnTheFly){
@Override
protected void registerProblem(String message, PsiElement psiElement, LocalQuickFix... quickFix) {
holder.registerProblem(psiElement, message, quickFix);
}
};
}
public static abstract class UncheckedWarningsVisitor extends JavaElementVisitor {
private final boolean myOnTheFly;
public UncheckedWarningsVisitor(boolean onTheFly) {
myOnTheFly = onTheFly;
}
protected abstract void registerProblem(String message, PsiElement psiElement, LocalQuickFix... quickFix);
@Override
public void visitReferenceExpression(PsiReferenceExpression expression) {
if (!PsiUtil.isLanguageLevel5OrHigher(expression)) return;
if (GenericsHighlightUtil.isUncheckedWarning(expression, expression.resolve())) {
registerProblem("Unchecked generics array creation for varargs parameter", expression, null);
}
}
@Override
public void visitNewExpression(PsiNewExpression expression) {
super.visitNewExpression(expression);
if (!PsiUtil.isLanguageLevel5OrHigher(expression)) return;
final PsiJavaCodeReferenceElement classReference = expression.getClassOrAnonymousClassReference();
if (GenericsHighlightUtil.isUncheckedWarning(classReference, expression.resolveConstructor())) {
registerProblem("Unchecked generics array creation for varargs parameter", classReference, null);
}
}
@Override
public void visitTypeCastExpression(PsiTypeCastExpression expression) {
super.visitTypeCastExpression(expression);
if (!PsiUtil.isLanguageLevel5OrHigher(expression)) return;
final PsiTypeElement typeElement = expression.getCastType();
if (typeElement == null) return;
final PsiType castType = typeElement.getType();
final PsiExpression operand = expression.getOperand();
if (operand == null) return;
final PsiType exprType = operand.getType();
if (exprType == null) return;
if (!TypeConversionUtil.areTypesConvertible(exprType, castType)) return;
if (GenericsHighlightUtil.isUncheckedCast(castType, exprType)) {
final String description =
JavaErrorMessages.message("generics.unchecked.cast", HighlightUtil.formatType(exprType), HighlightUtil.formatType(castType));
registerProblem(description, expression, myOnTheFly ? new GenerifyFileFix(operand.getContainingFile()) : null);
}
}
@Override
public void visitCallExpression(PsiCallExpression callExpression) {
super.visitCallExpression(callExpression);
if (!PsiUtil.isLanguageLevel5OrHigher(callExpression)) return;
final JavaResolveResult result = callExpression.resolveMethodGenerics();
final String description = getUncheckedCallDescription(result);
if (description != null) {
registerProblem(description, callExpression instanceof PsiMethodCallExpression
? ((PsiMethodCallExpression)callExpression).getMethodExpression()
: callExpression, myOnTheFly ? new GenerifyFileFix(callExpression.getContainingFile()) : null);
}
else {
final PsiSubstitutor substitutor = result.getSubstitutor();
final PsiExpressionList argumentList = callExpression.getArgumentList();
if (argumentList != null) {
final PsiMethod method = (PsiMethod)result.getElement();
if (method != null) {
final PsiExpression[] expressions = argumentList.getExpressions();
final PsiParameter[] parameters = method.getParameterList().getParameters();
if (parameters.length != 0) {
for (int i = 0; i < expressions.length; i++) {
PsiParameter parameter = parameters[Math.min(i, parameters.length - 1)];
final PsiExpression expression = expressions[i];
final PsiType parameterType = substitutor.substitute(parameter.getType());
final PsiType expressionType = substitutor.substitute(expression.getType());
if (expressionType != null) {
checkRawToGenericsAssignment(expression, parameterType, expressionType, true, myOnTheFly ? new GenerifyFileFix(expression.getContainingFile()) : null);
}
}
}
}
}
}
}
@Override
public void visitVariable(PsiVariable variable) {
super.visitVariable(variable);
if (!PsiUtil.isLanguageLevel5OrHigher(variable)) return;
PsiExpression initializer = variable.getInitializer();
if (initializer == null || initializer instanceof PsiArrayInitializerExpression) return;
final PsiType initializerType = initializer.getType();
checkRawToGenericsAssignment(initializer, variable.getType(), initializerType, true, myOnTheFly ? getChangeVariableTypeFixes(variable, initializerType) : null);
}
@Override
public void visitForeachStatement(PsiForeachStatement statement) {
super.visitForeachStatement(statement);
if (!PsiUtil.isLanguageLevel5OrHigher(statement)) return;
final PsiParameter parameter = statement.getIterationParameter();
final PsiType parameterType = parameter.getType();
final PsiType itemType = GenericsHighlightUtil.getCollectionItemType(statement.getIteratedValue());
if (!PsiUtil.isLanguageLevel5OrHigher(statement)) return;
checkRawToGenericsAssignment(parameter, parameterType, itemType, true, myOnTheFly ? getChangeVariableTypeFixes(parameter, itemType) : null);
}
@Override
public void visitAssignmentExpression(PsiAssignmentExpression expression) {
super.visitAssignmentExpression(expression);
if (!PsiUtil.isLanguageLevel5OrHigher(expression)) return;
if (!"=".equals(expression.getOperationSign().getText())) return;
PsiExpression lExpr = expression.getLExpression();
PsiExpression rExpr = expression.getRExpression();
if (rExpr == null) return;
PsiType lType = lExpr.getType();
PsiType rType = rExpr.getType();
if (rType == null) return;
PsiVariable leftVar = null;
if (lExpr instanceof PsiReferenceExpression) {
PsiElement element = ((PsiReferenceExpression)lExpr).resolve();
if (element instanceof PsiVariable) {
leftVar = (PsiVariable)element;
}
}
checkRawToGenericsAssignment(rExpr, lType, rType, true, myOnTheFly && leftVar != null ? getChangeVariableTypeFixes(leftVar, rType) : null);
}
@Override
public void visitArrayInitializerExpression(PsiArrayInitializerExpression arrayInitializer) {
super.visitArrayInitializerExpression(arrayInitializer);
if (!PsiUtil.isLanguageLevel5OrHigher(arrayInitializer)) return;
final PsiType type = arrayInitializer.getType();
if (!(type instanceof PsiArrayType)) return;
final PsiType componentType = ((PsiArrayType)type).getComponentType();
boolean arrayTypeFixChecked = false;
VariableArrayTypeFix fix = null;
final PsiExpression[] initializers = arrayInitializer.getInitializers();
for (PsiExpression expression : initializers) {
final PsiType itemType = expression.getType();
if (itemType == null) continue;
if (!TypeConversionUtil.isAssignable(componentType, itemType)) continue;
if (GenericsHighlightUtil.isRawToGeneric(componentType, itemType)) {
String description = JavaErrorMessages.message("generics.unchecked.assignment",
HighlightUtil.formatType(itemType),
HighlightUtil.formatType(componentType));
if (!arrayTypeFixChecked) {
final PsiType checkResult = HighlightUtil.sameType(initializers);
fix = checkResult != null ? new VariableArrayTypeFix(arrayInitializer, checkResult) : null;
arrayTypeFixChecked = true;
}
if (fix != null) {
registerProblem(description, expression, (LocalQuickFix)fix);
}
}
}
}
private void checkRawToGenericsAssignment(PsiElement parameter,
PsiType parameterType,
PsiType itemType,
boolean checkAssignability,
final LocalQuickFix... quickFix) {
if (parameterType == null || itemType == null) return;
if (checkAssignability && !TypeConversionUtil.isAssignable(parameterType, itemType)) return;
if (GenericsHighlightUtil.isRawToGeneric(parameterType, itemType)) {
String description = JavaErrorMessages.message("generics.unchecked.assignment",
HighlightUtil.formatType(itemType),
HighlightUtil.formatType(parameterType));
registerProblem(description, parameter, quickFix);
}
}
@Override
public void visitMethod(PsiMethod method) {
super.visitMethod(method);
if (!PsiUtil.isLanguageLevel5OrHigher(method)) return;
if (!method.isConstructor()) {
List<HierarchicalMethodSignature> superMethodSignatures = method.getHierarchicalMethodSignature().getSuperSignatures();
if (!superMethodSignatures.isEmpty() && !method.hasModifierProperty(PsiModifier.STATIC)) {
final MethodSignature signature = method.getSignature(PsiSubstitutor.EMPTY);
for (MethodSignatureBackedByPsiMethod superSignature : superMethodSignatures) {
PsiMethod baseMethod = superSignature.getMethod();
PsiSubstitutor substitutor = MethodSignatureUtil.getSuperMethodSignatureSubstitutor(signature, superSignature);
if (substitutor == null) substitutor = superSignature.getSubstitutor();
if (PsiUtil.isRawSubstitutor(baseMethod, superSignature.getSubstitutor())) continue;
final PsiType baseReturnType = substitutor.substitute(baseMethod.getReturnType());
final PsiType overriderReturnType = method.getReturnType();
if (baseReturnType == null || overriderReturnType == null) return;
if (GenericsHighlightUtil.isRawToGeneric(baseReturnType, overriderReturnType)) {
final String message = JavaErrorMessages.message("unchecked.overriding.incompatible.return.type",
HighlightUtil.formatType(overriderReturnType),
HighlightUtil.formatType(baseReturnType));
final PsiTypeElement returnTypeElement = method.getReturnTypeElement();
LOG.assertTrue(returnTypeElement != null);
registerProblem(message, returnTypeElement);
}
}
}
}
}
@Override
public void visitReturnStatement(PsiReturnStatement statement) {
super.visitReturnStatement(statement);
if (!PsiUtil.isLanguageLevel5OrHigher(statement)) return;
final PsiMethod method = PsiTreeUtil.getParentOfType(statement, PsiMethod.class);
if (method != null) {
final PsiType returnType = method.getReturnType();
if (returnType != null && returnType != PsiType.VOID) {
final PsiExpression returnValue = statement.getReturnValue();
if (returnValue != null) {
final PsiType valueType = returnValue.getType();
if (valueType != null) {
checkRawToGenericsAssignment(returnValue, returnType, valueType,
false,
(LocalQuickFix)QuickFixFactory.getInstance().createMethodReturnFix(method, valueType, true));
}
}
}
}
}
@Nullable
public static String getUncheckedCallDescription(JavaResolveResult resolveResult) {
final PsiMethod method = (PsiMethod)resolveResult.getElement();
if (method == null) return null;
final PsiSubstitutor substitutor = resolveResult.getSubstitutor();
final PsiParameter[] parameters = method.getParameterList().getParameters();
for (final PsiParameter parameter : parameters) {
final PsiType parameterType = parameter.getType();
if (parameterType.accept(new PsiTypeVisitor<Boolean>() {
public Boolean visitPrimitiveType(PsiPrimitiveType primitiveType) {
return Boolean.FALSE;
}
public Boolean visitArrayType(PsiArrayType arrayType) {
return arrayType.getComponentType().accept(this);
}
public Boolean visitClassType(PsiClassType classType) {
PsiClass psiClass = classType.resolve();
if (psiClass instanceof PsiTypeParameter) {
return substitutor.substitute((PsiTypeParameter)psiClass) == null ? Boolean.TRUE : Boolean.FALSE;
}
PsiType[] parameters = classType.getParameters();
for (PsiType parameter : parameters) {
if (parameter.accept(this).booleanValue()) return Boolean.TRUE;
}
return Boolean.FALSE;
}
public Boolean visitWildcardType(PsiWildcardType wildcardType) {
PsiType bound = wildcardType.getBound();
if (bound != null) return bound.accept(this);
return Boolean.FALSE;
}
public Boolean visitEllipsisType(PsiEllipsisType ellipsisType) {
return ellipsisType.getComponentType().accept(this);
}
}).booleanValue()) {
final PsiElementFactory elementFactory = JavaPsiFacade.getInstance(method.getProject()).getElementFactory();
PsiType type = elementFactory.createType(method.getContainingClass(), substitutor);
return JavaErrorMessages.message("generics.unchecked.call.to.member.of.raw.type",
HighlightUtil.formatMethod(method),
HighlightUtil.formatType(type));
}
}
return null;
}
}
public static LocalQuickFix[] getChangeVariableTypeFixes(PsiVariable parameter, PsiType itemType) {
final List<LocalQuickFix> result = new ArrayList<LocalQuickFix>();
for (ChangeVariableTypeQuickFixProvider fixProvider : Extensions.getExtensions(ChangeVariableTypeQuickFixProvider.EP_NAME)) {
for (IntentionAction action : fixProvider.getFixes(parameter, itemType)) {
if (action instanceof LocalQuickFix) {
result.add((LocalQuickFix)action);
}
}
}
return result.toArray(new LocalQuickFix[result.size()]);
}
}
@@ -66,7 +66,8 @@ public class ClassesTreeStructureProvider implements SelectableTreeStructureProv
PsiClass[] classes = classOwner.getClasses();
if (fileInRoots(file)) {
if (classes.length == 1 && !(classes[0] instanceof SyntheticElement)) {
if (classes.length == 1 && !(classes[0] instanceof SyntheticElement) &&
(file == null || file.getNameWithoutExtension().equals(classes[0].getName()))) {
result.add(new ClassTreeNode(myProject, classes[0], settings1));
} else {
result.add(new PsiClassOwnerTreeNode(classOwner, settings1));
@@ -18,6 +18,8 @@ package com.intellij.psi.impl;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.psi.*;
import com.intellij.psi.util.TypeConversionUtil;
import com.intellij.util.Function;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.containers.HashMap;
import gnu.trove.THashMap;
import gnu.trove.TObjectHashingStrategy;
@@ -25,10 +27,7 @@ import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import java.util.Set;
import java.util.*;
/**
* @author ik, dsl
@@ -99,11 +98,13 @@ public class PsiSubstitutorImpl implements PsiSubstitutor {
}
private abstract static class SubstitutionVisitorBase extends PsiTypeVisitorEx<PsiType> {
@Override
public PsiType visitType(PsiType type) {
LOG.assertTrue(false);
return null;
}
@Override
public PsiType visitWildcardType(PsiWildcardType wildcardType) {
final PsiType bound = wildcardType.getBound();
if (bound == null) {
@@ -135,10 +136,12 @@ public class PsiSubstitutorImpl implements PsiSubstitutor {
return PsiWildcardType.createUnbounded(wildcardType.getManager());
}
@Override
public PsiType visitPrimitiveType(PsiPrimitiveType primitiveType) {
return primitiveType;
}
@Override
public PsiType visitArrayType(PsiArrayType arrayType) {
final PsiType componentType = arrayType.getComponentType();
final PsiType substitutedComponentType = componentType.accept(this);
@@ -147,6 +150,7 @@ public class PsiSubstitutorImpl implements PsiSubstitutor {
return new PsiArrayType(substitutedComponentType);
}
@Override
public PsiType visitEllipsisType(PsiEllipsisType ellipsisType) {
final PsiType componentType = ellipsisType.getComponentType();
final PsiType substitutedComponentType = componentType.accept(this);
@@ -155,15 +159,26 @@ public class PsiSubstitutorImpl implements PsiSubstitutor {
return new PsiEllipsisType(substitutedComponentType);
}
@Override
public PsiType visitTypeVariable(final PsiTypeVariable var) {
return var;
}
@Override
public PsiType visitBottom(final Bottom bottom) {
return bottom;
}
@Override
public abstract PsiType visitClassType(PsiClassType classType);
@Override
public PsiType visitDisjunctionType(PsiDisjunctionType disjunctionType) {
final List<PsiType> substituted = ContainerUtil.map(disjunctionType.getDisjunctions(), new Function<PsiType, PsiType>() {
@Override public PsiType fun(PsiType psiType) { return psiType.accept(SubstitutionVisitorBase.this); }
});
return new PsiDisjunctionType(substituted, disjunctionType.getManager());
}
}
private final SubstitutionVisitor myAddingBoundsSubstitutionVisitor = new SubstitutionVisitor(SubstituteKind.ADD_BOUNDS);
@@ -13,10 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* @author max
*/
package com.intellij.psi.impl.smartPointers;
import com.intellij.openapi.diagnostic.Logger;
@@ -26,20 +22,28 @@ import com.intellij.psi.impl.PsiSubstitutorImpl;
import com.intellij.psi.impl.source.PsiClassReferenceType;
import com.intellij.psi.impl.source.PsiImmediateClassType;
import com.intellij.psi.util.PsiUtil;
import com.intellij.util.Function;
import com.intellij.util.IncorrectOperationException;
import com.intellij.util.NullableFunction;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.containers.HashMap;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* @author max
*/
public class SmartTypePointerManagerImpl extends SmartTypePointerManager {
private static final Logger LOG = Logger.getInstance("#com.intellij.psi.impl.smartPointers.SmartTypePointerManagerImpl");
private final SmartPointerManager myPsiPointerManager;
private final Project myProject;
public SmartTypePointerManagerImpl(SmartPointerManager psiPointerManager, final Project project) {
public SmartTypePointerManagerImpl(final SmartPointerManager psiPointerManager, final Project project) {
myPsiPointerManager = psiPointerManager;
myProject = project;
}
@@ -102,26 +106,24 @@ public class SmartTypePointerManagerImpl extends SmartTypePointerManager {
return PsiWildcardType.createUnbounded(myManager);
}
else {
final PsiType type = myBoundPointer.getType();
assert type != null : myBoundPointer;
if (myIsExtending) {
return PsiWildcardType.createExtends(myManager, myBoundPointer.getType());
return PsiWildcardType.createExtends(myManager, type);
}
else {
return PsiWildcardType.createSuper(myManager, myBoundPointer.getType());
return PsiWildcardType.createSuper(myManager, type);
}
}
}
}
private static class ClassTypePointer implements SmartTypePointer {
private PsiType myType;
private final SmartPsiElementPointer myClass;
private final Map<SmartPsiElementPointer, SmartTypePointer> myMap;
public ClassTypePointer(PsiType type,
SmartPsiElementPointer aClass,
Map<SmartPsiElementPointer, SmartTypePointer> map) {
public ClassTypePointer(PsiType type, SmartPsiElementPointer aClass, Map<SmartPsiElementPointer, SmartTypePointer> map) {
myType = type;
myClass = aClass;
myMap = map;
@@ -182,15 +184,40 @@ public class SmartTypePointerManagerImpl extends SmartTypePointerManager {
}
}
private class DisjunctionTypePointer implements SmartTypePointer {
private PsiType myType;
private final List<SmartTypePointer> myPointers;
private DisjunctionTypePointer(final PsiDisjunctionType type) {
myType = type;
myPointers = ContainerUtil.map(type.getDisjunctions(), new Function<PsiType, SmartTypePointer>() {
@Override public SmartTypePointer fun(PsiType psiType) { return createSmartTypePointer(psiType); }
});
}
@Override
public PsiType getType() {
if (myType.isValid()) return myType;
final List<PsiType> types = ContainerUtil.map(myPointers, new NullableFunction<SmartTypePointer, PsiType>() {
@Override public PsiType fun(SmartTypePointer typePointer) { return typePointer.getType(); }
});
return new PsiDisjunctionType(types, PsiManager.getInstance(myProject));
}
}
private class SmartTypeCreatingVisitor extends PsiTypeVisitor<SmartTypePointer> {
@Override
public SmartTypePointer visitPrimitiveType(PsiPrimitiveType primitiveType) {
return new SimpleTypePointer(primitiveType);
}
@Override
public SmartTypePointer visitArrayType(PsiArrayType arrayType) {
return new ArrayTypePointer(arrayType, arrayType.getComponentType().accept(this));
}
@Override
public SmartTypePointer visitWildcardType(PsiWildcardType wildcardType) {
final PsiType bound = wildcardType.getBound();
final SmartTypePointer boundPointer;
@@ -203,6 +230,7 @@ public class SmartTypePointerManagerImpl extends SmartTypePointerManager {
return new WildcardTypePointer(wildcardType, boundPointer);
}
@Override
public SmartTypePointer visitClassType(PsiClassType classType) {
final PsiClassType.ClassResolveResult resolveResult = classType.resolveGenerics();
final PsiClass aClass = resolveResult.getElement();
@@ -226,6 +254,10 @@ public class SmartTypePointerManagerImpl extends SmartTypePointerManager {
}
return new ClassTypePointer(classType, myPsiPointerManager.createSmartPsiElementPointer(aClass), map);
}
}
@Override
public SmartTypePointer visitDisjunctionType(PsiDisjunctionType disjunctionType) {
return new DisjunctionTypePointer(disjunctionType);
}
}
}
@@ -32,6 +32,7 @@ import com.intellij.util.Function;
import com.intellij.util.IncorrectOperationException;
import com.intellij.util.PatchedSoftReference;
import com.intellij.util.SmartList;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -102,7 +103,12 @@ public class PsiTypeElementImpl extends CompositePsiElement implements PsiTypeEl
cachedType = componentType.createArrayType();
}
else {
cachedType = new PsiDisjunctionType(this);
final List<PsiTypeElement> typeElements = PsiTreeUtil.getChildrenOfTypeAsList(this, PsiTypeElement.class);
if (typeElements.size() < 2) LOG.error("Incorrect nested type: " + this);
final List<PsiType> types = ContainerUtil.map(typeElements, new Function<PsiTypeElement, PsiType>() {
@Override public PsiType fun(final PsiTypeElement psiTypeElement) { return psiTypeElement.getType(); }
});
cachedType = new PsiDisjunctionType(types, getManager());
}
}
else if (elementType == JavaElementType.JAVA_CODE_REFERENCE) {
@@ -180,15 +180,18 @@ public class JavaChangeUtilSupport implements TreeGenerator, TreeCopyHandler {
return createType(original.getProject(), originalText, null, generated);
}
if (type instanceof PsiIntersectionType) {
PsiIntersectionType intersectionType = (PsiIntersectionType)type;
LightTypeElement te = new LightTypeElement(original.getManager(), intersectionType.getConjuncts()[0]);
LightTypeElement te = new LightTypeElement(original.getManager(), ((PsiIntersectionType)type).getRepresentative());
return ChangeUtil.generateTreeElement(te, table, manager);
}
if (type instanceof PsiDisjunctionType) {
LightTypeElement te = new LightTypeElement(original.getManager(), ((PsiDisjunctionType)type).getLeastUpperBound());
return ChangeUtil.generateTreeElement(te, table, manager);
}
PsiClassType classType = (PsiClassType)type;
String text = classType.getPresentableText();
final TreeElement element = createType(original.getProject(), text, original, false);
PsiTypeElementImpl result = (PsiTypeElementImpl)SourceTreeToPsiMap.treeElementToPsi(element);
PsiTypeElementImpl result = SourceTreeToPsiMap.treeToPsiNotNull(element);
CodeEditUtil.setNodeGenerated(result, generated);
if (generated) {
@@ -397,7 +400,7 @@ public class JavaChangeUtilSupport implements TreeGenerator, TreeCopyHandler {
case PsiJavaCodeReferenceElementImpl.CLASS_NAME_KIND:
case PsiJavaCodeReferenceElementImpl.CLASS_OR_PACKAGE_NAME_KIND:
case PsiJavaCodeReferenceElementImpl.CLASS_IN_QUALIFIED_NEW_KIND:
final PsiElement target = ((PsiJavaCodeReferenceElement)SourceTreeToPsiMap.treeElementToPsi(original)).resolve();
final PsiElement target = SourceTreeToPsiMap.<PsiJavaCodeReferenceElement>treeToPsiNotNull(original).resolve();
if (target instanceof PsiClass) {
ref.putCopyableUserData(REFERENCED_CLASS_KEY, (PsiClass)target);
}
@@ -40,7 +40,7 @@ import java.util.*;
public class TypeSelectorManagerImpl implements TypeSelectorManager {
private SmartTypePointer myPointer;
private PsiType myDefaultType;
private final PsiExpression myMainOccurence;
private final PsiExpression myMainOccurrence;
private final PsiExpression[] myOccurrences;
private final PsiType[] myTypesForMain;
private final PsiType[] myTypesForAll;
@@ -49,10 +49,9 @@ public class TypeSelectorManagerImpl implements TypeSelectorManager {
private final PsiElementFactory myFactory;
private final SmartTypePointerManager mySmartTypePointerManager;
private ExpectedTypesProvider.ExpectedClassProvider myOccurrenceClassProvider;
private ExpectedTypesProvider myExpectedTypesProvider;
public TypeSelectorManagerImpl(Project project, PsiType type, PsiExpression mainOccurence, PsiExpression[] occurrences) {
this(project, type, null, mainOccurence, occurrences);
public TypeSelectorManagerImpl(Project project, PsiType type, PsiExpression mainOccurrence, PsiExpression[] occurrences) {
this(project, type, null, mainOccurrence, occurrences);
}
public TypeSelectorManagerImpl(Project project, PsiType type, PsiExpression[] occurrences) {
@@ -63,14 +62,14 @@ public class TypeSelectorManagerImpl implements TypeSelectorManager {
myFactory = JavaPsiFacade.getInstance(project).getElementFactory();
mySmartTypePointerManager = SmartTypePointerManager.getInstance(project);
setDefaultType(type);
myMainOccurence = null;
myMainOccurrence = null;
myOccurrences = occurrences;
myExpectedTypesProvider = ExpectedTypesProvider.getInstance(project);
myOccurrenceClassProvider = createOccurrenceClassProvider();
myTypesForAll = getTypesForAll(areTypesDirected);
myTypesForMain = PsiType.EMPTY_ARRAY;
myIsOneSuggestion = myTypesForAll.length == 1;
myIsOneSuggestion = myTypesForAll.length == 1;
if (myIsOneSuggestion) {
myTypeSelector = new TypeSelector(myTypesForAll[0]);
}
@@ -83,14 +82,13 @@ public class TypeSelectorManagerImpl implements TypeSelectorManager {
public TypeSelectorManagerImpl(Project project,
PsiType type,
PsiMethod containingMethod,
PsiExpression mainOccurence,
PsiExpression mainOccurrence,
PsiExpression[] occurrences) {
myFactory = JavaPsiFacade.getInstance(project).getElementFactory();
mySmartTypePointerManager = SmartTypePointerManager.getInstance(project);
setDefaultType(type);
myMainOccurence = mainOccurence;
myMainOccurrence = mainOccurrence;
myOccurrences = occurrences;
myExpectedTypesProvider = ExpectedTypesProvider.getInstance(project);
myOccurrenceClassProvider = createOccurrenceClassProvider();
myTypesForMain = getTypesForMain();
@@ -149,8 +147,8 @@ public class TypeSelectorManagerImpl implements TypeSelectorManager {
private ExpectedTypesProvider.ExpectedClassProvider createOccurrenceClassProvider() {
final Set<PsiClass> occurrenceClasses = new HashSet<PsiClass>();
for (final PsiExpression occurence : myOccurrences) {
final PsiType occurrenceType = occurence.getType();
for (final PsiExpression occurrence : myOccurrences) {
final PsiType occurrenceType = occurrence.getType();
final PsiClass aClass = PsiUtil.resolveClassInType(occurrenceType);
if (aClass != null) {
occurrenceClasses.add(aClass);
@@ -160,8 +158,7 @@ public class TypeSelectorManagerImpl implements TypeSelectorManager {
}
private PsiType[] getTypesForMain() {
final ExpectedTypeInfo[] expectedTypes = ExpectedTypesProvider.getExpectedTypes(myMainOccurence, false, myOccurrenceClassProvider,
false);
final ExpectedTypeInfo[] expectedTypes = ExpectedTypesProvider.getExpectedTypes(myMainOccurrence, false, myOccurrenceClassProvider, false);
final ArrayList<PsiType> allowedTypes = new ArrayList<PsiType>();
RefactoringHierarchyUtil.processSuperTypes(getDefaultType(), new RefactoringHierarchyUtil.SuperTypeVisitor() {
public void visitType(PsiType aType) {
@@ -173,9 +170,8 @@ public class TypeSelectorManagerImpl implements TypeSelectorManager {
}
private void checkIfAllowed(PsiType type) {
if (expectedTypes != null && expectedTypes.length > 0) {
final ExpectedTypeInfo
typeInfo = ExpectedTypesProvider.createInfo(type, ExpectedTypeInfo.TYPE_STRICTLY, type, TailType.NONE);
if (expectedTypes.length > 0) {
final ExpectedTypeInfo typeInfo = ExpectedTypesProvider.createInfo(type, ExpectedTypeInfo.TYPE_STRICTLY, type, TailType.NONE);
for (ExpectedTypeInfo expectedType : expectedTypes) {
if (expectedType.intersect(typeInfo).length != 0) {
allowedTypes.add(type);
@@ -196,9 +192,7 @@ public class TypeSelectorManagerImpl implements TypeSelectorManager {
private PsiType[] getTypesForAll(final boolean areTypesDirected) {
final ArrayList<ExpectedTypeInfo[]> expectedTypesFromAll = new ArrayList<ExpectedTypeInfo[]>();
for (PsiExpression occurrence : myOccurrences) {
final ExpectedTypeInfo[] expectedTypes = ExpectedTypesProvider.getExpectedTypes(occurrence, false, myOccurrenceClassProvider,
isUsedAfter());
final ExpectedTypeInfo[] expectedTypes = ExpectedTypesProvider.getExpectedTypes(occurrence, false, myOccurrenceClassProvider, isUsedAfter());
if (expectedTypes.length > 0) {
expectedTypesFromAll.add(expectedTypes);
}
@@ -259,20 +253,22 @@ public class TypeSelectorManagerImpl implements TypeSelectorManager {
result.add(0, unboxedType);
}
if (defaultType instanceof PsiPrimitiveType && myMainOccurence != null) {
final PsiClassType boxedType = ((PsiPrimitiveType)defaultType).getBoxedType(myMainOccurence);
if (defaultType instanceof PsiPrimitiveType && myMainOccurrence != null) {
final PsiClassType boxedType = ((PsiPrimitiveType)defaultType).getBoxedType(myMainOccurrence);
if (boxedType != null) {
result.remove(boxedType);
result.add(0, boxedType);
}
}
result.add(0, defaultType);
if (!TypeConversionUtil.isComposite(defaultType)) {
result.add(0, defaultType);
}
return result;
}
public void setAllOccurences(boolean allOccurences) {
public void setAllOccurences(boolean occurrences) {
if (myIsOneSuggestion) return;
setTypesAndPreselect(allOccurences ? myTypesForAll : myTypesForMain);
setTypesAndPreselect(occurrences ? myTypesForAll : myTypesForMain);
}
private void setTypesAndPreselect(PsiType[] types) {
@@ -34,6 +34,7 @@ import com.intellij.refactoring.util.RefactoringUtil;
import com.intellij.util.ArrayUtil;
import com.intellij.util.IncorrectOperationException;
import com.intellij.util.containers.IntArrayList;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.*;
@@ -49,12 +50,12 @@ public class DuplicatesFinder {
private final List<? extends PsiVariable> myOutputParameters;
private final List<PsiElement> myPatternAsList;
private boolean myMultipleExitPoints = false;
private final ReturnValue myReturnValue;
@Nullable private final ReturnValue myReturnValue;
public DuplicatesFinder(PsiElement[] pattern,
InputVariables parameters,
ReturnValue returnValue,
List<? extends PsiVariable> outputParameters
@Nullable ReturnValue returnValue,
@NotNull List<? extends PsiVariable> outputParameters
) {
myReturnValue = returnValue;
LOG.assertTrue(pattern.length > 0);
@@ -109,6 +110,14 @@ public class DuplicatesFinder {
return result;
}
@Nullable
public Match isDuplicate(PsiElement element, boolean ignoreParameterTypes) {
annotatePattern();
Match match = isDuplicateFragment(element, ignoreParameterTypes);
deannotatePattern();
return match;
}
private void annotatePattern() {
for (final PsiElement patternComponent : myPattern) {
patternComponent.accept(new JavaRecursiveElementWalkingVisitor() {
@@ -146,7 +155,7 @@ public class DuplicatesFinder {
private void findPatternOccurrences(List<Match> array, PsiElement scope) {
PsiElement[] children = scope.getChildren();
for (PsiElement child : children) {
final Match match = isDuplicateFragment(child);
final Match match = isDuplicateFragment(child, false);
if (match != null) {
array.add(match);
continue;
@@ -157,7 +166,7 @@ public class DuplicatesFinder {
@Nullable
private Match isDuplicateFragment(PsiElement candidate) {
private Match isDuplicateFragment(PsiElement candidate, boolean ignoreParameterTypes) {
if (PsiTreeUtil.isAncestor(myPattern[0], candidate, false)) return null;
PsiElement sibling = candidate;
ArrayList<PsiElement> candidates = new ArrayList<PsiElement>();
@@ -188,7 +197,7 @@ public class DuplicatesFinder {
}
}
final Match match = new Match(candidates.get(0), candidates.get(candidates.size() - 1));
final Match match = new Match(candidates.get(0), candidates.get(candidates.size() - 1), ignoreParameterTypes);
for (int i = 0; i < myPattern.length; i++) {
if (!matchPattern(myPattern[i], candidates.get(i), candidates, match)) return null;
}
@@ -48,16 +48,18 @@ public final class Match {
private final PsiElement myMatchStart;
private final PsiElement myMatchEnd;
private final Map<PsiVariable, List<PsiElement>> myParameterValues = new HashMap<PsiVariable, List<PsiElement>>();
private final Map<PsiVariable, ArrayList<PsiElement>> myParameterOccurences = new HashMap<PsiVariable, ArrayList<PsiElement>>();
private final Map<PsiVariable, ArrayList<PsiElement>> myParameterOccurrences = new HashMap<PsiVariable, ArrayList<PsiElement>>();
private final Map<PsiElement, PsiElement> myDeclarationCorrespondence = new HashMap<PsiElement, PsiElement>();
private ReturnValue myReturnValue = null;
private Ref<PsiExpression> myInstanceExpression = null;
private final Map<PsiVariable, PsiType> myChangedParams = new HashMap<PsiVariable, PsiType>();
private final boolean myIgnoreParameterTypes;
Match(PsiElement start, PsiElement end) {
Match(PsiElement start, PsiElement end, boolean ignoreParameterTypes) {
LOG.assertTrue(start.getParent() == end.getParent());
myMatchStart = start;
myMatchEnd = end;
myIgnoreParameterTypes = ignoreParameterTypes;
}
@@ -135,14 +137,14 @@ public final class Match {
myChangedParams.put(psiVariable, new PsiEllipsisType(parameterType));
}
} else {
if (!parameterType.isAssignableFrom(type)) return false; //todo
if (!myIgnoreParameterTypes && !parameterType.isAssignableFrom(type)) return false; //todo
}
}
final List<PsiElement> values = new ArrayList<PsiElement>();
values.add(value);
myParameterValues.put(psiVariable, values);
final ArrayList<PsiElement> elements = new ArrayList<PsiElement>();
myParameterOccurences.put(psiVariable, elements);
myParameterOccurrences.put(psiVariable, elements);
return true;
}
else {
@@ -157,7 +159,7 @@ public final class Match {
currentValue.add(value);
}
}
myParameterOccurences.get(psiVariable).add(value);
myParameterOccurrences.get(psiVariable).add(value);
return true;
}
}
@@ -0,0 +1,8 @@
import java.util.ArrayList;
import java.util.List;
public class Foo {
public static void main(String[] args) {
List<Integer> set = new ArrayLis<caret>t<Integer>();
}
}
@@ -0,0 +1,8 @@
import java.util.ArrayList;
import java.util.List;
public class Foo {
public static void main(String[] args) {
List<Integer> set = new ArrayList<Integer>(<caret>);
}
}
@@ -0,0 +1,5 @@
public class Foo {
public static void main(String[] args) {
Set<caret><Integer>
}
}
@@ -0,0 +1,7 @@
import java.util.Set;
public class Foo {
public static void main(String[] args) {
Set<caret><Integer>
}
}
@@ -0,0 +1,14 @@
abstract class Base {
public static @interface IfNotParsed {}
static class X {}
}
class Derived extends Base {
}
class B {
void foo(Derived b) {
b.<caret>
}
}
@@ -0,0 +1,4 @@
class Foo {
Baaa<caret>x
}
@@ -5,9 +5,10 @@ abstract class C {
private static class E2 extends E { }
private static class E3 extends E { }
private static class RE extends RuntimeException { }
private interface I { }
private static class IE1 extends E implements I { }
private static class IE2 extends E implements I { }
private interface I<T> { }
private static class IE1 extends E implements I<Integer> { }
private static class IE2 extends E implements I<Long> { }
private static class F<X> { F(X x) { } }
abstract void f() throws E1, E2;
abstract void g() throws IE1, IE2;
@@ -18,6 +19,8 @@ abstract class C {
try { f(); } catch (E2 | E1 e) { } catch (E e) { } catch (RE e) { }
try { f(); } catch (E1 | E e) { E ee = e; }
try { g(); } catch (IE1 | IE2 e) { E ee = e; I ii = e; }
try { g(); } catch (IE1 | IE2 e) { F<?> f = new F<>(e); }
try { g(); } catch (IE1 | IE2 e) { new F<I<? extends Number>>(e); }
try { f(); } catch (E1 | E2 | <error descr="Exception 'C.E3' is never thrown in the corresponding try block">E3</error> e) { }
try { f(); } catch (<error descr="Exception 'C.E3' is never thrown in the corresponding try block">E3</error> | E e) { }
@@ -42,4 +42,80 @@ public class Test {
final ArrayList<String> list = new ArrayList<String>();
<warning descr="Unchecked generics array creation for varargs parameter">asList</warning>(list);
}
}
public static <V> void join(V[] list) {
Arrays.asList(list);
}
}
class NoWarngs {
static final SemKey<String> FILE_DESCRIPTION_KEY = <warning descr="Unchecked generics array creation for varargs parameter">SemKey.createKey</warning>("FILE_DESCRIPTION_KEY");
void f() {
OCM<String> o =
new <warning descr="Unchecked generics array creation for varargs parameter">OCM<></warning>("", true, new Condition<String>(){
@Override
public boolean val(String s) {
return false;
}
}, Condition.TRUE);
System.out.println(o);
}
}
class SemKey<T extends String> {
private final String myDebugName;
private final SemKey<? super T>[] mySupers;
private SemKey(String debugName, SemKey<? super T>... supers) {
myDebugName = debugName;
System.out.println(myDebugName);
mySupers = supers;
System.out.println(mySupers);
}
public static <T extends String> SemKey<T> createKey(String debugName, SemKey<? super T>... supers) {
return new SemKey<T>(debugName, supers);
}
public <K extends T> SemKey<K> subKey(String debugName, SemKey<? super T>... otherSupers) {
if (otherSupers.length == 0) {
return new <warning descr="Unchecked generics array creation for varargs parameter">SemKey<K></warning>(debugName, this);
}
return new SemKey<K>(debugName, append(otherSupers, this));
}
public static <T> T[] append(final T[] src, final T element) {
return append(src, element, <warning descr="Unchecked cast: 'java.lang.Class<capture<?>>' to 'java.lang.Class<T>'">(Class<T>)src.getClass().getComponentType()</warning>);
}
public static <T> T[] append(T[] src, final T element, Class<T> componentType) {
int length = src.length;
T[] result = <warning descr="Unchecked cast: 'java.lang.Object' to 'T[]'">(T[])java.lang.reflect.Array.newInstance(componentType, length + 1)</warning>;
System.arraycopy(src, 0, result, 0, length);
result[length] = element;
return result;
}
}
interface Condition<T> {
boolean val(T t);
Condition TRUE = new Condition() {
@Override
public boolean val(Object o) {
return true;
}
};
}
class OCM<T> {
OCM(T s, boolean b, Condition<T>... c) {
System.out.println(s);
System.out.println(b);
System.out.println(c);
}
OCM(T s, Condition<T>... c) {
this(s, false, c);
}
}
@@ -8,7 +8,7 @@ class Test {
}
void foo() {
<error descr="Incompatible types. Found: 'java.util.List<java.lang.Class<? extends java.io.Serializable & java.lang.Comparable<?>>>', required: 'java.util.List<java.lang.Class<? extends java.io.Serializable>>'">List<Class<? extends Serializable>> l = this.asList(String.class, Integer.class);</error>
<error descr="Incompatible types. Found: 'java.util.List<java.lang.Class<? extends java.io.Serializable & java.lang.Comparable<?>>>', required: 'java.util.List<java.lang.Class<? extends java.io.Serializable>>'">List<Class<? extends Serializable>> l = <warning descr="Unchecked generics array creation for varargs parameter">this.asList</warning>(String.class, Integer.class);</error>
l.size();
List<? extends Object> objects = this.asList(new String(), new Integer(0));
objects.size();
@@ -131,7 +131,7 @@ class IDEADEV25515 {
public static final
<error descr="Incompatible types. Found: 'java.util.List<java.lang.Class<? extends java.io.Serializable & java.lang.Comparable<?>>>', required: 'java.util.List<java.lang.Class<? extends java.io.Serializable>>'">List<Class<? extends Serializable>> SIMPLE_TYPES =
asList(String.class, Integer.class ,Long.class, Double.class, /*Date.class,*/
<warning descr="Unchecked generics array creation for varargs parameter">asList</warning>(String.class, Integer.class ,Long.class, Double.class, /*Date.class,*/
Boolean.class, Boolean.TYPE /*,String[].class */ /*,BigDecimal.class*/);</error>
@@ -162,4 +162,4 @@ public class MaximalType {
}
class M extends MaximalType implements L{}
class M2 extends MaximalType implements L{}
/////////////
/////////////
@@ -9,7 +9,7 @@ public class Test {
void foo() {
//noinspection unc<caret>hecked
foo(new ArrayList<String>()).addAll(Arrays.asList(new ArrayList<String>);
foo(new ArrayList<String>()).addAll(Arrays.asList(new ArrayList<String>()));
}
}
@@ -1,7 +0,0 @@
// "Annotate as @SafeVarargs" "false"
public class Test {
public <T> void m<caret>ain(T... args) {
}
}
@@ -0,0 +1,11 @@
class C {
static class E1 extends Exception { }
static class E2 extends Exception { }
void m() {
try { }
catch (E1 | E2 ex) {
final Exception e = ex;
}
}
}
@@ -0,0 +1,11 @@
class C {
static class E1 extends Exception { }
static class E2 extends Exception { }
void m() {
try { }
catch (E1 | E2 ex) {
<caret>ex;
}
}
}
@@ -0,0 +1,12 @@
class C {
interface B<T> { }
static class E1 extends Exception implements B<Integer> { }
static class E2 extends Exception implements B<Long> { }
void m() {
try { }
catch (E1 | E2 ex) {
final B<? extends Number> b = ex;
}
}
}
@@ -0,0 +1,12 @@
class C {
interface B<T> { }
static class E1 extends Exception implements B<Integer> { }
static class E2 extends Exception implements B<Long> { }
void m() {
try { }
catch (E1 | E2 ex) {
<caret>ex;
}
}
}
@@ -34,11 +34,6 @@ public class ClassNameCompletionTest extends CompletionTestCase {
return JavaTestUtil.getJavaTestDataPath();
}
@Override
protected Sdk getTestProjectJdk() {
return JavaSdkImpl.getMockJdk17("java 1.5");
}
@Override
protected void tearDown() throws Exception {
CodeInsightSettings.getInstance().AUTOCOMPLETE_ON_CLASS_NAME_COMPLETION = myOldSetting;
@@ -81,8 +81,4 @@ public class HeavySmartTypeCompletion15Test extends CompletionTestCase {
LookupManager.getInstance(myProject).hideActiveLookup();
super.tearDown();
}
protected Sdk getTestProjectJdk() {
return JavaSdkImpl.getMockJdk17("java 1.5");
}
}
@@ -476,5 +476,14 @@ class JavaAutoPopupTest extends CompletionAutoPopupTestCase {
assert !lookup
}
public void testDoubleLiteralInField() {
myFixture.configureByText "a.java", """
public interface Test {
double FULL = 1.0<caret>
}"""
type 'd'
assert !lookup
}
}
@@ -8,6 +8,7 @@ import com.intellij.JavaTestUtil;
import com.intellij.codeInsight.CodeInsightSettings;
import com.intellij.codeInsight.lookup.LookupElement;
import com.intellij.codeInsight.lookup.impl.LookupImpl;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiMethod;
import java.util.List;
@@ -182,4 +183,22 @@ public class NormalCompletionOrderingTest extends CompletionSortingTestCase {
checkPreferredItems(0, "XcodeProjectTemplate", "XcodeConfigurable");
}
public void testFqnStats() {
myFixture.addClass("public interface Baaaaaaar {}");
myFixture.addClass("package zoo; public interface Baaaaaaar {}");
final LookupImpl lookup = invokeCompletion(getTestName(false) + ".java");
assertEquals("Baaaaaaar", ((JavaPsiClassReferenceElement) lookup.getItems().get(0)).getQualifiedName());
assertEquals("zoo.Baaaaaaar", ((JavaPsiClassReferenceElement) lookup.getItems().get(1)).getQualifiedName());
incUseCount(lookup, 1);
assertEquals("zoo.Baaaaaaar", ((JavaPsiClassReferenceElement) lookup.getItems().get(0)).getQualifiedName());
assertEquals("Baaaaaaar", ((JavaPsiClassReferenceElement)lookup.getItems().get(1)).getQualifiedName());
}
public void testDispreferInnerClasses() {
checkPreferredItems(0); //no chosen items
assertFalse(getLookup().getItems().get(0).getObject() instanceof PsiClass);
}
}
@@ -676,6 +676,7 @@ public class NormalCompletionTest extends LightFixtureCompletionTestCase {
public void testReturningTypeVariable() throws Throwable { doTest(); }
public void testReturningTypeVariable2() throws Throwable { doTest(); }
public void testReturningTypeVariable3() throws Throwable { doTest(); }
public void testImportInGenericType() throws Throwable { doTest(); }
public void testCaseTailType() throws Throwable { doTest(); }
@@ -808,6 +809,7 @@ public class NormalCompletionTest extends LightFixtureCompletionTestCase {
public void testClassNameWithInnersTab() throws Throwable { doTest('\t') }
public void testClassNameWithGenericsTab() throws Throwable {doTest('\t') }
public void testClassNameWithGenericsTab2() throws Throwable {doTest('\t') }
public void testLiveTemplatePrefixTab() throws Throwable {doTest('\t') }
@@ -178,9 +178,4 @@ public class SecondSmartTypeCompletionTest extends LightCompletionTestCase {
LookupManager.getInstance(getProject()).hideActiveLookup();
super.tearDown();
}
@Override
protected Sdk getProjectJDK() {
return JavaSdkImpl.getMockJdk17("java 1.5");
}
}
@@ -37,8 +37,4 @@ public class AnnotationsHighlightingTest extends LightDaemonAnalyzerTestCase {
public void testPackageAnnotationNotInPackageInfo() throws Exception {
doTest(BASE_PATH + "/" + getTestName(true) + "/notPackageInfo.java", false, false);
}
@Override protected Sdk getProjectJDK() {
return JavaSdkImpl.getMockJdk17();
}
}
@@ -36,11 +36,6 @@ public class GenericsHighlightingTest extends LightDaemonAnalyzerTestCase {
LanguageLevelProjectExtension.getInstance(getJavaFacade().getProject()).setLanguageLevel(level);
}
@Override protected Sdk getProjectJDK() {
return JavaSdkImpl.getMockJdk17("java 1.5");
}
public void testReferenceTypeParams() throws Exception { doTest(false); }
public void testOverridingMethods() throws Exception { doTest(false); }
public void testTypeParameterBoundsList() throws Exception { doTest(false); }
@@ -106,9 +106,4 @@ public class JavadocHighlightingTest extends LightDaemonAnalyzerTestCase {
protected void doTest() throws Exception {
super.doTest(BASE_PATH + "/" + getTestName(false) + ".java", true, false);
}
@Override
protected Sdk getProjectJDK() {
return JavaSdkImpl.getMockJdk17("java 1.5");
}
}
@@ -6,6 +6,7 @@ import com.intellij.codeInspection.LocalInspectionTool;
import com.intellij.codeInspection.deadCode.UnusedDeclarationInspection;
import com.intellij.codeInspection.reference.EntryPoint;
import com.intellij.codeInspection.reference.RefElement;
import com.intellij.codeInspection.uncheckedWarnings.UncheckedWarningLocalInspection;
import com.intellij.codeInspection.unusedSymbol.UnusedSymbolLocalInspection;
import com.intellij.lang.annotation.HighlightSeverity;
import com.intellij.openapi.extensions.ExtensionPoint;
@@ -30,7 +31,7 @@ public class LightAdvHighlightingJdk7Test extends LightDaemonAnalyzerTestCase {
@Override
protected LocalInspectionTool[] configureLocalInspectionTools() {
return new LocalInspectionTool[]{new UnusedSymbolLocalInspection()};
return new LocalInspectionTool[]{new UnusedSymbolLocalInspection(), new UncheckedWarningLocalInspection()};
}
public void testDuplicateAnnotations() throws Exception {
@@ -17,10 +17,6 @@ public class SuppressWarningsTest extends LightDaemonAnalyzerTestCase {
doTest(BASE_PATH + "/" + getTestName(false) + ".java", checkWarnings, false);
}
@Override protected Sdk getProjectJDK() {
return JavaSdkImpl.getMockJdk17("java 1.5");
}
@Override
protected LocalInspectionTool[] configureLocalInspectionTools() {
return new LocalInspectionTool[]{new UnusedSymbolLocalInspection()};
@@ -30,8 +30,4 @@ public class CreateFieldFromParameterTest extends LightIntentionActionTestCase {
protected String getBasePath() {
return "/codeInsight/daemonCodeAnalyzer/quickFix/createFieldFromParameter";
}
@Override protected Sdk getProjectJDK() {
return JavaSdkImpl.getMockJdk17("java 1.5");
}
}
@@ -7,10 +7,4 @@ import com.intellij.openapi.projectRoots.impl.JavaSdkImpl;
* @author ven
*/
public abstract class LightQuickFix15TestCase extends LightQuickFixTestCase {
@Override
protected Sdk getProjectJDK() {
return JavaSdkImpl.getMockJdk17("java 1.5");
}
}
@@ -23,12 +23,6 @@ import com.intellij.openapi.projectRoots.impl.JavaSdkImpl;
public class RemoveRedundantUncheckedSuppressionTest extends LightQuickFixTestCase {
@Override
protected Sdk getProjectJDK() {
return JavaSdkImpl.getMockJdk17();
}
@Override
protected LocalInspectionTool[] configureLocalInspectionTools() {
return new LocalInspectionTool[]{
@@ -16,9 +16,4 @@ public class ReplaceAddAllArrayToCollectionsFixTest extends LightQuickFixTestCas
protected String getBasePath() {
return "/codeInsight/daemonCodeAnalyzer/quickFix/replaceAddAllArrayToCollections";
}
@Override
protected Sdk getProjectJDK() {
return JavaSdkImpl.getMockJdk17("java 1.5");
}
}
@@ -22,12 +22,6 @@ import com.intellij.openapi.projectRoots.impl.JavaSdkImpl;
public class SafeVarargsCanBeUsedTest extends LightQuickFixTestCase {
@Override
protected Sdk getProjectJDK() {
return JavaSdkImpl.getMockJdk17();
}
@Override
protected LocalInspectionTool[] configureLocalInspectionTools() {
return new LocalInspectionTool[]{
@@ -32,12 +32,6 @@ import com.intellij.openapi.projectRoots.impl.JavaSdkImpl;
//todo test3 should be checked if it compiles - as now javac infers Object instead of String?!
public class Simplify2DiamondInspectionsTest extends LightQuickFixTestCase {
@Override
protected Sdk getProjectJDK() {
return JavaSdkImpl.getMockJdk17();
}
@Override
protected LocalInspectionTool[] configureLocalInspectionTools() {
return new LocalInspectionTool[]{
@@ -16,12 +16,6 @@ import com.intellij.openapi.projectRoots.impl.JavaSdkImpl;
public class Suppress15InspectionsTest extends LightQuickFixTestCase {
@Override
protected Sdk getProjectJDK() {
return JavaSdkImpl.getMockJdk17();
}
@Override
protected void setUp() throws Exception {
super.setUp();
@@ -16,9 +16,4 @@ public class SurroundWithArrayFixTest extends LightQuickFix15TestCase {
protected String getBasePath() {
return "/codeInsight/daemonCodeAnalyzer/quickFix/surroundWithArray";
}
@Override
protected Sdk getProjectJDK() {
return JavaSdkImpl.getMockJdk17("java 1.5");
}
}
@@ -23,9 +23,4 @@ public class SurroundWithIfFixTest extends LightQuickFixTestCase {
protected String getBasePath() {
return "/codeInsight/daemonCodeAnalyzer/quickFix/surroundWithIf";
}
@Override
protected Sdk getProjectJDK() {
return JavaSdkImpl.getMockJdk17("java 1.5");
}
}
@@ -12,9 +12,4 @@ public class AddOnDemandStaticImportActionTest extends LightIntentionActionTestC
protected String getBasePath() {
return "/codeInsight/daemonCodeAnalyzer/quickFix/addOnDemandStaticImport";
}
@Override
protected Sdk getProjectJDK() {
return JavaSdkImpl.getMockJdk17();
}
}
@@ -33,11 +33,6 @@ import java.util.*;
public class SliceBackwardTest extends DaemonAnalyzerTestCase {
private final TIntObjectHashMap<IntArrayList> myFlownOffsets = new TIntObjectHashMap<IntArrayList>();
@Override
protected Sdk getTestProjectJdk() {
return JavaSdkImpl.getMockJdk17("java 1.5");
}
private void dotest() throws Exception {
configureByFile("/codeInsight/slice/backward/"+getTestName(false)+".java");
Map<String, RangeMarker> sliceUsageName2Offset = extractSliceOffsetsFromDocument(getEditor().getDocument());
@@ -24,11 +24,6 @@ import java.util.Map;
public class SliceForwardTest extends DaemonAnalyzerTestCase {
private final TIntObjectHashMap<IntArrayList> myFlownOffsets = new TIntObjectHashMap<IntArrayList>();
@Override
protected Sdk getTestProjectJdk() {
return JavaSdkImpl.getMockJdk17("java 1.5");
}
private void dotest() throws Exception {
configureByFile("/codeInsight/slice/forward/"+getTestName(false)+".java");
Map<String, RangeMarker> sliceUsageName2Offset = SliceBackwardTest.extractSliceOffsetsFromDocument(getEditor().getDocument());
@@ -24,10 +24,6 @@ import java.util.*;
* @author cdr
*/
public class SliceTreeTest extends LightDaemonAnalyzerTestCase {
@Override protected Sdk getProjectJDK() {
return JavaSdkImpl.getMockJdk17();
}
private SliceTreeStructure configureTree(@NonNls final String name) throws Exception {
configureByFile("/codeInsight/slice/backward/"+ name +".java");
PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
@@ -214,10 +214,4 @@ public class JavaTreeStructureTest extends TestSourceBasedTestCase {
protected String getTestDataPath() {
return JavaTestUtil.getJavaTestDataPath();
}
@Override
protected Sdk getTestProjectJdk() {
return JavaSdkImpl.getMockJdk17();
}
}
@@ -64,10 +64,4 @@ public class ProjectViewSwitchingTest extends TestSourceBasedTestCase {
protected String getTestDataPath() {
return JavaTestUtil.getJavaTestDataPath();
}
@Override
protected Sdk getTestProjectJdk() {
return JavaSdkImpl.getMockJdk17();
}
}
@@ -246,10 +246,4 @@ public class StructureViewUpdatingTest extends TestSourceBasedTestCase {
protected String getTestDataPath() {
return JavaTestUtil.getJavaTestDataPath();
}
@Override
protected Sdk getTestProjectJdk() {
return JavaSdkImpl.getMockJdk17();
}
}
@@ -24,11 +24,6 @@ public class ModifyAnnotationsTest extends PsiTestCase {
PsiTestUtil.createTestProjectStructure(myProject, myModule, root, myFilesToDelete);
}
@Override
protected Sdk getTestProjectJdk() {
return JavaSdkImpl.getMockJdk17("mock 1.5");
}
public void testReplaceAnnotation() throws Exception {
//be sure not to load tree
getJavaFacade().setAssertOnFileLoadingFilter(VirtualFileFilter.ALL);
@@ -43,11 +43,6 @@ public class OptimizeImportsTest extends PsiTestCase{
public void testNewImportListIsEmptyAndCommentPreserved() throws Exception { doTest(); }
public void testNewImportListIsEmptyAndJavaDocWithInvalidCodePreserved() throws Exception { doTest(); }
@Override
protected Sdk getTestProjectJdk() {
return JavaSdkImpl.getMockJdk17("mock 1.5");
}
private void doTest() throws Exception {
final String extension = ".java";
doTest(extension);
@@ -37,11 +37,6 @@ public class Src15RepositoryUseTest extends PsiTestCase {
PsiTestUtil.createTestProjectStructure(myProject, myModule, root, myFilesToDelete);
}
@Override
protected Sdk getTestProjectJdk() {
return JavaSdkImpl.getMockJdk17("mock 1.5");
}
@Override
protected void tearDown() throws Exception {
LanguageLevelProjectExtension.getInstance(myProject).setLanguageLevel(LanguageLevel.JDK_1_5);
@@ -354,8 +354,14 @@ public class JavaFormatterTest extends AbstractJavaFormatterTest {
public void testBraces() throws Exception {
final CodeStyleSettings settings = getSettings();
final String text = "class Foo {\n" + "void foo () {\n" + "if (a) {\n" + "int i = 0;\n" + "}\n" + "}\n" + "}";
final String text =
"class Foo {\n" +
"void foo () {\n" +
"if (a) {\n" +
"int i = 0;\n" +
"}\n" +
"}\n" +
"}";
settings.BRACE_STYLE = CodeStyleSettings.END_OF_LINE;
settings.METHOD_BRACE_STYLE = CodeStyleSettings.END_OF_LINE;
@@ -2199,7 +2205,14 @@ public void testSCR260() throws Exception {
getSettings().BRACE_STYLE = CodeStyleSettings.NEXT_LINE_SHIFTED;
doTextTest(
"public class ZZZZ \n" + " { \n" + " public ZZZZ() \n" + " { \n" + " if (a){\n" + "foo();}\n" + " } \n" + " }",
"public class ZZZZ \n" +
" { \n" +
" public ZZZZ() \n" +
" { \n" +
" if (a){\n" +
"foo();}\n" +
" } \n" +
" }",
"public class ZZZZ\n" +
" {\n" +
" public ZZZZ()\n" +
@@ -17,11 +17,6 @@ public class AnonymousToInnerTest extends LightCodeInsightTestCase {
return JavaTestUtil.getJavaTestDataPath();
}
@Override
protected Sdk getProjectJDK() {
return JavaSdkImpl.getMockJdk17("java 1.5");
}
public void testGenericTypeParameters() throws Exception { // IDEADEV-29446
doTest("MyIterator", true);
}
@@ -35,11 +35,6 @@ public class ChangeSignatureTargetTest extends LightCodeInsightTestCase {
doTest("A1");
}
@Override
protected Sdk getProjectJDK() {
return JavaSdkImpl.getMockJdk17("java 1.5");
}
private void doTest(String expectedMemberName) throws Exception {
String basePath = "/refactoring/changeSignatureTarget/" + getTestName(true);
@NonNls final String filePath = basePath + ".java";
@@ -23,10 +23,4 @@ public class ExtractMethod15Test extends LightCodeInsightTestCase {
assertTrue(success);
checkResultByFile(BASE_PATH + getTestName(false) + "_after.java");
}
@Override
protected Sdk getProjectJDK() {
return JavaSdkImpl.getMockJdk17("java 1.5");
}
}
@@ -30,11 +30,6 @@ public class ExtractMethodTest extends LightCodeInsightTestCase {
return JavaTestUtil.getJavaTestDataPath();
}
@Override
protected Sdk getProjectJDK() {
return JavaSdkImpl.getMockJdk17("java 1.5");
}
public void testExitPoints1() throws Exception {
doExitPointsTest(true);
}
@@ -108,11 +108,6 @@ public class ExtractSuperClassTest extends CodeInsightTestCase {
doTest("p1.A", "AA", new RefactoringTestUtil.MemberDescriptor("m1", PsiMethod.class));
}
@Override
protected Sdk getTestProjectJdk() {
return JavaSdkImpl.getMockJdk17();
}
@Override
protected void setUp() throws Exception {
super.setUp();
@@ -20,11 +20,6 @@ public abstract class FindMethodDuplicatesBaseTest extends LightCodeInsightTestC
return JavaTestUtil.getJavaTestDataPath();
}
@Override
protected Sdk getProjectJDK() {
return JavaSdkImpl.getMockJdk17("java 1.5");
}
protected void doTest() throws Exception {
doTest(true);
}
@@ -23,11 +23,6 @@ public class InheritanceToDelegationTest extends MultiFileTestCase {
return JavaTestUtil.getJavaTestDataPath();
}
@Override
protected Sdk getTestProjectJdk() {
return JavaSdkImpl.getMockJdk17("java 1.5");
}
@Override
protected String getTestRoot() {
return "/refactoring/inheritanceToDelegation/";
@@ -23,11 +23,6 @@ public class InlineSuperClassTest extends MultiFileTestCase {
return JavaTestUtil.getJavaTestDataPath();
}
@Override
protected Sdk getTestProjectJdk() {
return JavaSdkImpl.getMockJdk17();
}
private void doTest() throws Exception {
doTest(false);
}
@@ -124,9 +124,4 @@ public class IntroduceConstantTest extends LightCodeInsightTestCase {
}
}.invoke(getProject(), getEditor(), getFile(), null);
}
@Override
protected Sdk getProjectJDK() {
return JavaSdkImpl.getMockJdk17("java 1.5");
}
}
@@ -18,11 +18,6 @@ public class IntroduceFieldInSameClassTest extends LightCodeInsightTestCase {
return JavaTestUtil.getJavaTestDataPath();
}
@Override
protected Sdk getProjectJDK() {
return JavaSdkImpl.getMockJdk17("java 1.5");
}
public void testInClassInitializer () throws Exception {
configureByFile("/refactoring/introduceField/before1.java");
performRefactoring(BaseExpressionToFieldHandler.InitializationPlace.IN_FIELD_DECLARATION, true);
@@ -348,9 +348,4 @@ public class IntroduceParameterTest extends LightCodeInsightTestCase {
IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_INACCESSIBLE,
declareFinal, false, null, parametersToRemove).run();
}
@Override
protected Sdk getProjectJDK() {
return JavaSdkImpl.getMockJdk17("java 1.5");
}
}
@@ -3,8 +3,6 @@ package com.intellij.refactoring;
import com.intellij.JavaTestUtil;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.projectRoots.impl.JavaSdkImpl;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiExpression;
import com.intellij.psi.PsiType;
@@ -250,15 +248,18 @@ public class IntroduceVariableTest extends LightCodeInsightTestCase {
});
}
public void testMultiCatchSimple() throws Exception {
doTest(new MockIntroduceVariableHandler("e", true, true, false, "C.E1 | C.E2"));
}
public void testMultiCatchTyped() throws Exception {
doTest(new MockIntroduceVariableHandler("b", true, true, false, "C.E1 | C.E2"));
}
private void doTest(IntroduceVariableBase testMe) throws Exception {
@NonNls String baseName = "/refactoring/introduceVariable/" + getTestName(false);
configureByFile(baseName + ".java");
testMe.invoke(getProject(), getEditor(), getFile(), null);
checkResultByFile(baseName + ".after.java");
}
@Override
protected Sdk getProjectJDK() {
return JavaSdkImpl.getMockJdk17();
}
}
@@ -51,12 +51,6 @@ public class PullUpMultifileTest extends MultiFileTestCase {
return JavaTestUtil.getJavaTestDataPath();
}
@Override
protected Sdk getTestProjectJdk() {
return JavaSdkImpl.getMockJdk17("java 1.5");
}
private void doTest(final String... conflicts) throws Exception {
final MultiMap<PsiElement, String> conflictsMap = new MultiMap<PsiElement, String>();
doTest(new PerformAction() {
@@ -135,11 +135,6 @@ public class PullUpTest extends LightCodeInsightTestCase {
checkResultByFile(BASE_PATH + getTestName(false) + "_after.java");
}
@Override
protected Sdk getProjectJDK() {
return JavaSdkImpl.getMockJdk17("50");
}
@Override
protected String getTestDataPath() {
return JavaTestUtil.getJavaTestDataPath();
@@ -28,11 +28,6 @@ public class PushDownMultifileTest extends MultiFileTestCase {
return JavaTestUtil.getJavaTestDataPath();
}
@Override
protected Sdk getTestProjectJdk() {
return JavaSdkImpl.getMockJdk17("java 1.5");
}
private void doTest() throws Exception {
doTest(false);
}
@@ -113,9 +113,4 @@ public class RenameClassTest extends MultiFileTestCase {
protected String getTestRoot() {
return "/refactoring/renameClass/";
}
@Override
protected Sdk getTestProjectJdk() {
return JavaSdkImpl.getMockJdk17("java 1.5");
}
}
@@ -182,11 +182,6 @@ public class RenameCollisionsTest extends LightCodeInsightTestCase {
checkResultByFile(BASE_PATH + getTestName(false) + ".java.after");
}
@Override
protected Sdk getProjectJDK() {
return JavaSdkImpl.getMockJdk17("java 1.5");
}
public void testAllUsagesInCode() throws Exception {
configureByFile(BASE_PATH + getTestName(false) + ".java");
PsiElement element = TargetElementUtilBase
@@ -46,11 +46,6 @@ public class SuggestedParamTypesTest extends LightCodeInsightTestCase {
return JavaTestUtil.getJavaTestDataPath();
}
@Override
protected Sdk getProjectJDK() {
return JavaSdkImpl.getMockJdk17("java 1.5");
}
public void testPostfixExprUsedAsOutput() throws Exception {
doTest("byte");
}
@@ -159,9 +159,4 @@ public class TurnRefsToSuperTest extends MultiFileTestCase {
new TurnRefsToSuperProcessor(myProject, aClass, superClass, replaceInstanceOf).run();
FileDocumentManager.getInstance().saveAllDocuments();
}
@Override
protected Sdk getTestProjectJdk() {
return JavaSdkImpl.getMockJdk17("java 1.5");
}
}
@@ -29,11 +29,6 @@ import java.io.PrintWriter;
*/
public class TypeCookTest extends MultiFileTestCase {
@Override
protected Sdk getTestProjectJdk() {
return JavaSdkImpl.getMockJdk17("java 1.5");
}
@Override
protected String getTestDataPath() {
return JavaTestUtil.getJavaTestDataPath();
@@ -26,11 +26,6 @@ public class WrapReturnValueTest extends MultiFileTestCase{
return "/refactoring/wrapReturnValue/";
}
@Override
protected Sdk getTestProjectJdk() {
return JavaSdkImpl.getMockJdk17("java 1.5");
}
private void doTest(final boolean existing) throws Exception {
doTest(existing, null);
}
@@ -21,11 +21,6 @@ public class ChangeClassSignatureTest extends LightCodeInsightTestCase {
return JavaTestUtil.getJavaTestDataPath();
}
@Override
protected Sdk getProjectJDK() {
return JavaSdkImpl.getMockJdk17("java 1.5");
}
public void testNoParams() throws Exception {
doTest(new GenParams() {
@Override
@@ -29,11 +29,6 @@ public class InlineConstantFieldTest extends LightCodeInsightTestCase {
doTest();
}
@Override
protected Sdk getProjectJDK() {
return JavaSdkImpl.getMockJdk17("java 1.5");
}
private void doTest() throws Exception {
String name = getTestName(false);
@NonNls String fileName = "/refactoring/inlineConstantField/" + name + ".java";

Some files were not shown because too many files have changed in this diff Show More