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

This commit is contained in:
Michael Golubev
2013-12-09 16:09:21 +01:00
48 changed files with 518 additions and 169 deletions
+2 -2
View File
@@ -1,11 +1,11 @@
<component name="libraryTable">
<library name="Netty">
<CLASSES>
<root url="jar://$PROJECT_DIR$/lib/netty-all-15.13.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/netty-all-5.0.0.Alpha1-9.12.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$PROJECT_DIR$/lib/src/netty-all-sources.jar!/" />
<root url="jar://$PROJECT_DIR$/lib/src/netty-all-5.0.0.Alpha1-sources.jar!/" />
</SOURCES>
</library>
</component>
+1 -1
View File
@@ -253,7 +253,7 @@ libraryLicense(name: "XML-RPC", libraryName: "XmlRPC", version: "2.0", license:
libraryLicense(name: "XStream", version: "1.4.3", license: "BSD", url: "http://xstream.codehaus.org/", licenseUrl: "http://xstream.codehaus.org/license.html")
libraryLicense(name: "YourKit Java Profiler", libraryName: "yjp-controller-api-redist.jar", version: "8.0.x", license: "link (commercial license)", url: "http://yourkit.com/", licenseUrl: "http://www.yourkit.com/purchase/license.html")
libraryLicense(name: "protobuf", version: "2.5.0", license: "New BSD", url: "http://code.google.com/p/protobuf/", licenseUrl: "http://code.google.com/p/protobuf/source/browse/trunk/COPYING.txt?r=367")
libraryLicense(name: "Netty", libraryName: "Netty", version: "4.1.0.Alpha1", license: "Apache 2.0", url: "http://netty.io", licenseUrl: "http://www.apache.org/licenses/LICENSE-2.0")
libraryLicense(name: "Netty", libraryName: "Netty", version: "5.0.0.Alpha1", license: "Apache 2.0", url: "http://netty.io", licenseUrl: "http://www.apache.org/licenses/LICENSE-2.0")
libraryLicense(name: "Kryo", libraryName: "Kryo", version: "1.04", license: "New BSD License", url: "http://code.google.com/p/kryo/", licenseUrl: "http://www.opensource.org/licenses/bsd-license.php")
libraryLicense(name: "Snappy-Java", libraryName: "Snappy-Java", version: "1.0.5", license: "Apache 2.0", url: "http://code.google.com/p/snappy-java/", licenseUrl: "http://www.apache.org/licenses/LICENSE-2.0")
libraryLicense(name: "Cucumber-Java", libraryName: "cucumber-java", version: "1.0.14", license: "MIT License", url: "https://github.com/cucumber/cucumber-jvm/", licenseUrl: "http://www.opensource.org/licenses/mit-license.html")
@@ -40,7 +40,13 @@ public class ClassFileStubBuilder implements BinaryFileStubBuilder {
@Override
public boolean acceptsFile(final VirtualFile file) {
return !ClassFileViewProvider.isInnerClass(file);
final ClsStubBuilderFactory[] factories = Extensions.getExtensions(ClsStubBuilderFactory.EP_NAME);
for (ClsStubBuilderFactory factory : factories) {
if (!factory.isInnerClass(file)) {
return true;
}
}
return false;
}
@Override
@@ -18,6 +18,7 @@ package com.intellij.psi.impl.compiled;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.ClassFileViewProvider;
import com.intellij.psi.PsiClass;
import com.intellij.psi.impl.java.stubs.PsiClassStub;
import com.intellij.psi.impl.java.stubs.impl.PsiJavaFileStubImpl;
@@ -68,16 +69,7 @@ public class DefaultClsStubBuilderFactory extends ClsStubBuilderFactory {
@Override
public boolean isInnerClass(VirtualFile file) {
String name = file.getNameWithoutExtension();
int len = name.length();
int idx = name.indexOf('$');
while (idx > 0) {
if (idx + 1 < len && Character.isDigit(name.charAt(idx + 1))) return true;
idx = name.indexOf('$', idx + 1);
}
return false;
return ClassFileViewProvider.isInnerClass(file);
}
private static class VirtualFileInnerClassStrategy implements InnerClassSourceStrategy<VirtualFile> {
@@ -87,11 +87,16 @@ public class InferenceSession {
initBounds(typeParams);
}
public void initExpressionConstraints(PsiParameter[] parameters, PsiExpression[] args, PsiElement parent) {
final Pair<PsiMethod, PsiCallExpression> pair = getPair(parent);
public void initExpressionConstraints(PsiParameter[] parameters, PsiExpression[] args, PsiElement parent, PsiMethod method) {
if (method == null) {
final Pair<PsiMethod, PsiCallExpression> pair = getPair(parent);
if (pair != null) {
method = pair.first;
}
}
if (parameters.length > 0) {
for (int i = 0; i < args.length; i++) {
if (args[i] != null && (pair == null || isPertinentToApplicability(args[i], pair.first))) {
if (args[i] != null && isPertinentToApplicability(args[i], method)) {
PsiType parameterType = getParameterType(parameters, args, i, mySiteSubstitutor);
myConstraints.add(new ExpressionCompatibilityConstraint(args[i], parameterType));
}
@@ -18,8 +18,6 @@ package com.intellij.psi.impl.source.resolve.graphInference;
import com.intellij.pom.java.LanguageLevel;
import com.intellij.psi.*;
import com.intellij.psi.impl.source.resolve.ParameterTypeInferencePolicy;
import com.intellij.psi.util.PsiUtil;
import com.intellij.psi.util.TypeConversionUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -41,7 +39,7 @@ public class PsiGraphInferenceHelper implements PsiInferenceHelper {
@Nullable PsiElement parent,
@NotNull ParameterTypeInferencePolicy policy) {
final InferenceSession inferenceSession = new InferenceSession(new PsiTypeParameter[]{typeParameter}, partialSubstitutor, myManager);
inferenceSession.initExpressionConstraints(parameters, arguments, parent);
inferenceSession.initExpressionConstraints(parameters, arguments, parent, null);
return inferenceSession.infer(parameters, arguments, parent, policy).substitute(typeParameter);
}
@@ -56,7 +54,7 @@ public class PsiGraphInferenceHelper implements PsiInferenceHelper {
@NotNull LanguageLevel languageLevel) {
if (typeParameters.length == 0) return partialSubstitutor;
final InferenceSession inferenceSession = new InferenceSession(typeParameters, partialSubstitutor, myManager);
inferenceSession.initExpressionConstraints(parameters, arguments, parent);
inferenceSession.initExpressionConstraints(parameters, arguments, parent, null);
return inferenceSession.infer(parameters, arguments, parent, policy);
}
@@ -111,7 +111,7 @@ public class ExpressionCompatibilityConstraint extends InputOutputConstraintForm
InferenceSession callSession = new InferenceSession(typeParams, ((MethodCandidateInfo)resolveResult).getSiteSubstitutor(), myExpression.getManager());
final PsiExpression[] args = argumentList.getExpressions();
final PsiParameter[] parameters = method.getParameterList().getParameters();
callSession.initExpressionConstraints(parameters, args, myExpression);
callSession.initExpressionConstraints(parameters, args, myExpression, method);
substitutor = callSession.infer(parameters, args, myExpression, LiftParameterTypeInferencePolicy.INSTANCE);
}
} else {
@@ -509,8 +509,22 @@ public class JavaMethodsConflictResolver implements PsiConflictResolver{
final PsiType[] types2AtSite = typesAtSite(types2, siteSubstitutor2);
final PsiType[] types1AtSite = typesAtSite(types1, siteSubstitutor1);
final boolean applicable12 = isApplicableTo(types2AtSite, method1, typeParameters1, languageLevel, varargsPosition, types1, siteSubstitutor1);
final boolean applicable21 = isApplicableTo(types1AtSite, method2, typeParameters2, languageLevel, varargsPosition, types2, siteSubstitutor2);
final PsiSubstitutor methodSubstitutor1 = calculateMethodSubstitutor(typeParameters1, method1, siteSubstitutor1, types1, types2AtSite, languageLevel);
boolean applicable12 = isApplicableTo(types2AtSite, method1, languageLevel, varargsPosition, methodSubstitutor1);
final PsiSubstitutor methodSubstitutor2 = calculateMethodSubstitutor(typeParameters2, method2, siteSubstitutor2, types2, types1AtSite, languageLevel);
boolean applicable21 = isApplicableTo(types1AtSite, method2, languageLevel, varargsPosition, methodSubstitutor2);
final boolean typeArgsApplicable12 = GenericsUtil.isTypeArgumentsApplicable(typeParameters1, methodSubstitutor1, myArgumentsList, !applicable21);
final boolean typeArgsApplicable21 = GenericsUtil.isTypeArgumentsApplicable(typeParameters2, methodSubstitutor2, myArgumentsList, !applicable12);
if (!typeArgsApplicable12) {
applicable12 = false;
}
if (!typeArgsApplicable21) {
applicable21 = false;
}
if (applicable12 || applicable21) {
@@ -538,8 +552,10 @@ public class JavaMethodsConflictResolver implements PsiConflictResolver{
}
if (toCompareFunctional) {
final boolean applicable12ignoreFunctionalType = isApplicableTo(types2AtSite, method1, typeParameters1, languageLevel, varargsPosition, types1, siteSubstitutor1);
final boolean applicable21ignoreFunctionalType = isApplicableTo(types1AtSite, method2, typeParameters2, languageLevel, varargsPosition, types2, siteSubstitutor2);
final boolean applicable12ignoreFunctionalType = isApplicableTo(types2AtSite, method1, languageLevel, varargsPosition,
calculateMethodSubstitutor(typeParameters1, method1, siteSubstitutor1, types1, types2AtSite, languageLevel));
final boolean applicable21ignoreFunctionalType = isApplicableTo(types1AtSite, method2, languageLevel, varargsPosition,
calculateMethodSubstitutor(typeParameters2, method2, siteSubstitutor2, types2, types1AtSite, languageLevel));
if (applicable12ignoreFunctionalType || applicable21ignoreFunctionalType) {
Specifics specifics = null;
@@ -616,18 +632,13 @@ public class JavaMethodsConflictResolver implements PsiConflictResolver{
return Specifics.NEITHER;
}
private boolean isApplicableTo(PsiType[] types2AtSite,
PsiMethod method1,
PsiTypeParameter[] typeParameters1,
LanguageLevel languageLevel,
boolean varargsPosition, PsiType[] types1, PsiSubstitutor siteSubstitutor1) {
final PsiSubstitutor methodSubstitutor1 = calculateMethodSubstitutor(typeParameters1, method1, siteSubstitutor1, types1, types2AtSite, languageLevel);
private static boolean isApplicableTo(PsiType[] types2AtSite,
PsiMethod method1,
LanguageLevel languageLevel,
boolean varargsPosition,
final PsiSubstitutor methodSubstitutor1) {
final int applicabilityLevel = PsiUtil.getApplicabilityLevel(method1, methodSubstitutor1, types2AtSite, languageLevel, false, varargsPosition);
final boolean applicable = applicabilityLevel > MethodCandidateInfo.ApplicabilityLevel.NOT_APPLICABLE;
if (applicable && !GenericsUtil.isTypeArgumentsApplicable(typeParameters1, methodSubstitutor1, myArgumentsList, false)) {
return false;
}
return applicable;
return applicabilityLevel > MethodCandidateInfo.ApplicabilityLevel.NOT_APPLICABLE;
}
private static PsiType[] typesAtSite(PsiType[] types1, PsiSubstitutor siteSubstitutor1) {
@@ -650,7 +661,7 @@ public class JavaMethodsConflictResolver implements PsiConflictResolver{
ProgressManager.checkCanceled();
LOG.assertTrue(typeParameter != null);
if (!substitutor.getSubstitutionMap().containsKey(typeParameter)) {
substitutor = substitutor.put(typeParameter, siteSubstitutor.substitute(typeParameter));
substitutor = substitutor.put(typeParameter, TypeConversionUtil.erasure(siteSubstitutor.substitute(typeParameter), substitutor));
}
}
return substitutor;
@@ -0,0 +1,16 @@
import java.util.Collection;
import java.util.List;
public class Testsss {
public <TA, CA extends Iterable<TA>> void that(Iterable<TA> target) {}
public <T, C extends Collection<T>> void that(Collection<T> target) {}
void foo(ImmutableList<String> l) {
that( l);
}
interface ImmutableList<T> extends List<T> {}
}
@@ -0,0 +1,17 @@
public class Tmp
{
interface BiFunction<T, U, R> {
R apply(T t, U u);
}
interface Sequence<T>
{
<R> Sequence<R> scan(R init, BiFunction<R, T, R> func);
}
static <T> void foo(Sequence<T> sequence){}
void test(Sequence<String> strings) {
foo(strings.scan(1, (i, s) -> 1));
}
}
@@ -332,6 +332,7 @@ public class GenericsHighlightingTest extends LightDaemonAnalyzerTestCase {
public void testIDEA65377() { doTest5(false); }
public void testIDEA113526() { doTest5(true); }
public void testIDEA116493() { doTest(LanguageLevel.JDK_1_7, JavaSdkVersion.JDK_1_7, false); }
public void testIDEA117827() { doTest(LanguageLevel.JDK_1_7, JavaSdkVersion.JDK_1_7, false); }
public void testJavaUtilCollections_NoVerify() throws Exception {
PsiClass collectionsClass = getJavaFacade().findClass("java.util.Collections", GlobalSearchScope.moduleWithLibrariesScope(getModule()));
@@ -19,6 +19,7 @@ import com.intellij.codeInsight.daemon.LightDaemonAnalyzerTestCase;
import com.intellij.codeInspection.LocalInspectionTool;
import com.intellij.codeInspection.unusedSymbol.UnusedSymbolLocalInspection;
import com.intellij.openapi.projectRoots.JavaSdkVersion;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.testFramework.IdeaTestUtil;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
@@ -90,6 +91,10 @@ public class NewLambdaHighlightingTest extends LightDaemonAnalyzerTestCase {
doTest();
}
public void testOuterMethodPropagation() throws Exception {
doTest();
}
private void doTest() {
doTest(false);
}
@@ -98,4 +103,9 @@ public class NewLambdaHighlightingTest extends LightDaemonAnalyzerTestCase {
IdeaTestUtil.setTestVersion(JavaSdkVersion.JDK_1_8, getModule(), getTestRootDisposable());
doTestNewInference(BASE_PATH + "/" + getTestName(false) + ".java", warnings, false);
}
@Override
protected Sdk getProjectJDK() {
return IdeaTestUtil.getMockJdk18();
}
}
@@ -31,8 +31,7 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.jps.api.CanceledStatus;
import org.jetbrains.jps.service.SharedThreadPool;
import javax.tools.Diagnostic;
import javax.tools.JavaFileObject;
import javax.tools.*;
import java.io.File;
import java.util.*;
@@ -262,7 +261,7 @@ public class JavacServer {
}
@ChannelHandler.Sharable
private static final class ChannelRegistrar extends ChannelInboundHandlerAdapter {
private static final class ChannelRegistrar extends ChannelHandlerAdapter {
private final ChannelGroup openChannels = new DefaultChannelGroup(ImmediateEventExecutor.INSTANCE);
public boolean isEmpty() {
+1 -1
View File
@@ -34,7 +34,7 @@ microba.jar
miglayout-swing.jar
nanoxml-2.2.3.jar
nekohtml-1.9.14.jar
netty-all-15.13.jar
netty-all-5.0.0.Alpha1-9.12.jar
oromatcher.jar
picocontainer.jar
protobuf-2.5.0.jar
@@ -438,7 +438,7 @@ public class SingleRootFileViewProvider extends UserDataHolderBase implements Fi
}
@Nullable
protected static PsiElement findElementAt(@Nullable final PsiElement psiFile, final int offset) {
public static PsiElement findElementAt(@Nullable final PsiElement psiFile, final int offset) {
if (psiFile == null) return null;
int offsetInElement = offset;
PsiElement child = psiFile.getFirstChild();
@@ -481,16 +481,16 @@ public class ExternalSystemUtil {
DataNode<ProjectData> externalProject = task.getExternalProject();
if(externalProject != null) {
Set<String> myExternalModulePaths = ContainerUtil.newHashSet();
Set<String> externalModulePaths = ContainerUtil.newHashSet();
Collection<DataNode<ModuleData>> moduleNodes = ExternalSystemApiUtil.findAll(externalProject, ProjectKeys.MODULE);
for (DataNode<ModuleData> node : moduleNodes) {
myExternalModulePaths.add(node.getData().getLinkedExternalProjectPath());
externalModulePaths.add(node.getData().getLinkedExternalProjectPath());
}
String projectPath = externalProject.getData().getLinkedExternalProjectPath();
ExternalProjectSettings linkedProjectSettings = manager.getSettingsProvider().fun(project).getLinkedProjectSettings(projectPath);
if (linkedProjectSettings != null) {
linkedProjectSettings.setModules(myExternalModulePaths);
linkedProjectSettings.setModules(externalModulePaths);
}
}
@@ -45,9 +45,7 @@ class MoverWrapper {
}
public final void move(Editor editor, final PsiFile file) {
if (myInfo.toMove2 == null) {
return;
}
assert myInfo.toMove2 != null;
myMover.beforeMove(editor, myInfo, myIsDown);
final Document document = editor.getDocument();
final int start = StatementUpDownMover.getLineStartSafeOffset(document, myInfo.toMove.startLine);
@@ -19,6 +19,8 @@ import com.intellij.openapi.ui.popup.util.PopupUtil;
import com.intellij.openapi.util.ActionCallback;
import com.intellij.openapi.util.ActiveRunnable;
import com.intellij.openapi.util.Expirable;
import com.intellij.openapi.util.registry.Registry;
import com.intellij.util.ui.UIUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -149,8 +151,26 @@ public abstract class FocusCommand extends ActiveRunnable implements Expirable {
@NotNull
public final ActionCallback run() {
if (myToFocus != null) {
if (!myToFocus.requestFocusInWindow()) {
myToFocus.requestFocus();
if (Registry.is("actionSystem.doNotStealFocus")) {
Window topWindow = SwingUtilities.windowForComponent(myToFocus);
UIUtil.setAutoRequestFocus(topWindow, topWindow.isActive());
while (topWindow.getOwner() != null) {
topWindow = SwingUtilities.windowForComponent(topWindow);
UIUtil.setAutoRequestFocus(topWindow, topWindow.isActive());
}
if (topWindow.isActive()) {
if (!myToFocus.requestFocusInWindow()) {
myToFocus.requestFocus();
}
} else {
myToFocus.requestFocusInWindow();
}
} else {
if (!myToFocus.requestFocusInWindow()) {
myToFocus.requestFocus();
}
}
}
clear();
@@ -66,7 +66,7 @@ public class JBCheckBox extends JCheckBox implements AnchorableComponent {
* @return true in case of success and false otherwise
*/
public boolean setTextIcon(@NotNull Icon icon) {
if (UIUtil.isUnderDarcula()) {
if (UIUtil.isUnderDarcula() || UIUtil.isUnderIntelliJLaF()) {
return false;
}
ButtonUI ui = getUI();
@@ -16,7 +16,7 @@
package org.jetbrains.ide;
import com.intellij.openapi.extensions.ExtensionPointName;
import io.netty.channel.ChannelInboundHandler;
import io.netty.channel.ChannelHandler;
import org.jetbrains.annotations.NotNull;
import java.util.UUID;
@@ -30,5 +30,5 @@ public abstract class BinaryRequestHandler {
*/
public abstract UUID getId();
public abstract ChannelInboundHandler getInboundHandler();
public abstract ChannelHandler getInboundHandler();
}
@@ -28,9 +28,7 @@ import com.intellij.openapi.ui.MessageType;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.ui.popup.Balloon;
import com.intellij.openapi.ui.popup.JBPopupFactory;
import com.intellij.openapi.util.Computable;
import com.intellij.openapi.util.Ref;
import com.intellij.openapi.util.SystemInfo;
import com.intellij.openapi.util.*;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.wm.WindowManager;
import com.intellij.ui.HyperlinkAdapter;
@@ -50,7 +48,13 @@ import java.util.concurrent.atomic.AtomicBoolean;
public class SystemHealthMonitor extends ApplicationComponent.Adapter {
private static final Logger LOG = Logger.getInstance("#com.intellij.ide.SystemHealthMonitor");
private static final NotificationGroup LOG_GROUP = NotificationGroup.logOnlyGroup("System Health Log Messages");
private static final NotNullLazyValue<NotificationGroup> LOG_GROUP = new AtomicNotNullLazyValue<NotificationGroup>() {
@NotNull
@Override
protected NotificationGroup compute() {
return NotificationGroup.logOnlyGroup("System Health Log Messages");
}
};
@NotNull private final PropertiesComponent myProperties;
@@ -105,7 +109,7 @@ public class SystemHealthMonitor extends ApplicationComponent.Adapter {
.show(new RelativePoint(component, new Point(rect.x + 30, rect.y + rect.height - 10)), Balloon.Position.above);
}
Notification notification = LOG_GROUP.createNotification(message, NotificationType.WARNING);
Notification notification = LOG_GROUP.getValue().createNotification(message, NotificationType.WARNING);
notification.setImportant(true);
Notifications.Bus.notify(notification);
}
@@ -60,6 +60,7 @@ public class Splash extends JDialog implements StartupProgress {
setUndecorated(true);
setResizable(false);
setFocusableWindowState(false);
UIUtil.setAutoRequestFocus(this, false);
Icon originalImage = IconLoader.getIcon(imageName);
myImage = new SplashImage(originalImage, textColor);
@@ -79,7 +80,6 @@ public class Splash extends JDialog implements StartupProgress {
setSize(size);
pack();
setLocationRelativeTo(null);
UIUtil.setAutoRequestFocus(this, false);
}
public Splash(ApplicationInfoEx info) {
@@ -17,22 +17,21 @@ package org.jetbrains.io;
import com.intellij.openapi.diagnostic.Logger;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerAdapter;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandler;
import io.netty.channel.ChannelInboundHandlerAdapter;
import java.net.ConnectException;
@ChannelHandler.Sharable
public final class ChannelExceptionHandler extends ChannelInboundHandlerAdapter {
public final class ChannelExceptionHandler extends ChannelHandlerAdapter {
private static final Logger LOG = Logger.getInstance(ChannelExceptionHandler.class);
private static final ChannelInboundHandler INSTANCE = new ChannelExceptionHandler();
private static final ChannelHandler INSTANCE = new ChannelExceptionHandler();
private ChannelExceptionHandler() {
}
public static ChannelInboundHandler getInstance() {
public static ChannelHandler getInstance() {
return INSTANCE;
}
@@ -7,7 +7,7 @@ import io.netty.util.concurrent.ImmediateEventExecutor;
import org.jetbrains.annotations.NotNull;
@ChannelHandler.Sharable
public final class ChannelRegistrar extends ChannelInboundHandlerAdapter {
public final class ChannelRegistrar extends ChannelHandlerAdapter {
private final ChannelGroup openChannels = new DefaultChannelGroup(ImmediateEventExecutor.INSTANCE);
public boolean isEmpty() {
@@ -136,7 +136,7 @@ class PortUnificationServerHandler extends Decoder {
}
private static void ensureThatExceptionHandlerIsLast(ChannelPipeline pipeline) {
ChannelInboundHandler exceptionHandler = ChannelExceptionHandler.getInstance();
ChannelHandler exceptionHandler = ChannelExceptionHandler.getInstance();
if (pipeline.last() != exceptionHandler || pipeline.context(exceptionHandler) == null) {
return;
}
@@ -29,6 +29,7 @@ actionSystem.mac.screenMenuNotUpdatedFix=false
actionSystem.keyGestures.enabled=false
actionSystem.keyGestureDblClickTime=500
actionSystem.suspendFocusTransferIfApplicationInactive=true
actionSystem.doNotStealFocus=false
actionSystem.noContextComponentWhileFocusTransfer=true
actionSystem.secondKeystrokeTimeout=2000
actionSystem.secondKeystrokeAutoPopupEnabled=false
@@ -194,13 +194,13 @@ public class SelectedBlockHistoryTest extends TestCase {
}
private void doTest(
String[] beforePrevBlock,
String[] prevBlock,
String[] afterPrevBlock,
String[] beforeBlock,
String[] block,
String[] afterBlock) throws FilesTooBigForDiffException {
private static void doTest(
String[] beforePrevBlock,
String[] prevBlock,
String[] afterPrevBlock,
String[] beforeBlock,
String[] block,
String[] afterBlock) throws FilesTooBigForDiffException {
String[] prevVersion = composeVersion(beforePrevBlock, prevBlock, afterPrevBlock);
String[] currentVersion = composeVersion(beforeBlock, block, afterBlock);
@@ -214,12 +214,11 @@ public class SelectedBlockHistoryTest extends TestCase {
}
private String[] composeVersion(String[] beforeBlock, String[] block, String[] afterBlock) {
List beforeList = new ArrayList();
private static String[] composeVersion(String[] beforeBlock, String[] block, String[] afterBlock) {
List<String> beforeList = new ArrayList<String>();
ContainerUtil.addAll(beforeList, beforeBlock);
ContainerUtil.addAll(beforeList, block);
ContainerUtil.addAll(beforeList, afterBlock);
return (String[])ArrayUtil.toStringArray(beforeList);
return ArrayUtil.toStringArray(beforeList);
}
}
@@ -8,8 +8,8 @@ import io.netty.bootstrap.Bootstrap;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandler;
import io.netty.channel.ChannelInitializer;
import io.netty.util.CharsetUtil;
import org.jetbrains.annotations.NotNull;
@@ -87,7 +87,7 @@ public class BinaryRequestHandlerTest extends LightPlatformTestCase {
}
@Override
public ChannelInboundHandler getInboundHandler() {
public ChannelHandler getInboundHandler() {
return new MyDecoder();
}
@@ -44,8 +44,8 @@ public class ContainingBranchesGetter {
@NotNull private volatile SLRUMap<Hash, List<String>> myCache = createCache();
@Nullable private Runnable myLoadingFinishedListener; // access only from EDT
ContainingBranchesGetter(@NotNull VcsLogDataHolder disposable, @NotNull Disposable parentDisposable) {
myDataHolder = disposable;
ContainingBranchesGetter(@NotNull VcsLogDataHolder dataHolder, @NotNull Disposable parentDisposable) {
myDataHolder = dataHolder;
myTaskExecutor = new SequentialLimitedLifoExecutor<Task>(parentDisposable, 10, new ThrowableConsumer<Task, Throwable>() {
@Override
public void consume(final Task task) throws Throwable {
@@ -15,7 +15,8 @@ import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.Consumer;
import com.intellij.util.Function;
import com.intellij.util.ThrowableConvertor;
import com.intellij.util.containers.*;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.containers.Convertor;
import com.intellij.util.containers.HashMap;
import git4idea.DialogManager;
import git4idea.GitCommit;
@@ -43,8 +44,6 @@ import org.jetbrains.plugins.github.util.GithubUtil;
import java.io.IOException;
import java.util.*;
import java.util.HashSet;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;
@@ -244,11 +243,34 @@ public class GithubCreatePullRequestWorker {
@Nullable
public GithubFullPath showTargetDialog() {
return showTargetDialog(false);
}
@Nullable
public GithubFullPath showTargetDialog(boolean firstTime) {
final GithubInfo2 info = getAvailableForksInModal(myProject, myGitRepository, myAuth, myPath);
if (info == null) {
return null;
}
if (firstTime) {
if (info.getForks().size() == 1) {
return info.getForks().iterator().next();
}
if (info.getForks().size() == 2) {
Iterator<GithubFullPath> it = info.getForks().iterator();
GithubFullPath path1 = it.next();
GithubFullPath path2 = it.next();
if (myPath.equals(path1)) {
return path2;
}
if (myPath.equals(path2)) {
return path1;
}
}
}
Convertor<String, GithubFullPath> getForkPath = new Convertor<String, GithubFullPath>() {
@Nullable
@Override
@@ -106,7 +106,7 @@ public class GithubCreatePullRequestDialog extends DialogWrapper {
setTarget(defaultForkPath);
}
else {
if (!showTargetDialog()) {
if (!showTargetDialog(true)) {
close(CANCEL_EXIT_CODE);
return;
}
@@ -115,7 +115,11 @@ public class GithubCreatePullRequestDialog extends DialogWrapper {
}
private boolean showTargetDialog() {
GithubFullPath forkPath = myWorker.showTargetDialog();
return showTargetDialog(false);
}
private boolean showTargetDialog(boolean firstTime) {
GithubFullPath forkPath = myWorker.showTargetDialog(firstTime);
if (forkPath == null) {
return false;
}
@@ -121,6 +121,14 @@ public enum GradleDependencyScope {
return null;
}
@Nullable
public static GradleDependencyScope fromIdeaMappingName(final String ideaMappingName) {
for (GradleDependencyScope scope : values()) {
if (scope.myIdeaMappingName.equals(ideaMappingName.toLowerCase())) return scope;
}
return null;
}
public String getIdeaMappingName() {
return myIdeaMappingName;
}
@@ -62,12 +62,14 @@ public class ModelDependenciesBuilderImpl implements ModelBuilderService {
boolean downloadSources = true;
final IdeaPlugin ideaPlugin = project.getPlugins().getPlugin(IdeaPlugin.class);
Map<String, Map<String, Collection<Configuration>>> userScopes = Collections.emptyMap();
if (ideaPlugin != null) {
IdeaModel ideaModel = ideaPlugin.getModel();
if (ideaModel != null && ideaModel.getModule() == null) {
if (ideaModel != null && ideaModel.getModule() != null) {
offline = ideaModel.getModule().isOffline();
downloadJavadoc = ideaModel.getModule().isDownloadJavadoc();
downloadSources = ideaModel.getModule().isDownloadSources();
userScopes = ideaModel.getModule().getScopes();
}
}
@@ -79,7 +81,7 @@ public class ModelDependenciesBuilderImpl implements ModelBuilderService {
dependenciesExtractor.extractProjectDependencies(plusConfigurations, new ArrayList<Configuration>());
for (IdeDependenciesExtractor.IdeProjectDependency ideProjectDependency : ideProjectDependencies) {
merge(scopesMap, ideProjectDependency);
merge(scopesMap, ideProjectDependency, userScopes);
}
if (!offline) {
@@ -87,14 +89,14 @@ public class ModelDependenciesBuilderImpl implements ModelBuilderService {
dependenciesExtractor.extractRepoFileDependencies(
project.getConfigurations(), plusConfigurations, new ArrayList<Configuration>(), downloadSources, downloadJavadoc);
for (IdeDependenciesExtractor.IdeRepoFileDependency repoFileDependency : ideRepoFileDependencies) {
merge(scopesMap, repoFileDependency);
merge(scopesMap, repoFileDependency, userScopes);
}
}
final List<IdeDependenciesExtractor.IdeLocalFileDependency> ideLocalFileDependencies =
dependenciesExtractor.extractLocalFileDependencies(plusConfigurations, new ArrayList<Configuration>());
for (IdeDependenciesExtractor.IdeLocalFileDependency fileDependency : ideLocalFileDependencies) {
merge(scopesMap, fileDependency);
merge(scopesMap, fileDependency, userScopes);
}
}
@@ -166,9 +168,11 @@ public class ModelDependenciesBuilderImpl implements ModelBuilderService {
return null;
}
private static void merge(Map<DependencyVersionId, Scopes> map, IdeDependenciesExtractor.IdeProjectDependency dependency) {
private static void merge(Map<DependencyVersionId, Scopes> map,
IdeDependenciesExtractor.IdeProjectDependency dependency,
Map<String, Map<String, Collection<Configuration>>> userScopes) {
final String configurationName = dependency.getDeclaredConfiguration().getName();
final GradleDependencyScope scope = GradleDependencyScope.fromName(configurationName);
final GradleDependencyScope scope = deduceScope(configurationName, userScopes);
if (scope == null) return;
final Project project = dependency.getProject();
@@ -190,9 +194,11 @@ public class ModelDependenciesBuilderImpl implements ModelBuilderService {
return String.valueOf(o == null ? "" : o);
}
private static void merge(Map<DependencyVersionId, Scopes> map, IdeDependenciesExtractor.IdeRepoFileDependency dependency) {
private static void merge(Map<DependencyVersionId, Scopes> map,
IdeDependenciesExtractor.IdeRepoFileDependency dependency,
Map<String, Map<String, Collection<Configuration>>> userScopes) {
final String configurationName = dependency.getDeclaredConfiguration().getName();
final GradleDependencyScope scope = GradleDependencyScope.fromName(configurationName);
final GradleDependencyScope scope = deduceScope(configurationName, userScopes);
if (scope == null) return;
final ModuleVersionIdentifier dependencyId;
@@ -218,16 +224,18 @@ public class ModelDependenciesBuilderImpl implements ModelBuilderService {
}
private static String parseClassifier(ModuleVersionIdentifier dependencyId, File dependencyFile) {
if(dependencyFile == null) return null;
if (dependencyFile == null) return null;
String dependencyFileName = dependencyFile.getName();
int i = dependencyFileName.indexOf(dependencyId.getName() + '-' + dependencyId.getVersion() + '-');
return i != -1 ? dependencyFileName.substring(i, dependencyFileName.length()) : null;
}
private static void merge(Map<DependencyVersionId, Scopes> map, IdeDependenciesExtractor.IdeLocalFileDependency dependency) {
private static void merge(Map<DependencyVersionId, Scopes> map,
IdeDependenciesExtractor.IdeLocalFileDependency dependency,
Map<String, Map<String, Collection<Configuration>>> userScopes) {
final String configurationName = dependency.getDeclaredConfiguration().getName();
final GradleDependencyScope scope = GradleDependencyScope.fromName(configurationName);
final GradleDependencyScope scope = deduceScope(configurationName, userScopes);
if (scope == null) return;
String path = dependency.getFile().getPath();
@@ -242,6 +250,33 @@ public class ModelDependenciesBuilderImpl implements ModelBuilderService {
}
}
/**
* Deduce configuration scope based on configuration name using gradle conventions.
* IDEA gradle plugin only 'plus' configuration used to support configuration based on a custom configuration (not conventional)
*
* @param configurationName gradle configuration name
* @param userScopes gradle IDEA plugin scopes map
* @return deduced scope
*/
private static GradleDependencyScope deduceScope(String configurationName,
Map<String, Map<String, Collection<Configuration>>> userScopes) {
GradleDependencyScope scope = GradleDependencyScope.fromName(configurationName);
if (scope == null) {
for (Map.Entry<String, Map<String, Collection<Configuration>>> entry : userScopes.entrySet()) {
Collection<Configuration> plusConfigurations = entry.getValue().get("plus");
if (plusConfigurations == null) continue;
for (Configuration plus : plusConfigurations) {
if (plus.getName().equals(configurationName)) {
return GradleDependencyScope.fromIdeaMappingName(entry.getKey());
}
}
}
}
return scope;
}
private static class MyModuleVersionIdentifier implements ModuleVersionIdentifier, Serializable {
private final String myName;
@@ -33,7 +33,9 @@ public class Scopes {
myForProductionRuntime = scope.isForProductionRuntime();
myForTestCompile = scope.isForTestCompile();
myForTestRuntime = scope.isForTestRuntime();
myIsProvided = scope == GradleDependencyScope.PROVIDED_COMPILE || scope == GradleDependencyScope.PROVIDED_RUNTIME;
myIsProvided = scope == GradleDependencyScope.PROVIDED_COMPILE ||
scope == GradleDependencyScope.PROVIDED_RUNTIME ||
scope == GradleDependencyScope.PROVIDED;
}
public GradleDependencyScope[] getScopes() {
@@ -74,6 +76,9 @@ public class Scopes {
myForProductionRuntime = myForProductionRuntime || scope.isForProductionRuntime();
myForTestCompile = myForTestCompile || scope.isForTestCompile();
myForTestRuntime = myForTestRuntime || scope.isForTestRuntime();
myIsProvided = myIsProvided || scope == GradleDependencyScope.PROVIDED_COMPILE || scope == GradleDependencyScope.PROVIDED_RUNTIME;
myIsProvided = myIsProvided ||
scope == GradleDependencyScope.PROVIDED_COMPILE ||
scope == GradleDependencyScope.PROVIDED_RUNTIME ||
scope == GradleDependencyScope.PROVIDED;
}
}
@@ -0,0 +1,38 @@
//noinspection GrPackage
allprojects {
apply plugin: 'java'
apply plugin: 'idea'
version = '1.0'
sourceCompatibility = 1.6
configurations {
provided
}
sourceSets {
main {
compileClasspath += configurations.provided
}
}
idea {
module {
scopes.PROVIDED.plus += configurations.provided
}
}
}
project(":service") {
dependencies {
compile (project(':api'))
}
}
project(":api") {
dependencies {
provided(project(':lib'))
}
}
@@ -0,0 +1,4 @@
//noinspection GrPackage
include "lib"
include "api"
include "service"
@@ -20,6 +20,8 @@ import com.intellij.util.containers.ContainerUtil;
import org.gradle.tooling.model.DomainObjectSet;
import org.gradle.tooling.model.idea.IdeaDependency;
import org.gradle.tooling.model.idea.IdeaModule;
import org.gradle.tooling.model.idea.IdeaModuleDependency;
import org.jetbrains.plugins.gradle.model.GradleDependencyScope;
import org.jetbrains.plugins.gradle.model.ProjectDependenciesModel;
import org.junit.Test;
@@ -53,6 +55,53 @@ public class ModelDependenciesBuilderImplTest extends AbstractModelBuilderTest {
assertEquals(1, dependencies.size());
}
@Test
public void testGradleIdeaPluginPlusScopesDependenciesModel() throws Exception {
ModelDependenciesBuilderImpl dependenciesBuilder = new ModelDependenciesBuilderImpl();
assertTrue(dependenciesBuilder.canBuild("org.jetbrains.plugins.gradle.model.ProjectDependenciesModel"));
DomainObjectSet<? extends IdeaModule> ideaModules = allModels.getIdeaProject().getModules();
// test api module dependencies
IdeaModule apiModule = ContainerUtil.find(ideaModules, new Condition<IdeaModule>() {
@Override
public boolean value(IdeaModule module) {
return module.getName().equals("api");
}
});
assertNotNull(apiModule);
DomainObjectSet<? extends IdeaDependency> dependencies = apiModule.getDependencies();
assertEquals(1, dependencies.size());
IdeaDependency libDependency = dependencies.getAt(0);
assertEquals(GradleDependencyScope.PROVIDED.name(), libDependency.getScope().getScope());
assertTrue(libDependency instanceof IdeaModuleDependency);
IdeaModuleDependency libModuleDependency = (IdeaModuleDependency)libDependency;
assertNotNull(libModuleDependency.getDependencyModule());
assertEquals("lib", libModuleDependency.getDependencyModule().getName());
// test service module dependencies
IdeaModule serviceModule = ContainerUtil.find(ideaModules, new Condition<IdeaModule>() {
@Override
public boolean value(IdeaModule module) {
return module.getName().equals("service");
}
});
assertNotNull(serviceModule);
DomainObjectSet<? extends IdeaDependency> serviceModuleDependencies = serviceModule.getDependencies();
assertEquals(1, serviceModuleDependencies.size());
IdeaDependency apiDependency = serviceModuleDependencies.getAt(0);
assertEquals(GradleDependencyScope.COMPILE.name(), apiDependency.getScope().getScope());
assertTrue(apiDependency instanceof IdeaModuleDependency);
IdeaModuleDependency apiModuleDependency = (IdeaModuleDependency)apiDependency;
assertNotNull(apiModuleDependency.getDependencyModule());
assertEquals("api", apiModuleDependency.getDependencyModule().getName());
}
@Override
protected Set<Class> getModels() {
return ContainerUtil.<Class>set(ProjectDependenciesModel.class);
@@ -46,11 +46,9 @@ import java.util.regex.Pattern;
* @author ilyas
*/
public abstract class GroovyConfigUtils extends AbstractConfigUtils {
@NonNls private static final Pattern GROOVY_ALL_JAR_PATTERN = Pattern.compile("groovy-all-(.*)\\.jar");
private static GroovyConfigUtils myGroovyConfigUtils;
@NonNls public static final Pattern GROOVY_ALL_JAR_PATTERN = Pattern.compile("groovy-all(-(.*))?\\.jar");
@NonNls public static final Pattern GROOVY_JAR_PATTERN = Pattern.compile("groovy(-(\\d.*))?\\.jar");
@NonNls public static final String GROOVY_JAR_PATTERN_NOVERSION = "groovy\\.jar";
@NonNls public static final String GROOVY_JAR_PATTERN = "groovy-(\\d.*)\\.jar";
public static final String NO_VERSION = "<no version>";
public static final String GROOVY1_7 = "1.7";
public static final String GROOVY1_8 = "1.8";
@@ -58,6 +56,8 @@ public abstract class GroovyConfigUtils extends AbstractConfigUtils {
public static final String GROOVY2_1 = "2.1";
public static final String GROOVY2_2 = "2.2";
private static GroovyConfigUtils myGroovyConfigUtils;
private GroovyConfigUtils() {
}
@@ -83,9 +83,6 @@ public abstract class GroovyConfigUtils extends AbstractConfigUtils {
@NotNull
public String getSDKVersion(@NotNull final String path) {
String groovyJarVersion = getSDKJarVersion(path + "/lib", GROOVY_JAR_PATTERN, MANIFEST_PATH);
if (groovyJarVersion == null) {
groovyJarVersion = getSDKJarVersion(path + "/lib", GROOVY_JAR_PATTERN_NOVERSION, MANIFEST_PATH);
}
if (groovyJarVersion == null) {
groovyJarVersion = getSDKJarVersion(path + "/lib", GROOVY_ALL_JAR_PATTERN, MANIFEST_PATH);
}
@@ -143,7 +140,6 @@ public abstract class GroovyConfigUtils extends AbstractConfigUtils {
if (file != null && file.isDirectory()) {
final String path = file.getPath();
if (GroovyUtils.getFilesInDirectoryByPattern(path + "/lib", GROOVY_JAR_PATTERN).length > 0 ||
GroovyUtils.getFilesInDirectoryByPattern(path + "/lib", GROOVY_JAR_PATTERN_NOVERSION).length > 0 ||
GroovyUtils.getFilesInDirectoryByPattern(path + "/embeddable", GROOVY_ALL_JAR_PATTERN).length > 0 ||
GroovyUtils.getFilesInDirectoryByPattern(path, GROOVY_JAR_PATTERN).length > 0) {
return true;
@@ -44,4 +44,14 @@ public class GrAnnotationUtil {
}
return null;
}
@Nullable
public static Boolean inferBooleanAttribute(@NotNull PsiAnnotation annotation, @NotNull String attributeName) {
final PsiAnnotationMemberValue targetValue = annotation.findAttributeValue(attributeName);
if (targetValue instanceof PsiLiteral) {
final Object value = ((PsiLiteral)targetValue).getValue();
if (value instanceof Boolean) return (Boolean)value;
}
return null;
}
}
@@ -22,9 +22,12 @@ import com.intellij.psi.*;
import com.intellij.psi.impl.source.tree.LeafPsiElement;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.tree.TokenSet;
import com.intellij.psi.util.CachedValueProvider;
import com.intellij.psi.util.CachedValuesManager;
import com.intellij.psi.util.InheritanceUtil;
import com.intellij.psi.util.PsiModificationTracker;
import com.intellij.util.Function;
import com.intellij.util.ReflectionCache;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.plugins.groovy.findUsages.LiteralConstructorReference;
@@ -46,7 +49,6 @@ import org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.TypesUt
import org.jetbrains.plugins.groovy.lang.psi.util.GroovyCommonClassNames;
import org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -118,11 +120,13 @@ public class GrListOrMapImpl extends GrExpressionImpl implements GrListOrMap {
@NotNull
public GrExpression[] getInitializers() {
List<GrExpression> result = new ArrayList<GrExpression>();
List<GrExpression> result = ContainerUtil.newArrayList();
for (PsiElement cur = getFirstChild(); cur != null; cur = cur.getNextSibling()) {
if (ReflectionCache.isInstance(cur, GrExpression.class)) result.add((GrExpression)cur);
if (cur instanceof GrExpression) {
result.add((GrExpression)cur);
}
}
return result.toArray((GrExpression[]) Array.newInstance(GrExpression.class, result.size()));
return result.toArray(new GrExpression[result.size()]);
}
@NotNull
@@ -141,13 +145,21 @@ public class GrListOrMapImpl extends GrExpressionImpl implements GrListOrMap {
@Override
public PsiReference getReference() {
return CachedValuesManager.getCachedValue(this, new CachedValueProvider<PsiReference>() {
@Nullable
@Override
public Result<PsiReference> compute() {
return Result.create(getReferenceImpl(), PsiModificationTracker.MODIFICATION_COUNT);
}
});
}
@Nullable
private PsiReference getReferenceImpl() {
final PsiClassType conversionType = LiteralConstructorReference.getTargetConversionType(this);
if (conversionType == null) return null;
PsiType ownType = getType();
if (ownType instanceof PsiClassType) {
ownType = ((PsiClassType)ownType).rawType();
}
PsiType ownType = getTypeWithoutGenerics();
if (ownType != null && TypesUtil.isAssignableWithoutConversions(conversionType.rawType(), ownType, this)) return null;
final PsiClass resolved = conversionType.resolve();
@@ -159,6 +171,17 @@ public class GrListOrMapImpl extends GrExpressionImpl implements GrListOrMap {
return new LiteralConstructorReference(this, conversionType);
}
@Nullable
private PsiType getTypeWithoutGenerics() {
PsiType ownType = getType();
if (ownType instanceof PsiClassType) {
return ((PsiClassType)ownType).rawType();
}
else {
return ownType;
}
}
private static class MyTypesCalculator implements Function<GrListOrMapImpl, PsiType> {
@Nullable
public PsiType fun(GrListOrMapImpl listOrMap) {
@@ -23,6 +23,7 @@ import com.intellij.psi.*;
import com.intellij.psi.impl.PsiImplUtil;
import com.intellij.psi.impl.light.LightClassReference;
import com.intellij.psi.meta.PsiMetaData;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.util.PairFunction;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
@@ -82,10 +83,6 @@ public class GrAnnotationImpl extends GrStubElementBase<GrAnnotationStub> implem
@NotNull
public GrAnnotationArgumentList getParameterList() {
final GrAnnotationStub stub = getStub();
if (stub != null) {
return stub.getPsiElement().getParameterList();
}
return findNotNullChildByClass(GrAnnotationArgumentList.class);
}
@@ -105,29 +102,44 @@ public class GrAnnotationImpl extends GrStubElementBase<GrAnnotationStub> implem
@Nullable
public PsiJavaCodeReferenceElement getNameReferenceElement() {
final GrAnnotationStub stub = getStub();
if (stub != null) {
return stub.getPsiElement().getNameReferenceElement();
}
final GroovyResolveResult resolveResult = resolveWithStub();
final GroovyResolveResult resolveResult = getClassReference().advancedResolve();
final PsiElement resolved = resolveResult.getElement();
if (!(resolved instanceof PsiClass)) return null;
if (resolved instanceof PsiClass) {
return new LightClassReference(getManager(), getClassReference().getText(), (PsiClass)resolved, resolveResult.getSubstitutor());
}
else {
return null;
}
return new LightClassReference(getManager(), getClassReference().getText(), (PsiClass)resolved, resolveResult.getSubstitutor());
}
@NotNull
private GroovyResolveResult resolveWithStub() {
final GrAnnotationStub stub = getStub();
final GrCodeReferenceElement reference = stub != null ? stub.getPsiElement().getClassReference() : getClassReference();
return reference.advancedResolve();
}
@Nullable
public PsiAnnotationMemberValue findAttributeValue(@Nullable String attributeName) {
final GrAnnotationStub stub = getStub();
if (stub != null) {
final GrAnnotation stubbedPsi = stub.getPsiElement();
final PsiAnnotationMemberValue value = PsiImplUtil.findAttributeValue(stubbedPsi, attributeName);
if (value == null || !PsiTreeUtil.isAncestor(stubbedPsi, value, true)) { // if value is a default value we can use it
return value;
}
}
return PsiImplUtil.findAttributeValue(this, attributeName);
}
@Nullable
public PsiAnnotationMemberValue findDeclaredAttributeValue(@NonNls final String attributeName) {
final GrAnnotationStub stub = getStub();
if (stub != null) {
final GrAnnotation stubbedPsi = stub.getPsiElement();
final PsiAnnotationMemberValue value = PsiImplUtil.findDeclaredAttributeValue(stubbedPsi, attributeName);
if (value == null) {
return null;
}
}
return PsiImplUtil.findDeclaredAttributeValue(this, attributeName);
}
@@ -40,7 +40,6 @@ import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifierL
import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.annotation.GrAnnotation;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrField;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrLiteral;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrEnumConstantInitializer;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrReferenceList;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition;
@@ -50,6 +49,7 @@ import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrGd
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrReflectedMethod;
import org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement;
import org.jetbrains.plugins.groovy.lang.psi.impl.GrAnnotationUtil;
import org.jetbrains.plugins.groovy.lang.psi.impl.GroovyPsiManager;
import org.jetbrains.plugins.groovy.lang.psi.impl.PsiImplUtil;
import org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.TypesUtil;
@@ -616,21 +616,8 @@ public class GrClassImplUtil {
}
private static boolean shouldImplementDelegatedInterfaces(PsiAnnotation delegate) {
final PsiAnnotationParameterList parameterList = delegate.getParameterList();
final PsiNameValuePair[] attributes = parameterList.getAttributes();
for (PsiNameValuePair attribute : attributes) {
final String name = attribute.getName();
if ("interfaces".equals(name)) {
final PsiAnnotationMemberValue value = attribute.getValue();
if (value instanceof GrLiteral) {
final Object innerValue = ((GrLiteral)value).getValue();
if (innerValue instanceof Boolean) {
return (Boolean)innerValue;
}
}
}
}
return true;
final Boolean result = GrAnnotationUtil.inferBooleanAttribute(delegate, "interfaces");
return result != null ? result.booleanValue() : true;
}
public static void addExpandingReflectedMethods(List<PsiMethod> result, PsiMethod method) {
@@ -31,11 +31,11 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.plugins.groovy.GroovyFileType;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrField;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrLiteral;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrExtendsClause;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrImplementsClause;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinitionBody;
import org.jetbrains.plugins.groovy.lang.psi.impl.GrAnnotationUtil;
import org.jetbrains.plugins.groovy.lang.psi.impl.PsiImplUtil;
import org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.TypesUtil;
import org.jetbrains.plugins.groovy.lang.psi.util.GrClassImplUtil;
@@ -272,21 +272,8 @@ public class DelegatedMethodsContributor extends AstTransformContributor {
}
private static boolean shouldDelegateDeprecated(PsiAnnotation delegate) {
final PsiAnnotationParameterList parameterList = delegate.getParameterList();
final PsiNameValuePair[] attributes = parameterList.getAttributes();
for (PsiNameValuePair attribute : attributes) {
final String name = attribute.getName();
if ("deprecated".equals(name)) {
final PsiAnnotationMemberValue value = attribute.getValue();
if (value instanceof GrLiteral) {
final Object innerValue = ((GrLiteral)value).getValue();
if (innerValue instanceof Boolean) {
return (Boolean)innerValue;
}
}
}
}
return false;
final Boolean result = GrAnnotationUtil.inferBooleanAttribute(delegate, "deprecated");
return result != null ? result.booleanValue() : false;
}
private static PsiMethod generateDelegateMethod(PsiMethod method, PsiClass superClass, PsiSubstitutor substitutor) {
@@ -143,7 +143,7 @@ public class LibrariesUtil {
private static String getGroovySdkHome(VirtualFile[] classRoots) {
for (VirtualFile file : classRoots) {
final String name = file.getName();
if (name.matches(GroovyConfigUtils.GROOVY_JAR_PATTERN_NOVERSION) || name.matches(GroovyConfigUtils.GROOVY_JAR_PATTERN)) {
if (GroovyConfigUtils.GROOVY_JAR_PATTERN.matcher(name).matches()) {
String jarPath = file.getPresentableUrl();
File realFile = new File(jarPath);
if (realFile.exists()) {
@@ -132,4 +132,92 @@ class B {
assert clazzB.methods.find {it.name =='foo'}
assert !file.contentsLoaded
}
void testDefaultValueForAnnotation() {
myFixture.addFileToProject('pack/Ann.groovy', '''\
package pack
@interface Ann {
String foo() default 'def'
}
''')
GroovyFileImpl file = myFixture.addFileToProject('usage.groovy', '''\
import pack.Ann
class X {
@Ann()
String bar() {}
}
''') as GroovyFileImpl
assert !file.contentsLoaded
PsiClass clazz = file.classes[0]
assert !file.contentsLoaded
PsiMethod method = clazz.methods[0]
assert !file.contentsLoaded
PsiAnnotation annotation = method.modifierList.findAnnotation('pack.Ann')
assert !file.contentsLoaded
assert annotation.findAttributeValue('foo') != null
assert !file.contentsLoaded
}
void testDefaultValueForAnnotationWithAliases() {
myFixture.addFileToProject('pack/Ann.groovy', '''\
package pack
@interface Ann {
String foo() default 'def'
}
''')
GroovyFileImpl file = myFixture.addFileToProject('usage.groovy', '''\
import pack.Ann as A
class X {
@A()
String bar() {}
}
''') as GroovyFileImpl
assert !file.contentsLoaded
PsiClass clazz = file.classes[0]
assert !file.contentsLoaded
PsiMethod method = clazz.methods[0]
assert !file.contentsLoaded
PsiAnnotation annotation = method.modifierList.findAnnotation('pack.Ann')
assert !file.contentsLoaded
assert annotation.findAttributeValue('foo') != null
assert !file.contentsLoaded
}
void testValueForAnnotationWithAliases() {
myFixture.addFileToProject('pack/Ann.groovy', '''\
package pack
@interface Ann {
String foo() default 'def'
}
''')
GroovyFileImpl file = myFixture.addFileToProject('usage.groovy', '''\
import pack.Ann as A
class X {
@A(foo='non_def')
String bar() {}
}
''') as GroovyFileImpl
assert !file.contentsLoaded
PsiClass clazz = file.classes[0]
assert !file.contentsLoaded
PsiMethod method = clazz.methods[0]
assert !file.contentsLoaded
PsiAnnotation annotation = method.modifierList.findAnnotation('pack.Ann')
assert !file.contentsLoaded
assert annotation.findAttributeValue('foo') != null
assert file.contentsLoaded
}
}
@@ -23,10 +23,7 @@ import com.intellij.openapi.editor.ScrollType;
import com.intellij.openapi.fileTypes.FileType;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.FileViewProvider;
import com.intellij.psi.PsiDocumentManager;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.*;
import com.intellij.psi.impl.source.tree.TreeUtil;
import com.intellij.psi.templateLanguages.OuterLanguageElement;
import com.intellij.psi.tree.IElementType;
@@ -86,6 +83,14 @@ public class XmlSlashTypedHandler extends TypedHandlerDelegate implements XmlTok
if ("</".equals(prevLeafText) && prevLeaf.getElementType() == XML_END_TAG_START) {
XmlTag tag = PsiTreeUtil.getParentOfType(element, XmlTag.class);
if (tag != null && StringUtil.isNotEmpty(tag.getName()) && TreeUtil.findSibling(prevLeaf, XmlTokenType.XML_NAME) == null) {
// check for template language like JSP
if (provider instanceof MultiplePsiFilesPerDocumentFileViewProvider) {
PsiElement element1 = SingleRootFileViewProvider.findElementAt(file, offset - 1);
XmlTag tag1 = PsiTreeUtil.getParentOfType(element1, XmlTag.class);
if (tag1 != null && tag1 != tag && tag1.getTextOffset() > tag.getTextOffset() && element1.getText().startsWith("</")) {
tag = tag1;
}
}
EditorModificationUtil.insertStringAtCaret(editor, tag.getName() + ">");
return Result.STOP;
}