<module name="remote-servers-agent-rt" target="1.5" />
<module name="testng_rt" target="1.5" />
<module name="ui-designer-jps-plugin" target="1.6" />
- <module name="util" target="1.5" />
<module name="util-rt" target="1.5" />
</bytecodeTargetLevel>
</component>
1.6 =>
1.3 => lib/idea_rt.jar
-1.5 => lib/util.jar
1.7 => lib/fxHelpBrowser.jar
1.7 => lib/optimizedFileManager.jar
"remote-servers-java-impl",
"testFramework",
"tests_bootstrap",
- ].flatten()
+ "ui-designer-core"
+ ].flatten()
implementationModules.removeAll(jpsCommonModules) //todo[nik] remove jps modules from platformImplementationModules instead and update layouts of minor IDEs accordingly
ant.patternset(id: "resources.included") {
dir("android-designer") {
dir("lib") {
- jar("resources_en.jar") {
- module("ui-designer-core") {
- patternset(refid: "resources.included")
- }
- }
jar("android-designer.jar") {
- module("ui-designer-core") {
- patternset(refid: "resources.excluded")
- }
module("android-designer")
}
}
<?xml version="1.0" encoding="UTF-8"?>
<module relativePaths="true" type="JAVA_MODULE" version="4">
- <component name="NewModuleRootManager" inherit-compiler-output="true">
+ <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_6" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
import com.intellij.debugger.impl.DebuggerContextListener;
import com.intellij.debugger.impl.DebuggerSession;
import com.intellij.debugger.impl.PositionUtil;
+import com.intellij.debugger.ui.impl.ValueNodeDnD;
import com.intellij.debugger.ui.impl.WatchDebuggerTree;
import com.intellij.debugger.ui.impl.WatchPanel;
import com.intellij.debugger.ui.impl.watch.DebuggerTreeNodeImpl;
});
setUpdateEnabled(true);
getTree().getEmptyText().setText(XDebuggerBundle.message("debugger.no.results"));
+ new ValueNodeDnD(myTree, project);
}
protected ActionPopupMenu createPopupMenu() {
DefaultActionGroup group = new DefaultActionGroup();
for (Pair<Breakpoint, Event> eventDescriptor : myEventsOutOfLine) {
Breakpoint breakpoint = eventDescriptor.getFirst();
- AnAction viewBreakpointsAction = new ViewBreakpointsAction(breakpoint.getDisplayName(), breakpoint);
+ AnAction viewBreakpointsAction = new ViewBreakpointsAction(breakpoint.getDisplayName(), breakpoint.getXBreakpoint());
group.add(viewBreakpointsAction);
}
return myXBreakpoint.getProperties();
}
+ public XBreakpoint<P> getXBreakpoint() {
+ return myXBreakpoint;
+ }
+
@Nullable
public abstract PsiClass getPsiClass();
/**
int minUsagesNumberToShowDialog);
@NotNull public abstract IntentionAction createCreateMethodFromUsageFix(@NotNull PsiMethodCallExpression call);
+ @NotNull public abstract IntentionAction createCreateMethodFromUsageFix(PsiMethodReferenceExpression methodReferenceExpression);
@NotNull public abstract IntentionAction createCreateAbstractMethodFromUsageFix(@NotNull PsiMethodCallExpression call);
}
@Nullable
- public static HighlightInfo checkEnumInstantiation(PsiNewExpression expression, PsiClass aClass) {
- if (aClass != null && aClass.isEnum() && expression.getArrayDimensions().length == 0 && expression.getArrayInitializer() == null) {
+ public static HighlightInfo checkEnumInstantiation(PsiElement expression, PsiClass aClass) {
+ if (aClass != null && aClass.isEnum() &&
+ (!(expression instanceof PsiNewExpression) ||
+ ((PsiNewExpression)expression).getArrayDimensions().length == 0 && ((PsiNewExpression)expression).getArrayInitializer() == null)) {
String description = JavaErrorMessages.message("enum.types.cannot.be.instantiated");
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(expression).descriptionAndTooltip(description).create();
}
continue;
}
}
+ if (JavaGenericsUtil.isRawToGeneric(currentType, otherSuperReturnType)) continue;
}
return createIncompatibleReturnTypeMessage(currentMethod, otherSuperMethod, otherSuperReturnType,
currentType, JavaErrorMessages.message("unrelated.overriding.methods.return.types"),
if (!myHolder.hasErrorResults() && method.isConstructor()) {
myHolder.add(HighlightClassUtil.checkThingNotAllowedInInterface(method, aClass));
}
- if (!myHolder.hasErrorResults() && method.hasModifierProperty(PsiModifier.DEFAULT)) {
+ if (!myHolder.hasErrorResults() && (method.hasModifierProperty(PsiModifier.DEFAULT) ||
+ aClass != null && aClass.isInterface() && method.hasModifierProperty(PsiModifier.STATIC))) {
myHolder.add(HighlightUtil.checkExtensionMethodsFeature(method, myLanguageLevel, myFile));
}
@Override
public void visitMethodReferenceExpression(PsiMethodReferenceExpression expression) {
myHolder.add(HighlightUtil.checkMethodReferencesFeature(expression, myLanguageLevel,myFile));
- JavaResolveResult result;
+ final JavaResolveResult result;
+ final JavaResolveResult[] results;
try {
- result = expression.advancedResolve(true);
+ results = expression.multiResolve(true);
+ result = results.length == 1 ? results[0] : JavaResolveResult.EMPTY;
}
catch (IndexNotReadyException e) {
return;
}
myHolder.add(GenericsHighlightUtil.checkInferredTypeArguments(typeParameters, expression, result.getSubstitutor()));
}
+
+ if (!myHolder.hasErrorResults()) {
+ if (results.length == 0) {
+ String description = null;
+ if (expression.isConstructor()) {
+ final PsiClass containingClass = PsiMethodReferenceUtil.getQualifierResolveResult(expression).getContainingClass();
+
+ if (containingClass != null) {
+ if (!myHolder.add(HighlightClassUtil.checkInstantiationOfAbstractClass(containingClass, expression)) &&
+ !myHolder.add(GenericsHighlightUtil.checkEnumInstantiation(expression, containingClass)) &&
+ containingClass.isPhysical()) {
+ description = JavaErrorMessages.message("cannot.resolve.constructor", containingClass.getName());
+ }
+ }
+ }
+ else {
+ description = JavaErrorMessages.message("cannot.resolve.method", expression.getReferenceName());
+ }
+
+ if (description != null) {
+ final PsiElement referenceNameElement = expression.getReferenceNameElement();
+ final HighlightInfo highlightInfo =
+ HighlightInfo.newHighlightInfo(HighlightInfoType.WRONG_REF).descriptionAndTooltip(description).range(referenceNameElement).create();
+ myHolder.add(highlightInfo);
+ final TextRange fixRange = HighlightMethodUtil.getFixRange(referenceNameElement);
+ QuickFixAction.registerQuickFixAction(highlightInfo, fixRange, QuickFixFactory.getInstance().createCreateMethodFromUsageFix(expression));
+ }
+ }
+ }
}
@Override
final PsiParameter parameter = foreachStatement.getIterationParameter();
final PsiIfStatement ifStmt = extractIfStatement(body);
- String foreEachText = body.getText();
+ String foreEachText = wrapInBlock(body);
String iterated = iteratedValue.getText();
if (ifStmt != null) {
final PsiExpression condition = ifStmt.getCondition();
LOG.assertTrue(thenBranch != null);
if (InheritanceUtil.isInheritor(iteratedValue.getType(), CommonClassNames.JAVA_UTIL_COLLECTION)) {
body = thenBranch;
- foreEachText = thenBranch.getText();
+ foreEachText = wrapInBlock(thenBranch);
iterated += ".stream().filter(" + parameter.getName() + " -> " + condition.getText() +")";
}
}
}
}
}
+
+ private static String wrapInBlock(PsiStatement body) {
+
+ if (body instanceof PsiExpressionStatement) {
+ return ((PsiExpressionStatement)body).getExpression().getText();
+ }
+
+ final String bodyText = body.getText();
+ if (!(body instanceof PsiBlockStatement)) {
+ return "{" + bodyText + "}";
+ }
+ return bodyText;
+ }
}
private static class ReplaceWithCollectCallFix implements LocalQuickFix {
--- /dev/null
+/*
+ * Copyright 2000-2014 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.codeInsight.daemon.impl.quickfix;
+
+import com.intellij.codeInsight.ExpectedTypeInfo;
+import com.intellij.codeInsight.ExpectedTypeInfoImpl;
+import com.intellij.codeInsight.TailType;
+import com.intellij.codeInsight.daemon.QuickFixBundle;
+import com.intellij.openapi.diagnostic.Logger;
+import com.intellij.openapi.project.Project;
+import com.intellij.openapi.util.Pair;
+import com.intellij.psi.*;
+import com.intellij.psi.util.PsiTreeUtil;
+import com.intellij.psi.util.PsiUtil;
+import com.intellij.util.Function;
+import com.intellij.util.containers.ContainerUtil;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+import java.util.Collections;
+import java.util.List;
+
+public class CreateMethodFromMethodReferenceFix extends CreateFromUsageBaseFix {
+ private static final Logger LOG = Logger.getInstance("#" + CreateMethodFromMethodReferenceFix.class.getName());
+
+ private final SmartPsiElementPointer myMethodReferenceExpression;
+
+ public CreateMethodFromMethodReferenceFix(@NotNull PsiMethodReferenceExpression methodRef) {
+ myMethodReferenceExpression = SmartPointerManager.getInstance(methodRef.getProject()).createSmartPsiElementPointer(methodRef);
+ }
+
+ @Override
+ protected boolean isAvailableImpl(int offset) {
+ final PsiMethodReferenceExpression call = getMethodReference();
+ if (call == null || !call.isValid()) return false;
+ final PsiType functionalInterfaceType = call.getFunctionalInterfaceType();
+ if (functionalInterfaceType == null ||
+ LambdaUtil.getFunctionalInterfaceMethod(functionalInterfaceType) == null){
+ return false;
+ }
+
+ final String name = call.getReferenceName();
+
+ if (name == null) return false;
+ if (call.isConstructor() && name.equals("new") || PsiNameHelper.getInstance(call.getProject()).isIdentifier(name)) {
+ setText(call.isConstructor() ? QuickFixBundle.message("create.constructor.from.new.text") : QuickFixBundle.message("create.method.from.usage.text", name));
+ return true;
+ }
+ return false;
+ }
+
+ @Override
+ protected PsiElement getElement() {
+ final PsiMethodReferenceExpression call = getMethodReference();
+ if (call == null || !call.getManager().isInProject(call)) return null;
+ return call;
+ }
+
+ @Override
+ @NotNull
+ protected List<PsiClass> getTargetClasses(PsiElement element) {
+ List<PsiClass> targets = super.getTargetClasses(element);
+ PsiMethodReferenceExpression call = getMethodReference();
+ if (call == null) return Collections.emptyList();
+ return targets;
+ }
+
+ @Override
+ protected void invokeImpl(final PsiClass targetClass) {
+ if (targetClass == null) return;
+ PsiMethodReferenceExpression expression = getMethodReference();
+ if (expression == null) return;
+
+ if (isValidElement(expression)) return;
+
+ PsiClass parentClass = PsiTreeUtil.getParentOfType(expression, PsiClass.class);
+ PsiMember enclosingContext = PsiTreeUtil.getParentOfType(expression, PsiMethod.class, PsiField.class, PsiClassInitializer.class);
+
+ String methodName = expression.getReferenceName();
+ LOG.assertTrue(methodName != null);
+
+
+ final Project project = targetClass.getProject();
+ JVMElementFactory elementFactory = JVMElementFactories.getFactory(targetClass.getLanguage(), project);
+ if (elementFactory == null) elementFactory = JavaPsiFacade.getElementFactory(project);
+
+ PsiMethod method = expression.isConstructor() ? (PsiMethod)targetClass.add(elementFactory.createConstructor())
+ : CreateMethodFromUsageFix.createMethod(targetClass, parentClass, enclosingContext, methodName);
+ if (method == null) {
+ return;
+ }
+
+ if (!expression.isConstructor()) {
+ setupVisibility(parentClass, targetClass, method.getModifierList());
+ }
+
+ expression = getMethodReference();
+ LOG.assertTrue(expression.isValid());
+
+ if (!expression.isConstructor() && shouldCreateStaticMember(expression, targetClass)) {
+ PsiUtil.setModifierProperty(method, PsiModifier.STATIC, true);
+ }
+
+ final PsiElement context = PsiTreeUtil.getParentOfType(expression, PsiClass.class, PsiMethod.class);
+
+ final PsiType functionalInterfaceType = expression.getFunctionalInterfaceType();
+ final PsiClassType.ClassResolveResult classResolveResult = PsiUtil.resolveGenericsClassInType(functionalInterfaceType);
+ final PsiMethod interfaceMethod = LambdaUtil.getFunctionalInterfaceMethod(classResolveResult);
+ LOG.assertTrue(interfaceMethod != null);
+
+ final PsiType interfaceReturnType = LambdaUtil.getFunctionalInterfaceReturnType(functionalInterfaceType);
+ LOG.assertTrue(interfaceReturnType != null);
+
+ final ExpectedTypeInfo[] expectedTypes = {new ExpectedTypeInfoImpl(interfaceReturnType, ExpectedTypeInfo.TYPE_OR_SUBTYPE, interfaceReturnType, TailType.NONE, null, ExpectedTypeInfoImpl.NULL)};
+ CreateMethodFromUsageFix.doCreate(targetClass, method, false,
+ ContainerUtil.map2List(interfaceMethod.getParameterList().getParameters(), new Function<PsiParameter, Pair<PsiExpression, PsiType>>() {
+ @Override
+ public Pair<PsiExpression, PsiType> fun(PsiParameter parameter) {
+ return Pair.create(null, parameter.getType());
+ }
+ }),
+ LambdaUtil.getSubstitutor(interfaceMethod, classResolveResult),
+ expectedTypes, context);
+ }
+
+
+
+ @Override
+ protected boolean isValidElement(PsiElement element) {
+ return false;
+ }
+
+ @Override
+ @NotNull
+ public String getFamilyName() {
+ return QuickFixBundle.message("create.method.from.usage.family");
+ }
+
+ @Nullable
+ protected PsiMethodReferenceExpression getMethodReference() {
+ return (PsiMethodReferenceExpression)myMethodReferenceExpression.getElement();
+ }
+}
PsiReferenceExpression ref = call.getMethodExpression();
String name = ref.getReferenceName();
- if (name == null || !JavaPsiFacade.getInstance(ref.getProject()).getNameHelper().isIdentifier(name)) return false;
+ if (name == null || !PsiNameHelper.getInstance(ref.getProject()).isIdentifier(name)) return false;
if (hasErrorsInArgumentList(call)) return false;
setText(getDisplayString(name));
return true;
if (targetClass == null) return;
PsiMethodCallExpression expression = getMethodCall();
if (expression == null) return;
- final Project project = expression.getProject();
PsiReferenceExpression ref = expression.getMethodExpression();
if (isValidElement(expression)) return;
String methodName = ref.getReferenceName();
LOG.assertTrue(methodName != null);
- JVMElementFactory factory = JVMElementFactories.getFactory(targetClass.getLanguage(), project);
- if (factory == null) {
+ PsiMethod method = createMethod(targetClass, parentClass, enclosingContext, methodName);
+ if (method == null) {
return;
}
- PsiMethod method = factory.createMethod(methodName, PsiType.VOID);
-
- if (targetClass.equals(parentClass)) {
- method = (PsiMethod)targetClass.addAfter(method, enclosingContext);
- }
- else {
- PsiElement anchor = enclosingContext;
- while (anchor != null && anchor.getParent() != null && !anchor.getParent().equals(targetClass)) {
- anchor = anchor.getParent();
- }
- if (anchor != null && anchor.getParent() == null) anchor = null;
- if (anchor != null) {
- method = (PsiMethod)targetClass.addAfter(method, anchor);
- }
- else {
- method = (PsiMethod)targetClass.add(method);
- }
- }
-
if (enclosingContext instanceof PsiMethod && methodName.equals(enclosingContext.getName()) &&
PsiTreeUtil.isAncestor(targetClass, parentClass, true) && !ref.isQualified()) {
RefactoringChangeUtil.qualifyReference(ref, method, null);
context);
}
+ protected static PsiMethod createMethod(PsiClass targetClass,
+ PsiClass parentClass,
+ PsiMember enclosingContext,
+ String methodName) {
+ JVMElementFactory factory = JVMElementFactories.getFactory(targetClass.getLanguage(), targetClass.getProject());
+ if (factory == null) {
+ return null;
+ }
+
+ PsiMethod method = factory.createMethod(methodName, PsiType.VOID);
+
+ if (targetClass.equals(parentClass)) {
+ method = (PsiMethod)targetClass.addAfter(method, enclosingContext);
+ }
+ else {
+ PsiElement anchor = enclosingContext;
+ while (anchor != null && anchor.getParent() != null && !anchor.getParent().equals(targetClass)) {
+ anchor = anchor.getParent();
+ }
+ if (anchor != null && anchor.getParent() == null) anchor = null;
+ if (anchor != null) {
+ method = (PsiMethod)targetClass.addAfter(method, anchor);
+ }
+ else {
+ method = (PsiMethod)targetClass.add(method);
+ }
+ }
+ return method;
+ }
+
public static void doCreate(PsiClass targetClass, PsiMethod method, List<Pair<PsiExpression, PsiType>> arguments, PsiSubstitutor substitutor,
ExpectedTypeInfo[] expectedTypes, @Nullable PsiElement context) {
doCreate(targetClass, method, shouldBeAbstractImpl(targetClass), arguments, substitutor, expectedTypes, context);
TemplateBuilderImpl builder = new TemplateBuilderImpl(method);
CreateFromUsageUtils.setupMethodParameters(method, builder, context, substitutor, arguments);
- new GuessTypeParameters(JavaPsiFacade.getInstance(project).getElementFactory())
- .setupTypeElement(method.getReturnTypeElement(), expectedTypes, substitutor, builder, context, targetClass);
+ final PsiTypeElement returnTypeElement = method.getReturnTypeElement();
+ if (returnTypeElement != null) {
+ new GuessTypeParameters(JavaPsiFacade.getInstance(project).getElementFactory())
+ .setupTypeElement(returnTypeElement, expectedTypes, substitutor, builder, context, targetClass);
+ }
PsiCodeBlock body = method.getBody();
builder.setEndVariableAfter(shouldBeAbstract || body == null ? method : body.getLBrace());
method = CodeInsightUtilCore.forcePsiPostprocessAndRestoreElement(method);
return new CreateMethodFromUsageFix(call);
}
+ @NotNull
+ @Override
+ public IntentionAction createCreateMethodFromUsageFix(PsiMethodReferenceExpression methodReferenceExpression) {
+ return new CreateMethodFromMethodReferenceFix(methodReferenceExpression);
+ }
+
@NotNull
@Override
public IntentionAction createCreateAbstractMethodFromUsageFix(@NotNull PsiMethodCallExpression call) {
HashMap<String, String> map = new HashMap<String, String>(2);
map.put(getId(), getValue());
map.put("IJ_BASE_PACKAGE_DIR", getValue().replace('.', '/'));
+ map.put("IJ_BASE_PACKAGE_PREFIX", StringUtil.isEmpty(getValue()) ? "" : getValue() + ".");
return map;
}
@Override
public boolean validate() throws ConfigurationException {
- if (!PsiNameHelperImpl.getInstance().isQualifiedName(getValue())) {
- throw new ConfigurationException(getValue() + " is not a valid package name");
+ String value = getValue();
+ if (!StringUtil.isEmpty(value) && !PsiNameHelperImpl.getInstance().isQualifiedName(value)) {
+ throw new ConfigurationException(value + " is not a valid package name");
}
return true;
}
*/
package com.intellij.psi.impl.smartPointers;
+import com.intellij.lang.LanguageUtil;
import com.intellij.openapi.editor.RangeMarker;
import com.intellij.openapi.util.ProperTextRange;
import com.intellij.openapi.util.TextRange;
AnchorElementInfo(@NotNull PsiElement anchor, @NotNull PsiFile containingFile) {
super(containingFile.getProject(), ProperTextRange.create(anchor.getTextRange()), anchor.getClass(), containingFile,
- containingFile.getLanguage());
+ LanguageUtil.getRootLanguage(anchor));
assert !(anchor instanceof PsiFile) : "FileElementInfo must be used for file: "+anchor;
}
// will restore by stub index until file tree get loaded
/*
- * Copyright 2000-2013 JetBrains s.r.o.
+ * Copyright 2000-2014 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.
@Nullable
@Override
- public String getCharset(@NotNull VirtualFile file, byte[] content) {
+ public String getCharset(@NotNull VirtualFile file, @NotNull byte[] content) {
return CharsetToolkit.UTF8;
}
}
/*
- * Copyright 2000-2009 JetBrains s.r.o.
+ * Copyright 2000-2014 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.
}
@Override
- public String getCharset(@NotNull VirtualFile file, final byte[] content) {
+ public String getCharset(@NotNull VirtualFile file, @NotNull final byte[] content) {
return null;
}
}
}
//resolve input variables
- PsiSubstitutor substitutor = resolveSubset(varsToResolve, siteSubstitutor);
-
+ PsiSubstitutor substitutor = resolveSubset(varsToResolve, retrieveNonPrimitiveEqualsBounds(getInferenceVariables()).putAll(siteSubstitutor));
if (substitutor == null) {
return false;
}
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.psi.*;
-import com.intellij.psi.impl.PsiImplUtil;
import com.intellij.psi.impl.source.resolve.graphInference.FunctionalInterfaceParameterizationUtil;
import com.intellij.psi.impl.source.resolve.graphInference.InferenceSession;
import com.intellij.psi.impl.source.resolve.graphInference.PsiPolyExpressionUtil;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.containers.HashMap;
-import java.util.*;
+import java.util.List;
+import java.util.Map;
/**
* User: anna
final PsiSubstitutor substitutor = LambdaUtil.getSubstitutor(interfaceMethod, classResolveResult);
final PsiParameter[] targetParameters = interfaceMethod.getParameterList().getParameters();
final PsiType interfaceMethodReturnType = interfaceMethod.getReturnType();
- PsiType returnType = substitutor.substitute(interfaceMethodReturnType);
- if (myExpression.getTypeParameters().length == 0 && returnType != null) {
- returnType = PsiImplUtil.normalizeWildcardTypeByPosition(returnType, myExpression);
- }
+ final PsiType returnType = substitutor.substitute(interfaceMethodReturnType);
final PsiType[] typeParameters = myExpression.getTypeParameters();
if (!myExpression.isExact()) {
for (PsiParameter parameter : targetParameters) {
final PsiSubstitutor functionalInterfaceSubstitutor = interfaceMethod != null ? LambdaUtil.getSubstitutor(interfaceMethod, resolveResult) : null;
final MethodSignature signature = interfaceMethod != null ? interfaceMethod.getSignature(functionalInterfaceSubstitutor) : null;
final PsiType interfaceMethodReturnType = LambdaUtil.getFunctionalInterfaceReturnType(functionalInterfaceType);
- if (isConstructor && interfaceMethod != null && containingClass.getConstructors().length == 0) {
- final PsiClassType returnType = composeReturnType(containingClass, substitutor);
- final InferenceSession session = new InferenceSession(containingClass.getTypeParameters(), substitutor, getManager(), null);
- if (!(session.isProperType(returnType) && session.isProperType(interfaceMethodReturnType))) {
- session.registerConstraints(returnType, interfaceMethodReturnType);
- substitutor = session.infer();
+ if (isConstructor && containingClass.getConstructors().length == 0) {
+ if (interfaceMethod != null) {
+ final PsiClassType returnType = composeReturnType(containingClass, substitutor);
+ final InferenceSession session = new InferenceSession(containingClass.getTypeParameters(), substitutor, getManager(), null);
+ if (!(session.isProperType(returnType) && session.isProperType(interfaceMethodReturnType))) {
+ session.registerConstraints(returnType, interfaceMethodReturnType);
+ substitutor = session.infer();
+ }
}
ClassCandidateInfo candidateInfo = null;
final boolean isArray = containingClass == JavaPsiFacade.getElementFactory(getProject()).getArrayClass(PsiUtil.getLanguageLevel(containingClass));
- if (!isArray && (containingClass.getContainingClass() == null || !isLocatedInStaticContext(containingClass)) && signature.getParameterTypes().length == 0 ||
+ if (signature == null ||
+ !isArray && (containingClass.getContainingClass() == null || !isLocatedInStaticContext(containingClass)) && signature.getParameterTypes().length == 0 ||
isArray && arrayCreationSignature(signature)) {
candidateInfo = new ClassCandidateInfo(containingClass, substitutor);
}
interface I {
<error descr="Extension methods are not supported at this language level">default void m() { }</error>
+ <error descr="Extension methods are not supported at this language level">static void m() { }</error>
}
}
--- /dev/null
+class Temp {
+
+ interface Future<F> {}
+
+ class Message {
+ }
+
+ interface Client<C extends Client, M> {
+ <T> Future<T> request(M request);
+ }
+
+ interface MessageClient extends Client<MessageClient, Message> {
+ Future<Message> request(Message request);
+ }
+
+ abstract class AbstractClient implements MessageClient {
+ }
+
+ class ConcreteClient extends AbstractClient {
+ public Future<Message> request(Message request) {
+ return null;
+ }
+ }
+}
\ No newline at end of file
I<Integer> i1 = (i, j) -> i + j;
foo((i, j) -> i + j);
I<Integer> i2 = bar((i, j) -> i + j);
- I<Integer> i3 = bar(<error descr="Cyclic inference">(i, j) -> "" + i + j</error>);
+ I<Integer> i3 = bar(<error descr="Incompatible return type String in lambda expression">(i, j) -> "" + i + j</error>);
}
}
I<Integer> i1 = bar(x -> x);
I1<Integer> i2 = bar1(x -> 1);
I2<String> aI2 = bar2(x -> "");
- I2<Integer> aI28 = bar2( <error descr="Cyclic inference">x-> ""</error>);
+ I2<Integer> aI28 = bar2( <error descr="Incompatible return type String in lambda expression">x-> ""</error>);
I2<Integer> i3 = bar2(x -> x);
I2<Integer> i4 = bar2(x -> foooI());
System.out.println(i4.foo(2));
}
static {
- <error descr="Incompatible types. Found: '<method reference>', required: 'AlienTest.IInt'">IInt i1 = MyTest::abracadabra;</error>
- <error descr="Incompatible types. Found: '<method reference>', required: 'AlienTest.IInt'">IInt i2 = MyTest::foo;</error>
- <error descr="Incompatible types. Found: '<method reference>', required: 'AlienTest.IInt'">IInt i3 = MyTest::bar;</error>
+ IInt i1 = MyTest::<error descr="Cannot resolve method 'abracadabra'">abracadabra</error>;
+ IInt i2 = MyTest::<error descr="Cannot resolve method 'foo'">foo</error>;
+ IInt i3 = MyTest::<error descr="Cannot resolve method 'bar'">bar</error>;
<error descr="Incompatible types. Found: '<method reference>', required: 'AlienTest.IIntInt'">IIntInt i4 = MyTest::bar;</error>
IInt i5 = <error descr="Non-static method cannot be referenced from a static context">MyTest::baz</error>;
IInt i6 = <error descr="'foo(int)' is not public in 'MyTest.Foo'. Cannot be accessed from outside package">MyTest.foo::foo</error>;
}
{
- <error descr="Incompatible types. Found: '<method reference>', required: 'todelete.MyTest1.Bar1'">Bar1 b1 = MyTest2 :: foo;</error>
+ Bar1 b1 = MyTest2 :: <error descr="Cannot resolve method 'foo'">foo</error>;
bar(MyTest1 :: foo);
}
}
}*/
{
- <error descr="Incompatible types. Found: '<method reference>', required: 'todelete.MyTest2.Bar1'">Bar1 b1 = MyTest2 :: foo;</error>
+ Bar1 b1 = MyTest2 :: <error descr="Cannot resolve method 'foo'">foo</error>;
bar(MyTest2 :: foo);
}
}
}
{
- <error descr="Incompatible types. Found: '<method reference>', required: 'todelete.MyTest3.Bar1'">Bar1 b1 = MyTest2 :: foo;</error>
- bar<error descr="'bar(todelete.MyTest3.Bar2)' in 'todelete.MyTest3' cannot be applied to '(<method reference>)'">(MyTest3 :: foo)</error>;
+ Bar1 b1 = MyTest2 :: <error descr="Cannot resolve method 'foo'">foo</error>;
+ bar(MyTest3 :: <error descr="Cannot resolve method 'foo'">foo</error>);
}
}
}
{
- bar<error descr="'bar(todelete.MyTest4.Bar1)' in 'todelete.MyTest4' cannot be applied to '(<method reference>)'">(MyTest4:: foo)</error>;
+ bar(MyTest4:: <error descr="Cannot resolve method 'foo'">foo</error>);
}
}
class Test {
{
- <error descr="Incompatible types. Found: '<method reference>', required: 'java.lang.Runnable'">Runnable b = Test :: length;</error>
+ Runnable b = Test :: <error descr="Cannot resolve method 'length'">length</error>;
Comparable<String> c = Test :: length;
- <error descr="Incompatible types. Found: '<method reference>', required: 'java.lang.Comparable<java.lang.Integer>'">Comparable<Integer> c1 = Test :: length;</error>
+ Comparable<Integer> c1 = Test :: <error descr="Cannot resolve method 'length'">length</error>;
}
public static Integer length(String s) {
class Test1 {
{
- <error descr="Incompatible types. Found: '<method reference>', required: 'java.lang.Runnable'">Runnable b = Test1 :: length;</error>
+ Runnable b = Test1 :: <error descr="Cannot resolve method 'length'">length</error>;
Comparable<String> c = Test1 :: length;
Comparable<Integer> c1 = Test1 :: length;
}
}
void test() {
- <error descr="Incompatible types. Found: '<method reference>', required: 'MyTest.Child.I'">I var = Child.Inner::new;</error>
+ I var = Child.Inner::<error descr="Cannot resolve constructor 'Inner'">new</error>;
}
}
}
static void test(I<Integer> s) { }
public static void main(String[] args) {
- <error descr="Incompatible types. Found: '<method reference>', required: 'MyTest3.I<java.lang.Integer>'">I<Integer> s = MyTest3<String>::new;</error>
- test<error descr="'test(MyTest3.I<java.lang.Integer>)' in 'MyTest3' cannot be applied to '(<method reference>)'">(MyTest3<String>::new)</error>;
+ I<Integer> s = MyTest3<String>::<error descr="Cannot resolve constructor 'MyTest3'">new</error>;
+ test(MyTest3<String>::<error descr="Cannot resolve constructor 'MyTest3'">new</error>);
}
}
interface I {
A foo();
}
- <error descr="Incompatible types. Found: '<method reference>', required: 'MyTestInvalidQ.A.I'">I i = A :: new;</error>
+ I i = <error descr="'A' is abstract; cannot be instantiated">A :: new</error>;
}
}
\ No newline at end of file
static {
- <error descr="Incompatible types. Found: '<method reference>', required: 'StaticInner2.I1'">I1 i1 = StaticInner2.Inner :: new;</error>
+ I1 i1 = StaticInner2.Inner :: <error descr="Cannot resolve constructor 'Inner'">new</error>;
}
{
- <error descr="Incompatible types. Found: '<method reference>', required: 'StaticInner2.I1'">I1 i1 = StaticInner2.Inner :: new;</error>
+ I1 i1 = StaticInner2.Inner :: <error descr="Cannot resolve constructor 'Inner'">new</error>;
}
}
static {
- <error descr="Incompatible types. Found: '<method reference>', required: 'NonStaticInner2.I1'">I1 i1 = NonStaticInner2.Inner :: new;</error>
+ I1 i1 = NonStaticInner2.Inner :: <error descr="Cannot resolve constructor 'Inner'">new</error>;
}
{
- <error descr="Incompatible types. Found: '<method reference>', required: 'NonStaticInner2.I1'">I1 i1 = NonStaticInner2.Inner :: new;</error>
+ I1 i1 = NonStaticInner2.Inner :: <error descr="Cannot resolve constructor 'Inner'">new</error>;
}
}
}
{
- <error descr="Incompatible types. Found: '<method reference>', required: 'NonStaticInner3.I3<NonStaticInner3.Foo>'">I3<Foo> b1 = Foo::new;</error>
- <error descr="Incompatible types. Found: '<method reference>', required: 'NonStaticInner3.I4<NonStaticInner3.Foo>'">I4<Foo> b2 = Foo::new;</error>
+ I3<Foo> b1 = Foo::<error descr="Cannot resolve constructor 'Foo'">new</error>;
+ I4<Foo> b2 = Foo::<error descr="Cannot resolve constructor 'Foo'">new</error>;
}
}
}
static void test1() {
- <error descr="Incompatible types. Found: '<method reference>', required: 'DefaultConstructor.I2<DefaultConstructor.Outer.Inner,DefaultConstructor.Outer>'">I2<Inner, Outer> i2 = Inner :: new;</error>
- <error descr="Incompatible types. Found: '<method reference>', required: 'DefaultConstructor.I2<DefaultConstructor.Outer.Inner,java.lang.String>'">I2<Inner, String> i2str = Inner :: new;</error>
+ I2<Inner, Outer> i2 = Inner :: <error descr="Cannot resolve constructor 'Inner'">new</error>;
+ I2<Inner, String> i2str = Inner :: <error descr="Cannot resolve constructor 'Inner'">new</error>;
}
void test2() {
I1<Inner> i1 = Inner :: new;
<error descr="Incompatible types. Found: '<method reference>', required: 'DefaultConstructor.I1<java.lang.Integer>'">I1<Integer> i1Int = Inner :: new;</error>
- <error descr="Incompatible types. Found: '<method reference>', required: 'DefaultConstructor.I2<DefaultConstructor.Outer.Inner,DefaultConstructor.Outer>'">I2<Inner, Outer> i2 = Inner :: new;</error>
+ I2<Inner, Outer> i2 = Inner :: <error descr="Cannot resolve constructor 'Inner'">new</error>;
}
}
static void test1() {
- <error descr="Incompatible types. Found: '<method reference>', required: 'DefaultConstructor.I2<DefaultConstructor.Outer.Inner,DefaultConstructor.Outer>'">I2<Outer.Inner, Outer> i2 = Outer.Inner::new;</error>
- <error descr="Incompatible types. Found: '<method reference>', required: 'DefaultConstructor.I2<DefaultConstructor.Outer.Inner,java.lang.String>'">I2<Outer.Inner, String> i2str = Outer.Inner::new;</error>
+ I2<Outer.Inner, Outer> i2 = Outer.Inner::<error descr="Cannot resolve constructor 'Inner'">new</error>;
+ I2<Outer.Inner, String> i2str = Outer.Inner::<error descr="Cannot resolve constructor 'Inner'">new</error>;
}
void test2() {
- <error descr="Incompatible types. Found: '<method reference>', required: 'DefaultConstructor.I2<DefaultConstructor.Outer.Inner,DefaultConstructor.Outer>'">I2<Outer.Inner, Outer> i2 = Outer.Inner::new;</error>
- <error descr="Incompatible types. Found: '<method reference>', required: 'DefaultConstructor.I2<DefaultConstructor.Outer.Inner,java.lang.String>'">I2<Outer.Inner, String> i2str = Outer.Inner::new;</error>
+ I2<Outer.Inner, Outer> i2 = Outer.Inner::<error descr="Cannot resolve constructor 'Inner'">new</error>;
+ I2<Outer.Inner, String> i2str = Outer.Inner::<error descr="Cannot resolve constructor 'Inner'">new</error>;
}
}
void f() {
- <error descr="Incompatible types. Found: '<method reference>', required: 'DefaultConstructor2.I'">I i1 = DefaultConstructor2 :: new;</error>
+ I i1 = DefaultConstructor2 :: <error descr="Cannot resolve constructor 'DefaultConstructor2'">new</error>;
I i2 = <error descr="Cannot find class this">this</error>::new;
}
}
public class Inner {}
public static class StaticInner {}
- static <error descr="Incompatible types. Found: '<method reference>', required: 'DefaultConstructor3.I'">I i = Inner::new;</error>
+ static I i = Inner::<error descr="Cannot resolve constructor 'Inner'">new</error>;
static I1 i1 = StaticInner::new;
interface I {
Inner foo();
public class Inner {}
public static class StaticInner {}
- static <error descr="Incompatible types. Found: '<method reference>', required: 'DefaultConstructor4.I'">I i = Inner::new;</error>
- static <error descr="Incompatible types. Found: '<method reference>', required: 'DefaultConstructor4.I1'">I1 i1 = StaticInner::new;</error>
+ static I i = Inner::<error descr="Cannot resolve constructor 'Inner'">new</error>;
+ static I1 i1 = StaticInner::<error descr="Cannot resolve constructor 'StaticInner'">new</error>;
interface I {
Inner foo(DefaultConstructor4 receiver);
}
public class Inner {}
static void test() {
- <error descr="Incompatible types. Found: '<method reference>', required: 'DefaultConstructor5.I'">I i = Inner::new;</error>
+ I i = Inner::<error descr="Cannot resolve constructor 'Inner'">new</error>;
}
void test1() {
}
{
A a = new A();
- <error descr="Incompatible types. Found: '<method reference>', required: 'ThreadExample.Function<? super ThreadExample.A,? extends java.lang.String>'">Function<? super A,? extends String> foo = a::foo;</error>
+ Function<? super A,? extends String> foo = a::<error descr="Cannot resolve method 'foo'">foo</error>;
}
static class A {
void foo(IFactory cf) { }
void testAssign() {
- <error descr="Incompatible types. Found: '<method reference>', required: 'Test.IFactory'">IFactory c1 = Anno::new;</error>
- <error descr="Incompatible types. Found: '<method reference>', required: 'Test.IFactory'">IFactory c2 = E::new;</error>
- <error descr="Incompatible types. Found: '<method reference>', required: 'Test.IFactory'">IFactory c3 = I::new;</error>
+ IFactory c1 = <error descr="'Anno' is abstract; cannot be instantiated">Anno::new</error>;
+ IFactory c2 = <error descr="Enum types cannot be instantiated">E::new</error>;
+ IFactory c3 = <error descr="'I' is abstract; cannot be instantiated">I::new</error>;
IFactory c4 = <error descr="Unexpected wildcard">Foo<?></error>::new;
IFactory c5 = <error descr="Cannot find class 1">1</error>::new;
- <error descr="Incompatible types. Found: '<method reference>', required: 'Test.IFactory'">IFactory c6 = ABar::new;</error>
- <error descr="Incompatible types. Found: '<method reference>', required: 'Test.IFactory'">IFactory c7 = ABaz::new;</error>
+ IFactory c6 = <error descr="'ABar' is abstract; cannot be instantiated">ABar::new</error>;
+ IFactory c7 = <error descr="'ABaz' is abstract; cannot be instantiated">ABaz::new</error>;
- foo<error descr="'foo(Test.IFactory)' in 'Test' cannot be applied to '(<method reference>)'">(Anno::new)</error>;
- foo<error descr="'foo(Test.IFactory)' in 'Test' cannot be applied to '(<method reference>)'">(E::new)</error>;
- foo<error descr="'foo(Test.IFactory)' in 'Test' cannot be applied to '(<method reference>)'">(I::new)</error>;
+ foo(<error descr="'Anno' is abstract; cannot be instantiated">Anno::new</error>);
+ foo(<error descr="Enum types cannot be instantiated">E::new</error>);
+ foo(<error descr="'I' is abstract; cannot be instantiated">I::new</error>);
foo(<error descr="Unexpected wildcard">Foo<?></error>::new);
foo(<error descr="Cannot find class 1">1</error>::new);
- foo<error descr="'foo(Test.IFactory)' in 'Test' cannot be applied to '(<method reference>)'">(ABar::new)</error>;
- foo<error descr="'foo(Test.IFactory)' in 'Test' cannot be applied to '(<method reference>)'">(ABaz::new)</error>;
+ foo(<error descr="'ABar' is abstract; cannot be instantiated">ABar::new</error>);
+ foo(<error descr="'ABaz' is abstract; cannot be instantiated">ABaz::new</error>);
}
}
\ No newline at end of file
enum E { }
void test() {
- <error descr="Incompatible types. Found: '<method reference>', required: 'MyTest7.I'">I s1 = A::new;</error>
- <error descr="Incompatible types. Found: '<method reference>', required: 'MyTest7.I'">I s2 = I::new;</error>
- <error descr="Incompatible types. Found: '<method reference>', required: 'MyTest7.I'">I s3 = AC::new;</error>
- <error descr="Incompatible types. Found: '<method reference>', required: 'MyTest7.I'">I s4 = E::new;</error>
+ I s1 = <error descr="'A' is abstract; cannot be instantiated">A::new</error>;
+ I s2 = <error descr="'I' is abstract; cannot be instantiated">I::new</error>;
+ I s3 = <error descr="'AC' is abstract; cannot be instantiated">AC::new</error>;
+ I s4 = <error descr="Enum types cannot be instantiated">E::new</error>;
}
}
}
void test() {
- <error descr="Incompatible types. Found: '<method reference>', required: 'MyTest8.Sub.I'">I var = Sub.Inner::new;</error>;
+ I var = Sub.Inner::<error descr="Cannot resolve constructor 'Inner'">new</error>;;
}
}
}
{
I i = Foo<String> :: foo;
- <error descr="Incompatible types. Found: '<method reference>', required: 'MyTest.I'">I i1 = Foo<Integer> :: foo;</error>
+ I i1 = Foo<Integer> :: <error descr="Cannot resolve method 'foo'">foo</error>;
}
}
}
Cln s = int[]::clone;
IA a = int[]::new;
<error descr="Incompatible types. Found: '<method reference>', required: 'OnArrayTest.I'">I i = int[]::new;</error>
- <error descr="Incompatible types. Found: '<method reference>', required: 'OnArrayTest.Len<java.lang.String>'">Len<String> strLen = String[]::length;</error>
+ Len<String> strLen = String[]::<error descr="Cannot resolve method 'length'">length</error>;
ToStr<Integer> toStr = Integer[]::toString;
ArrayReturnType<String[]> a1 = String[]::new;
static {
I1 i1 = MyTest::static_1;
- <error descr="Incompatible types. Found: '<method reference>', required: 'MyTest.I1'">I1 i2 = MyTest::static_2;</error>
- <error descr="Incompatible types. Found: '<method reference>', required: 'MyTest.I1'">I1 i3 = MyTest::static_3;</error>
- <error descr="Incompatible types. Found: '<method reference>', required: 'MyTest.I1'">I1 i4 = MyTest::static_4;</error>
+ I1 i2 = MyTest::<error descr="Cannot resolve method 'static_2'">static_2</error>;
+ I1 i3 = MyTest::<error descr="Cannot resolve method 'static_3'">static_3</error>;
+ I1 i4 = MyTest::<error descr="Cannot resolve method 'static_4'">static_4</error>;
}
{
I1 i_1 = <error descr="Non-static method cannot be referenced from a static context">MyTest::_1</error>;
- <error descr="Incompatible types. Found: '<method reference>', required: 'MyTest.I1'">I1 i_2 = MyTest::_2;</error>
- <error descr="Incompatible types. Found: '<method reference>', required: 'MyTest.I1'">I1 i_3 = MyTest::_3;</error>
- <error descr="Incompatible types. Found: '<method reference>', required: 'MyTest.I1'">I1 i_4 = MyTest::_4;</error>
+ I1 i_2 = MyTest::<error descr="Cannot resolve method '_2'">_2</error>;
+ I1 i_3 = MyTest::<error descr="Cannot resolve method '_3'">_3</error>;
+ I1 i_4 = MyTest::<error descr="Cannot resolve method '_4'">_4</error>;
I1 i1 = this::_1;
- <error descr="Incompatible types. Found: '<method reference>', required: 'MyTest.I1'">I1 i2 = this::_2;</error>
- <error descr="Incompatible types. Found: '<method reference>', required: 'MyTest.I1'">I1 i3 = this::_3;</error>
- <error descr="Incompatible types. Found: '<method reference>', required: 'MyTest.I1'">I1 i4 = this::_4;</error>
-
- <error descr="Incompatible types. Found: '<method reference>', required: 'MyTest.I2'">I2 i21 = MyTest::m1;</error>
- <error descr="Incompatible types. Found: '<method reference>', required: 'MyTest.I2'">I2 i22 = MyTest::m2;</error>
- <error descr="Incompatible types. Found: '<method reference>', required: 'MyTest.I2'">I2 i23 = MyTest::m3;</error>
- <error descr="Incompatible types. Found: '<method reference>', required: 'MyTest.I2'">I2 i24 = MyTest::m4;</error>
+ I1 i2 = this::<error descr="Cannot resolve method '_2'">_2</error>;
+ I1 i3 = this::<error descr="Cannot resolve method '_3'">_3</error>;
+ I1 i4 = this::<error descr="Cannot resolve method '_4'">_4</error>;
+
+ I2 i21 = MyTest::<error descr="Cannot resolve method 'm1'">m1</error>;
+ I2 i22 = MyTest::<error descr="Cannot resolve method 'm2'">m2</error>;
+ I2 i23 = MyTest::<error descr="Cannot resolve method 'm3'">m3</error>;
+ I2 i24 = MyTest::<error descr="Cannot resolve method 'm4'">m4</error>;
}
}
void test() {
Comparator<Test> r2 = Test::yyy;
Comparator1<Test> c1 = <error descr="Non-static method cannot be referenced from a static context">Test::yyy</error>;
- <error descr="Incompatible types. Found: '<method reference>', required: 'Comparator1<Test>'">Comparator1<Test> c2 = Test::xxx;</error>
+ Comparator1<Test> c2 = Test::<error descr="Cannot resolve method 'xxx'">xxx</error>;
}
int yyy(Test... p) { return 1; }
int xxx(Test t) {return 42;}
<T> void bar(I i) {}
void test() {
- bar<error descr="'bar(Test.I)' in 'Test' cannot be applied to '(<method reference>)'">(Foo::foo)</error>;
+ bar(Foo::<error descr="Cannot resolve method 'foo'">foo</error>);
}
}
\ No newline at end of file
--- /dev/null
+import java.util.List;
+import java.util.function.Function;
+
+class FluTr<K> {
+
+ class Group {
+ List<Authority> getAuthorities() {
+ return null;
+ }
+ }
+
+ class Authority {
+ String getPermission() {
+ return null;
+ }
+ }
+
+ public void filterForPermission(final String permission) {
+ transformAndConcat(Group::getAuthorities)
+ .transform(Authority::getPermission)
+ .contains(permission);
+ }
+
+ boolean contains(String f) {
+ return false;
+ }
+
+ public final <T> FluTr<T> transform(Function<? super K,T> function) { return null; }
+ public <T> FluTr<T> transformAndConcat(Function<? super Group,? extends Iterable<? extends T>> function) { return null; }
+
+}
--- /dev/null
+import java.util.HashMap;
+import java.util.Map;
+import java.util.stream.Stream;
+
+class App {
+
+ void foo(Stream<Integer> boxed) {
+ final Map<Integer, Integer> count = boxed.collect(HashMap::new, null, HashMap::putAll);
+ }
+
+}
--- /dev/null
+// "Create Constructor" "true"
+class FooBar {
+ FooBar(int i) {
+ }
+
+ {
+ Runnable r = FooBar::new;
+ }
+
+ public FooBar() {
+
+ }
+}
--- /dev/null
+// "Create Method 'fooBar'" "true"
+class FooBar {
+ {
+ Runnable r = FooBar::fooBar;
+ }
+
+ private static void fooBar() {
+
+ }
+}
--- /dev/null
+// "Create Method 'fooBar'" "true"
+class FooBar {
+ {
+ Runnable r = this::fooBar;
+ }
+
+ private void fooBar() {
+
+ }
+}
--- /dev/null
+// "Create Constructor" "true"
+class FooBar {
+ FooBar(int i) {
+ }
+
+ {
+ Runnable r = FooBar::ne<caret>w;
+ }
+}
--- /dev/null
+// "Create Method 'fooBar'" "true"
+class FooBar {
+ {
+ Runnable r = FooBar::foo<caret>Bar;
+ }
+}
--- /dev/null
+// "Create Method 'fooBar'" "true"
+class FooBar {
+ {
+ Runnable r = this::foo<caret>Bar;
+ }
+}
--- /dev/null
+// "Replace with forEach" "true"
+import java.util.ArrayList;
+import java.util.List;
+
+class Sample {
+ List<String> foo = new ArrayList<>();
+ String foo(){
+ foo.stream().filter(s -> s == null).forEach(s -> {
+ int i = 0;
+ });
+ return null;
+ }
+}
--- /dev/null
+// "Replace with forEach" "true"
+import java.util.ArrayList;
+import java.util.List;
+
+class Sample {
+ List<String> foo = new ArrayList<>();
+ String foo(){
+ for (String s : fo<caret>o) {
+ if (s == null) int i = 0;
+ }
+ return null;
+ }
+}
class Foo {
void test() {
- SAM<X> c = (i, j) -> "" + i + j;
+ SAM<Integer> c = (i, j) -> "" + i + j;
SAM<Integer> s3 = m(c);
}
<X> SAM<X> m(SAM<X> s) { return null; }
public void testIDEA120153() { doTest(LanguageLevel.JDK_1_7, JavaSdkVersion.JDK_1_7, false); }
public void testIDEA120563() { doTest(LanguageLevel.JDK_1_7, JavaSdkVersion.JDK_1_7, false); }
public void testIDEA121400() { doTest(LanguageLevel.JDK_1_7, JavaSdkVersion.JDK_1_7, false); }
+ public void testIDEA123316() { 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()));
doTest();
}
+ public void testIDEA123223() throws Exception {
+ doTest();
+ }
+
+ public void testIDEA123248() throws Exception {
+ doTest();
+ }
+
private void doTest() {
doTest(false);
}
--- /dev/null
+/*
+ * Copyright 2000-2014 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.codeInsight.daemon.quickFix;
+
+public class CreateMethodFromMethodReferenceFixTest extends LightQuickFixParameterizedTestCase {
+ public void test() throws Exception { doAllTests(); }
+
+ @Override
+ protected String getBasePath() {
+ return "/codeInsight/daemonCodeAnalyzer/quickFix/createMethodFromMethodRef";
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright 2000-2014 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.ide.fileTemplates;
+
+import com.intellij.ide.fileTemplates.impl.CustomFileTemplate;
+import com.intellij.testFramework.IdeaTestCase;
+import com.intellij.testFramework.LightPlatformTestCase;
+
+import java.util.Properties;
+
+/**
+ * @author Dmitry Avdeev
+ */
+public class SimpleTemplatesTest extends LightPlatformTestCase {
+
+ @SuppressWarnings("JUnitTestCaseWithNonTrivialConstructors")
+ public SimpleTemplatesTest() {
+ IdeaTestCase.initPlatformPrefix();
+ }
+
+ public void testConditional() throws Exception {
+ CustomFileTemplate template = new CustomFileTemplate("foo", "bar");
+ template.setText("#set($flag = \"$!IJ_BASE_PACKAGE\" != \"\")\n" +
+ "<option name=\"MAIN_CLASS_NAME\" value=\"$IJ_BASE_PACKAGE#if($flag).#{end}Main\" />"
+ );
+ Properties attributes = new Properties();
+ attributes.setProperty("IJ_BASE_PACKAGE", "");
+ assertEquals("<option name=\"MAIN_CLASS_NAME\" value=\"Main\" />", template.getText(attributes));
+ attributes.setProperty("IJ_BASE_PACKAGE", "foo.bar");
+ assertEquals("<option name=\"MAIN_CLASS_NAME\" value=\"foo.bar.Main\" />", template.getText(attributes));
+ }
+
+ public void testInline() throws Exception {
+ CustomFileTemplate template = new CustomFileTemplate("foo", "bar");
+ template.setText("$IJ_BASE_PACKAGE.replace(\".\", \"/\")");
+ Properties attributes = new Properties();
+ attributes.setProperty("IJ_BASE_PACKAGE", "foo.bar");
+ assertEquals("foo/bar", template.getText(attributes));
+ }
+}
private static class Indexer implements DataIndexer<String, String, PathContentPair> {
@Override
@NotNull
- public Map<String,String> map(final PathContentPair inputData) {
+ public Map<String,String> map(@NotNull final PathContentPair inputData) {
final Map<String,String> _map = new HashMap<String, String>();
final StringBuilder builder = new StringBuilder();
final String content = inputData.content;
}
public void testLambdaExprNotAccepted() {
- doTest(new MockIntroduceVariableHandler("c", false, false, false, "SAM<X>"));
+ doTest(new MockIntroduceVariableHandler("c", false, false, false, "SAM<java.lang.Integer>"));
}
public void testOneLineLambdaVoidCompatible() {
context.checkCanceled();
boolean okToDelete = true;
final File outputRoot = entry.getKey();
- if (JpsPathUtil.isUnder(allSourceRoots, outputRoot)) {
- okToDelete = false;
- }
- else {
- final Set<File> _outRoot = Collections.singleton(outputRoot);
- for (File srcRoot : allSourceRoots) {
- if (JpsPathUtil.isUnder(_outRoot, srcRoot)) {
- okToDelete = false;
- break;
+ if (!moduleIndex.isExcluded(outputRoot)) {
+ // if output root itself is directly or indirectly excluded,
+ // there cannot be any manageable sources under it, even if the output root is located under some source root
+ // so in this case it is safe to delete such root
+ if (JpsPathUtil.isUnder(allSourceRoots, outputRoot)) {
+ okToDelete = false;
+ }
+ else {
+ final Set<File> _outRoot = Collections.singleton(outputRoot);
+ for (File srcRoot : allSourceRoots) {
+ if (JpsPathUtil.isUnder(_outRoot, srcRoot)) {
+ okToDelete = false;
+ break;
+ }
}
}
}
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
- <component name="NewModuleRootManager" inherit-compiler-output="true">
+ <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_6" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$/testSrc">
<sourceFolder url="file://$MODULE_DIR$/testSrc" isTestSource="true" />
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
- <component name="NewModuleRootManager" inherit-compiler-output="true">
+ <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_6" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
/*
- * Copyright 2000-2013 JetBrains s.r.o.
+ * Copyright 2000-2014 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.
}
@Override
- public String getCharset(@NotNull VirtualFile file, final byte[] content) {
+ public String getCharset(@NotNull VirtualFile file, @NotNull final byte[] content) {
return null;
}
}
import com.intellij.lexer.Lexer;
import com.intellij.openapi.util.Condition;
+import com.intellij.psi.FileViewProvider;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.templateLanguages.TemplateLanguage;
import java.util.Comparator;
import java.util.List;
+import java.util.Set;
public final class LanguageUtil {
private LanguageUtil() {
}
return true;
}
+
+ @NotNull
+ public static Language getRootLanguage(@NotNull PsiElement element) {
+ final FileViewProvider provider = element.getContainingFile().getViewProvider();
+ final Set<Language> languages = provider.getLanguages();
+ if (languages.size() > 1) {
+ PsiElement current = element;
+ while (current != null) {
+ final Language language = current.getLanguage();
+ if (languages.contains(language)) return language;
+ current = current.getParent();
+ }
+ }
+ return provider.getBaseLanguage();
+ }
}
/*
- * Copyright 2000-2009 JetBrains s.r.o.
+ * Copyright 2000-2014 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.
* Returns the name of the file type. The name must be unique among all file types registered in the system.
* @return The file type name.
*/
-
@Override
@NotNull
@NonNls
/**
* Returns the character set for the specified file.
* @param file The file for which the character set is requested.
- * @param content
* @return The character set name, in the format supported by {@link java.nio.charset.Charset} class.
*/
@Nullable
@NonNls
- String getCharset(@NotNull VirtualFile file, final byte[] content);
+ String getCharset(@NotNull VirtualFile file, @NotNull byte[] content);
}
/*
- * Copyright 2000-2010 JetBrains s.r.o.
+ * Copyright 2000-2014 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.
}
@Override
- public String getCharset(@NotNull VirtualFile file, final byte[] content) {
+ public String getCharset(@NotNull VirtualFile file, @NotNull final byte[] content) {
return null;
}
/*
- * Copyright 2000-2009 JetBrains s.r.o.
+ * Copyright 2000-2014 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.
}
@Override
- public String getCharset(@NotNull VirtualFile file, final byte[] content) {
+ public String getCharset(@NotNull VirtualFile file, @NotNull final byte[] content) {
return null;
}
}
/*
- * Copyright 2000-2011 JetBrains s.r.o.
+ * Copyright 2000-2014 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.
public class PersistentFSConstants {
public static final long FILE_LENGTH_TO_CACHE_THRESHOLD = FileUtilRt.LARGE_FOR_CONTENT_LOADING;
/**
- * always in range [0, PersistentFS.FILE_LENGTH_TO_CACHE_THRESHOLD]
+ * always in range [0, {@link #FILE_LENGTH_TO_CACHE_THRESHOLD}]
*/
private static int ourMaxIntellisenseFileSize = Math.min(FileUtilRt.getUserFileSizeLimit(), (int)FILE_LENGTH_TO_CACHE_THRESHOLD);
final String pathProperty = System.getProperty(PROPERTY_PLUGIN_PATH);
if (pathProperty == null) return;
- for (StringTokenizer t = new StringTokenizer(pathProperty, File.pathSeparator); t.hasMoreTokens();) {
+ for (StringTokenizer t = new StringTokenizer(pathProperty, File.pathSeparator + ","); t.hasMoreTokens();) {
String s = t.nextToken();
final IdeaPluginDescriptorImpl ideaPluginDescriptor = loadDescriptor(new File(s), PLUGIN_XML);
if (ideaPluginDescriptor != null) {
package com.intellij.psi.impl.smartPointers;
import com.intellij.lang.Language;
+import com.intellij.lang.LanguageUtil;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.RangeMarker;
protected SelfElementInfo(@NotNull Project project, @NotNull PsiElement anchor) {
this(project, ProperTextRange.create(anchor.getTextRange()), anchor.getClass(), anchor.getContainingFile(),
- anchor.getContainingFile().getLanguage());
+ LanguageUtil.getRootLanguage(anchor));
}
public SelfElementInfo(@NotNull Project project,
@NotNull ProperTextRange range,
package com.intellij.psi.impl.smartPointers;
+import com.intellij.lang.LanguageUtil;
import com.intellij.lang.injection.InjectedLanguageManager;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.editor.Document;
}
ProperTextRange proper = ProperTextRange.create(elementRange);
- return new SelfElementInfo(project, proper, element.getClass(), containingFile, containingFile.getLanguage());
+ return new SelfElementInfo(project, proper, element.getClass(), containingFile, LanguageUtil.getRootLanguage(element));
}
@Override
import com.intellij.openapi.vfs.VirtualFileWithId;
import com.intellij.psi.*;
import com.intellij.psi.impl.*;
-import com.intellij.psi.impl.cache.CacheUtil;
import com.intellij.psi.impl.file.PsiFileImplUtil;
import com.intellij.psi.impl.source.codeStyle.CodeEditUtil;
import com.intellij.psi.impl.source.resolve.FileContextUtil;
import com.intellij.util.PatchedWeakReference;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.text.CharArrayUtil;
-import com.intellij.util.ui.UIUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
}
private void scheduleDropCachesWithInvalidStubPsi() {
- UIUtil.invokeLaterIfNeeded(new Runnable() {
+ // invokeLater even if already on EDT, because
+ // we might be inside an index query and write actions might result in deadlocks there (http://youtrack.jetbrains.com/issue/IDEA-123118)
+ ApplicationManager.getApplication().invokeLater(new Runnable() {
@Override
public void run() {
ApplicationManager.getApplication().runWriteAction(new Runnable() {
/*
- * Copyright 2000-2012 JetBrains s.r.o.
+ * Copyright 2000-2014 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.
return psi;
}
- public PsiFile createFileFromText(CharSequence text) {
+ public PsiFile createFileFromText(@NotNull CharSequence text) {
Project project = getProject();
if (project == null) {
project = DefaultProjectFactory.getInstance().getDefaultProject();
this(file, null, null, null, -1);
}
- private FileContentImpl(@NotNull VirtualFile file, CharSequence contentAsText, byte[] content, Charset charset, long stamp) {
+ private FileContentImpl(@NotNull VirtualFile file,
+ CharSequence contentAsText,
+ byte[] content,
+ Charset charset,
+ long stamp) {
myFile = file;
myContentAsText = contentAsText;
myContent = content;
/*
- * Copyright 2000-2010 JetBrains s.r.o.
+ * Copyright 2000-2014 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.
}
@Override
- public String getCharset(@NotNull VirtualFile file, byte[] content) {
+ public String getCharset(@NotNull VirtualFile file, @NotNull byte[] content) {
return myFileType.getCharset(file, content);
}
@NotNull
@Override
- public Map<TodoIndexEntry, Integer> map(FileContent inputData) {
+ public Map<TodoIndexEntry, Integer> map(@NotNull FileContent inputData) {
Map<TodoIndexEntry, Integer> result = ContainerUtil.newTroveMap();
for (DataIndexer<TodoIndexEntry, Integer, FileContent> indexer : indexers) {
for (Map.Entry<TodoIndexEntry, Integer> entry : indexer.map(inputData).entrySet()) {
@Override
@NotNull
- public Map<TodoIndexEntry, Integer> map(final FileContent inputData) {
+ public Map<TodoIndexEntry, Integer> map(@NotNull final FileContent inputData) {
if (IndexPatternUtil.getIndexPatternCount() > 0) {
final CharSequence chars = inputData.getContentAsText();
final OccurrenceConsumer occurrenceConsumer = new OccurrenceConsumer(null, true);
public static class PlainTextTodoIndexer implements DataIndexer<TodoIndexEntry, Integer, FileContent> {
@Override
@NotNull
- public Map<TodoIndexEntry, Integer> map(final FileContent inputData) {
+ public Map<TodoIndexEntry, Integer> map(@NotNull final FileContent inputData) {
String chars = inputData.getContentAsText().toString(); // matching strings is faster than HeapCharBuffer
final IndexPattern[] indexPatterns = IndexPatternUtil.getIndexPatterns();
private final DataIndexer<TodoIndexEntry, Integer, FileContent> myIndexer = new DataIndexer<TodoIndexEntry, Integer, FileContent>() {
@Override
@NotNull
- public Map<TodoIndexEntry,Integer> map(final FileContent inputData) {
+ public Map<TodoIndexEntry,Integer> map(@NotNull final FileContent inputData) {
final VirtualFile file = inputData.getFile();
final DataIndexer<TodoIndexEntry, Integer, FileContent> indexer = PlatformIdTableBuilding
.getTodoIndexer(inputData.getFileType(), file);
action.open.config.description=Allows to open project file of the linked {0} project at the editor
# Notification
-notification.project.refresh.fail.description={0} ''{1}'' project refresh failed:\n{2}
-notification.action.show.settings=<a href="configure">{0} settings</a>
+notification.project.refresh.fail.title={0} ''{1}'' project refresh failed
+notification.messages.project.sync.tab.name={0} Sync
# Tasks.
tasks.recent.title=Recent tasks
private final String myOriginalReason;
+ @NotNull
+ private final String[] myQuickFixes;
+
public ExternalSystemException() {
this(null, null);
}
this("", cause);
}
- public ExternalSystemException(@Nullable String message, @Nullable Throwable cause) {
+ public ExternalSystemException(@Nullable String message, @Nullable Throwable cause, @NotNull String... quickFixes) {
super(extractMessage(message, cause));
+ myQuickFixes = quickFixes;
if (cause == null) {
myOriginalReason = "";
return;
return myOriginalReason;
}
+ @NotNull
+ public String[] getQuickFixes() {
+ return myQuickFixes;
+ }
+
@Override
public void printStackTrace(PrintWriter s) {
super.printStackTrace(s);
--- /dev/null
+/*
+ * Copyright 2000-2014 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.externalSystem.model;
+
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * @author Vladislav.Soroka
+ * @since 3/26/14
+ */
+public class LocationAwareExternalSystemException extends ExternalSystemException {
+ private final String myFilePath;
+ private final Integer myLine;
+ private final Integer myColumn;
+
+ public LocationAwareExternalSystemException(@Nullable String message, String filePath, @NotNull String... quickFixes) {
+ this(message, null, filePath, -1, -1, quickFixes);
+ }
+
+ public LocationAwareExternalSystemException(@Nullable String message, String filePath, Integer line, @NotNull String... quickFixes) {
+ this(message, null, filePath, line, -1, quickFixes);
+ }
+
+ public LocationAwareExternalSystemException(@Nullable String message, String filePath, Integer line, Integer column, @NotNull String... quickFixes) {
+ this(message, null, filePath, line, column, quickFixes);
+ }
+
+ public LocationAwareExternalSystemException(@Nullable Throwable cause, String filePath, Integer line, Integer column, @NotNull String... quickFixes) {
+ this(null, cause, filePath, line, column, quickFixes);
+ }
+
+ public LocationAwareExternalSystemException(@Nullable String message,
+ @Nullable Throwable cause,
+ String filePath,
+ Integer line,
+ Integer column,
+ @NotNull String... quickFixes) {
+ super(message, cause, quickFixes);
+ myFilePath = filePath;
+ myLine = line;
+ myColumn = column;
+ }
+
+ public String getFilePath() {
+ return myFilePath;
+ }
+
+ public Integer getLine() {
+ return myLine;
+ }
+
+ public Integer getColumn() {
+ return myColumn;
+ }
+}
if (unitTestMode) {
UIUtil.invokeLaterIfNeeded(runnable);
}
- else if (application.isHeadlessEnvironment() || SwingUtilities.isEventDispatchThread()) {
+ else if (application.isHeadlessEnvironment() || application.isDispatchThread()) {
runnable.run();
}
else {
--- /dev/null
+/*
+ * Copyright 2000-2014 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.externalSystem.service.notification;
+
+import com.intellij.ide.IdeTooltipManager;
+import com.intellij.ide.errorTreeView.*;
+import com.intellij.notification.Notification;
+import com.intellij.notification.NotificationListener;
+import com.intellij.openapi.actionSystem.*;
+import com.intellij.pom.Navigatable;
+import com.intellij.ui.*;
+import com.intellij.util.containers.ContainerUtil;
+import com.intellij.util.ui.UIUtil;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+import javax.swing.*;
+import javax.swing.event.HyperlinkEvent;
+import javax.swing.event.HyperlinkListener;
+import javax.swing.text.AttributeSet;
+import javax.swing.text.SimpleAttributeSet;
+import javax.swing.text.Style;
+import javax.swing.text.StyleConstants;
+import javax.swing.text.html.HTML;
+import javax.swing.text.html.HTMLDocument;
+import javax.swing.tree.TreeCellEditor;
+import javax.swing.tree.TreePath;
+import java.awt.*;
+import java.util.Map;
+
+/**
+ * @author Vladislav.Soroka
+ * @since 3/24/2014
+ */
+public class EditableNotificationMessageElement extends NotificationMessageElement implements EditableMessageElement {
+
+ @NotNull private final TreeCellEditor myRightTreeCellEditor;
+ @NotNull private final Notification myNotification;
+ @NotNull private final Map<String/*url*/, String/*link text to replace*/> disabledLinks;
+
+ public EditableNotificationMessageElement(@NotNull Notification notification,
+ @NotNull ErrorTreeElementKind kind,
+ @Nullable GroupingElement parent,
+ String[] message,
+ Navigatable navigatable,
+ String exportText, String rendererTextPrefix) {
+ super(kind, parent, message, navigatable, exportText, rendererTextPrefix);
+ myNotification = notification;
+ disabledLinks = ContainerUtil.newHashMap();
+ myRightTreeCellEditor = new MyCellEditor();
+ }
+
+
+ public void addDisabledLink(@NotNull String url, @Nullable String text) {
+ disabledLinks.put(url, text);
+ }
+
+ @NotNull
+ @Override
+ public TreeCellEditor getRightSelfEditor() {
+ return myRightTreeCellEditor;
+ }
+
+ @Override
+ public boolean startEditingOnMouseMove() {
+ return true;
+ }
+
+ public static void disableLink(@NotNull HyperlinkEvent event) {
+ disableLink(event, null);
+ }
+
+ private static void disableLink(@NotNull final HyperlinkEvent event, @Nullable final String linkText) {
+ if (event.getSource() instanceof MyJEditorPane) {
+ UIUtil.invokeLaterIfNeeded(new Runnable() {
+ @Override
+ public void run() {
+ final MyJEditorPane editorPane = (MyJEditorPane)event.getSource();
+ editorPane.myElement.addDisabledLink(event.getDescription(), linkText);
+ editorPane.myElement.updateStyle(editorPane, null, null, true, false);
+ }
+ });
+ }
+ }
+
+ protected void updateStyle(@NotNull JEditorPane editorPane, @Nullable JTree tree, Object value, boolean selected, boolean hasFocus) {
+ super.updateStyle(editorPane, tree, value, selected, hasFocus);
+
+ final HTMLDocument htmlDocument = (HTMLDocument)editorPane.getDocument();
+ final Style linkStyle = htmlDocument.getStyleSheet().getStyle(LINK_STYLE);
+ StyleConstants.setForeground(linkStyle, IdeTooltipManager.getInstance().getLinkForeground(false));
+ StyleConstants.setItalic(linkStyle, true);
+ HTMLDocument.Iterator iterator = htmlDocument.getIterator(HTML.Tag.A);
+ while (iterator.isValid()) {
+ boolean disabledLink = false;
+ final AttributeSet attributes = iterator.getAttributes();
+ if (attributes instanceof SimpleAttributeSet) {
+ final Object attribute = attributes.getAttribute(HTML.Attribute.HREF);
+ if (attribute instanceof String && disabledLinks.containsKey(attribute)) {
+ disabledLink = true;
+ //TODO [Vlad] add support for disabled link text update
+ ////final String linkText = disabledLinks.get(attribute);
+ //if (linkText != null) {
+ //}
+ ((SimpleAttributeSet)attributes).removeAttribute(HTML.Attribute.HREF);
+ }
+ if (attribute == null) {
+ disabledLink = true;
+ }
+ }
+ if (!disabledLink) {
+ htmlDocument.setCharacterAttributes(
+ iterator.getStartOffset(), iterator.getEndOffset() - iterator.getStartOffset(), linkStyle, false);
+ }
+ iterator.next();
+ }
+ }
+
+ private static class MyJEditorPane extends JEditorPane {
+ @NotNull
+ private final EditableNotificationMessageElement myElement;
+
+ public MyJEditorPane(@NotNull EditableNotificationMessageElement element) {
+ myElement = element;
+ }
+ }
+
+ private class MyCellEditor extends AbstractCellEditor implements TreeCellEditor {
+ private final JEditorPane editorComponent;
+ @Nullable
+ private JTree myTree;
+
+ private MyCellEditor() {
+ editorComponent = installJep(new MyJEditorPane(EditableNotificationMessageElement.this));
+
+ HyperlinkListener hyperlinkListener = new ActivatedHyperlinkListener();
+ editorComponent.addHyperlinkListener(hyperlinkListener);
+ editorComponent.addMouseListener(new PopupHandler() {
+ @Override
+ public void invokePopup(Component comp, int x, int y) {
+ if (myTree == null) return;
+
+ final TreePath path = myTree.getLeadSelectionPath();
+ if (path == null) {
+ return;
+ }
+ DefaultActionGroup group = new DefaultActionGroup();
+ group.add(ActionManager.getInstance().getAction(IdeActions.ACTION_EDIT_SOURCE));
+ group.add(ActionManager.getInstance().getAction(IdeActions.ACTION_COPY));
+
+ ActionPopupMenu menu = ActionManager.getInstance().createActionPopupMenu(ActionPlaces.COMPILER_MESSAGES_POPUP, group);
+ menu.getComponent().show(comp, x, y);
+ }
+ });
+ }
+
+ @Override
+ public Component getTreeCellEditorComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row) {
+ myTree = tree;
+ updateStyle(editorComponent, tree, value, selected, false);
+ return editorComponent;
+ }
+
+ @Override
+ public Object getCellEditorValue() {
+ return null;
+ }
+
+ private class ActivatedHyperlinkListener implements HyperlinkListener {
+
+ @Override
+ public void hyperlinkUpdate(HyperlinkEvent e) {
+ if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
+ final NotificationListener notificationListener = myNotification.getListener();
+ if (notificationListener != null) {
+ notificationListener.hyperlinkUpdate(myNotification, e);
+ }
+ }
+ }
+ }
+ }
+}
package com.intellij.openapi.externalSystem.service.notification;
+import com.intellij.execution.rmi.RemoteUtil;
+import com.intellij.ide.errorTreeView.*;
import com.intellij.notification.Notification;
import com.intellij.notification.NotificationGroup;
-import com.intellij.notification.NotificationListener;
import com.intellij.notification.NotificationType;
+import com.intellij.openapi.command.CommandProcessor;
+import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.externalSystem.ExternalSystemConfigurableAware;
import com.intellij.openapi.externalSystem.ExternalSystemManager;
import com.intellij.openapi.externalSystem.model.ExternalSystemDataKeys;
+import com.intellij.openapi.externalSystem.model.LocationAwareExternalSystemException;
import com.intellij.openapi.externalSystem.model.ProjectSystemId;
import com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil;
import com.intellij.openapi.externalSystem.util.ExternalSystemBundle;
import com.intellij.openapi.externalSystem.util.ExternalSystemUtil;
import com.intellij.openapi.fileEditor.OpenFileDescriptor;
-import com.intellij.openapi.options.Configurable;
-import com.intellij.openapi.options.ShowSettingsUtil;
import com.intellij.openapi.project.Project;
+import com.intellij.openapi.util.Disposer;
+import com.intellij.openapi.util.Key;
+import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFile;
+import com.intellij.openapi.wm.ToolWindow;
+import com.intellij.openapi.wm.ToolWindowId;
+import com.intellij.openapi.wm.ToolWindowManager;
+import com.intellij.pom.Navigatable;
import com.intellij.ui.EditorNotifications;
+import com.intellij.ui.content.Content;
+import com.intellij.ui.content.ContentFactory;
+import com.intellij.ui.content.MessageView;
+import com.intellij.util.ArrayUtil;
+import com.intellij.util.ObjectUtils;
import com.intellij.util.ui.UIUtil;
import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
-import javax.swing.event.HyperlinkEvent;
import java.util.concurrent.atomic.AtomicReference;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
/**
* This class is responsible for ide user by external system integration-specific events.
* show corresponding message to the end-user.
* <p/>
* Thread-safe.
- *
- * @author Denis Zhdanov
+ *
+ * @author Denis Zhdanov, Vladislav Soroka
* @since 3/21/12 4:04 PM
*/
public class ExternalSystemIdeNotificationManager {
- private static final Pattern ERROR_LOCATION_PATTERN;
-
- static {
- ERROR_LOCATION_PATTERN = Pattern.compile("error in file: (.*?) at line: (\\d+)");
- }
-
+ @NotNull private static final Key<Pair<NotificationSource, ProjectSystemId>> CONTENT_ID_KEY = Key.create("CONTENT_ID");
@NotNull private final AtomicReference<Notification> myNotification = new AtomicReference<Notification>();
public void processExternalProjectRefreshError(@NotNull Throwable error,
@NotNull final Project project,
@NotNull String externalProjectName,
- @NotNull ProjectSystemId externalSystemId)
- {
+ @NotNull ProjectSystemId externalSystemId) {
if (project.isDisposed() || !project.isOpen()) {
return;
}
return;
}
+ String title =
+ ExternalSystemBundle.message("notification.project.refresh.fail.title", externalSystemId.getReadableName(), externalProjectName);
String message = ExternalSystemApiUtil.buildErrorMessage(error);
- String title = ExternalSystemBundle.message("notification.project.refresh.fail.description",
- externalSystemId.getReadableName(), externalProjectName, message);
- String messageToShow = ExternalSystemBundle.message("notification.action.show.settings", externalSystemId.getReadableName());
- NotificationType notificationType = NotificationType.WARNING;
- final Configurable configurable = ((ExternalSystemConfigurableAware)manager).getConfigurable(project);
- NotificationListener listener = new NotificationListener() {
- @Override
- public void hyperlinkUpdate(@NotNull Notification notification, @NotNull HyperlinkEvent event) {
- if (event.getEventType() != HyperlinkEvent.EventType.ACTIVATED) {
- return;
- }
- if ("configure".equals(event.getDescription())) {
- ShowSettingsUtil.getInstance().editConfigurable(project, configurable);
- }
- else if (!StringUtil.isEmpty(event.getDescription())) {
- Matcher matcher = ERROR_LOCATION_PATTERN.matcher(event.getDescription());
- if(matcher.find()) {
- String file = matcher.group(1);
- String lineText = matcher.group(2);
- Integer line;
- try {
- line = Integer.valueOf(lineText);
- }
- catch (NumberFormatException e) {
- line = 0;
- }
- VirtualFile virtualFile = LocalFileSystem.getInstance().refreshAndFindFileByPath(file);
- if(virtualFile != null) {
- new OpenFileDescriptor(project, virtualFile, line - 1, -1).navigate(true);
- }
- }
- }
- }
- };
-
+ NotificationType notificationType = NotificationType.ERROR;
+ String filePath = null;
+ Integer line = null;
+ Integer column = null;
+
+ //noinspection ThrowableResultOfMethodCallIgnored
+ Throwable unwrapped = RemoteUtil.unwrap(error);
+ if (unwrapped instanceof LocationAwareExternalSystemException) {
+ LocationAwareExternalSystemException locationAwareExternalSystemException = (LocationAwareExternalSystemException)unwrapped;
+ filePath = locationAwareExternalSystemException.getFilePath();
+ line = locationAwareExternalSystemException.getLine();
+ column = locationAwareExternalSystemException.getColumn();
+ }
+
+ NotificationData notificationData =
+ new NotificationData(
+ title, message, notificationType, NotificationSource.PROJECT_SYNC,
+ filePath, ObjectUtils.notNull(line, -1), ObjectUtils.notNull(column, -1), false);
+
for (ExternalSystemNotificationExtension extension : ExternalSystemNotificationExtension.EP_NAME.getExtensions()) {
if (!externalSystemId.equals(extension.getTargetExternalSystemId())) {
continue;
}
- ExternalSystemNotificationExtension.CustomizationResult customizationResult = extension.customize(
- project, error, ExternalSystemNotificationExtension.UsageHint.PROJECT_REFRESH
- );
- if (customizationResult == null) {
- continue;
- }
- if (customizationResult.getTitle() != null) {
- title = customizationResult.getTitle();
- }
- if (customizationResult.getMessage() != null) {
- messageToShow = customizationResult.getMessage();
- }
- if (customizationResult.getNotificationType() != null) {
- notificationType = customizationResult.getNotificationType();
- }
- if (customizationResult.getListener() != null) {
- listener = customizationResult.getListener();
- }
+ extension.customize(notificationData, project, error);
}
EditorNotifications.getInstance(project).updateAllNotifications();
- showNotification(title, messageToShow, notificationType, project, externalSystemId, listener);
+ showNotification(project, externalSystemId, notificationData);
}
- public void showNotification(@NotNull final String title,
- @NotNull final String message,
- @NotNull final NotificationType type,
- @NotNull final Project project,
+ public void showNotification(@NotNull final Project project,
@NotNull final ProjectSystemId externalSystemId,
- @Nullable final NotificationListener listener)
- {
+ @NotNull final NotificationData notificationData) {
+
UIUtil.invokeLaterIfNeeded(new Runnable() {
@Override
public void run() {
- NotificationGroup group = ExternalSystemUtil.getToolWindowElement(NotificationGroup.class,
- project,
- ExternalSystemDataKeys.NOTIFICATION_GROUP,
- externalSystemId);
- if (group == null) {
- return;
+ if (project.isDisposed()) return;
+
+ final NotificationGroup group = ExternalSystemUtil.getToolWindowElement(
+ NotificationGroup.class, project, ExternalSystemDataKeys.NOTIFICATION_GROUP, externalSystemId);
+ if (group == null) return;
+
+ final Notification notification = group.createNotification(
+ notificationData.getTitle(), notificationData.getMessage(),
+ notificationData.getNotificationType(), notificationData.getListener());
+
+ if (notificationData.isBalloonNotification()) {
+ applyNotification(notification, project);
}
+ else {
+ addMessage(notification, project, externalSystemId, notificationData);
+ }
+ }
+ });
+ }
- Notification notification = group.createNotification(title, message, type, listener);
- applyNotification(notification, project);
+ public void clearNotificationMessages(@NotNull final Project project,
+ @NotNull final NotificationSource notificationSource,
+ @NotNull final ProjectSystemId externalSystemId) {
+ UIUtil.invokeLaterIfNeeded(new Runnable() {
+ @Override
+ public void run() {
+ final ToolWindow toolWindow = ToolWindowManager.getInstance(project).getToolWindow(ToolWindowId.MESSAGES_WINDOW);
+ if (toolWindow == null) return;
+
+ final Pair<NotificationSource, ProjectSystemId> contentIdPair = Pair.create(notificationSource, externalSystemId);
+ final MessageView messageView = ServiceManager.getService(project, MessageView.class);
+ for (Content content : messageView.getContentManager().getContents()) {
+ if (!content.isPinned() && contentIdPair.equals(content.getUserData(CONTENT_ID_KEY))) {
+ messageView.getContentManager().removeContent(content, true);
+ }
+ }
}
});
-
}
-
+
+
+ private static void addMessage(@NotNull final Notification notification,
+ @NotNull final Project project,
+ @NotNull final ProjectSystemId externalSystemId,
+ @NotNull final NotificationData notificationData) {
+ notification.expire();
+
+ final NewErrorTreeViewPanel[] errorTreeView = {null};
+ CommandProcessor commandProcessor = CommandProcessor.getInstance();
+ commandProcessor.executeCommand(project, new Runnable() {
+ @Override
+ public void run() {
+ errorTreeView[0] = prepareMessagesView(project, externalSystemId, notificationData);
+ }
+ }, "Open message view", null);
+
+ final ToolWindow tw = ToolWindowManager.getInstance(project).getToolWindow(ToolWindowId.MESSAGES_WINDOW);
+ if (tw != null) {
+ tw.activate(null, false);
+ }
+
+ final VirtualFile virtualFile = notificationData.getFilePath() != null
+ ?
+ LocalFileSystem.getInstance().refreshAndFindFileByPath(notificationData.getFilePath())
+ : null;
+
+ final String groupName = virtualFile != null ? virtualFile.getPresentableUrl() : notificationData.getTitle();
+
+ int line = notificationData.getLine() - 1;
+ int column = notificationData.getColumn() - 1;
+
+ if (virtualFile == null) line = column = -1;
+
+ final int guiLine = line < 0 ? -1 : line + 1;
+ final int guiColumn = column < 0 ? 0 : column + 1;
+
+ final Navigatable navigatable = notificationData.getNavigatable() != null
+ ? notificationData.getNavigatable()
+ : virtualFile != null ? new OpenFileDescriptor(project, virtualFile, line, column) : null;
+
+ final ErrorTreeElementKind kind = getErrorTreeElementKind(notificationData.getNotificationType());
+ final String[] message = notificationData.getMessage().split("\n");
+ final GroupingElement groupingElement = errorTreeView[0].getErrorViewStructure().getGroupingElement(groupName, null, virtualFile);
+ final String exportPrefix = NewErrorTreeViewPanel.createExportPrefix(guiLine);
+ final String rendererPrefix = NewErrorTreeViewPanel.createRendererPrefix(guiLine, guiColumn);
+
+ final NavigatableMessageElement navigatableMessageElement;
+ if (notificationData.hasLinks()) {
+ navigatableMessageElement = new EditableNotificationMessageElement(
+ notification,
+ kind,
+ groupingElement,
+ message,
+ navigatable,
+ exportPrefix,
+ rendererPrefix);
+ }
+ else {
+ navigatableMessageElement = new NotificationMessageElement(
+ kind,
+ groupingElement,
+ message,
+ navigatable,
+ exportPrefix,
+ rendererPrefix);
+ }
+
+ errorTreeView[0].getErrorViewStructure().addNavigatableMessage(groupName, navigatableMessageElement);
+ errorTreeView[0].updateTree();
+ }
+
private void applyNotification(@NotNull final Notification notification, @NotNull final Project project) {
final Notification oldNotification = myNotification.get();
if (oldNotification != null && myNotification.compareAndSet(oldNotification, null)) {
notification.notify(project);
}
}
-}
+
+ @NotNull
+ private static ErrorTreeElementKind getErrorTreeElementKind(@NotNull final NotificationType notificationType) {
+ ErrorTreeElementKind errorTreeElementKind = ErrorTreeElementKind.GENERIC;
+ switch (notificationType) {
+ case INFORMATION:
+ errorTreeElementKind = ErrorTreeElementKind.INFO;
+ break;
+ case WARNING:
+ errorTreeElementKind = ErrorTreeElementKind.WARNING;
+ break;
+ case ERROR:
+ errorTreeElementKind = ErrorTreeElementKind.ERROR;
+ break;
+ }
+ return errorTreeElementKind;
+ }
+
+ @NotNull
+ private static NewErrorTreeViewPanel prepareMessagesView(@NotNull final Project project,
+ @NotNull final ProjectSystemId externalSystemId,
+ @NotNull final NotificationData notificationData) {
+ final NotificationSource notificationSource = notificationData.getNotificationSource();
+ final String contentDisplayName = getContentDisplayName(notificationSource, externalSystemId);
+ final Pair<NotificationSource, ProjectSystemId> contentIdPair = Pair.create(notificationSource, externalSystemId);
+
+ Content projectSyncContent = null;
+ final MessageView messageView = ServiceManager.getService(project, MessageView.class);
+ for (Content content : messageView.getContentManager().getContents()) {
+ if (contentIdPair.equals(content.getUserData(CONTENT_ID_KEY))
+ && StringUtil.equals(content.getDisplayName(), contentDisplayName) && !content.isPinned()) {
+ projectSyncContent = content;
+ }
+ }
+ final NewEditableErrorTreeViewPanel errorTreeView;
+ if (projectSyncContent == null || !contentIdPair.equals(projectSyncContent.getUserData(CONTENT_ID_KEY))) {
+ errorTreeView = new NewEditableErrorTreeViewPanel(project, null, true, true, null);
+
+ projectSyncContent = ContentFactory.SERVICE.getInstance().createContent(errorTreeView, contentDisplayName, true);
+ projectSyncContent.putUserData(CONTENT_ID_KEY, contentIdPair);
+
+ messageView.getContentManager().addContent(projectSyncContent);
+ Disposer.register(projectSyncContent, errorTreeView);
+ }
+ else {
+ assert projectSyncContent.getComponent() instanceof NewEditableErrorTreeViewPanel;
+ errorTreeView = (NewEditableErrorTreeViewPanel)projectSyncContent.getComponent();
+ }
+
+ messageView.getContentManager().setSelectedContent(projectSyncContent);
+ return errorTreeView;
+ }
+
+ @NotNull
+ private static String getContentDisplayName(@NotNull final NotificationSource notificationSource,
+ @NotNull final ProjectSystemId externalSystemId) {
+ final String contentDisplayName;
+ switch (notificationSource) {
+ case PROJECT_SYNC:
+ contentDisplayName =
+ ExternalSystemBundle.message("notification.messages.project.sync.tab.name", externalSystemId.getReadableName());
+ break;
+ default:
+ throw new AssertionError("unsupported notification source found: " + notificationSource);
+ }
+ return contentDisplayName;
+ }
+}
\ No newline at end of file
*/
package com.intellij.openapi.externalSystem.service.notification;
-import com.intellij.notification.NotificationListener;
-import com.intellij.notification.NotificationType;
import com.intellij.openapi.extensions.ExtensionPointName;
import com.intellij.openapi.externalSystem.model.ProjectSystemId;
import com.intellij.openapi.project.Project;
/**
* Allows to customize {@link ExternalSystemIdeNotificationManager external system notifications} shown to end-user by the ide.
- *
+ *
* @author Denis Zhdanov
* @since 8/5/13 8:52 AM
*/
ExtensionPointName<ExternalSystemNotificationExtension> EP_NAME
= ExtensionPointName.create("com.intellij.externalSystemNotificationExtension");
-
+
@NotNull
ProjectSystemId getTargetExternalSystemId();
/**
- * Allows to customize external system processing error.
- *
- * @param project target ide project
- * @param error error occurred during external system processing
- * @param hint hint for a use-case during processing of which given error occurs
- * @return customization result (if applicable)
+ * Allows to customize external system processing notification.
+ *
+ * @param notificationData notification data
+ * @param project target ide project
+ * @param error error occurred during external system processing
*/
- @Nullable
- CustomizationResult customize(@NotNull Project project, @NotNull Throwable error, @Nullable UsageHint hint);
-
- enum UsageHint {
- PROJECT_REFRESH
- }
-
- class CustomizationResult {
-
- @Nullable private final String myTitle;
- @Nullable private final String myMessage;
- @Nullable private final NotificationType myNotificationType;
- @Nullable private final NotificationListener myListener;
-
- public CustomizationResult(@Nullable String title,
- @Nullable String message,
- @Nullable NotificationType notificationType,
- @Nullable NotificationListener listener)
- {
- myTitle = title;
- myMessage = message;
- myNotificationType = notificationType;
- myListener = listener;
- }
-
- @Nullable
- public String getTitle() {
- return myTitle;
- }
-
- @Nullable
- public String getMessage() {
- return myMessage;
- }
-
- @Nullable
- public NotificationType getNotificationType() {
- return myNotificationType;
- }
-
- @Nullable
- public NotificationListener getListener() {
- return myListener;
- }
- }
+ void customize(@NotNull NotificationData notificationData,
+ @NotNull Project project,
+ @Nullable Throwable error);
}
--- /dev/null
+/*
+ * Copyright 2000-2014 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.externalSystem.service.notification;
+
+import com.intellij.notification.Notification;
+import com.intellij.notification.NotificationListener;
+import com.intellij.notification.NotificationType;
+import com.intellij.pom.Navigatable;
+import com.intellij.util.containers.ContainerUtil;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+import javax.swing.event.HyperlinkEvent;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author Vladislav.Soroka
+ * @since 3/28/14
+ */
+public class NotificationData {
+
+ @NotNull private String myTitle;
+ @NotNull private String myMessage;
+ @NotNull private NotificationType myNotificationType;
+ @NotNull private final NotificationSource myNotificationSource;
+ @NotNull private NotificationListener myListener;
+ @Nullable private String myFilePath;
+ @Nullable private Navigatable navigatable;
+ private int myLine;
+ private int myColumn;
+ private boolean myBalloonNotification;
+
+ private final Map<String, NotificationListener> myListenerMap;
+
+ public NotificationData(@NotNull String title,
+ @NotNull String message,
+ @NotNull NotificationType notificationType,
+ @NotNull NotificationSource notificationSource) {
+ this(title, message, notificationType, notificationSource, null, -1, -1, false);
+ }
+
+ public NotificationData(@NotNull String title,
+ @NotNull String message,
+ @NotNull NotificationType notificationType,
+ @NotNull NotificationSource notificationSource,
+ @Nullable String filePath,
+ int line,
+ int column,
+ boolean balloonNotification) {
+ myTitle = title;
+ myMessage = message;
+ myNotificationType = notificationType;
+ myNotificationSource = notificationSource;
+ myListenerMap = ContainerUtil.newHashMap();
+ myListener = new NotificationListener.Adapter() {
+ @Override
+ protected void hyperlinkActivated(@NotNull Notification notification, @NotNull HyperlinkEvent event) {
+ if (event.getEventType() != HyperlinkEvent.EventType.ACTIVATED) return;
+
+ final NotificationListener notificationListener = myListenerMap.get(event.getDescription());
+ if (notificationListener != null) {
+ notificationListener.hyperlinkUpdate(notification, event);
+ }
+ }
+ };
+ myFilePath = filePath;
+ myLine = line;
+ myColumn = column;
+ myBalloonNotification = balloonNotification;
+ }
+
+ @NotNull
+ public String getTitle() {
+ return myTitle;
+ }
+
+ public void setTitle(@NotNull String title) {
+ myTitle = title;
+ }
+
+ @NotNull
+ public String getMessage() {
+ return myMessage;
+ }
+
+ public void setMessage(@NotNull String message) {
+ myMessage = message;
+ }
+
+ @NotNull
+ public NotificationType getNotificationType() {
+ return myNotificationType;
+ }
+
+ public void setNotificationType(@NotNull NotificationType notificationType) {
+ myNotificationType = notificationType;
+ }
+
+ @NotNull
+ public NotificationSource getNotificationSource() {
+ return myNotificationSource;
+ }
+
+ @NotNull
+ public NotificationListener getListener() {
+ return myListener;
+ }
+
+ @Nullable
+ public String getFilePath() {
+ return myFilePath;
+ }
+
+ public void setFilePath(@Nullable String filePath) {
+ myFilePath = filePath;
+ }
+
+ @NotNull
+ public Integer getLine() {
+ return myLine;
+ }
+
+ public void setLine(int line) {
+ myLine = line;
+ }
+
+ public int getColumn() {
+ return myColumn;
+ }
+
+ public void setColumn(int column) {
+ myColumn = column;
+ }
+
+ public boolean isBalloonNotification() {
+ return myBalloonNotification;
+ }
+
+ public void setBalloonNotification(boolean balloonNotification) {
+ myBalloonNotification = balloonNotification;
+ }
+
+ public void setListener(@NotNull String listenerId, @NotNull NotificationListener listener) {
+ myListenerMap.put(listenerId, listener);
+ }
+
+ boolean hasLinks() {
+ return !myListenerMap.isEmpty();
+ }
+
+ public List<String> getRegisteredListenerIds() {
+ return ContainerUtil.newArrayList(myListenerMap.keySet());
+ }
+
+ @Nullable
+ public Navigatable getNavigatable() {
+ return navigatable;
+ }
+
+ public void setNavigatable(@Nullable Navigatable navigatable) {
+ this.navigatable = navigatable;
+ }
+}
--- /dev/null
+/*
+ * Copyright 2000-2014 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.externalSystem.service.notification;
+
+import com.intellij.icons.AllIcons;
+import com.intellij.ide.errorTreeView.*;
+import com.intellij.openapi.util.text.StringUtil;
+import com.intellij.pom.Navigatable;
+import com.intellij.ui.CustomizeColoredTreeCellRenderer;
+import com.intellij.ui.JBColor;
+import com.intellij.ui.LoadingNode;
+import com.intellij.ui.SimpleColoredComponent;
+import com.intellij.util.ui.UIUtil;
+import com.intellij.util.ui.tree.WideSelectionTreeUI;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+import javax.swing.*;
+import javax.swing.text.Style;
+import javax.swing.text.StyleConstants;
+import javax.swing.text.html.HTMLDocument;
+import javax.swing.text.html.StyleSheet;
+import java.awt.*;
+
+/**
+ * @author Vladislav.Soroka
+ * @since 3/24/2014
+ */
+public class NotificationMessageElement extends NavigatableMessageElement {
+ public static final String MSG_STYLE = "messageStyle";
+ public static final String LINK_STYLE = "linkStyle";
+
+ @NotNull private final CustomizeColoredTreeCellRenderer myLeftTreeCellRenderer;
+ @NotNull private final CustomizeColoredTreeCellRenderer myRightTreeCellRenderer;
+
+ public NotificationMessageElement(@NotNull final ErrorTreeElementKind kind,
+ @Nullable GroupingElement parent,
+ String[] message,
+ Navigatable navigatable,
+ String exportText,
+ String rendererTextPrefix) {
+ super(kind, parent, message, navigatable, exportText, rendererTextPrefix);
+ myLeftTreeCellRenderer = new CustomizeColoredTreeCellRenderer() {
+ public void customizeCellRenderer(SimpleColoredComponent renderer,
+ JTree tree,
+ Object value,
+ boolean selected,
+ boolean expanded,
+ boolean leaf,
+ int row,
+ boolean hasFocus) {
+ renderer.setIcon(getIcon(kind));
+ renderer.setFont(tree.getFont());
+ renderer.append(NewErrorTreeRenderer.calcPrefix(NotificationMessageElement.this));
+ }
+
+ @NotNull
+ private Icon getIcon(@NotNull ErrorTreeElementKind kind) {
+ Icon icon = AllIcons.General.Mdot_empty;
+ switch (kind) {
+ case INFO:
+ icon = AllIcons.General.Information;
+ break;
+ case ERROR:
+ icon = AllIcons.General.Error;
+ break;
+ case WARNING:
+ icon = AllIcons.General.Warning;
+ break;
+ case NOTE:
+ icon = AllIcons.General.Tip;
+ break;
+ case GENERIC:
+ icon = AllIcons.General.Mdot_empty;
+ break;
+ }
+ return icon;
+ }
+ };
+
+ myRightTreeCellRenderer = new MyCustomizeColoredTreeCellRendererReplacement();
+ }
+
+ @Nullable
+ @Override
+ public CustomizeColoredTreeCellRenderer getRightSelfRenderer() {
+ return myRightTreeCellRenderer;
+ }
+
+ @Nullable
+ @Override
+ public CustomizeColoredTreeCellRenderer getLeftSelfRenderer() {
+ return myLeftTreeCellRenderer;
+ }
+
+ protected JEditorPane installJep(@NotNull JEditorPane myEditorPane) {
+ String message = StringUtil.join(this.getText(), "<br>");
+ myEditorPane.setEditable(false);
+ myEditorPane.setOpaque(false);
+ myEditorPane.setEditorKit(UIUtil.getHTMLEditorKit());
+ myEditorPane.setHighlighter(null);
+
+ final StyleSheet styleSheet = ((HTMLDocument)myEditorPane.getDocument()).getStyleSheet();
+ final Style style = styleSheet.addStyle(MSG_STYLE, null);
+ styleSheet.addStyle(LINK_STYLE, style);
+ myEditorPane.setText(message);
+
+ return myEditorPane;
+ }
+
+ protected void updateStyle(@NotNull JEditorPane editorPane, @Nullable JTree tree, Object value, boolean selected, boolean hasFocus) {
+ final HTMLDocument htmlDocument = (HTMLDocument)editorPane.getDocument();
+ final Style style = htmlDocument.getStyleSheet().getStyle(MSG_STYLE);
+ if (value instanceof LoadingNode) {
+ StyleConstants.setForeground(style, JBColor.GRAY);
+ }
+ else {
+ if (selected) {
+ StyleConstants.setForeground(style, hasFocus ? UIUtil.getTreeSelectionForeground() : UIUtil.getTreeTextForeground());
+ }
+ else {
+ StyleConstants.setForeground(style, UIUtil.getTreeTextForeground());
+ }
+ }
+
+ if (UIUtil.isUnderGTKLookAndFeel() ||
+ UIUtil.isUnderNimbusLookAndFeel() && selected && hasFocus ||
+ tree != null && tree.getUI() instanceof WideSelectionTreeUI && ((WideSelectionTreeUI)tree.getUI()).isWideSelection()) {
+ editorPane.setOpaque(false);
+ }
+ else {
+ editorPane.setOpaque(selected && hasFocus);
+ }
+
+ htmlDocument.setCharacterAttributes(0, htmlDocument.getLength(), style, false);
+ }
+
+ private class MyCustomizeColoredTreeCellRendererReplacement extends CustomizeColoredTreeCellRendererReplacement {
+ @NotNull
+ private final JEditorPane myEditorPane;
+
+ private MyCustomizeColoredTreeCellRendererReplacement() {
+ myEditorPane = installJep(new JEditorPane());
+ }
+
+ @Override
+ public Component getTreeCellRendererComponent(JTree tree,
+ Object value,
+ boolean selected,
+ boolean expanded,
+ boolean leaf,
+ int row,
+ boolean hasFocus) {
+ updateStyle(myEditorPane, tree, value, selected, hasFocus);
+ return myEditorPane;
+ }
+ }
+}
--- /dev/null
+/*
+ * Copyright 2000-2014 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.externalSystem.service.notification;
+
+/**
+ * @author Vladislav.Soroka
+ * @since 3/28/14
+ */
+public enum NotificationSource {
+ PROJECT_SYNC
+}
public DataNode<ProjectData> resolveProjectInfo(@NotNull final ExternalSystemTaskId id,
@NotNull final String projectPath,
final boolean isPreviewMode,
- ExternalSystemExecutionSettings settings)
+ final S settings)
throws ExternalSystemException, IllegalArgumentException, IllegalStateException
{
return execute(id, new Producer<DataNode<ProjectData>>() {
@Nullable
@Override
public DataNode<ProjectData> produce() {
- return myDelegate.resolveProjectInfo(id, projectPath, isPreviewMode, getSettings(), getNotificationListener());
+ return myDelegate.resolveProjectInfo(id, projectPath, isPreviewMode, settings, getNotificationListener());
}
});
}
import com.intellij.openapi.externalSystem.service.internal.ExternalSystemProcessingManager;
import com.intellij.openapi.externalSystem.service.internal.ExternalSystemResolveProjectTask;
import com.intellij.openapi.externalSystem.service.notification.ExternalSystemIdeNotificationManager;
+import com.intellij.openapi.externalSystem.service.notification.NotificationSource;
import com.intellij.openapi.externalSystem.service.project.ExternalProjectRefreshCallback;
import com.intellij.openapi.externalSystem.service.project.PlatformFacade;
import com.intellij.openapi.externalSystem.service.project.ProjectStructureHelper;
import com.intellij.openapi.roots.libraries.LibraryTable;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.util.text.StringUtil;
-import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.wm.ToolWindow;
import com.intellij.openapi.wm.ToolWindowEP;
final ProjectDataManager projectDataManager = ServiceManager.getService(ProjectDataManager.class);
final int[] counter = new int[1];
- ExternalProjectRefreshCallback callback = new ExternalProjectRefreshCallback() {
-
- @NotNull
- private final Set<String> myExternalModulePaths = ContainerUtilRt.newHashSet();
-
- @Override
- public void onSuccess(@Nullable final DataNode<ProjectData> externalProject) {
- if (externalProject == null) {
- return;
- }
- Collection<DataNode<ModuleData>> moduleNodes = ExternalSystemApiUtil.findAll(externalProject, ProjectKeys.MODULE);
- for (DataNode<ModuleData> node : moduleNodes) {
- myExternalModulePaths.add(node.getData().getLinkedExternalProjectPath());
- }
- ExternalSystemApiUtil.executeProjectChangeAction(true, new DisposeAwareProjectChange(project) {
- @Override
- public void execute() {
- ProjectRootManagerEx.getInstanceEx(project).mergeRootsChangesDuring(new Runnable() {
- @Override
- public void run() {
- projectDataManager.importData(externalProject.getKey(), Collections.singleton(externalProject), project, true);
- }
- });
-
- processOrphanProjectLibraries();
- }
- });
- if (--counter[0] <= 0) {
- processOrphanModules();
- }
- }
-
- @Override
- public void onFailure(@NotNull String errorMessage, @Nullable String errorDetails) {
- counter[0] = Integer.MAX_VALUE; // Don't process orphan modules if there was an error on refresh.
- }
-
- private void processOrphanModules() {
- if(project.isDisposed()) return;
- if(ExternalSystemDebugEnvironment.DEBUG_ORPHAN_MODULES_PROCESSING) {
- LOG.info(String.format(
- "Checking for orphan modules. External paths returned by external system: '%s'", myExternalModulePaths
- ));
- }
- PlatformFacade platformFacade = ServiceManager.getService(PlatformFacade.class);
- List<Module> orphanIdeModules = ContainerUtilRt.newArrayList();
- String externalSystemIdAsString = externalSystemId.toString();
-
- for (Module module : platformFacade.getModules(project)) {
- String s = module.getOptionValue(ExternalSystemConstants.EXTERNAL_SYSTEM_ID_KEY);
- String p = module.getOptionValue(ExternalSystemConstants.LINKED_PROJECT_PATH_KEY);
- if(ExternalSystemDebugEnvironment.DEBUG_ORPHAN_MODULES_PROCESSING) {
- LOG.info(String.format(
- "IDE module: EXTERNAL_SYSTEM_ID_KEY - '%s', LINKED_PROJECT_PATH_KEY - '%s'.", s, p
- ));
- }
- if (externalSystemIdAsString.equals(s) && !myExternalModulePaths.contains(p)) {
- orphanIdeModules.add(module);
- if(ExternalSystemDebugEnvironment.DEBUG_ORPHAN_MODULES_PROCESSING) {
- LOG.info(String.format(
- "External paths doesn't contain IDE module LINKED_PROJECT_PATH_KEY anymore => add to orphan IDE modules."
- ));
- }
- }
- }
-
- if (!orphanIdeModules.isEmpty()) {
- ruleOrphanModules(orphanIdeModules, project, externalSystemId);
- }
- }
-
- private void processOrphanProjectLibraries() {
- PlatformFacade platformFacade = ServiceManager.getService(PlatformFacade.class);
- List<Library> orphanIdeLibraries = ContainerUtilRt.newArrayList();
-
- LibraryTable projectLibraryTable = platformFacade.getProjectLibraryTable(project);
- for (Library library : projectLibraryTable.getLibraries()) {
- if (!ExternalSystemApiUtil.isExternalSystemLibrary(library, externalSystemId)) continue;
- if (ProjectStructureHelper.isOrphanProjectLibrary(library, platformFacade.getModules(project))) {
- orphanIdeLibraries.add(library);
- }
- }
- for (Library orphanIdeLibrary : orphanIdeLibraries) {
- projectLibraryTable.removeLibrary(orphanIdeLibrary);
- }
- }
- };
+ ExternalProjectRefreshCallback callback =
+ new MyMultiExternalProjectRefreshCallback(project, projectDataManager, counter, externalSystemId);
Map<String, Long> modificationStamps = manager.getLocalSettingsProvider().fun(project).getExternalConfigModificationStamps();
Set<String> toRefresh = ContainerUtilRt.newHashSet();
}
if (!toRefresh.isEmpty()) {
+ ExternalSystemIdeNotificationManager notificationManager = ServiceManager.getService(ExternalSystemIdeNotificationManager.class);
+ if (notificationManager != null) {
+ notificationManager.clearNotificationMessages(project, NotificationSource.PROJECT_SYNC, externalSystemId);
+ }
+
counter[0] = toRefresh.size();
for (String path : toRefresh) {
refreshProject(project, externalSystemId, path, callback, false, progressExecutionMode);
return;
}
+ if(!(callback instanceof MyMultiExternalProjectRefreshCallback)) {
+ ExternalSystemIdeNotificationManager notificationManager = ServiceManager.getService(ExternalSystemIdeNotificationManager.class);
+ if (notificationManager != null) {
+ notificationManager.clearNotificationMessages(project, NotificationSource.PROJECT_SYNC, externalSystemId);
+ }
+ }
+
ExternalSystemResolveProjectTask task
= new ExternalSystemResolveProjectTask(externalSystemId, project, externalProjectPath, isPreviewMode);
private interface TaskUnderProgress {
void execute(@NotNull ProgressIndicator indicator);
}
+
+ private static class MyMultiExternalProjectRefreshCallback implements ExternalProjectRefreshCallback {
+
+ @NotNull
+ private final Set<String> myExternalModulePaths;
+ private final Project myProject;
+ private final ProjectDataManager myProjectDataManager;
+ private final int[] myCounter;
+ private final ProjectSystemId myExternalSystemId;
+
+ public MyMultiExternalProjectRefreshCallback(Project project,
+ ProjectDataManager projectDataManager,
+ int[] counter,
+ ProjectSystemId externalSystemId) {
+ myProject = project;
+ myProjectDataManager = projectDataManager;
+ myCounter = counter;
+ myExternalSystemId = externalSystemId;
+ myExternalModulePaths = ContainerUtilRt.newHashSet();
+ }
+
+ @Override
+ public void onSuccess(@Nullable final DataNode<ProjectData> externalProject) {
+ if (externalProject == null) {
+ return;
+ }
+ Collection<DataNode<ModuleData>> moduleNodes = ExternalSystemApiUtil.findAll(externalProject, ProjectKeys.MODULE);
+ for (DataNode<ModuleData> node : moduleNodes) {
+ myExternalModulePaths.add(node.getData().getLinkedExternalProjectPath());
+ }
+ ExternalSystemApiUtil.executeProjectChangeAction(true, new DisposeAwareProjectChange(myProject) {
+ @Override
+ public void execute() {
+ ProjectRootManagerEx.getInstanceEx(myProject).mergeRootsChangesDuring(new Runnable() {
+ @Override
+ public void run() {
+ myProjectDataManager.importData(externalProject.getKey(), Collections.singleton(externalProject), myProject, true);
+ }
+ });
+
+ processOrphanProjectLibraries();
+ }
+ });
+ if (--myCounter[0] <= 0) {
+ processOrphanModules();
+ }
+ }
+
+ @Override
+ public void onFailure(@NotNull String errorMessage, @Nullable String errorDetails) {
+ myCounter[0] = Integer.MAX_VALUE; // Don't process orphan modules if there was an error on refresh.
+ }
+
+ private void processOrphanModules() {
+ if(myProject.isDisposed()) return;
+ if(ExternalSystemDebugEnvironment.DEBUG_ORPHAN_MODULES_PROCESSING) {
+ LOG.info(String.format(
+ "Checking for orphan modules. External paths returned by external system: '%s'", myExternalModulePaths
+ ));
+ }
+ PlatformFacade platformFacade = ServiceManager.getService(PlatformFacade.class);
+ List<Module> orphanIdeModules = ContainerUtilRt.newArrayList();
+ String externalSystemIdAsString = myExternalSystemId.toString();
+
+ for (Module module : platformFacade.getModules(myProject)) {
+ String s = module.getOptionValue(ExternalSystemConstants.EXTERNAL_SYSTEM_ID_KEY);
+ String p = module.getOptionValue(ExternalSystemConstants.LINKED_PROJECT_PATH_KEY);
+ if(ExternalSystemDebugEnvironment.DEBUG_ORPHAN_MODULES_PROCESSING) {
+ LOG.info(String.format(
+ "IDE module: EXTERNAL_SYSTEM_ID_KEY - '%s', LINKED_PROJECT_PATH_KEY - '%s'.", s, p
+ ));
+ }
+ if (externalSystemIdAsString.equals(s) && !myExternalModulePaths.contains(p)) {
+ orphanIdeModules.add(module);
+ if(ExternalSystemDebugEnvironment.DEBUG_ORPHAN_MODULES_PROCESSING) {
+ LOG.info(String.format(
+ "External paths doesn't contain IDE module LINKED_PROJECT_PATH_KEY anymore => add to orphan IDE modules."
+ ));
+ }
+ }
+ }
+
+ if (!orphanIdeModules.isEmpty()) {
+ ruleOrphanModules(orphanIdeModules, myProject, myExternalSystemId);
+ }
+ }
+
+ private void processOrphanProjectLibraries() {
+ PlatformFacade platformFacade = ServiceManager.getService(PlatformFacade.class);
+ List<Library> orphanIdeLibraries = ContainerUtilRt.newArrayList();
+
+ LibraryTable projectLibraryTable = platformFacade.getProjectLibraryTable(myProject);
+ for (Library library : projectLibraryTable.getLibraries()) {
+ if (!ExternalSystemApiUtil.isExternalSystemLibrary(library, myExternalSystemId)) continue;
+ if (ProjectStructureHelper.isOrphanProjectLibrary(library, platformFacade.getModules(myProject))) {
+ orphanIdeLibraries.add(library);
+ }
+ }
+ for (Library orphanIdeLibrary : orphanIdeLibraries) {
+ projectLibraryTable.removeLibrary(orphanIdeLibrary);
+ }
+ }
+ }
}
/*
- * Copyright 2000-2009 JetBrains s.r.o.
+ * Copyright 2000-2014 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.
*/
public interface DataIndexer<Key, Value, Data> {
@NotNull
- Map<Key,Value> map(Data inputData);
+ Map<Key,Value> map(@NotNull Data inputData);
}
*
* Use carefully, because indexing large files may influence index update speed dramatically.
*
- * @see com.intellij.openapi.vfs.PersistentFSConstants#MAX_INTELLISENSE_FILESIZE
+ * @see com.intellij.openapi.vfs.PersistentFSConstants#getMaxIntellisenseFileSize()
*/
@NotNull
public Collection<FileType> getFileTypesWithSizeLimitNotApplicable() {
private final DataIndexer<IdIndexEntry, Integer, FileContent> myIndexer = new DataIndexer<IdIndexEntry, Integer, FileContent>() {
@Override
@NotNull
- public Map<IdIndexEntry, Integer> map(final FileContent inputData) {
+ public Map<IdIndexEntry, Integer> map(@NotNull final FileContent inputData) {
final FileTypeIdIndexer indexer = IdTableBuilding.getFileTypeIndexer(inputData.getFileType());
if (indexer != null) {
return indexer.map(inputData);
/*
- * Copyright 2000-2012 JetBrains s.r.o.
+ * Copyright 2000-2014 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.
public static class PlainTextIndexer extends FileTypeIdIndexer {
@Override
@NotNull
- public Map<IdIndexEntry, Integer> map(final FileContent inputData) {
+ public Map<IdIndexEntry, Integer> map(@NotNull final FileContent inputData) {
final IdDataConsumer consumer = new IdDataConsumer();
final CharSequence chars = inputData.getContentAsText();
scanWords(new ScanWordProcessor() {
@Override
@NotNull
- public Map<IdIndexEntry, Integer> map(final FileContent inputData) {
+ public Map<IdIndexEntry, Integer> map(@NotNull final FileContent inputData) {
final CharSequence chars = inputData.getContentAsText();
final char[] charsArray = CharArrayUtil.fromSequenceWithoutCopying(chars);
final IdDataConsumer consumer = new IdDataConsumer();
/*
- * Copyright 2000-2009 JetBrains s.r.o.
+ * Copyright 2000-2014 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.
@Override
@NotNull
- public final Map<IdIndexEntry,Integer> map(final FileContent inputData) {
+ public final Map<IdIndexEntry,Integer> map(@NotNull final FileContent inputData) {
return BaseFilterLexerUtil.scanContent(inputData, this).idMap;
}
}
/*
- * Copyright 2000-2009 JetBrains s.r.o.
+ * Copyright 2000-2014 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.
IdAndToDoScannerBasedOnFilterLexer {
@Override
@NotNull
- public Map<TodoIndexEntry,Integer> map(final FileContent inputData) {
+ public Map<TodoIndexEntry,Integer> map(@NotNull final FileContent inputData) {
return BaseFilterLexerUtil.scanContent(inputData, this).todoMap;
}
}
*/
public class FileTypeIndex extends ScalarIndexExtension<FileType>
implements FileBasedIndex.InputFilter, KeyDescriptor<FileType>, DataIndexer<FileType, Void, FileContent> {
- private final EnumeratorStringDescriptor myEnumeratorStringDescriptor = new EnumeratorStringDescriptor();
+ private static final EnumeratorStringDescriptor ENUMERATOR_STRING_DESCRIPTOR = new EnumeratorStringDescriptor();
- public static Collection<VirtualFile> getFiles(FileType fileType, GlobalSearchScope scope) {
+ @NotNull
+ public static Collection<VirtualFile> getFiles(@NotNull FileType fileType, @NotNull GlobalSearchScope scope) {
return FileBasedIndex.getInstance().getContainingFiles(NAME, fileType, scope);
}
@Override
public void save(@NotNull DataOutput out, FileType value) throws IOException {
- myEnumeratorStringDescriptor.save(out, value.getName());
+ ENUMERATOR_STRING_DESCRIPTOR.save(out, value.getName());
}
@Override
public FileType read(@NotNull DataInput in) throws IOException {
- String read = myEnumeratorStringDescriptor.read(in);
+ String read = ENUMERATOR_STRING_DESCRIPTOR.read(in);
return myFileTypeManager.findFileTypeByName(read);
}
@NotNull
@Override
- public Map<FileType, Void> map(FileContent inputData) {
+ public Map<FileType, Void> map(@NotNull FileContent inputData) {
return Collections.singletonMap(inputData.getFileType(), null);
}
private static class MyDataIndexer implements DataIndexer<String, Void, FileContent> {
@Override
@NotNull
- public Map<String, Void> map(final FileContent inputData) {
+ public Map<String, Void> map(@NotNull final FileContent inputData) {
return Collections.singletonMap(inputData.getFileName(), null);
}
}
/*
- * Copyright 2000-2009 JetBrains s.r.o.
+ * Copyright 2000-2014 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.
@Override
@NotNull
- public final Map<Integer, V> map(FileContent inputData) {
+ public final Map<Integer, V> map(@NotNull FileContent inputData) {
if (inputData == null) {
return Collections.emptyMap();
}
/*
- * Copyright 2000-2009 JetBrains s.r.o.
+ * Copyright 2000-2014 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.
}
@Override
- public String getCharset(@NotNull VirtualFile file, byte[] content) {
+ public String getCharset(@NotNull VirtualFile file, @NotNull byte[] content) {
return null;
}
}
return new DataIndexer<Integer, Void, FileContent>() {
@Override
@NotNull
- public Map<Integer, Void> map(FileContent inputData) {
+ public Map<Integer, Void> map(@NotNull FileContent inputData) {
final Map<Integer, Void> result = new THashMap<Integer, Void>();
TIntHashSet built = TrigramBuilder.buildTrigram(inputData.getContentAsText());
built.forEach(new TIntProcedure() {
return new DataIndexer<Integer, Void, FileContent>() {
@NotNull
@Override
- public Map<Integer, Void> map(FileContent inputData) {
+ public Map<Integer, Void> map(@NotNull FileContent inputData) {
final FileType fileType = inputData.getFileType();
if (!detectors.containsKey(fileType)) {
return Collections.emptyMap();
/*
- * Copyright 2000-2011 JetBrains s.r.o.
+ * Copyright 2000-2014 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.
}
@Override
- public String getCharset(@NotNull VirtualFile file, byte[] content) {
+ public String getCharset(@NotNull VirtualFile file, @NotNull byte[] content) {
return null;
}
};
return new DataIndexer<Key, List<FileIncludeInfoImpl>, FileContent>() {
@Override
@NotNull
- public Map<Key, List<FileIncludeInfoImpl>> map(FileContent inputData) {
+ public Map<Key, List<FileIncludeInfoImpl>> map(@NotNull FileContent inputData) {
Map<Key, List<FileIncludeInfoImpl>> map = new FactoryMap<Key, List<FileIncludeInfoImpl>>() {
@Override
/*
- * Copyright 2000-2010 JetBrains s.r.o.
+ * Copyright 2000-2014 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.
}
@Override
- public String getCharset(@NotNull VirtualFile file, byte[] content) {
+ public String getCharset(@NotNull VirtualFile file, @NotNull byte[] content) {
return CharsetToolkit.UTF8;
}
}
+/*
+ * Copyright 2000-2014 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.util.indexing;
-import com.intellij.openapi.application.AccessToken;
import com.intellij.openapi.application.ApplicationManager;
-import com.intellij.openapi.application.ReadAction;
import com.intellij.openapi.util.Computable;
+import org.jetbrains.annotations.NotNull;
+import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
class TaskQueue {
private final AtomicInteger myDoWorkRequest = new AtomicInteger();
private final AtomicInteger myUpdatesCount = new AtomicInteger();
- private final LinkedBlockingQueue<Runnable> myPendingWriteRequestsQueue = new LinkedBlockingQueue<Runnable>();
- private final LinkedBlockingQueue<Runnable> myTimestampUpdates = new LinkedBlockingQueue<Runnable>();
+ private final BlockingQueue<Runnable> myPendingWriteRequestsQueue = new LinkedBlockingQueue<Runnable>();
+ private final BlockingQueue<Runnable> myTimestampUpdates = new LinkedBlockingQueue<Runnable>();
private final int myLimit;
private final int myStealLimit;
private final int myTimeStampUpdateSizeLimit;
myTimeStampUpdateSizeLimit = 32;
}
- void submit(final Computable<Boolean> update, final Runnable successRunnable) {
+ void submit(@NotNull final Computable<Boolean> update, @NotNull final Runnable successRunnable) {
int currentTasksCount = myUpdatesCount.incrementAndGet();
myPendingWriteRequestsQueue.add(new Runnable() {
}
}
- private void applyTimeStamps(int max) {
- Runnable runnable = myTimestampUpdates.poll();
+ private void applyTimeStamps(final int max) {
+ final Runnable runnable = myTimestampUpdates.poll();
if (runnable == null) return;
- int updates = 0;
- AccessToken accessToken = ReadAction.start();
- try {
- while(runnable != null) {
- runnable.run();
- if (++updates == max) break;
- runnable = myTimestampUpdates.poll();
+ ApplicationManager.getApplication().runReadAction(new Runnable() {
+ @Override
+ public void run() {
+ int updates = 0;
+ for (Runnable r = runnable; r != null; r = myTimestampUpdates.poll()) {
+ r.run();
+ if (++updates == max) break;
+ }
}
- } finally {
- accessToken.finish();
- }
+ });
}
public void ensureUpToDate() {
if (runnable != null) runnable.run();
}
applyTimeStamps(Integer.MAX_VALUE);
- } catch (Exception e) {
+ }
+ catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
/*
- * Copyright 2000-2013 JetBrains s.r.o.
+ * Copyright 2000-2014 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.
}
@Override
- public String getCharset(@NotNull VirtualFile file, final byte[] content) {
+ public String getCharset(@NotNull VirtualFile file, @NotNull final byte[] content) {
return CharsetToolkit.UTF8;
}
}
/*
- * Copyright 2000-2009 JetBrains s.r.o.
+ * Copyright 2000-2014 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.
void consume(@NotNull FileType fileType);
- void consume(@NotNull FileType fileType, @NonNls final String extensions);
+ void consume(@NotNull FileType fileType, @NonNls String extensions);
- void consume(@NotNull FileType fileType, final FileNameMatcher... matchers);
+ void consume(@NotNull FileType fileType, @NotNull FileNameMatcher... matchers);
@Nullable
FileType getStandardFileTypeByName(@NonNls @NotNull String name);
/*
- * Copyright 2000-2012 JetBrains s.r.o.
+ * Copyright 2000-2014 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.
return false;
}
- public String getCharset(@NotNull VirtualFile file, byte[] content) {
+ public String getCharset(@NotNull VirtualFile file, @NotNull byte[] content) {
return null;
}
/*
- * Copyright 2000-2009 JetBrains s.r.o.
+ * Copyright 2000-2014 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.
return false;
}
- public String getCharset(@NotNull VirtualFile file, final byte[] content) {
+ public String getCharset(@NotNull VirtualFile file, @NotNull final byte[] content) {
return null;
}
@NotNull
ComponentPopupBuilder setMinSize(Dimension minSize);
+ /**
+ * Use this method to customize shape of popup window (e.g. to use bounded corners).
+ */
+ @SuppressWarnings("UnusedDeclaration")//used in 'Presentation Assistant' plugin
+ @NotNull
+ ComponentPopupBuilder setMaskProvider(MaskProvider maskProvider);
+
@NotNull
ComponentPopupBuilder setAlpha(float alpha);
/*
- * Copyright 2000-2009 JetBrains s.r.o.
+ * Copyright 2000-2014 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.
}
@Nullable
- public DataInputStream readAttribute(VirtualFile file) {
+ public DataInputStream readAttribute(@NotNull VirtualFile file) {
DataInputStream stream = ManagingFS.getInstance().readAttribute(file, this);
if (stream != null) {
try {
return stream;
}
- public DataOutputStream writeAttribute(VirtualFile file) {
+ @NotNull
+ public DataOutputStream writeAttribute(@NotNull VirtualFile file) {
final DataOutputStream stream = ManagingFS.getInstance().writeAttribute(file, this);
try {
DataInputOutputUtil.writeINT(stream, myVersion);
/*
- * Copyright 2000-2013 JetBrains s.r.o.
+ * Copyright 2000-2014 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.
if (intersection.isEmpty()) continue;
final int sq1 = intersection.width * intersection.height;
final int sq2 = bounds.width * bounds.height;
- return (double)sq1 / (double)sq2 > 0.1;
+ double visibleFraction = (double)sq1 / (double)sq2;
+ if (visibleFraction > 0.1) {
+ return true;
+ }
}
return false;
}
/*
- * Copyright 2000-2009 JetBrains s.r.o.
+ * Copyright 2000-2014 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.
*/
package com.intellij.ide.actions;
-import com.intellij.openapi.actionSystem.*;
+import com.intellij.openapi.actionSystem.AnActionEvent;
+import com.intellij.openapi.actionSystem.DataContext;
+import com.intellij.openapi.actionSystem.DefaultActionGroup;
+import com.intellij.openapi.actionSystem.Separator;
import com.intellij.openapi.editor.colors.EditorColorsManager;
import com.intellij.openapi.editor.colors.EditorColorsScheme;
import com.intellij.openapi.editor.colors.impl.EditorColorsManagerImpl;
import com.intellij.openapi.editor.colors.impl.EditorColorsSchemeImpl;
import com.intellij.openapi.options.SharedScheme;
+import com.intellij.openapi.project.DumbAwareAction;
import com.intellij.openapi.project.Project;
import org.jetbrains.annotations.NotNull;
final EditorColorsScheme current,
final EditorColorsScheme scheme,
final boolean addScheme) {
- group.add(new AnAction(scheme.getName(), "", scheme == current ? ourCurrentAction : ourNotCurrentAction) {
+ group.add(new DumbAwareAction(scheme.getName(), "", scheme == current ? ourCurrentAction : ourNotCurrentAction) {
public void actionPerformed(AnActionEvent e) {
if (addScheme) {
EditorColorsManager.getInstance().addColorsScheme(scheme);
/*
- * Copyright 2000-2012 JetBrains s.r.o.
+ * Copyright 2000-2014 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.
public static class Left extends TabsPlacementAction {int getPlace() {return SwingConstants.LEFT;}}
public static class Bottom extends TabsPlacementAction {int getPlace() {return SwingConstants.BOTTOM;}}
public static class Right extends TabsPlacementAction {int getPlace() {return SwingConstants.RIGHT;}}
+ public static class None extends TabsPlacementAction {int getPlace() {return UISettings.TABS_NONE;}}
}
--- /dev/null
+/*
+ * Copyright 2000-2014 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.ide.errorTreeView;
+
+import com.intellij.ui.CustomizeColoredTreeCellRenderer;
+import com.intellij.ui.SimpleColoredComponent;
+
+import javax.swing.*;
+import java.awt.*;
+
+/**
+ * @author Vladislav.Soroka
+ * @since 3/25/14
+ */
+public abstract class CustomizeColoredTreeCellRendererReplacement extends CustomizeColoredTreeCellRenderer {
+ @Override
+ public final void customizeCellRenderer(SimpleColoredComponent renderer,
+ JTree tree,
+ Object value,
+ boolean selected,
+ boolean expanded,
+ boolean leaf,
+ int row,
+ boolean hasFocus) {
+ }
+
+ public abstract Component getTreeCellRendererComponent(JTree tree,
+ Object value,
+ boolean selected,
+ boolean expanded,
+ boolean leaf,
+ int row,
+ boolean hasFocus);
+}
--- /dev/null
+/*
+ * Copyright 2000-2014 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.ide.errorTreeView;
+
+import com.intellij.ui.CustomizeColoredTreeCellRenderer;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+import javax.swing.tree.TreeCellEditor;
+
+/**
+ * @author Vladislav.Soroka
+ * @since 3/26/14
+ */
+public interface EditableMessageElement {
+ @NotNull
+ TreeCellEditor getRightSelfEditor();
+ @Nullable
+ CustomizeColoredTreeCellRenderer getLeftSelfRenderer();
+
+ boolean startEditingOnMouseMove();
+}
}
}
+ public void addNavigatableMessage(@NotNull String groupName,
+ @NotNull NavigatableMessageElement navigatableMessageElement) {
+ synchronized (myLock) {
+ List<NavigatableMessageElement> elements = myGroupNameToMessagesMap.get(groupName);
+ if (elements == null) {
+ elements = new ArrayList<NavigatableMessageElement>();
+ myGroupNameToMessagesMap.put(groupName, elements);
+ }
+ if (!myGroupNameToElementMap.containsKey(groupName)) {
+ myGroupNames.add(groupName);
+ myGroupNameToElementMap.put(groupName, navigatableMessageElement.getParent());
+ }
+ elements.add(navigatableMessageElement);
+ }
+ }
+
private void addSimpleMessage(@NotNull ErrorTreeElementKind kind, final String[] text, final Object data) {
addSimpleMessageElement(new SimpleMessageElement(kind, text, data));
}
--- /dev/null
+/*
+ * Copyright 2000-2014 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.ide.errorTreeView;
+
+import com.intellij.openapi.project.Project;
+import org.jetbrains.annotations.Nullable;
+
+public class NewEditableErrorTreeViewPanel extends NewErrorTreeViewPanel {
+
+
+ public NewEditableErrorTreeViewPanel(Project project, String helpId) {
+ this(project, helpId, true);
+ }
+
+ public NewEditableErrorTreeViewPanel(Project project, String helpId, boolean createExitAction) {
+ this(project, helpId, createExitAction, true);
+ }
+
+ public NewEditableErrorTreeViewPanel(Project project, String helpId, boolean createExitAction, boolean createToolbar) {
+ this(project, helpId, createExitAction, createToolbar, null);
+ }
+
+ public NewEditableErrorTreeViewPanel(Project project,
+ String helpId,
+ boolean createExitAction,
+ boolean createToolbar,
+ @Nullable Runnable rerunAction) {
+ super(project, helpId, createExitAction, createToolbar, rerunAction);
+ NewErrorTreeEditor.install(myTree);
+ }
+}
--- /dev/null
+/*
+ * Copyright 2000-2014 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.ide.errorTreeView;
+
+import com.intellij.ui.CustomizeColoredTreeCellRenderer;
+import com.intellij.ui.JBColor;
+import com.intellij.ui.LoadingNode;
+import com.intellij.ui.treeStructure.Tree;
+import com.intellij.util.ui.UIUtil;
+import com.intellij.util.ui.tree.WideSelectionTreeUI;
+import org.jetbrains.annotations.Nullable;
+
+import javax.swing.*;
+import javax.swing.tree.DefaultMutableTreeNode;
+import javax.swing.tree.TreeCellEditor;
+import javax.swing.tree.TreeCellRenderer;
+import javax.swing.tree.TreePath;
+import java.awt.*;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseMotionListener;
+import java.util.EventObject;
+
+/**
+ * @author Vladislav.Soroka
+ * @since 3/25/14
+ */
+public class NewErrorTreeEditor extends AbstractCellEditor implements TreeCellEditor, MouseMotionListener {
+
+ public static void install(Tree tree) {
+ NewErrorTreeEditor treeEditor = new NewErrorTreeEditor(tree);
+ tree.setCellEditor(treeEditor);
+ tree.addMouseMotionListener(treeEditor);
+ tree.setEditable(true);
+ }
+
+ private final MyWrapperEditor myWrapperEditor;
+ private final CallingBackColoredTreeCellRenderer myColoredTreeCellRenderer;
+ private final CellEditorDelegate myRightCellRenderer;
+ private final JTree myTree;
+
+ private NewErrorTreeEditor(JTree tree) {
+ myTree = tree;
+ myRightCellRenderer = new CellEditorDelegate();
+ myColoredTreeCellRenderer = new CallingBackColoredTreeCellRenderer();
+ myWrapperEditor = new MyWrapperEditor(myColoredTreeCellRenderer, myRightCellRenderer);
+ }
+
+ @Override
+ public boolean isCellEditable(EventObject e) {
+ Object node;
+ if(e instanceof MouseEvent) {
+ final Point point = ((MouseEvent)e).getPoint();
+ final TreePath location = myTree.getClosestPathForLocation(point.x, point.y);
+ node = location.getLastPathComponent();
+ } else {
+ node = myTree.getLastSelectedPathComponent();
+ }
+ final ErrorTreeElement element = getElement(node);
+ return element instanceof EditableMessageElement;
+ }
+
+ @Override
+ public Component getTreeCellEditorComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row) {
+ final ErrorTreeElement element = getElement(value);
+ if (element instanceof EditableMessageElement) {
+ EditableMessageElement editableMessageElement = (EditableMessageElement)element;
+ final CustomizeColoredTreeCellRenderer leftSelfRenderer = editableMessageElement.getLeftSelfRenderer();
+ final TreeCellEditor rightSelfEditor = editableMessageElement.getRightSelfEditor();
+ myColoredTreeCellRenderer.setCurrentCallback(leftSelfRenderer);
+ myRightCellRenderer.setCurrentCallback(rightSelfEditor);
+ return myWrapperEditor.getTreeCellEditorComponent(tree, value, selected, expanded, leaf, row);
+ }
+ return myTree.getCellRenderer().getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, true);
+ }
+
+ @Override
+ public Object getCellEditorValue() {
+ return null;
+ }
+
+ @Override
+ public void mouseDragged(MouseEvent e) {
+ }
+
+ @Override
+ public void mouseMoved(MouseEvent e) {
+ JTree tree = (JTree)e.getSource();
+ int selRow = tree.getRowForLocation(e.getX(), e.getY());
+ if (selRow != -1) {
+ TreePath treePath = tree.getPathForRow(selRow);
+ if (treePath != null && treePath != tree.getEditingPath()) {
+ final ErrorTreeElement element = getElement(treePath.getLastPathComponent());
+ if (element instanceof EditableMessageElement && ((EditableMessageElement)element).startEditingOnMouseMove()) {
+ if (!tree.isRowSelected(selRow)) {
+ tree.setSelectionRow(selRow);
+ }
+ tree.startEditingAtPath(treePath);
+ }
+ }
+ }
+ }
+
+ @Nullable
+ private static ErrorTreeElement getElement(@Nullable Object value) {
+ if (!(value instanceof DefaultMutableTreeNode)) return null;
+ final Object userObject = ((DefaultMutableTreeNode)value).getUserObject();
+ if (!(userObject instanceof ErrorTreeNodeDescriptor)) return null;
+ return ((ErrorTreeNodeDescriptor)userObject).getElement();
+ }
+
+ private static class MyWrapperEditor extends AbstractCellEditor implements TreeCellEditor {
+ private final TreeCellRenderer myLeft;
+ private final TreeCellEditor myRight;
+ private final JPanel myPanel;
+
+ public TreeCellRenderer getLeft() {
+ return myLeft;
+ }
+
+ public TreeCellEditor getRight() {
+ return myRight;
+ }
+
+ public MyWrapperEditor(final TreeCellRenderer left, final TreeCellEditor right) {
+ myLeft = left;
+ myRight = right;
+ myPanel = new JPanel(new BorderLayout());
+ }
+
+ public Component getTreeCellEditorComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row) {
+ myPanel.removeAll();
+ myPanel.add(myLeft.getTreeCellRendererComponent(tree, value, false, expanded, leaf, row, true), BorderLayout.WEST);
+ myPanel.add(myRight.getTreeCellEditorComponent(tree, value, selected, expanded, leaf, row), BorderLayout.EAST);
+
+ if (UIUtil.isFullRowSelectionLAF()) {
+ myPanel.setBackground(selected ? UIUtil.getTreeSelectionBackground() : null);
+ }
+ else if (tree.getUI() instanceof WideSelectionTreeUI && ((WideSelectionTreeUI)tree.getUI()).isWideSelection()) {
+ if (selected) {
+ myPanel.setBackground(UIUtil.getTreeSelectionBackground());
+ }
+ }
+ else if (selected) {
+ myPanel.setBackground(UIUtil.getTreeSelectionBackground());
+ }
+ else {
+ myPanel.setBackground(null);
+ }
+
+ if (value instanceof LoadingNode) {
+ myPanel.setForeground(JBColor.GRAY);
+ }
+ else {
+ myPanel.setForeground(tree.getForeground());
+ }
+
+ if (UIUtil.isUnderGTKLookAndFeel() ||
+ UIUtil.isUnderNimbusLookAndFeel() && selected ||
+ tree.getUI() instanceof WideSelectionTreeUI && ((WideSelectionTreeUI)tree.getUI()).isWideSelection()) {
+ myPanel.setOpaque(false);
+ }
+ return myPanel;
+ }
+
+ @Override
+ public Object getCellEditorValue() {
+ return null;
+ }
+ }
+
+
+ private static class CellEditorDelegate extends AbstractCellEditor implements TreeCellEditor {
+ private TreeCellEditor myCurrentCallback;
+
+ public Component getTreeCellEditorComponent(JTree tree,
+ Object value,
+ boolean selected,
+ boolean expanded,
+ boolean leaf,
+ int row) {
+ return myCurrentCallback.getTreeCellEditorComponent(tree, value, selected, expanded, leaf, row);
+ }
+
+ public void setCurrentCallback(final TreeCellEditor currentCallback) {
+ myCurrentCallback = currentCallback;
+ }
+
+ @Override
+ public Object getCellEditorValue() {
+ return null;
+ }
+ }
+}
boolean leaf,
int row,
boolean hasFocus) {
+ if (myCurrentCallback instanceof CustomizeColoredTreeCellRendererReplacement) {
+ return ((CustomizeColoredTreeCellRendererReplacement)myCurrentCallback)
+ .getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
+ }
+
clear();
setBackground(UIUtil.getBgFillColor(tree));
boolean leaf,
int row,
boolean hasFocus) {
+ myPanel.removeAll();
myPanel.setBackground(tree.getBackground());
myPanel.add(myLeft.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus), BorderLayout.WEST);
myPanel.add(myRight.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus), BorderLayout.EAST);
}
@NotNull
- static String calcPrefix(@Nullable ErrorTreeElement element) {
+ public static String calcPrefix(@Nullable ErrorTreeElement element) {
if(element instanceof SimpleMessageElement || element instanceof NavigatableMessageElement) {
String prefix = element.getKind().getPresentableText();
/*
- * Copyright 2000-2013 JetBrains s.r.o.
+ * Copyright 2000-2014 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.
public static JEditorPane createTipBrowser() {
JEditorPane browser = new JEditorPane();
browser.setEditable(false);
+ HTMLEditorKit editorKit = new HTMLEditorKit();
+ browser.setEditorKit(editorKit);
browser.setBackground(UIUtil.getTextFieldBackground());
browser.addHyperlinkListener(
new HyperlinkListener() {
}
}
);
- HTMLEditorKit kit;
try {
// set default CSS for plugin tips
URL resource = ResourceUtil.getResource(TipUIUtil.class, "/tips/css/", UIUtil.isUnderDarcula() ? "tips_darcula.css" : "tips.css");
- final StyleSheet styleSheet = new StyleSheet();
- styleSheet.loadRules(new InputStreamReader(resource.openStream()), resource);
- kit = new HTMLEditorKit() {
- @Override
- public StyleSheet getStyleSheet() {
- return styleSheet;
- }
- };
+ StyleSheet sheet = new StyleSheet();
+ sheet.loadRules(new InputStreamReader(resource.openStream()), resource);
+ editorKit.setStyleSheet(sheet);
}
catch (IOException ignored) {
- kit = new HTMLEditorKit();
}
- browser.setEditorKit(kit);
+
return browser;
}
}
/*
- * Copyright 2000-2009 JetBrains s.r.o.
+ * Copyright 2000-2014 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.
return true;
}
- public String getCharset(@NotNull VirtualFile file, final byte[] content) {
+ public String getCharset(@NotNull VirtualFile file, @NotNull final byte[] content) {
return null;
}
}
\ No newline at end of file
throw new IOException(VfsBundle.message("jar.modification.not.supported.error", vFile.getUrl()));
}
+ @Override
+ public boolean markNewFilesAsDirty() {
+ return true;
+ }
+
@Override
public int getRank() {
return 2;
+++ /dev/null
-/*
- * Copyright 2000-2014 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.wm.impl;
-
-import com.intellij.concurrency.JobScheduler;
-import com.intellij.openapi.Disposable;
-import com.intellij.openapi.editor.impl.EditorComponentImpl;
-import com.intellij.openapi.editor.impl.EditorImpl;
-import com.intellij.openapi.util.Disposer;
-import com.intellij.openapi.util.registry.Registry;
-import com.intellij.ui.ColorUtil;
-import com.intellij.ui.JBColor;
-import com.intellij.util.Alarm;
-import com.intellij.util.containers.HashMap;
-
-import javax.swing.*;
-import java.awt.*;
-import java.awt.event.AWTEventListener;
-import java.awt.event.KeyEvent;
-import java.awt.event.MouseEvent;
-import java.awt.geom.AffineTransform;
-import java.awt.geom.Ellipse2D;
-import java.awt.image.BufferedImage;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.Random;
-import java.util.concurrent.ScheduledFuture;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicBoolean;
-
-class FogLayer extends JComponent implements AWTEventListener, Runnable, Disposable {
- private static final int MAX_SPOT_NUMBER = 20000;
- private static final int LAYER_NUMBER = 5;
- private static final int INIT_DELAY = 5000;
- private static final int IDLE_THRESHOLD = 20000;
- private static final int FADE_CYCLE = 20000;
- private static final int EYE_SIZE = 50;
- private static final int REPAINT_INTERVAL = 66;//ms
- private static final Color BASE = Color.DARK_GRAY;
- private static final Color D_BASE = Color.LIGHT_GRAY;
- private static final Color FOG = new JBColor(ColorUtil.toAlpha(BASE, 1), ColorUtil.toAlpha(D_BASE, 1));
- private static final double MIN_ROTATION_RATE = .0016;
- private static final double MAX_ROTATION_RATE = .002;
- private static final double MIN_SUBROTATION_RATE = 0.01;
- private static final double MAX_SUBROTATION_RATE = 0.02;
- private static final int SPOT_RADIUS_FACTOR = 150;
-
-
- private final Random myRandom = new Random();
- private final Alarm myAlarm;
- private final AtomicBoolean myInitialized = new AtomicBoolean(false);
- private final AtomicBoolean myDisposed = new AtomicBoolean(false);
-
- private BufferedImage myTexture;
- private HashMap<Integer, BufferedImage> myCache = new HashMap<Integer, BufferedImage>();
-
-
- private double[] myTextureAngle = new double[LAYER_NUMBER];
- private double[] myTextureRate = new double[LAYER_NUMBER];//rotation rate
-
- private double[] myCenterAngle = new double[LAYER_NUMBER];
- private double[] myCenterRate = new double[LAYER_NUMBER];
- private long myLastTime = System.currentTimeMillis();
- private Point myPoint = null;
- private long myLastPaintTime = -1;
- private long myStartPaintTime = -1;
-
- private int myEffectiveRadius;
- private final ScheduledFuture<?> myFuture;
-
- static boolean isAvailable() {
- return (new SimpleDateFormat("dd/MM").format(new Date()).equals("01/04") || Boolean.getBoolean("eggs"))
- && !Registry.is("ui.no.bangs.and.whistles", false) && !Boolean.getBoolean("noeggs")
- && Runtime.getRuntime().availableProcessors() >= 4;
- }
-
-
- FogLayer(Disposable parent) {
- setOpaque(false);
- myAlarm = new Alarm(Alarm.ThreadToUse.POOLED_THREAD, this);
- myFuture = JobScheduler.getScheduler().scheduleWithFixedDelay(new Runnable() {
- @Override
- public void run() {
- if (System.currentTimeMillis() - myLastTime >= IDLE_THRESHOLD &&
- myPoint != null &&
- myAlarm.isEmpty() &&
- myInitialized.get() &&
- !myDisposed.get()) {
- repaint();
- }
- }
- }, (long)INIT_DELAY, (long)REPAINT_INTERVAL, TimeUnit.MILLISECONDS);
- Disposer.register(parent, this);
- }
-
- @Override
- public void dispose() {
- if (myDisposed.get()) return;
- myFuture.cancel(true);
- myDisposed.set(true);
- }
-
- @Override
- public void addNotify() {
- super.addNotify();
- Toolkit.getDefaultToolkit().addAWTEventListener(this,
- AWTEvent.KEY_EVENT_MASK |
- AWTEvent.MOUSE_EVENT_MASK |
- AWTEvent.MOUSE_MOTION_EVENT_MASK
- );
- }
-
- @Override
- public void removeNotify() {
- super.removeNotify();
- Toolkit.getDefaultToolkit().removeAWTEventListener(this);
- }
-
- //update textures
- @Override
- public void run() {
- if (myPoint == null || myDisposed.get()) return;
- if (Runtime.getRuntime().maxMemory() - Runtime.getRuntime().totalMemory() + Runtime.getRuntime().freeMemory() < 1L << 25) return;
- int width = getWidth();
- int height = getHeight();
- myEffectiveRadius = (int)(Math.max(
- Math.max(myPoint.distance(0, 0), myPoint.distance(width, 0)),
- Math.max(myPoint.distance(0, height), myPoint.distance(width, height)))) + 2 * EYE_SIZE;
-
- for (int i = 0; i < LAYER_NUMBER; i++) {
- myTextureAngle[i] = getRandomDouble(0, 2 * Math.PI);
- myTextureRate[i] = getRandomDouble(MIN_ROTATION_RATE, MAX_ROTATION_RATE) * ((myEffectiveRadius < 1000) ? 2 : 1);
- myCenterAngle[i] = getRandomDouble(0, 2 * Math.PI);
- myCenterRate[i] = -getRandomDouble(MIN_SUBROTATION_RATE, MAX_SUBROTATION_RATE) * (myRandom.nextDouble() > .5 ? 1 : -1);
- }
- myTexture = GraphicsEnvironment.getLocalGraphicsEnvironment()
- .getDefaultScreenDevice().getDefaultConfiguration()
- .createCompatibleImage(2 * myEffectiveRadius, 2 * myEffectiveRadius, Transparency.TRANSLUCENT);
- myLastPaintTime = -1;
- Graphics2D graphics = (Graphics2D)myTexture.getGraphics();
- for (int j = 0; j < MAX_SPOT_NUMBER; j++) {
- double v = (1 + Math.cos(myRandom.nextDouble() * Math.PI)) / 2;
- v = Math.pow(v, .18);
- double spotDistance = 2 * EYE_SIZE + (myEffectiveRadius - 2 * EYE_SIZE) * v;
- double distanceRatio = spotDistance / myEffectiveRadius;
- double minR = 30;
- double maxR = Math.max(Math.sqrt(distanceRatio) * SPOT_RADIUS_FACTOR, minR);
- int spotSize = (int)getRandomDouble(minR, maxR);
- spotSize -= spotSize % 4;
- double spotPhi = getRandomDouble(0, 2 * Math.PI);
- BufferedImage ellipseImage = myCache.get(spotSize);
- if (ellipseImage == null) {
- myCache.put(spotSize, ellipseImage = GraphicsEnvironment.getLocalGraphicsEnvironment()
- .getDefaultScreenDevice().getDefaultConfiguration()
- .createCompatibleImage(spotSize, spotSize, Transparency.TRANSLUCENT));
- Graphics2D g2d = (Graphics2D)ellipseImage.getGraphics();
- g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
- g2d.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
- g2d.setColor(FOG);
- g2d.fill(new Ellipse2D.Double(0, 0, spotSize, spotSize)
- );
- }
- graphics.drawImage(ellipseImage, (int)(myEffectiveRadius + spotDistance * Math.cos(spotPhi) - spotSize / 2),
- (int)(myEffectiveRadius - spotDistance * Math.sin(spotPhi) - spotSize / 2), this);
- }
- myCache.clear();
- myStartPaintTime = -1;
- myInitialized.set(true);
- }
-
- private double getRandomDouble(double min, double max) {
- return min + myRandom.nextDouble() * (max - min);
- }
-
- @Override
- public void reshape(int x, int y, int w, int h) {
- int width = getWidth();
- int height = getHeight();
- super.reshape(x, y, w, h);
- if (width != w || height != h) {
- scheduleUpdate();
- }
- }
-
- @Override
- public void eventDispatched(AWTEvent event) {
- myLastTime = System.currentTimeMillis();
- myInitialized.set(false);
- if (event instanceof KeyEvent) {
- Component component = ((KeyEvent)event).getComponent();
- if (component instanceof EditorComponentImpl) {
- EditorImpl editor = ((EditorComponentImpl)component).getEditor();
- Point position = editor.visualPositionToXY(editor.getCaretModel().getVisualPosition());
- myPoint = SwingUtilities.convertPoint(component, position, this);
- }
- else {
- Point position = new Point(component.getWidth() / 2, component.getHeight() / 2);
- myPoint = SwingUtilities.convertPoint(component, position, this);
- }
- }
- if (event instanceof MouseEvent) {
- if (event.getID() == MouseEvent.MOUSE_EXITED) {
- myPoint = null;
- }
- else {
- Point point = ((MouseEvent)event).getPoint();
- myPoint = SwingUtilities.convertPoint(((MouseEvent)event).getComponent(), point, this);
- }
- }
- if (myPoint != null) {
- myPoint.x = Math.min(getWidth(), Math.max(0, myPoint.x));
- myPoint.y = Math.min(getHeight(), Math.max(0, myPoint.y));
- scheduleUpdate();
- }
- }
-
- private void scheduleUpdate() {
- if (myDisposed.get()) return;
- myInitialized.set(false);
- repaint();
- myTexture = null;
- myCache.clear();
- myAlarm.cancelAllRequests();
- myAlarm.addRequest(this, INIT_DELAY);
- }
-
- @Override
- protected void paintComponent(Graphics g) {
- long now = System.currentTimeMillis();
- if (now - myLastTime < IDLE_THRESHOLD || myPoint == null || !myAlarm.isEmpty() || !myInitialized.get()) {
- return;
- }
- Window window = SwingUtilities.getWindowAncestor(this);
- if (window == null || !window.isActive()) {
- myPoint = null;
- return;
- }
- if (myLastPaintTime == -1) myLastPaintTime = now - REPAINT_INTERVAL;
- if (myStartPaintTime == -1) myStartPaintTime = now;
-
- long passedTime = now - myLastPaintTime;
-
- for (int i = 0; i < LAYER_NUMBER; i++) {
- myTextureAngle[i] += (myTextureRate[i] * passedTime) / REPAINT_INTERVAL;
- myCenterAngle[i] += (myCenterRate[i] * passedTime) / REPAINT_INTERVAL;
- }
-
- double linearProgress = (double)(myLastPaintTime - myStartPaintTime) / FADE_CYCLE;
- if (linearProgress > 1) {
- myPoint = null;
- repaint();
- return;
- }
- double progress = (1 - Math.cos(2 * Math.PI * linearProgress)) / 2;
-
-
- Graphics2D g2d = (Graphics2D)g.create();
- try {
- g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
- g2d.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
- AffineTransform pointTransform = AffineTransform.getTranslateInstance(myPoint.x, myPoint.y);
- AffineTransform oldTransform = g2d.getTransform();
- pointTransform.concatenate(oldTransform);
- float textureProgress = (float)(progress < 1 ? Math.sqrt(progress) * (LAYER_NUMBER + 1) : LAYER_NUMBER);
- int textureNumber = (int)textureProgress;
- float localProgress = textureProgress - textureNumber;
- for (int i = 0; i < textureNumber; i++) {
- AffineTransform t = AffineTransform.getRotateInstance(myTextureAngle[i]);
- t.concatenate(
- AffineTransform.getTranslateInstance(EYE_SIZE * Math.cos(myCenterAngle[i]), -EYE_SIZE * Math.sin(myCenterAngle[i])));
- t.preConcatenate(pointTransform);
- g2d.setTransform(t);
- if (i == textureNumber - 1 && progress < 1) {
- g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, localProgress));
- }
- g2d.drawImage(myTexture, -myEffectiveRadius, -myEffectiveRadius, this);
- }
- }
- finally {
- g2d.dispose();
- }
- myLastPaintTime = now;
- }
-
- @Override
- public String toString() {
- return "Day#16161";
- }
-}
super.setGlassPane(glass);
}
- @Override
- public void setLayeredPane(final JLayeredPane layered) {
- super.setLayeredPane(layered);
- //noinspection UnnecessaryFullyQualifiedName
- if (FogLayer.isAvailable()) {
- //noinspection SSBasedInspection
- SwingUtilities.invokeLater(new Runnable() {
- @Override
- public void run() {
- layered.add(new FogLayer(myApplication), new Integer(JLayeredPane.DRAG_LAYER + 1));
- }
- });
- }
- }
-
/**
* Invoked when enclosed frame is being shown.
import com.intellij.openapi.Disposable;
import com.intellij.openapi.actionSystem.ex.ActionManagerEx;
import com.intellij.openapi.application.Application;
-import com.intellij.openapi.application.ApplicationInfo;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ex.ApplicationInfoEx;
import com.intellij.openapi.components.*;
/**
* invoked by reflection
- * @param dataManager
- * @param applicationInfoEx
- * @param actionManager
- * @param uiSettings
*/
public WindowManagerImpl(DataManager dataManager,
ApplicationInfoEx applicationInfoEx,
myScreenBounds = screenBounds;
myActivationListener = new WindowAdapter() {
+ @Override
public void windowActivated(WindowEvent e) {
Window activeWindow = e.getWindow();
if (activeWindow instanceof IdeFrameImpl) { // must be
}
}
+ @Override
@NotNull
public IdeFrameImpl[] getAllProjectFrames() {
final Collection<IdeFrameImpl> ideFrames = myProject2Frame.values();
myEventDispatcher.addListener(listener);
}
+ @Override
public void removeListener(final WindowManagerListener listener) {
myEventDispatcher.removeListener(listener);
}
+ @Override
public final Rectangle getScreenBounds() {
return myScreenBounds;
}
return null;
}
+ @Override
public final boolean isInsideScreenBounds(final int x, final int y, final int width) {
return
x >= myScreenBounds.x + 50 - width &&