Merge remote-tracking branch 'origin/master'

This commit is contained in:
Vladimir.Orlov
2015-11-17 15:14:56 +03:00
28 changed files with 409 additions and 310 deletions
@@ -15,6 +15,7 @@
*/
package com.intellij.codeInsight.daemon.impl.analysis;
import com.intellij.codeInsight.AnnotationTargetUtil;
import com.intellij.codeInsight.FileModificationService;
import com.intellij.codeInsight.daemon.JavaErrorMessages;
import com.intellij.codeInsight.daemon.impl.HighlightInfo;
@@ -212,8 +213,8 @@ public class AnnotationsHighlightUtil {
PsiClass container = getRepeatableContainer(metaAnno);
if (container != null) {
PsiAnnotation.TargetType[] targets = PsiImplUtil.getTargetsForLocation(owner);
PsiAnnotation.TargetType applicable = PsiImplUtil.findApplicableTarget(container, targets);
PsiAnnotation.TargetType[] targets = AnnotationTargetUtil.getTargetsForLocation(owner);
PsiAnnotation.TargetType applicable = AnnotationTargetUtil.findAnnotationTarget(container, targets);
if (applicable == null) {
String target = JavaErrorMessages.message("annotation.target." + targets[0]);
String message = JavaErrorMessages.message("annotation.container.not.applicable", container.getName(), target);
@@ -323,7 +324,7 @@ public class AnnotationsHighlightUtil {
if (type != null && type.accept(AnnotationReturnTypeVisitor.INSTANCE).booleanValue()) {
return null;
}
String description = JavaErrorMessages.message("annotation.invalid.annotation.member.type", type != null ? type.getPresentableText() : type);
String description = JavaErrorMessages.message("annotation.invalid.annotation.member.type", type != null ? type.getPresentableText() : null);
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(typeElement).descriptionAndTooltip(description).create();
}
@@ -344,7 +345,7 @@ public class AnnotationsHighlightUtil {
if (nameRef == null) return null;
PsiAnnotationOwner owner = annotation.getOwner();
PsiAnnotation.TargetType[] targets = PsiImplUtil.getTargetsForLocation(owner);
PsiAnnotation.TargetType[] targets = AnnotationTargetUtil.getTargetsForLocation(owner);
if (owner == null || targets.length == 0) {
String message = JavaErrorMessages.message("annotation.not.allowed.here");
return annotationError(annotation, message);
@@ -355,7 +356,7 @@ public class AnnotationsHighlightUtil {
if (info != null) return info;
}
PsiAnnotation.TargetType applicable = PsiImplUtil.findApplicableTarget(annotation, targets);
PsiAnnotation.TargetType applicable = AnnotationTargetUtil.findAnnotationTarget(annotation, targets);
if (applicable == PsiAnnotation.TargetType.UNKNOWN) return null;
if (applicable == null) {
@@ -673,9 +674,9 @@ public class AnnotationsHighlightUtil {
}
}
Set<PsiAnnotation.TargetType> repeatableTargets = PsiImplUtil.getAnnotationTargets((PsiClass)target);
Set<PsiAnnotation.TargetType> repeatableTargets = AnnotationTargetUtil.getAnnotationTargets((PsiClass)target);
if (repeatableTargets != null) {
Set<PsiAnnotation.TargetType> containerTargets = PsiImplUtil.getAnnotationTargets(container);
Set<PsiAnnotation.TargetType> containerTargets = AnnotationTargetUtil.getAnnotationTargets(container);
if (containerTargets != null && !repeatableTargets.containsAll(containerTargets)) {
return JavaErrorMessages.message("annotation.container.wide.target", container.getQualifiedName());
}
@@ -766,6 +767,7 @@ public class AnnotationsHighlightUtil {
if (field instanceof PsiEnumConstant) {
String name = ((PsiEnumConstant)field).getName();
try {
//noinspection ConstantConditions
return Enum.valueOf(RetentionPolicy.class, name);
}
catch (Exception e) {
@@ -15,6 +15,7 @@
*/
package com.intellij.codeInsight.completion;
import com.intellij.codeInsight.AnnotationTargetUtil;
import com.intellij.codeInsight.ExceptionUtil;
import com.intellij.codeInsight.completion.scope.JavaCompletionProcessor;
import com.intellij.codeInsight.lookup.LookupElement;
@@ -25,7 +26,6 @@ import com.intellij.openapi.util.text.StringUtil;
import com.intellij.patterns.ElementPattern;
import com.intellij.psi.*;
import com.intellij.psi.filters.getters.MembersGetter;
import com.intellij.psi.impl.PsiImplUtil;
import com.intellij.psi.impl.source.tree.JavaElementType;
import com.intellij.psi.util.InheritanceUtil;
import com.intellij.psi.util.PropertyUtil;
@@ -128,11 +128,11 @@ public class PreferByKindWeigher extends LookupElementWeigher {
if (psiElement().withParents(PsiJavaCodeReferenceElement.class, PsiAnnotation.class).accepts(position)) {
final PsiAnnotation annotation = PsiTreeUtil.getParentOfType(position, PsiAnnotation.class);
assert annotation != null;
final PsiAnnotation.TargetType[] targets = PsiImplUtil.getTargetsForLocation(annotation.getOwner());
final PsiAnnotation.TargetType[] targets = AnnotationTargetUtil.getTargetsForLocation(annotation.getOwner());
return new Condition<PsiClass>() {
@Override
public boolean value(PsiClass psiClass) {
return psiClass.isAnnotationType() && PsiImplUtil.findApplicableTarget(psiClass, targets) != null;
return psiClass.isAnnotationType() && AnnotationTargetUtil.findAnnotationTarget(psiClass, targets) != null;
}
};
}
@@ -342,7 +342,7 @@ public class CreateConstructorParameterFromFieldFix implements IntentionAction {
if (parameter == null) {
continue;
}
notNull(field, parameter);
NullableNotNullManager.getInstance(field.getProject()).copyNotNullAnnotation(field, parameter);
cleanupElements.add(parameter);
final PsiElement assignmentStatement = AssignFieldFromParameterAction.addFieldAssignmentStatement(project, field, parameter, editor);
if (assignmentStatement != null) {
@@ -356,14 +356,6 @@ public class CreateConstructorParameterFromFieldFix implements IntentionAction {
}
}
private static void notNull(PsiField field, PsiParameter parameter) {
final PsiAnnotation notNull = NullableNotNullManager.getInstance(field.getProject()).copyNotNullAnnotation(field);
if (notNull != null) {
//noinspection ConstantConditions
parameter.getModifierList().addBefore(notNull, null);
}
}
@Nullable
private static PsiParameter findParamByName(String newName,
PsiType type,
@@ -275,13 +275,7 @@ public class GenerateConstructorHandler extends GenerateMembersHandlerBase {
parmName = javaStyle.suggestUniqueVariableName(parmName, dummyConstructor, true);
PsiParameter parm = factory.createParameter(parmName, field.getType(), aClass);
PsiAnnotation notNull = NullableNotNullManager.getInstance(project).copyNotNullAnnotation(field);
if (notNull != null) {
PsiModifierList modifierList = parm.getModifierList();
if (modifierList != null) {
modifierList.addAfter(notNull, null);
}
}
NullableNotNullManager.getInstance(project).copyNotNullAnnotation(field, parm);
if (constructor.isVarArgs()) {
final PsiParameterList parameterList = constructor.getParameterList();
@@ -15,7 +15,9 @@
*/
package com.intellij.codeInsight.generation;
import com.intellij.codeInsight.AnnotationTargetUtil;
import com.intellij.codeInsight.ExceptionUtil;
import com.intellij.codeInsight.NullableNotNullManager;
import com.intellij.codeInsight.daemon.impl.quickfix.CreateFromUsageUtils;
import com.intellij.lang.ASTNode;
import com.intellij.openapi.diagnostic.Logger;
@@ -31,7 +33,6 @@ import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.*;
import com.intellij.psi.codeStyle.*;
import com.intellij.psi.impl.PsiImplUtil;
import com.intellij.psi.impl.light.LightTypeElement;
import com.intellij.psi.impl.source.codeStyle.JavaCodeStyleManagerImpl;
import com.intellij.psi.impl.source.tree.PsiWhiteSpaceImpl;
@@ -572,7 +573,7 @@ public class GenerateMembersUtil {
if (sourceModifierList != null && targetModifierList != null) {
JVMElementFactory factory = JVMElementFactories.requireFactory(targetParam.getLanguage(), targetParam.getProject());
for (PsiAnnotation annotation : sourceModifierList.getAnnotations()) {
if (!PsiImplUtil.isTypeAnnotation(annotation)) {
if (!AnnotationTargetUtil.isTypeAnnotation(annotation)) {
targetModifierList.add(factory.createAnnotationFromText(annotation.getText(), sourceParam));
}
}
@@ -685,19 +686,9 @@ public class GenerateMembersUtil {
}
result = (PsiMethod)CodeStyleManager.getInstance(project).reformat(result);
PsiModifierListOwner listOwner = null;
if (isGetter) {
listOwner = result;
}
else {
final PsiParameter[] parameters = result.getParameterList().getParameters();
if (parameters.length == 1) {
listOwner = parameters[0];
}
}
if (listOwner != null) {
PropertyUtil.annotateWithNullableStuff(field, listOwner);
}
PsiModifierListOwner annotationTarget = isGetter ? result : result.getParameterList().getParameters()[0];
NullableNotNullManager.getInstance(project).copyNullableOrNotNullAnnotation(field, annotationTarget);
return generatePrototype(field, result);
}
@@ -195,17 +195,7 @@ public final class FieldFromParameterUtils {
modifierList.setModifierProperty(PsiModifier.STATIC, isStatic);
modifierList.setModifierProperty(PsiModifier.FINAL, isFinal);
final NullableNotNullManager manager = NullableNotNullManager.getInstance(project);
final PsiAnnotation nullable = manager.copyNullableAnnotation(parameter);
if (nullable != null) {
modifierList.addAfter(nullable, null);
}
else if (isFinal) {
final PsiAnnotation notNull = manager.copyNotNullAnnotation(parameter);
if (notNull != null) {
modifierList.addAfter(notNull, null);
}
}
NullableNotNullManager.getInstance(project).copyNullableOrNotNullAnnotation(parameter, field);
PsiCodeBlock methodBody = method.getBody();
if (methodBody == null) return;
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2015 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.
@@ -15,6 +15,7 @@
*/
package com.intellij.psi.impl.source.codeStyle;
import com.intellij.codeInsight.AnnotationTargetUtil;
import com.intellij.lang.ASTNode;
import com.intellij.openapi.project.Project;
import com.intellij.psi.*;
@@ -154,7 +155,7 @@ public class JavaReferenceAdjuster implements ReferenceAdjuster {
PsiModifierList modifierList = PsiImplUtil.findNeighbourModifierList(ref);
if (modifierList != null) {
for (PsiAnnotation annotation : modifierList.getAnnotations()) {
if (PsiImplUtil.findApplicableTarget(annotation, PsiAnnotation.TargetType.TYPE_USE) != null) {
if (AnnotationTargetUtil.findAnnotationTarget(annotation, PsiAnnotation.TargetType.TYPE_USE) != null) {
return true;
}
}
@@ -18,7 +18,7 @@ package com.intellij.refactoring.inheritanceToDelegation;
import com.intellij.codeInsight.NullableNotNullManager;
import com.intellij.codeInsight.daemon.impl.analysis.JavaHighlightUtil;
import com.intellij.codeInsight.generation.GenerateMembersUtil;
import com.intellij.codeInsight.generation.OverrideImplementUtil;
import com.intellij.codeInsight.generation.OverrideImplementExploreUtil;
import com.intellij.find.findUsages.PsiElement2UsageTargetAdapter;
import com.intellij.lang.findUsages.DescriptiveNameUtil;
import com.intellij.openapi.diagnostic.Logger;
@@ -53,7 +53,6 @@ import com.intellij.util.IncorrectOperationException;
import com.intellij.util.VisibilityUtil;
import com.intellij.util.containers.HashMap;
import com.intellij.util.containers.MultiMap;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -465,7 +464,7 @@ public class InheritanceToDelegationProcessor extends BaseRefactoringProcessor {
final PsiExpression newExpr;
final PsiReferenceExpression ref;
@NonNls final String delegateQualifier;
final String delegateQualifier;
if (!(expression instanceof PsiThisExpression || expression instanceof PsiSuperExpression)) {
delegateQualifier = "a.";
} else {
@@ -498,7 +497,7 @@ public class InheritanceToDelegationProcessor extends BaseRefactoringProcessor {
if (!myAbstractDelegatedMethods.contains(method)) {
PsiMethod methodToAdd = delegateMethod(myFieldName, method, getSuperSubstitutor(method.getContainingClass()));
String visibility = myDelegatedMethodsVisibility.get(method);
@PsiModifier.ModifierConstant String visibility = myDelegatedMethodsVisibility.get(method);
if (visibility != null) {
PsiUtil.setModifierProperty(methodToAdd, visibility, true);
}
@@ -508,25 +507,15 @@ public class InheritanceToDelegationProcessor extends BaseRefactoringProcessor {
}
}
private PsiMethod delegateMethod(@NonNls String delegationTarget,
private PsiMethod delegateMethod(String delegationTarget,
PsiMethod method,
PsiSubstitutor substitutor) throws IncorrectOperationException {
substitutor = OverrideImplementUtil.correctSubstitutor(method, substitutor);
substitutor = OverrideImplementExploreUtil.correctSubstitutor(method, substitutor);
PsiMethod methodToAdd = GenerateMembersUtil.substituteGenericMethod(method, substitutor);
final PsiModifierList modifierList = methodToAdd.getModifierList();
final NullableNotNullManager manager = NullableNotNullManager.getInstance(myProject);
modifierList.setModifierProperty(PsiModifier.ABSTRACT, false);
final PsiAnnotation nullable = manager.copyNullableAnnotation(method);
if (nullable != null) {
modifierList.addAfter(nullable, null);
}
else {
final PsiAnnotation notNull = manager.copyNotNullAnnotation(method);
if (notNull != null) {
modifierList.addAfter(notNull, null);
}
}
methodToAdd.getModifierList().setModifierProperty(PsiModifier.ABSTRACT, false);
NullableNotNullManager.getInstance(myProject).copyNullableOrNotNullAnnotation(method, methodToAdd);
final String delegationBody = getDelegationBody(methodToAdd, delegationTarget);
PsiCodeBlock newBody = myFactory.createCodeBlockFromText(delegationBody, method);
@@ -546,7 +535,7 @@ public class InheritanceToDelegationProcessor extends BaseRefactoringProcessor {
}
private static String getDelegationBody(PsiMethod methodToAdd, String delegationTarget) {
@NonNls final StringBuffer buffer = new StringBuffer();
StringBuilder buffer = new StringBuilder();
buffer.append("{\n");
if (!PsiType.VOID.equals(methodToAdd.getReturnType())) {
@@ -618,7 +607,7 @@ public class InheritanceToDelegationProcessor extends BaseRefactoringProcessor {
if (myGenerateGetter) {
final String getterVisibility = PsiModifier.PUBLIC;
@NonNls StringBuffer getterBuffer = new StringBuffer();
StringBuffer getterBuffer = new StringBuffer();
getterBuffer.append(getterVisibility);
getterBuffer.append(" Object ");
getterBuffer.append(myGetterName);
@@ -647,12 +636,12 @@ public class InheritanceToDelegationProcessor extends BaseRefactoringProcessor {
return PsiModifier.PRIVATE;
}
private @NonNls String defaultClassFieldType() {
private String defaultClassFieldType() {
return (myIsInnerClassNeeded ? myInnerClassName : "Object");
}
private PsiField createField(final String fieldVisibility, final boolean fieldInitializerNeeded, String defaultTypeName) throws IncorrectOperationException {
@NonNls StringBuffer buffer = new StringBuffer();
StringBuffer buffer = new StringBuffer();
buffer.append(fieldVisibility);
buffer.append(" final " + defaultTypeName + " ");
buffer.append(myFieldName);
@@ -671,7 +660,7 @@ public class InheritanceToDelegationProcessor extends BaseRefactoringProcessor {
for (PsiMethod constructor : constructors) {
PsiCodeBlock body = constructor.getBody();
final PsiStatement[] statements = body.getStatements();
@NonNls String fieldQualifier = "";
String fieldQualifier = "";
PsiParameter[] constructorParams = constructor.getParameterList().getParameters();
for (PsiParameter constructorParam : constructorParams) {
if (myFieldName.equals(constructorParam.getName())) {
@@ -679,7 +668,7 @@ public class InheritanceToDelegationProcessor extends BaseRefactoringProcessor {
break;
}
}
final @NonNls String assignmentText = fieldQualifier + myFieldName + "= new " + defaultClassFieldType() + "()";
final String assignmentText = fieldQualifier + myFieldName + "= new " + defaultClassFieldType() + "()";
if (statements.length < 1 || !JavaHighlightUtil.isSuperOrThisCall(statements[0], true, true) || myBaseClass.isInterface()) {
PsiExpressionStatement assignmentStatement =
(PsiExpressionStatement)myFactory.createStatementFromText(
@@ -147,4 +147,65 @@ public class AnnotationTargetUtil {
}
return null;
}
}
/**
* Returns {@code true} if the annotation resolves to a class having {@link TargetType#TYPE_USE} in it's targets.
*/
public static boolean isTypeAnnotation(@NotNull PsiAnnotation element) {
return findAnnotationTarget(element, TargetType.TYPE_USE) == TargetType.TYPE_USE;
}
/**
* From given targets, returns first where the annotation may be applied. Returns {@code null} when the annotation is not applicable
* at any of the targets, or {@linkplain TargetType#UNKNOWN} if the annotation does not resolve to a valid annotation type.
*/
@Nullable
public static TargetType findAnnotationTarget(@NotNull PsiAnnotation annotation, @NotNull TargetType... types) {
if (types.length != 0) {
PsiJavaCodeReferenceElement ref = annotation.getNameReferenceElement();
if (ref != null) {
PsiElement annotationType = ref.resolve();
if (annotationType instanceof PsiClass) {
return findAnnotationTarget((PsiClass)annotationType, types);
}
}
}
return TargetType.UNKNOWN;
}
/**
* From given targets, returns first where the annotation may be applied. Returns {@code null} when the annotation is not applicable
* at any of the targets, or {@linkplain TargetType#UNKNOWN} if the type is not a valid annotation (e.g. cannot be resolved).
*/
@Nullable
public static TargetType findAnnotationTarget(@NotNull PsiClass annotationType, @NotNull TargetType... types) {
if (types.length != 0) {
Set<TargetType> targets = getAnnotationTargets(annotationType);
if (targets != null) {
for (TargetType type : types) {
if (type != TargetType.UNKNOWN && targets.contains(type)) {
return type;
}
}
return null;
}
}
return TargetType.UNKNOWN;
}
/**
* Returns a set of targets where the given annotation may be applied, or {@code null} when the type is not a valid annotation.
*/
@Nullable
public static Set<TargetType> getAnnotationTargets(@NotNull PsiClass annotationType) {
if (!annotationType.isAnnotationType()) return null;
PsiModifierList modifierList = annotationType.getModifierList();
if (modifierList == null) return null;
PsiAnnotation target = modifierList.findAnnotation(CommonClassNames.JAVA_LANG_ANNOTATION_TARGET);
if (target == null) return DEFAULT_TARGETS; // if omitted it is applicable to all but Java 8 TYPE_USE/TYPE_PARAMETERS targets
return extractRequiredAnnotationTargets(target.findAttributeValue(null));
}
}
@@ -137,10 +137,42 @@ public abstract class NullableNotNullManager implements PersistentStateComponent
return findNullabilityAnnotationWithDefault(owner, checkBases, false);
}
@Nullable
public PsiAnnotation copyNotNullAnnotation(@NotNull PsiModifierListOwner original, @NotNull PsiModifierListOwner generated) {
return copyAnnotation(getNotNullAnnotation(original, false), generated);
}
@Nullable
public PsiAnnotation copyNullableOrNotNullAnnotation(@NotNull PsiModifierListOwner original, @NotNull PsiModifierListOwner generated) {
PsiAnnotation annotation = getNullableAnnotation(original, false);
if (annotation == null) annotation = getNotNullAnnotation(original, false);
return copyAnnotation(annotation, generated);
}
@Nullable
private PsiAnnotation copyAnnotation(PsiAnnotation annotation, PsiModifierListOwner target) {
// type annotations are part of target's type and should not to be copied explicitly to avoid duplication
if (annotation != null && !AnnotationTargetUtil.isTypeAnnotation(annotation)) {
String qualifiedName = checkContainer(annotation, false);
if (qualifiedName != null) {
PsiModifierList modifierList = target.getModifierList();
if (modifierList != null && modifierList.findAnnotation(qualifiedName) == null) {
return modifierList.addAnnotation(qualifiedName);
}
}
}
return null;
}
/** @deprecated use {@link #copyNotNullAnnotation(PsiModifierListOwner, PsiModifierListOwner)} (to be removed in IDEA 17) */
@SuppressWarnings("unused")
public PsiAnnotation copyNotNullAnnotation(PsiModifierListOwner owner) {
return copyAnnotation(owner, getNotNullAnnotation(owner, false));
}
/** @deprecated use {@link #copyNullableOrNotNullAnnotation(PsiModifierListOwner, PsiModifierListOwner)} (to be removed in IDEA 17) */
@SuppressWarnings("unused")
public PsiAnnotation copyNullableAnnotation(PsiModifierListOwner owner) {
return copyAnnotation(owner, getNullableAnnotation(owner, false));
}
@@ -256,19 +288,14 @@ public abstract class NullableNotNullManager implements PersistentStateComponent
PsiElement declaration = element == null ? null : element.resolve();
if (!(declaration instanceof PsiClass)) return false;
if (!AnnotationUtil.isAnnotated((PsiClass)declaration,
nullable ? JAVAX_ANNOTATION_NULLABLE : JAVAX_ANNOTATION_NONNULL,
false,
true)) {
return false;
}
String fqn = nullable ? JAVAX_ANNOTATION_NULLABLE : JAVAX_ANNOTATION_NONNULL;
if (!AnnotationUtil.isAnnotated((PsiClass)declaration, fqn, false, true)) return false;
PsiAnnotation tqDefault = AnnotationUtil.findAnnotation((PsiClass)declaration, true, "javax.annotation.meta.TypeQualifierDefault");
if (tqDefault == null) return false;
Set<PsiAnnotation.TargetType> required = AnnotationTargetUtil.extractRequiredAnnotationTargets(tqDefault.findAttributeValue(null));
if (required == null) return false;
return required.isEmpty() || ContainerUtil.intersects(required, Arrays.asList(placeTargetTypes));
return required != null && (required.isEmpty() || ContainerUtil.intersects(required, Arrays.asList(placeTargetTypes)));
}
@NotNull
@@ -401,7 +401,7 @@ public class PropertyUtil {
PsiUtil.setModifierProperty(getMethod, PsiModifier.STATIC, true);
}
annotateWithNullableStuff(field, getMethod);
NullableNotNullManager.getInstance(project).copyNullableOrNotNullAnnotation(field, getMethod);
PsiCodeBlock body = factory.createCodeBlockFromText("{\nreturn " + name + ";\n}", null);
getMethod.getBody().replace(body);
@@ -457,7 +457,7 @@ public class PropertyUtil {
String parameterName = codeStyleManager.propertyNameToVariableName(propertyName, VariableKind.PARAMETER);
PsiParameter param = factory.createParameter(parameterName, field.getType());
annotateWithNullableStuff(field, param);
NullableNotNullManager.getInstance(project).copyNullableOrNotNullAnnotation(field, param);
setMethod.getParameterList().add(param);
PsiUtil.setModifierProperty(setMethod, PsiModifier.PUBLIC, true);
@@ -496,27 +496,11 @@ public class PropertyUtil {
}
}
/** @deprecated use {@link NullableNotNullManager#copyNullableOrNotNullAnnotation(PsiModifierListOwner, PsiModifierListOwner)} (to be removed in IDEA 17) */
@SuppressWarnings("unused")
public static void annotateWithNullableStuff(@NotNull PsiModifierListOwner field,
@NotNull PsiModifierListOwner listOwner)
throws IncorrectOperationException {
final NullableNotNullManager manager = NullableNotNullManager.getInstance(field.getProject());
final PsiAnnotation notNull = manager.copyNotNullAnnotation(field);
if (notNull != null) {
annotate(listOwner, notNull);
}
else {
final PsiAnnotation nullable = manager.copyNullableAnnotation(field);
if (nullable != null) {
annotate(listOwner, nullable);
}
}
}
private static void annotate(@NotNull PsiModifierListOwner listOwner, @NotNull PsiAnnotation annotation)
throws IncorrectOperationException {
final PsiModifierList modifierList = listOwner.getModifierList();
LOG.assertTrue(modifierList != null);
modifierList.addAfter(annotation, null);
@NotNull PsiModifierListOwner listOwner) throws IncorrectOperationException {
NullableNotNullManager.getInstance(field.getProject()).copyNullableOrNotNullAnnotation(field, listOwner);
}
public static String suggestPropertyName(@NotNull PsiField field) {
@@ -320,50 +320,26 @@ public class PsiImplUtil {
return null;
}
@Nullable
/** @deprecated use {@link AnnotationTargetUtil#findAnnotationTarget(PsiAnnotation, TargetType...)} (to be removed ion IDEA 17) */
@SuppressWarnings("unused")
public static TargetType findApplicableTarget(@NotNull PsiAnnotation annotation, @NotNull TargetType... types) {
if (types.length != 0) {
PsiJavaCodeReferenceElement ref = annotation.getNameReferenceElement();
if (ref != null) {
PsiElement annotationType = ref.resolve();
if (annotationType instanceof PsiClass) {
return findApplicableTarget((PsiClass)annotationType, types);
}
}
}
return TargetType.UNKNOWN;
return AnnotationTargetUtil.findAnnotationTarget(annotation, types);
}
@Nullable
/** @deprecated use {@link AnnotationTargetUtil#findAnnotationTarget(PsiClass, TargetType...)} (to be removed ion IDEA 17) */
@SuppressWarnings("unused")
public static TargetType findApplicableTarget(@NotNull PsiClass annotationType, @NotNull TargetType... types) {
if (types.length != 0) {
Set<TargetType> targets = getAnnotationTargets(annotationType);
if (targets != null) {
for (TargetType type : types) {
if (type != TargetType.UNKNOWN && targets.contains(type)) {
return type;
}
}
return null;
}
}
return TargetType.UNKNOWN;
return AnnotationTargetUtil.findAnnotationTarget(annotationType, types);
}
@Nullable
/** @deprecated use {@link AnnotationTargetUtil#getAnnotationTargets(PsiClass)} (to be removed ion IDEA 17) */
@SuppressWarnings("unused")
public static Set<TargetType> getAnnotationTargets(@NotNull PsiClass annotationType) {
if (!annotationType.isAnnotationType()) return null;
PsiModifierList modifierList = annotationType.getModifierList();
if (modifierList == null) return null;
PsiAnnotation target = modifierList.findAnnotation(CommonClassNames.JAVA_LANG_ANNOTATION_TARGET);
if (target == null) return AnnotationTargetUtil.DEFAULT_TARGETS; // if omitted it is applicable to all but Java 8 TYPE_USE/TYPE_PARAMETERS targets
return AnnotationTargetUtil.extractRequiredAnnotationTargets(target.findAttributeValue(null));
return AnnotationTargetUtil.getAnnotationTargets(annotationType);
}
@NotNull
/** @deprecated use {@link AnnotationTargetUtil#getTargetsForLocation(PsiAnnotationOwner)} (to be removed ion IDEA 17) */
@SuppressWarnings("unused")
public static TargetType[] getTargetsForLocation(@Nullable PsiAnnotationOwner owner) {
return AnnotationTargetUtil.getTargetsForLocation(owner);
}
@@ -654,13 +630,12 @@ public class PsiImplUtil {
}
public static boolean isTypeAnnotation(@Nullable PsiElement element) {
return element instanceof PsiAnnotation &&
findApplicableTarget((PsiAnnotation)element, TargetType.TYPE_USE) == TargetType.TYPE_USE;
return element instanceof PsiAnnotation && AnnotationTargetUtil.isTypeAnnotation((PsiAnnotation)element);
}
public static void collectTypeUseAnnotations(@NotNull PsiModifierList modifierList, @NotNull List<PsiAnnotation> annotations) {
for (PsiAnnotation annotation : modifierList.getAnnotations()) {
if (isTypeAnnotation(annotation)) {
if (AnnotationTargetUtil.isTypeAnnotation(annotation)) {
annotations.add(annotation);
}
}
@@ -687,7 +662,7 @@ public class PsiImplUtil {
PsiElement left = PsiTreeUtil.skipSiblingsBackward(typeElement, PsiComment.class, PsiWhiteSpace.class, PsiTypeParameterList.class);
if (left instanceof PsiModifierList) {
for (PsiAnnotation annotation : ((PsiModifierList)left).getAnnotations()) {
if (isTypeAnnotation(annotation)) {
if (AnnotationTargetUtil.isTypeAnnotation(annotation)) {
annotation.putUserData(TYPE_ANNO_MARK, Boolean.TRUE);
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
* Copyright 2000-2015 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.
@@ -15,6 +15,7 @@
*/
package com.intellij.psi.impl.source;
import com.intellij.codeInsight.AnnotationTargetUtil;
import com.intellij.lang.ASTNode;
import com.intellij.openapi.util.Condition;
import com.intellij.psi.*;
@@ -266,11 +267,11 @@ public class PsiModifierListImpl extends JavaStubPsiElement<PsiModifierListStub>
@Override
@NotNull
public PsiAnnotation[] getApplicableAnnotations() {
final PsiAnnotation.TargetType[] targets = PsiImplUtil.getTargetsForLocation(this);
final PsiAnnotation.TargetType[] targets = AnnotationTargetUtil.getTargetsForLocation(this);
List<PsiAnnotation> filtered = ContainerUtil.findAll(getAnnotations(), new Condition<PsiAnnotation>() {
@Override
public boolean value(PsiAnnotation annotation) {
PsiAnnotation.TargetType target = PsiImplUtil.findApplicableTarget(annotation, targets);
PsiAnnotation.TargetType target = AnnotationTargetUtil.findAnnotationTarget(annotation, targets);
return target != null && target != PsiAnnotation.TargetType.UNKNOWN;
}
});
@@ -0,0 +1,9 @@
import foo.TestNotNull;
class C {
private @TestNotNull String s;
public C(@TestNotNull String s) {
this.s = s;
}
}
@@ -0,0 +1,7 @@
import foo.TestNotNull;
class C {
private @TestNotNull String s;
<caret>
}
@@ -15,21 +15,36 @@
*/
package com.intellij.codeInsight;
import com.intellij.JavaTestUtil;
import com.intellij.codeInsight.generation.ClassMember;
import com.intellij.codeInsight.generation.GenerateConstructorHandler;
import com.intellij.lang.java.JavaLanguage;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Disposer;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.psi.codeStyle.CommonCodeStyleSettings;
import com.intellij.testFramework.LightCodeInsightTestCase;
import com.intellij.testFramework.LightProjectDescriptor;
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase;
import org.jetbrains.annotations.NotNull;
import java.util.List;
/**
* @author ven
*/
public class GenerateConstructorTest extends LightCodeInsightTestCase {
public class GenerateConstructorTest extends LightCodeInsightFixtureTestCase {
@NotNull
@Override
protected LightProjectDescriptor getProjectDescriptor() {
return JAVA_8;
}
@Override
protected String getBasePath() {
return JavaTestUtil.getRelativeJavaTestDataPath() + "/codeInsight/generateConstructor";
}
public void testAbstractClass() { doTest(); }
public void testPackageLocalClass() { doTest(); }
public void testPrivateClass() { doTest(); }
@@ -61,13 +76,21 @@ public class GenerateConstructorTest extends LightCodeInsightTestCase {
doTest();
}
public void testTypeAnnotatedField() {
myFixture.addClass("package foo;\n\nimport java.lang.annotation.*;\n\n@Target(ElementType.TYPE_USE) public @interface TestNotNull { }");
NullableNotNullManager manager = NullableNotNullManager.getInstance(getProject());
manager.setNotNulls("foo.TestNotNull");
Disposer.register(myTestRootDisposable, manager::setNotNulls);
doTest();
}
private void doTest() {
doTest(false);
}
private void doTest(boolean preSelect) {
String name = getTestName(false);
configureByFile("/codeInsight/generateConstructor/before" + name + ".java");
myFixture.configureByFile("before" + name + ".java");
new GenerateConstructorHandler() {
@Override
protected ClassMember[] chooseMembers(ClassMember[] members, boolean allowEmpty, boolean copyJavadoc, Project project, Editor editor) {
@@ -80,6 +103,6 @@ public class GenerateConstructorTest extends LightCodeInsightTestCase {
}
}
}.invoke(getProject(), getEditor(), getFile());
checkResultByFile("/codeInsight/generateConstructor/after" + name + ".java");
myFixture.checkResultByFile("after" + name + ".java");
}
}
@@ -1,14 +1,14 @@
// This file contains list of broken plugins.
// Each line contains plugin ID and list of versions that are broken.
// If plugin name or version contains a space you can quote it like in command line.
NodeJS 143.444 143.379.15 143.21 143.110 143.250 142.4426 142.4100 142.3858 142.3224 142.2650 142.2492 142.2481 142.2064 141.1108 140.2045 140.1669 140.642 139.173 139.105 139.496 139.1 139.8 138.2196 138.2254 138.1684 138.1744 138.1879 138.2051 138.1367 138.1495 138.1189 138.1145 138.937 138.1013 138.921 138.447 138.172 138.317 138.21 138.35 138.96 138.85 136.1205 134.1276 134.1163 134.1145 134.1081 134.1039 134.985 134.680 134.31 134.307 134.262 134.198 134.125 136.1141
com.jetbrains.php 143.129 142.5282 142.2716 142.3969 142.4491 140.2765 141.332 139.732 139.659 139.496 139.173 139.105 138.2502 138.2000.2262 138.1751 138.1806 138.1505 138.1161 138.826 136.1768 136.1672 134.1456 133.982 133.679 133.51 133.326 131.98 131.374 131.332 131.235 131.205 130.1639 130.1481 130.1176 129.91 129.814 129.672 129.362 127.67 127.100 126.334 123.66 122.875 121.62 121.390 121.215 121.12
NodeJS 143.516 143.381.8 143.380.6 143.381.11 143.380.8 143.444 143.379.15 143.21 143.110 143.250 142.4426 142.4100 142.3858 142.3224 142.2650 142.2492 142.2481 142.2064 141.1108 140.2045 140.1669 140.642 139.173 139.105 139.496 139.1 139.8 138.2196 138.2254 138.1684 138.1744 138.1879 138.2051 138.1367 138.1495 138.1189 138.1145 138.937 138.1013 138.921 138.447 138.172 138.317 138.21 138.35 138.96 138.85 136.1205 134.1276 134.1163 134.1145 134.1081 134.1039 134.985 134.680 134.31 134.307 134.262 134.198 134.125 136.1141
com.jetbrains.php 143.382.38 143.279 143.381.48 143.129 142.5282 142.2716 142.3969 142.4491 140.2765 141.332 139.732 139.659 139.496 139.173 139.105 138.2502 138.2000.2262 138.1751 138.1806 138.1505 138.1161 138.826 136.1768 136.1672 134.1456 133.982 133.679 133.51 133.326 131.98 131.374 131.332 131.235 131.205 130.1639 130.1481 130.1176 129.91 129.814 129.672 129.362 127.67 127.100 126.334 123.66 122.875 121.62 121.390 121.215 121.12
com.jetbrains.lang.ejs 131.17 131.12
com.jetbrains.twig 133.51 130.1639
org.jetbrains.plugins.ruby 8.0.0.20151005 8.0.0.20180821 8.0.0.20150708 8.0.0.20150624 8.0.0.20150616 7.0.0.20150216 7.0.0.20150204 7.0.0.20141010 7.0.0.20140915 7.0.0.20140901 7.0.0.20140807 6.0.0.20140207 6.5.2.20140512 7.0.0.20140704 7.0.0.20140707 7.0.0.20140724
Pythonid 5.0.143.53 5.0.142.2 "142.176 v4.5" 4.1 "4.1 141.4 EAP" 3.1 4.0.25 4.0.26
Pythonid 5.0.143.100 5.0.143.103 5.0.143.95 5.0.142.1060 5.0.143.53 5.0.142.2 "142.176 v4.5" 4.1 "4.1 141.4 EAP" 3.1 4.0.25 4.0.26
Karma 142.3390 142.2492 142.2064 140.2109 138.1684 138.1879 138.317 138.21 134.1163 134.1039 134.686 134.31
org.intellij.scala 1.9.2 1.8.5 1.8.0 1.8.2 1.8.4 1.7.4 1.7.2 1.6.2 1.6.1 1.6.0 1.2.67.3.EAP 1.3.2-14.1 1.3.3-14.1 1.0.93.10.EAP 1.0.93.4.EAP 1.0.93.9.EAP 1.0.58 1.0.16 1.0.14 1.0.13 0.42.28 0.42.23 0.40.20 0.40.18 0.40.16 0.32.593 0.32.562 0.32.558 0.32.550 0.32.520 0.32.512
org.intellij.scala 1.9.133 1.9.140 1.9.147 1.9.151 1.9.2.2 1.9.4 1.9.4.1 1.9.2 1.8.5 1.8.0 1.8.2 1.8.4 1.7.4 1.7.2 1.6.2 1.6.1 1.6.0 1.2.67.3.EAP 1.3.2-14.1 1.3.3-14.1 1.0.93.10.EAP 1.0.93.4.EAP 1.0.93.9.EAP 1.0.58 1.0.16 1.0.14 1.0.13 0.42.28 0.42.23 0.40.20 0.40.18 0.40.16 0.32.593 0.32.562 0.32.558 0.32.550 0.32.520 0.32.512
org.jetbrains.kannotator 0.2.420
org.jetbrains.kotlin 0.10.555 0.10.4 0.8.1615 0.7.1360 0.7.1376 0.8.7
SBT 1.0.0 1.1.0 1.2.0 1.3.0 1.3.1 1.4.0 1.5.0 1.5.1 1.6.0 1.6.1 1.7.0
@@ -23,4 +23,5 @@ IdeaVIM
IDETalk
Commander
SourceSafe
TFS
TFS
ro.redeul.google.go
@@ -0,0 +1,37 @@
package com.intellij.openapi.util;
import junit.framework.TestCase;
import java.util.regex.Pattern;
public class VersionTest extends TestCase {
private static final Pattern[] VERSION_PATTERNS = {
Pattern.compile("^GNU gdb ([\\d]+\\.[\\d]+\\.?[\\d]*)", Pattern.MULTILINE),
Pattern.compile("^GNU gdb \\(GDB(?:;.*)?\\) ([\\d]+\\.[\\d]+(?:\\.[\\d]+)*).*", Pattern.MULTILINE),
Pattern.compile("^java version \"([\\d]+\\.[\\d]+\\.[\\d]+)_[\\d]+\".*", Pattern.MULTILINE),
Pattern.compile("^openjdk version \"([\\d]+\\.[\\d]+\\.[\\d]+)_[\\d]+.*\".*", Pattern.MULTILINE),
Pattern.compile("^[a-zA-Z() \\d]*([\\d]+\\.[\\d]+\\.?[\\d]*).*", Pattern.MULTILINE)
};
private static final Object[][] testData = {
{"GNU gdb 6.3.50-20050815 (Apple version gdb-1824) (Wed Feb 6 22:51:23 UTC 2013)", new Version(6, 3, 50)},
{"GNU gdb (GDB) 7.6", new Version(7, 6, 0)},
{"GNU gdb (GDB) 7.6something123", new Version(7, 6, 0)},
{"GNU gdb (GDB; openSUSE 13.1) 7.6.50.20130731-cvs", new Version(7, 6, 50)},
{"GNU gdb (GDB; devel:gcc) 7.8", new Version(7, 8, 0)},
{"GNU gdb (GDB; devel:gcc) 7.8.55", new Version(7, 8, 55)},
{"GNU gdb (GDB; devel:gcc) 7.8.55.123123-cvs", new Version(7, 8, 55)},
{"GNU gdb (GDB) Red Hat Enterprise Linux (7.2-60.el6_4.1)", new Version(7, 2, 0)},
{"java version \"1.6.0_36\"", new Version(1, 6, 0)},
{"java version \"1.7.0_85\"", new Version(1, 7, 0)},
{"openjdk version \"1.8.0_45-internal\"", new Version(1, 8, 0)},
{"openjdk version \"1.8.1_60-release\"", new Version(1, 8, 1)}
};
public void testParseVersion() throws Exception {
for (Object[] aTestData : testData) {
String versionString = (String)aTestData[0];
assertEquals("For \"" + versionString + "\"", aTestData[1], Version.parseVersion(versionString, VERSION_PATTERNS));
}
}
}
@@ -25,7 +25,10 @@ import com.intellij.openapi.editor.colors.EditorColorsScheme;
import com.intellij.openapi.editor.impl.DocumentMarkupModel;
import com.intellij.openapi.editor.impl.EditorImpl;
import com.intellij.openapi.editor.markup.*;
import com.intellij.openapi.fileEditor.FileEditor;
import com.intellij.openapi.fileEditor.FileEditorManager;
import com.intellij.openapi.fileEditor.OpenFileDescriptor;
import com.intellij.openapi.fileEditor.TextEditor;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Key;
import com.intellij.openapi.util.TextRange;
@@ -166,7 +169,18 @@ public class ExecutionPointHighlighter {
if (!navigate && myOpenFileDescriptor != null) {
fileDescriptor = new OpenFileDescriptor(myProject, myOpenFileDescriptor.getFile());
}
myEditor = fileDescriptor == null ? null : XDebuggerUtilImpl.createEditor(fileDescriptor);
myEditor = null;
if (fileDescriptor != null) {
if (!navigate) {
FileEditor editor = FileEditorManager.getInstance(fileDescriptor.getProject()).getSelectedEditor(fileDescriptor.getFile());
if (editor instanceof TextEditor) {
myEditor = ((TextEditor)editor).getEditor();
}
}
if (myEditor == null) {
myEditor = XDebuggerUtilImpl.createEditor(fileDescriptor);
}
}
if (myEditor != null) {
addHighlighter();
}
@@ -17,22 +17,18 @@ package org.jetbrains.plugins.gradle.tooling.builder;
import org.gradle.api.Project;
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.artifacts.ConfigurationContainer;
import org.gradle.api.artifacts.repositories.ArtifactRepository;
import org.gradle.plugins.ide.idea.IdeaPlugin;
import org.gradle.plugins.ide.idea.model.Dependency;
import org.gradle.plugins.ide.idea.model.IdeaModule;
import org.gradle.plugins.ide.idea.model.ModuleLibrary;
import org.gradle.plugins.ide.idea.model.Path;
import org.gradle.util.GradleVersion;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.plugins.gradle.model.BuildScriptClasspathModel;
import org.jetbrains.plugins.gradle.model.ClasspathEntryModel;
import org.jetbrains.plugins.gradle.model.*;
import org.jetbrains.plugins.gradle.tooling.ErrorMessageBuilder;
import org.jetbrains.plugins.gradle.tooling.ModelBuilderService;
import org.jetbrains.plugins.gradle.tooling.internal.BuildScriptClasspathModelImpl;
import org.jetbrains.plugins.gradle.tooling.internal.ClasspathEntryModelImpl;
import org.jetbrains.plugins.gradle.tooling.util.DependencyResolverImpl;
import org.jetbrains.plugins.gradle.tooling.util.DependencyTraverser;
import java.io.File;
import java.util.*;
@@ -44,9 +40,6 @@ import java.util.concurrent.ConcurrentHashMap;
*/
public class ModelBuildScriptClasspathBuilderImpl implements ModelBuilderService {
private static final String COMPILE_SCOPE = "COMPILE";
private static final String PLUS_CONFIGURATION = "plus";
private static final String MINUS_CONFIGURATION = "minus";
private static final String CLASSPATH_CONFIGURATION_NAME = "classpath";
private final Map<String, BuildScriptClasspathModelImpl> cache = new ConcurrentHashMap<String, BuildScriptClasspathModelImpl>();
@@ -66,73 +59,57 @@ public class ModelBuildScriptClasspathBuilderImpl implements ModelBuilderService
buildScriptClasspath.setGradleHomeDir(gradleHomeDir);
buildScriptClasspath.setGradleVersion(GradleVersion.current().getVersion());
boolean downloadJavadoc = false;
boolean downloadSources = true;
final IdeaPlugin ideaPlugin = project.getPlugins().findPlugin(IdeaPlugin.class);
if (ideaPlugin != null) {
Project parent = project.getParent();
if (parent != null) {
BuildScriptClasspathModelImpl parentBuildScriptClasspath = (BuildScriptClasspathModelImpl)buildAll(modelName, parent);
if (parentBuildScriptClasspath != null) {
for (ClasspathEntryModel classpathEntryModel : parentBuildScriptClasspath.getClasspath()) {
buildScriptClasspath.add(classpathEntryModel);
}
}
}
Configuration classpathConfiguration = project.getBuildscript().getConfigurations().findByName(CLASSPATH_CONFIGURATION_NAME);
if (classpathConfiguration == null) return null;
final Configuration configuration;
final IdeaModule ideaModule = ideaPlugin.getModel().getModule();
final ConfigurationContainer configurations = ideaModule.getProject().getConfigurations();
downloadJavadoc = ideaModule.isDownloadJavadoc();
downloadSources = ideaModule.isDownloadSources();
}
if (classpathConfiguration.getState() == Configuration.State.UNRESOLVED) {
configuration = classpathConfiguration;
configurations.add(configuration);
}
else {
String confName = project.getPath() + ":" + classpathConfiguration.getName();
if(configurations.findByName(confName) != null) {
confName += (":" + UUID.randomUUID().toString());
}
configuration = configurations.maybeCreate(confName);
configuration.getDependencies().addAll(classpathConfiguration.getAllDependencies());
configuration.getArtifacts().addAll(classpathConfiguration.getAllArtifacts());
}
final List<ArtifactRepository> buildscriptRepositories = project.getBuildscript().getRepositories();
final List<ArtifactRepository> projectRepositories = new ArrayList<ArtifactRepository>(project.getRepositories());
project.getRepositories().clear();
project.getRepositories().addAll(buildscriptRepositories);
Collection<Configuration> plusConfigurations = Collections.singletonList(configuration);
final Map<String, Map<String, Collection<Configuration>>> scopes =
new HashMap<String, Map<String, Collection<Configuration>>>(ideaModule.getScopes());
Map<String, Map<String, Collection<Configuration>>> buildScriptScope = new HashMap<String, Map<String, Collection<Configuration>>>();
Map<String, Collection<Configuration>> plusConfiguration = new HashMap<String, Collection<Configuration>>();
plusConfiguration.put(PLUS_CONFIGURATION, plusConfigurations);
if (scopes.get(COMPILE_SCOPE) != null) {
plusConfiguration.put(MINUS_CONFIGURATION, scopes.get(COMPILE_SCOPE).get(PLUS_CONFIGURATION));
}
buildScriptScope.put(COMPILE_SCOPE, plusConfiguration);
ideaModule.setScopes(buildScriptScope);
final Set<Dependency> buildScriptDependencies = ideaModule.resolveDependencies();
for (Dependency dependency : buildScriptDependencies) {
if (dependency instanceof ModuleLibrary) {
ModuleLibrary moduleLibrary = (ModuleLibrary)dependency;
if (COMPILE_SCOPE.equals(moduleLibrary.getScope())) {
buildScriptClasspath.add(new ClasspathEntryModelImpl(
convert(moduleLibrary.getClasses()), convert(moduleLibrary.getSources()), convert(moduleLibrary.getJavadoc())));
}
Project parent = project.getParent();
if (parent != null) {
BuildScriptClasspathModelImpl parentBuildScriptClasspath = (BuildScriptClasspathModelImpl)buildAll(modelName, parent);
if (parentBuildScriptClasspath != null) {
for (ClasspathEntryModel classpathEntryModel : parentBuildScriptClasspath.getClasspath()) {
buildScriptClasspath.add(classpathEntryModel);
}
}
}
Configuration classpathConfiguration = project.getBuildscript().getConfigurations().findByName(CLASSPATH_CONFIGURATION_NAME);
if (classpathConfiguration == null) return null;
// revert project and ideaModule modifications
ideaModule.setScopes(scopes);
configurations.remove(configuration);
project.getRepositories().clear();
project.getRepositories().addAll(projectRepositories);
Collection<ExternalDependency> dependencies =
new DependencyResolverImpl(project, false, downloadJavadoc, downloadSources).resolveDependencies(classpathConfiguration);
for (ExternalDependency dependency : new DependencyTraverser(dependencies)) {
if (dependency instanceof ExternalLibraryDependency) {
final ExternalLibraryDependency libraryDep = (ExternalLibraryDependency)dependency;
buildScriptClasspath.add(new ClasspathEntryModelImpl(
pathSet(libraryDep.getFile()),
pathSet(libraryDep.getSource()),
pathSet(libraryDep.getJavadoc())
));
}
if (dependency instanceof ExternalMultiLibraryDependency) {
ExternalMultiLibraryDependency multiLibraryDependency = (ExternalMultiLibraryDependency)dependency;
buildScriptClasspath.add(new ClasspathEntryModelImpl(
pathSet(multiLibraryDependency.getFiles()),
pathSet(multiLibraryDependency.getSources()),
pathSet(multiLibraryDependency.getJavadoc())
));
}
if (dependency instanceof FileCollectionDependency) {
FileCollectionDependency fileCollectionDependency = (FileCollectionDependency)dependency;
buildScriptClasspath.add(new ClasspathEntryModelImpl(
pathSet(fileCollectionDependency.getFiles()),
new HashSet<String>(),
new HashSet<String>()
));
}
}
cache.put(project.getPath(), buildScriptClasspath);
@@ -147,11 +124,17 @@ public class ModelBuildScriptClasspathBuilderImpl implements ModelBuilderService
).withDescription("Unable to resolve additional buildscript classpath dependencies");
}
private static Set<String> convert(Set<Path> paths) {
Set<String> result = new HashSet<String>(paths.size());
for (Path path : paths) {
result.add(path.getRelPath());
private static Set<String> pathSet(Collection<File> files) {
Set<String> set = new HashSet<String>();
for (File file : files) {
if(file != null) {
set.add(file.getPath());
}
}
return result;
return set;
}
private static Set<String> pathSet(File... files) {
return pathSet(Arrays.asList(files));
}
}
@@ -162,12 +162,12 @@ class DependencyResolverImpl implements DependencyResolver {
def providedScope = 'PROVIDED'
Multimap<ExternalDependencyId, ExternalDependency> resolvedMap = ArrayListMultimap.create()
new Traverser(compileDependencies).each { resolvedMap.put(it.id, it) }
new DependencyTraverser(compileDependencies).each { resolvedMap.put(it.id, it) }
Multimap<ExternalDependencyId, ExternalDependency> toDelete = ArrayListMultimap.create()
new Traverser(runtimeDependencies).each { toDelete.put(it.id, it) }
new DependencyTraverser(runtimeDependencies).each { toDelete.put(it.id, it) }
new Traverser(runtimeDependencies).each {
new DependencyTraverser(runtimeDependencies).each {
Collection<ExternalDependency> dependencies = resolvedMap.get(it.id);
if (dependencies && !dependencies.isEmpty()) {
if (it.dependencies.isEmpty()) {
@@ -181,14 +181,14 @@ class DependencyResolverImpl implements DependencyResolver {
}
toDelete = ArrayListMultimap.create()
new Traverser(runtimeDependencies).each { toDelete.put(it.id, it) }
new DependencyTraverser(runtimeDependencies).each { toDelete.put(it.id, it) }
result.addAll(compileDependencies)
result.addAll(runtimeDependencies)
result.unique()
toDelete = ArrayListMultimap.create()
new Traverser(result).each { toDelete.put(it.id, it) }
new DependencyTraverser(result).each { toDelete.put(it.id, it) }
// merge file dependencies
def jvmLanguages = ['Java', 'Groovy', 'Scala']
@@ -240,7 +240,7 @@ class DependencyResolverImpl implements DependencyResolver {
Multimap<String, File> resolvedDependenciesMap = ArrayListMultimap.create()
Project rootProject = myProject.rootProject
new Traverser(result).each {
new DependencyTraverser(result).each {
def dependency = it
def scope = dependency.scope
order = -1;
@@ -365,7 +365,7 @@ class DependencyResolverImpl implements DependencyResolver {
def providedConfigurations = new LinkedHashSet<Configuration>()
if (sourceSet.name == 'main' || sourceSet.name == 'test') {
resolvedMap = ArrayListMultimap.create()
new Traverser(result).each { resolvedMap.put(it.id, it) }
new DependencyTraverser(result).each { resolvedMap.put(it.id, it) }
final IdeaPlugin ideaPlugin = myProject.getPlugins().findPlugin(IdeaPlugin.class);
if (ideaPlugin) {
def scopes = ideaPlugin.model.module.scopes
@@ -381,7 +381,7 @@ class DependencyResolverImpl implements DependencyResolver {
}
providedConfigurations.each {
def providedDependencies = resolveDependencies(it, providedScope)
new Traverser(providedDependencies).each {
new DependencyTraverser(providedDependencies).each {
Collection<ExternalDependency> dependencies = resolvedMap.get(it.id);
if (!dependencies.isEmpty()) {
dependencies.each { ((AbstractExternalDependency)it).scope = providedScope }
@@ -709,39 +709,6 @@ class DependencyResolverImpl implements DependencyResolver {
return dependencies
}
class Traverser implements Iterable {
private Collection<ExternalDependency> collection
Traverser(Collection<ExternalDependency> c) {
collection = c
}
@Override
Iterator<ExternalDependency> iterator() {
return new Itr(collection)
}
private class Itr implements Iterator<ExternalDependency> {
Queue<ExternalDependency> queue
Itr(Collection<ExternalDependency> c) {
queue = new LinkedList<>(c);
}
@Override
boolean hasNext() {
return !queue.isEmpty()
}
@Override
ExternalDependency next() {
def dependency = queue.remove()
queue.addAll(dependency.dependencies)
return dependency
}
}
}
private static toMyModuleIdentifier(ModuleVersionIdentifier id) {
return new MyModuleIdentifier(name: id.getName(), group: id.getGroup());
}
@@ -0,0 +1,65 @@
/*
* Copyright 2000-2015 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 org.jetbrains.plugins.gradle.tooling.util;
import org.jetbrains.plugins.gradle.model.ExternalDependency;
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Queue;
/**
* @author Vladislav.Soroka
* @since 11/17/2015
*/
public class DependencyTraverser implements Iterable<ExternalDependency> {
private Collection<ExternalDependency> collection;
public DependencyTraverser(Collection<ExternalDependency> c) {
collection = c;
}
@Override
public Iterator<ExternalDependency> iterator() {
return new Itr(collection);
}
private static class Itr implements Iterator<ExternalDependency> {
Queue<ExternalDependency> queue;
Itr(Collection<ExternalDependency> c) {
queue = new LinkedList<ExternalDependency>(c);
}
@Override
public boolean hasNext() {
return !queue.isEmpty();
}
@Override
public ExternalDependency next() {
ExternalDependency dependency = queue.remove();
queue.addAll(dependency.getDependencies());
return dependency;
}
@Override
public void remove() {
throw new UnsupportedOperationException("remove");
}
}
}
@@ -15,6 +15,7 @@
*/
package org.jetbrains.plugins.gradle.tooling.builder;
import com.google.common.collect.Multimap;
import org.jetbrains.plugins.gradle.model.ExternalProject;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.io.FileUtil;
@@ -156,6 +157,7 @@ public abstract class AbstractModelBuilderTest {
ProjectImportAction.class,
// gradle-tooling-extension-impl jar
ModelBuildScriptClasspathBuilderImpl.class,
Multimap.class,
ShortTypeHandling.class
);
@@ -21,7 +21,7 @@ import org.gradle.tooling.model.DomainObjectSet;
import org.gradle.tooling.model.idea.IdeaModule;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.plugins.gradle.model.BuildScriptClasspathModel;
import org.jetbrains.plugins.gradle.model.ClasspathEntryModel;
import org.jetbrains.plugins.gradle.tooling.annotation.TargetVersions;
import org.junit.Test;
import java.io.File;
@@ -41,6 +41,7 @@ public class ModelBuildScriptClasspathBuilderImplTest extends AbstractModelBuild
}
@Test
@TargetVersions("2.0+")
public void testModelBuildScriptClasspathBuilder() throws Exception {
DomainObjectSet<? extends IdeaModule> ideaModules = allModels.getIdeaProject().getModules();
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2015 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.
@@ -16,6 +16,7 @@
package org.jetbrains.plugins.groovy.lang.psi.impl.auxiliary.annotation;
import com.intellij.codeInsight.AnnotationTargetUtil;
import com.intellij.lang.ASTNode;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
@@ -240,6 +241,6 @@ public class GrAnnotationImpl extends GrStubElementBase<GrAnnotationStub> implem
}
public static boolean isAnnotationApplicableTo(GrAnnotation annotation, @NotNull TargetType... elementTypeFields) {
return elementTypeFields.length == 0 || PsiImplUtil.findApplicableTarget(annotation, elementTypeFields) != null;
return elementTypeFields.length == 0 || AnnotationTargetUtil.findAnnotationTarget(annotation, elementTypeFields) != null;
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2015 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.
@@ -554,35 +554,17 @@ public class GroovyPropertyUtils {
}
}
private static void annotateWithNullableStuff(final PsiModifierListOwner field, final PsiModifierListOwner listOwner)
throws IncorrectOperationException {
final NullableNotNullManager manager = NullableNotNullManager.getInstance(field.getProject());
final PsiAnnotation notNull = manager.copyNotNullAnnotation(field);
if (notNull != null) {
annotate(listOwner, notNull);
}
else {
final PsiAnnotation nullable = manager.copyNullableAnnotation(field);
if (nullable != null) {
annotate(listOwner, nullable);
}
}
@SuppressWarnings("MagicConstant")
private static void annotateWithNullableStuff(PsiModifierListOwner original,
PsiModifierListOwner generated) throws IncorrectOperationException {
NullableNotNullManager.getInstance(original.getProject()).copyNullableOrNotNullAnnotation(original, generated);
final PsiModifierList modifierList = listOwner.getModifierList();
if (modifierList.hasExplicitModifier(GrModifier.DEF)) {
PsiModifierList modifierList = generated.getModifierList();
if (modifierList != null && modifierList.hasExplicitModifier(GrModifier.DEF)) {
LOG.assertTrue(modifierList instanceof GrModifierList);
if (modifierList.getAnnotations().length > 0 || ((GrModifierList)modifierList).getModifiers().length > 1) {
((GrModifierList)modifierList).setModifierProperty(GrModifier.DEF, false);
modifierList.setModifierProperty(GrModifier.DEF, false);
}
}
}
private static void annotate(final PsiModifierListOwner listOwner, final PsiAnnotation annotation)
throws IncorrectOperationException {
final PsiModifierList modifierList = listOwner.getModifierList();
LOG.assertTrue(modifierList != null);
modifierList.addAnnotation(annotation.getQualifiedName());
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2015 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.
@@ -15,12 +15,12 @@
*/
package org.jetbrains.plugins.groovy.lang.completion.weighers;
import com.intellij.codeInsight.AnnotationTargetUtil;
import com.intellij.codeInsight.completion.CompletionLocation;
import com.intellij.codeInsight.completion.CompletionWeigher;
import com.intellij.codeInsight.lookup.LookupElement;
import com.intellij.codeInsight.lookup.PsiTypeLookupItem;
import com.intellij.psi.*;
import com.intellij.psi.impl.PsiImplUtil;
import com.intellij.psi.impl.light.LightElement;
import com.intellij.psi.util.InheritanceUtil;
import com.intellij.psi.util.PsiTreeUtil;
@@ -98,7 +98,7 @@ public class GrKindWeigher extends CompletionWeigher {
PsiElement annoParent = annotation.getParent();
PsiElement ownerToUse = annoParent instanceof PsiModifierList ? annoParent.getParent() : annoParent;
PsiAnnotation.TargetType[] elementTypeFields = GrAnnotationImpl.getApplicableElementTypeFields(ownerToUse);
if (PsiImplUtil.findApplicableTarget((PsiClass)o, elementTypeFields) != null) {
if (AnnotationTargetUtil.findAnnotationTarget((PsiClass)o, elementTypeFields) != null) {
return NotQualifiedKind.restrictedClass;
}
}