Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
yole committed Jan 28, 2013
2 parents 8b9e7c5 + 4be20db commit e4bd534
Show file tree
Hide file tree
Showing 64 changed files with 764 additions and 255 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,14 @@ public static HighlightInfo checkTargetAnnotationDuplicates(PsiAnnotation annota
return null;
}

public static HighlightInfo checkFunctionalInterface(PsiAnnotation annotation) {
final String errorMessage = LambdaUtil.checkFunctionalInterface(annotation);
if (errorMessage != null) {
return HighlightInfo.createHighlightInfo(HighlightInfoType.ERROR, annotation, errorMessage);
}
return null;
}

public static class AnnotationReturnTypeVisitor extends PsiTypeVisitor<Boolean> {
public static final AnnotationReturnTypeVisitor INSTANCE = new AnnotationReturnTypeVisitor();
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ public void visitAnnotation(PsiAnnotation annotation) {
if (!myHolder.hasErrorResults()) myHolder.add(AnnotationsHighlightUtil.checkTargetAnnotationDuplicates(annotation));
if (!myHolder.hasErrorResults()) myHolder.add(AnnotationsHighlightUtil.checkDuplicateAnnotations(annotation));
if (!myHolder.hasErrorResults()) myHolder.add(AnnotationsHighlightUtil.checkForeignInnerClassesUsed(annotation));
if (!myHolder.hasErrorResults()) myHolder.add(AnnotationsHighlightUtil.checkFunctionalInterface(annotation));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.*;
import com.intellij.util.ProcessingContext;
import com.intellij.util.containers.*;
import com.intellij.util.containers.HashSet;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand All @@ -45,11 +47,15 @@ public FilePathReferenceProvider(boolean endingSlashNotAllowed) {

@NotNull
public PsiReference[] getReferencesByElement(PsiElement element, String text, int offset, final boolean soft) {
return getReferencesByElement(element, text, offset, soft, null);
return getReferencesByElement(element, text, offset, soft, Module.EMPTY_ARRAY);
}

@NotNull
public PsiReference[] getReferencesByElement(PsiElement element, String text, int offset, final boolean soft, final @Nullable Module forModule) {
public PsiReference[] getReferencesByElement(PsiElement element,
String text,
int offset,
final boolean soft,
final @NotNull Module... forModules) {
return new FileReferenceSet(text, element, offset, this, true, myEndingSlashNotAllowed) {


Expand All @@ -75,9 +81,17 @@ public boolean absoluteUrlNeedsStartSlash() {
}

@Override
@NotNull public Collection<PsiFileSystemItem> computeDefaultContexts() {
final Module module = forModule == null ? ModuleUtil.findModuleForPsiElement(getElement()) : forModule;
return getRoots(module, true);
@NotNull
public Collection<PsiFileSystemItem> computeDefaultContexts() {
Set<PsiFileSystemItem> systemItems = new HashSet<PsiFileSystemItem>();
if (forModules.length > 0) {
for (Module forModule : forModules) {
systemItems.addAll(getRoots(forModule, true));
}
} else {
systemItems.addAll(getRoots(ModuleUtil.findModuleForPsiElement(getElement()), true));
}
return systemItems;
}

@Override
Expand All @@ -95,7 +109,6 @@ public boolean value(final PsiFileSystemItem element) {
};
}
}.getAllReferences();

}

@Override
Expand Down Expand Up @@ -162,5 +175,4 @@ public static Collection<PsiFileSystemItem> getRoots(final Module thisModule, bo
}
return result;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public static PsiType convertFromString(final String s, final ConvertContext con
if (Arrays.binarySearch(CanonicalPsiTypeConverterImpl.PRIMITIVES, s) >= 0) {
return JavaPsiFacade.getInstance(context.getProject()).getElementFactory().createPrimitiveType(s);
}
final PsiClass aClass1 = DomJavaUtil.findClass(s, context.getFile(), context.getModule(), null);
final PsiClass aClass1 = DomJavaUtil.findClass(s, context.getFile(), context.getModule(), context.getSearchScope());
return aClass1 == null ? null : createType(aClass1);
}

Expand Down
23 changes: 5 additions & 18 deletions java/java-impl/src/com/intellij/util/xml/PsiClassConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public PsiClass fromString(final String s, final ConvertContext context) {

public static PsiClass findClass(String s, ConvertContext context) {
final DomElement element = context.getInvocationElement();
final GlobalSearchScope scope = element instanceof GenericDomValue ? getSearchScope(context) : null;
final GlobalSearchScope scope = element instanceof GenericDomValue ? context.getSearchScope() : null;
return DomJavaUtil.findClass(s, context.getFile(), context.getModule(), scope);
}

Expand All @@ -64,7 +64,8 @@ public PsiReference[] createReferences(GenericDomValue<PsiClass> genericDomValue
return provider.getReferencesByElement(element);
}

protected JavaClassReferenceProvider createClassReferenceProvider(final GenericDomValue<PsiClass> genericDomValue, final ConvertContext context,
protected JavaClassReferenceProvider createClassReferenceProvider(final GenericDomValue<PsiClass> genericDomValue,
final ConvertContext context,
ExtendClass extendClass) {
return createJavaClassReferenceProvider(genericDomValue, extendClass, new JavaClassReferenceProvider() {

Expand Down Expand Up @@ -99,7 +100,6 @@ public static JavaClassReferenceProvider createJavaClassReferenceProvider(final
provider.setOption(JavaClassReferenceProvider.JVM_FORMAT, Boolean.TRUE);
}
provider.setAllowEmpty(extendClass.allowEmpty());

}

ClassTemplate template = genericDomValue.getAnnotation(ClassTemplate.class);
Expand All @@ -114,22 +114,9 @@ public static JavaClassReferenceProvider createJavaClassReferenceProvider(final
return provider;
}

public static GlobalSearchScope getSearchScope(@NotNull ConvertContext context) {
final Module module = context.getModule();
if (module == null) return null;
PsiFile file = context.getFile();
file = file.getOriginalFile();
VirtualFile virtualFile = file.getVirtualFile();
if (virtualFile == null) return null;
ProjectFileIndex fileIndex = ProjectRootManager.getInstance(file.getProject()).getFileIndex();
boolean tests = fileIndex.isInTestSourceContent(virtualFile);
return module.getModuleRuntimeScope(tests);

}

@Nullable
protected GlobalSearchScope getScope(@NotNull ConvertContext context) {
return getSearchScope(context);
protected GlobalSearchScope getScope(@NotNull ConvertContext context) {
return context.getSearchScope();
}

public static class AnnotationType extends PsiClassConverter {
Expand Down
16 changes: 16 additions & 0 deletions java/java-psi-api/src/com/intellij/psi/LambdaUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.intellij.psi.infos.CandidateInfo;
import com.intellij.psi.infos.MethodCandidateInfo;
import com.intellij.psi.util.*;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand All @@ -37,6 +38,7 @@
public class LambdaUtil {
private static final Logger LOG = Logger.getInstance("#" + LambdaUtil.class.getName());
public static ThreadLocal<Set<PsiParameterList>> ourParams = new ThreadLocal<Set<PsiParameterList>>();
@NonNls public static final String JAVA_LANG_FUNCTIONAL_INTERFACE = "java.lang.FunctionalInterface";

@Nullable
public static PsiType getFunctionalInterfaceReturnType(PsiLambdaExpression expr) {
Expand Down Expand Up @@ -659,6 +661,20 @@ private static PsiType getReturnType(int functionalTypeIdx, CandidateInfo method
return getFunctionalInterfaceReturnType(functionalInterfaceType);
}

@Nullable
public static String checkFunctionalInterface(PsiAnnotation annotation) {
if (PsiUtil.isLanguageLevel8OrHigher(annotation) && Comparing.strEqual(annotation.getQualifiedName(), JAVA_LANG_FUNCTIONAL_INTERFACE)) {
final PsiAnnotationOwner owner = annotation.getOwner();
if (owner instanceof PsiModifierList) {
final PsiElement parent = ((PsiModifierList)owner).getParent();
if (parent instanceof PsiClass) {
return LambdaHighlightingUtil.checkInterfaceFunctional((PsiClass)parent);
}
}
}
return null;
}

static class TypeParamsChecker extends PsiTypeVisitor<Boolean> {
private PsiMethod myMethod;
private final PsiClass myClass;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<error descr="Multiple non-overriding abstract methods found">@FunctionalInterface</error>
interface Test {
void foo();
void bar();
}
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,10 @@ public void testAmbiguitySpecificReturn() throws Exception {
doTest(true);
}

public void testFunctionalInterfaceAnnotation() throws Exception {
doTest();
}

private void doTest() throws Exception {
doTest(false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package com.intellij.codeInspection;

import com.intellij.codeInsight.daemon.HighlightDisplayKey;
import com.intellij.codeInspection.dataFlow.DataFlowInspection;
import com.intellij.codeInspection.deadCode.UnusedDeclarationInspection;
import com.intellij.codeInspection.ex.*;
import com.intellij.openapi.util.JDOMUtil;
Expand Down Expand Up @@ -254,7 +255,8 @@ public void testDoNotInstantiateOnSave() throws Exception {
assertEquals(0, countInitializedTools(profile));
InspectionProfileEntry[] tools = profile.getInspectionTools(null);
assertTrue(tools.length > 0);
InspectionProfileEntry tool = tools[0];
InspectionProfileEntry tool = profile.getInspectionTool(new DataFlowInspection().getShortName());
assertNotNull(tool);
String id = tool.getShortName();
System.out.println(id);
if (profile.isToolEnabled(HighlightDisplayKey.findById(id))) {
Expand All @@ -269,7 +271,6 @@ public void testDoNotInstantiateOnSave() throws Exception {
if (initializedTools.size() != 1) {
for (InspectionProfileEntry initializedTool : initializedTools) {
System.out.println(initializedTool.getShortName());
((InspectionToolWrapper)initializedTool).instantated.printStackTrace();
}
fail();
}
Expand Down
Binary file modified java/mockJDK-1.7/jre/lib/rt.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,6 @@ public FileBasedArtifactRootDescriptor createFileBasedRoot(@NotNull File file,
public JarBasedArtifactRootDescriptor createJarBasedRoot(@NotNull File jarFile,
@NotNull String pathInJar,
@NotNull SourceFileFilter filter, final DestinationInfo destinationInfo) {
return new JarBasedArtifactRootDescriptor(jarFile, pathInJar, filter, myRootIndex, myBuildTarget, destinationInfo);
return new JarBasedArtifactRootDescriptor(jarFile, pathInJar, filter, myRootIndex++, myBuildTarget, destinationInfo);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ public void process(@Nullable InputStream inputStream, @NotNull String relativeP
outputFile.mkdir();
}
else {
String fullSourcePath = filePath + JarPathUtil.JAR_SEPARATOR + relativePath;
if (outSrcMapping.getState(fullOutputPath) == null) {
final BufferedInputStream from = new BufferedInputStream(inputStream);
final BufferedOutputStream to = new BufferedOutputStream(new FileOutputStream(outputFile));
Expand All @@ -112,7 +111,7 @@ public void process(@Nullable InputStream inputStream, @NotNull String relativeP
}
outputConsumer.registerOutputFile(outputFile, Collections.singletonList(filePath));
}
outSrcMapping.appendData(fullOutputPath, Collections.singletonList(new ArtifactOutputToSourceMapping.SourcePathAndRootIndex(fullSourcePath, rootIndex)));
outSrcMapping.appendData(fullOutputPath, Collections.singletonList(new ArtifactOutputToSourceMapping.SourcePathAndRootIndex(filePath, rootIndex)));
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,17 @@
*/
package org.jetbrains.jps.incremental.artifacts;

import com.intellij.openapi.util.io.FileUtil;
import com.intellij.util.PathUtil;
import com.intellij.util.text.CharsetUtil;
import org.jetbrains.jps.model.artifact.JpsArtifact;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

import static com.intellij.util.io.TestFileSystemBuilder.fs;
import static org.jetbrains.jps.incremental.artifacts.LayoutElementTestUtil.root;

Expand Down Expand Up @@ -121,6 +129,65 @@ public void testOverwriteArchiveByFile() {
buildAllAndAssertUpToDate();
}

public void testOverwriteCopiedFileByExtracted() {
String jar = createArchive("x.jar", "x.txt", "1");
String file = createFile("x.txt", "2");
JpsArtifact a = addArtifact(root().extractedDir(jar, "").fileCopy(file));
buildAll();
assertOutput(a, fs().file("x.txt", "1"));
buildAllAndAssertUpToDate();

change(file, "3");
buildAllAndAssertUpToDate();
assertOutput(a, fs().file("x.txt", "1"));

delete(jar);
createArchive("x.jar", "x.txt", "4");
buildAll();
assertOutput(a, fs().file("x.txt", "4"));

delete(jar);
buildAll();
assertOutput(a, fs().file("x.txt", "3"));
}

public void testOverwriteExtractedFileByCopied() {
String file = createFile("x.txt", "1");
String jar = createArchive("x.jar", "x.txt", "2");
JpsArtifact a = addArtifact(root().fileCopy(file).extractedDir(jar, ""));
buildAll();
assertOutput(a, fs().file("x.txt", "1"));
buildAllAndAssertUpToDate();

delete(jar);
createArchive("x.jar", "x.txt", "3");
buildAll();
assertOutput(a, fs().file("x.txt", "1"));

delete(file);
buildAll();
assertOutput(a, fs().file("x.txt", "3"));
}

private String createArchive(String relativeArchivePath, String fileNameInArchive, String text) {
try {
File file = new File(getOrCreateProjectDir(), relativeArchivePath);
ZipOutputStream output = new ZipOutputStream(new FileOutputStream(file));
try {
output.putNextEntry(new ZipEntry(fileNameInArchive));
output.write(text.getBytes(CharsetUtil.UTF8));
output.closeEntry();
}
finally {
output.close();
}
return FileUtil.toSystemIndependentName(file.getAbsolutePath());
}
catch (IOException e) {
throw new RuntimeException(e);
}
}

public void testFileOrder() {
final String firstFile = createFile("d1/xxx.txt", "first");
final String secondFile = createFile("d2/xxx.txt", "second");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ public abstract PsiReference[] createCustomReferences(@NotNull PsiElement psiEle


@Nullable
public abstract PathReference getPathReference(@NotNull String path, @NotNull Module module, @NotNull PsiElement element, PathReferenceProvider... additionalProviders);
public abstract PathReference getPathReference(@NotNull String path,
@NotNull PsiElement element,
PathReferenceProvider... additionalProviders);

@Nullable
public abstract PathReference getCustomPathReference(@NotNull String path, @NotNull Module module, @NotNull PsiElement element, PathReferenceProvider... providers);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -395,31 +395,39 @@ else if (effectType == EffectType.BOLD_DOTTED_LINE) {
else {
myEffectsCombo.setEnabled(false);
}
setInheritanceLabel(description);
}


if (description.isInherited()) {
myInheritanceLabel.setIcon(INHERITED_ICON);
Pair<ColorSettingsPage,AttributesDescriptor> baseDescriptor = description.getBaseAttributeDescriptor();
String attrName = "?";
private void setInheritanceLabel(ColorAndFontDescription description) {
Pair<ColorSettingsPage, AttributesDescriptor> baseDescriptor = description.getBaseAttributeDescriptor();
if (baseDescriptor != null && baseDescriptor.second.getDisplayName() != null) {
String attrName = baseDescriptor.second.getDisplayName();
ColorSettingsPage settingsPage = baseDescriptor.first;
String pageName = "?";
if (baseDescriptor != null && baseDescriptor.second.getDisplayName() != null) {
attrName = baseDescriptor.second.getDisplayName();
ColorSettingsPage settingsPage = baseDescriptor.first;
if (settingsPage != null) {
pageName = settingsPage.getDisplayName();
}
if (settingsPage != null) {
pageName = settingsPage.getDisplayName();
}
String tooltipText = attrName + " (" + pageName + ")";
String labelText = tooltipText;
if (labelText.length() > 30 && pageName.length() >= 4) {
labelText = attrName + " (" + pageName.substring(0, 4) + "...)";
}
if (description.isInherited()) {
myInheritanceLabel.setIcon(INHERITED_ICON);
}
else {
myInheritanceLabel.setDisabledIcon(INHERITED_ICON);
}
myInheritanceLabel.setText(labelText);
myInheritanceLabel.setToolTipText(tooltipText);
myInheritanceLabel.setForeground(myLabelFont.getForeground());
myInheritanceLabel.setEnabled(description.isInherited());
}
else {
myInheritanceLabel.setText("X");
myInheritanceLabel.setIcon(null);
myInheritanceLabel.setDisabledIcon(null);
myInheritanceLabel.setForeground(myLabelFont.getBackground());
}
}
Expand Down
Loading

0 comments on commit e4bd534

Please sign in to comment.