Merge remote-tracking branch 'origin/master'

This commit is contained in:
Alexander Lobas
2012-06-06 20:01:40 +04:00
234 changed files with 3702 additions and 360 deletions
+2
View File
@@ -68,6 +68,8 @@
<module fileurl="file://$PROJECT_DIR$/jps/plugins/appLauncher/jps-appLauncher.iml" filepath="$PROJECT_DIR$/jps/plugins/appLauncher/jps-appLauncher.iml" group="jps" />
<module fileurl="file://$PROJECT_DIR$/jps/jps-builders/jps-builders.iml" filepath="$PROJECT_DIR$/jps/jps-builders/jps-builders.iml" group="jps" />
<module fileurl="file://$PROJECT_DIR$/jps/model/jps-model.iml" filepath="$PROJECT_DIR$/jps/model/jps-model.iml" group="jps" />
<module fileurl="file://$PROJECT_DIR$/jps/model-api/jps-model-api.iml" filepath="$PROJECT_DIR$/jps/model-api/jps-model-api.iml" group="jps" />
<module fileurl="file://$PROJECT_DIR$/jps/model-impl/jps-model-impl.iml" filepath="$PROJECT_DIR$/jps/model-impl/jps-model-impl.iml" group="jps" />
<module fileurl="file://$PROJECT_DIR$/jps/plugins/scala/jps-scala.iml" filepath="$PROJECT_DIR$/jps/plugins/scala/jps-scala.iml" group="jps" />
<module fileurl="file://$PROJECT_DIR$/jps/jps-tests.iml" filepath="$PROJECT_DIR$/jps/jps-tests.iml" group="jps" />
<module fileurl="file://$PROJECT_DIR$/java/jsp-base-openapi/jsp-base-openapi.iml" filepath="$PROJECT_DIR$/java/jsp-base-openapi/jsp-base-openapi.iml" group="java" />
@@ -108,7 +108,7 @@ public class BasicExpressionCompletionContributor {
}
PsiScopesUtil.treeWalkUp(new BaseScopeProcessor() {
public boolean execute(PsiElement element, ResolveState state) {
public boolean execute(@NotNull PsiElement element, ResolveState state) {
if (element instanceof PsiLocalVariable) {
if (!matcher.prefixMatches(((PsiLocalVariable)element).getName())) {
return true;
@@ -389,7 +389,7 @@ public class JavaCompletionUtil {
public static PsiType getQualifiedMemberReferenceType(@Nullable PsiType qualifierType, @NotNull final PsiMember member) {
final Ref<PsiSubstitutor> subst = Ref.create(PsiSubstitutor.EMPTY);
class MyProcessor extends BaseScopeProcessor implements NameHint, ElementClassHint {
public boolean execute(PsiElement element, ResolveState state) {
public boolean execute(@NotNull PsiElement element, ResolveState state) {
if (element == member) {
subst.set(state.get(PsiSubstitutor.KEY));
}
@@ -407,7 +407,7 @@ public class JavaCompletionUtil {
}
@Override
public <T> T getHint(Key<T> hintKey) {
public <T> T getHint(@NotNull Key<T> hintKey) {
return hintKey == NameHint.KEY || hintKey == ElementClassHint.KEY ? (T)this : null;
}
}
@@ -19,6 +19,7 @@ import com.intellij.codeInsight.CodeInsightUtil;
import com.intellij.codeInsight.ExpectedTypeInfo;
import com.intellij.codeInsight.daemon.impl.analysis.HighlightClassUtil;
import com.intellij.codeInsight.lookup.*;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.Condition;
import com.intellij.pom.java.LanguageLevel;
import com.intellij.psi.*;
@@ -154,14 +155,15 @@ public class JavaInheritorsGetter extends CompletionProvider<CompletionParameter
}
private static boolean areInferredTypesApplicable(@NotNull PsiType[] types, PsiElement originalPosition) {
final PsiNewExpression newExpression = PsiTreeUtil.getParentOfType(originalPosition, PsiNewExpression.class);
if (newExpression != null) {
final PsiMethodCallExpression methodCallExpression = PsiTreeUtil.getParentOfType(originalPosition, PsiMethodCallExpression.class);
if (methodCallExpression != null &&
ArrayUtil.find(methodCallExpression.getArgumentList().getExpressions(), newExpression) > -1) {
final PsiMethodCallExpression methodCallExpression = PsiTreeUtil.getParentOfType(originalPosition, PsiMethodCallExpression.class);
if (methodCallExpression != null) {
final PsiNewExpression newExpression = PsiTreeUtil.getParentOfType(originalPosition, PsiNewExpression.class);
if (newExpression != null && ArrayUtil.find(methodCallExpression.getArgumentList().getExpressions(), newExpression) > -1 ||
Comparing.equal(originalPosition.getParent(), methodCallExpression.getArgumentList())) {
final JavaResolveResult resolveResult = methodCallExpression.resolveMethodGenerics();
PsiMethod method = (PsiMethod)resolveResult.getElement();
return method == null || PsiUtil.getApplicabilityLevel(method, resolveResult.getSubstitutor(), types, PsiUtil.getLanguageLevel(originalPosition))
final PsiMethod method = (PsiMethod)resolveResult.getElement();
return method == null ||
PsiUtil.getApplicabilityLevel(method, resolveResult.getSubstitutor(), types, PsiUtil.getLanguageLevel(originalPosition))
!= MethodCandidateInfo.ApplicabilityLevel.NOT_APPLICABLE;
}
}
@@ -31,6 +31,7 @@ import com.intellij.psi.ResolveState;
import com.intellij.psi.scope.BaseScopeProcessor;
import com.intellij.psi.scope.ElementClassHint;
import com.intellij.psi.scope.JavaScopeProcessorEvent;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
@@ -63,7 +64,7 @@ public class VariablesProcessor
}
/** Always return true since we wanna get all vars in scope */
public boolean execute(PsiElement pe, ResolveState state){
public boolean execute(@NotNull PsiElement pe, ResolveState state){
if(pe instanceof PsiVariable){
final PsiVariable pvar = (PsiVariable)pe;
final String pvar_name = pvar.getName();
@@ -90,7 +91,7 @@ public class VariablesProcessor
}
@Override
public <T> T getHint(Key<T> hintKey) {
public <T> T getHint(@NotNull Key<T> hintKey) {
if (hintKey == ElementClassHint.KEY) {
return (T)this;
}
@@ -193,7 +193,7 @@ public class JavaCompletionProcessor extends BaseScopeProcessor implements Eleme
}
}
public boolean execute(PsiElement element, ResolveState state) {
public boolean execute(@NotNull PsiElement element, ResolveState state) {
//noinspection SuspiciousMethodCalls
if (myNonInitializedFields.contains(element)) {
return true;
@@ -294,7 +294,7 @@ public class JavaCompletionProcessor extends BaseScopeProcessor implements Eleme
}
@Override
public <T> T getHint(Key<T> hintKey) {
public <T> T getHint(@NotNull Key<T> hintKey) {
if (hintKey == ElementClassHint.KEY) {
return (T)this;
}
@@ -99,7 +99,7 @@ public class RefCountHolder {
public static RefCountHolder startUsing(@NotNull PsiFile file) {
Pair<RefCountHolder, HolderReference> pair = getInstance(file);
HolderReference reference = pair.second;
reference.makeHardReachable(true);
reference.makeHardReachable(true); // make sure RefCountHolder won't be gced during highlighting
return pair.first;
}
@NotNull
@@ -127,7 +127,7 @@ public class RefCountHolder {
myDclsUsedMap.put(result,Boolean.TRUE);
}
public void registerReference(@NotNull PsiJavaReference ref, JavaResolveResult resolveResult) {
public void registerReference(@NotNull PsiJavaReference ref, @NotNull JavaResolveResult resolveResult) {
assertIsAnalyzing();
PsiElement refElement = resolveResult.getElement();
PsiFile psiFile = refElement == null ? null : refElement.getContainingFile();
@@ -142,11 +142,11 @@ public class RefCountHolder {
}
}
private void registerImportStatement(@NotNull PsiReference ref, PsiImportStatementBase importStatement) {
private void registerImportStatement(@NotNull PsiReference ref, @NotNull PsiImportStatementBase importStatement) {
myImportStatements.put(ref, importStatement);
}
public boolean isRedundant(PsiImportStatementBase importStatement) {
public boolean isRedundant(@NotNull PsiImportStatementBase importStatement) {
assertIsRetrieving();
return !myImportStatements.containsValue(importStatement);
}
@@ -227,7 +227,7 @@ public class RefCountHolder {
return true;
}
public boolean isReferencedForRead(PsiElement element) {
public boolean isReferencedForRead(@NotNull PsiElement element) {
assertIsRetrieving();
LOG.assertTrue(element instanceof PsiVariable);
List<PsiReference> array = myLocalRefsMap.getKeysByValue(element);
@@ -249,7 +249,7 @@ public class RefCountHolder {
return false;
}
public boolean isReferencedForWrite(PsiElement element) {
public boolean isReferencedForWrite(@NotNull PsiElement element) {
assertIsRetrieving();
LOG.assertTrue(element instanceof PsiVariable);
List<PsiReference> array = myLocalRefsMap.getKeysByValue(element);
@@ -271,7 +271,7 @@ public class RefCountHolder {
if (!myState.compareAndSet(State.VIRGIN, State.BEING_WRITTEN_BY_GHP)) {
return false;
}
boolean finished = false;
try {
if (dirtyScope != null) {
if (dirtyScope.equals(file.getTextRange())) {
@@ -283,15 +283,16 @@ public class RefCountHolder {
}
analyze.run();
finished = true;
}
finally {
boolean set = myState.compareAndSet(State.BEING_WRITTEN_BY_GHP, State.READY);
boolean set = myState.compareAndSet(State.BEING_WRITTEN_BY_GHP, finished ? State.READY : State.VIRGIN);
assert set : myState.get();
}
return true;
}
public boolean retrieveUnusedReferencesInfo(Runnable analyze) {
public boolean retrieveUnusedReferencesInfo(@NotNull Runnable analyze) {
if (!myState.compareAndSet(State.READY, State.BEING_USED_BY_PHP)) {
return false;
}
@@ -306,10 +307,12 @@ public class RefCountHolder {
}
private void assertIsAnalyzing() {
assert myState.get() == State.BEING_WRITTEN_BY_GHP : myState.get();
State state = myState.get();
assert state == State.BEING_WRITTEN_BY_GHP : state;
}
private void assertIsRetrieving() {
assert myState.get() == State.BEING_USED_BY_PHP : myState.get();
State state = myState.get();
assert state == State.BEING_USED_BY_PHP : state;
}
}
@@ -514,7 +514,7 @@ public class CreateFromUsageUtils {
final List<PsiVariable> list = new ArrayList<PsiVariable>();
VariablesProcessor varproc = new VariablesProcessor("", true, list){
@Override
public boolean execute(PsiElement element, ResolveState state) {
public boolean execute(@NotNull PsiElement element, ResolveState state) {
if(!(element instanceof PsiField) ||
JavaPsiFacade.getInstance(element.getProject()).getResolveHelper().isAccessible((PsiField)element, expression, null)) {
return super.execute(element, state);
@@ -160,7 +160,7 @@ public class RenameWrongRefFix implements IntentionAction {
}
@Override
public boolean execute(PsiElement element, ResolveState state) {
public boolean execute(@NotNull PsiElement element, ResolveState state) {
if (element instanceof PsiNamedElement
&& element instanceof PsiModifierListOwner
&& myFilterMethods == element instanceof PsiMethod) {
@@ -295,12 +295,7 @@ public class GenerateConstructorHandler extends GenerateMembersHandlerBase {
PsiModifierList modifierList = parm.getModifierList();
PsiModifierList newMList = newParam.getModifierList();
if (modifierList != null && newMList != null) {
for (PsiAnnotation annotation : modifierList.getAnnotations()) {
newMList.add(factory.createAnnotationFromText(annotation.getText(), newParam));
}
for (@PsiModifier.ModifierConstant String m : PsiModifier.MODIFIERS) {
newMList.setModifierProperty(m, parm.hasModifierProperty(m));
}
newMList.replace(modifierList);
}
}
@@ -162,7 +162,7 @@ public class MacroUtil {
final List<PsiVariable> list = new ArrayList<PsiVariable>();
VariablesProcessor varproc = new VariablesProcessor(prefix, true, list) {
public boolean execute(PsiElement pe, ResolveState state) {
public boolean execute(@NotNull PsiElement pe, ResolveState state) {
if (pe instanceof PsiVariable) {
//exclude variables that are initialized in 'place'
final PsiExpression initializer = ((PsiVariable)pe).getInitializer();
@@ -21,6 +21,7 @@ import com.intellij.psi.scope.BaseScopeProcessor;
import com.intellij.psi.util.MethodSignature;
import com.intellij.psi.util.PsiUtil;
import com.intellij.util.containers.HashMap;
import org.jetbrains.annotations.NotNull;
import java.util.Collection;
import java.util.Map;
@@ -41,7 +42,7 @@ public class AddAllMembersProcessor extends BaseScopeProcessor {
myPsiClass = psiClass;
}
public boolean execute(PsiElement element, ResolveState state) {
public boolean execute(@NotNull PsiElement element, ResolveState state) {
PsiMember member = (PsiMember)element;
if (!isInteresting(element)) return true;
if (myPsiClass.isInterface() && isObjectMember(element)) return true;
@@ -247,7 +247,7 @@ public abstract class AbstractQualifiedReference<T extends AbstractQualifiedRefe
private final Set<ResolveResult> myResults = new LinkedHashSet<ResolveResult>();
@Override
public boolean execute(final PsiElement element, final ResolveState state) {
public boolean execute(@NotNull final PsiElement element, final ResolveState state) {
if (isFound()) return false;
process(element);
return true;
@@ -110,12 +110,12 @@ public class JavaClassReference extends GenericReference implements PsiJavaRefer
}
processorToUse = new PsiScopeProcessor() {
@Override
public boolean execute(PsiElement element, ResolveState state) {
public boolean execute(@NotNull PsiElement element, ResolveState state) {
return !(element instanceof PsiClass || element instanceof PsiPackage) || processor.execute(element, state);
}
@Override
public <V> V getHint(Key<V> hintKey) {
public <V> V getHint(@NotNull Key<V> hintKey) {
return processor.getHint(hintKey);
}
@@ -24,6 +24,7 @@ import com.intellij.psi.scope.BaseScopeProcessor;
import com.intellij.psi.scope.ElementClassHint;
import com.intellij.psi.scope.JavaScopeProcessorEvent;
import com.intellij.util.SmartList;
import org.jetbrains.annotations.NotNull;
import java.util.List;
@@ -52,7 +53,7 @@ public abstract class VariablesProcessor extends BaseScopeProcessor implements E
/** Always return true since we wanna get all vars in scope */
@Override
public boolean execute(PsiElement pe, ResolveState state){
public boolean execute(@NotNull PsiElement pe, ResolveState state){
if(pe instanceof PsiVariable){
final PsiVariable pvar = (PsiVariable)pe;
if(!myStaticSensitiveFlag || !myStaticScopeFlag || pvar.hasModifierProperty(PsiModifier.STATIC)){
@@ -79,7 +80,7 @@ public abstract class VariablesProcessor extends BaseScopeProcessor implements E
}
@Override
public <T> T getHint(Key<T> hintKey) {
public <T> T getHint(@NotNull Key<T> hintKey) {
if (hintKey == ElementClassHint.KEY) {
return (T)this;
}
@@ -40,6 +40,7 @@ import com.intellij.util.VisibilityUtil;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.containers.HashSet;
import com.intellij.util.containers.MultiMap;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.*;
@@ -512,7 +513,7 @@ public class JavaChangeSignatureUsageProcessor implements ChangeSignatureUsagePr
return type.isAssignableFrom(varType);
}
public boolean execute(PsiElement pe, ResolveState state) {
public boolean execute(@NotNull PsiElement pe, ResolveState state) {
super.execute(pe, state);
return size() < 2;
}
@@ -100,7 +100,19 @@ public class CopyClassesHandler extends CopyHandlerDelegateBase {
}
}
}
return result.isEmpty() ? null : result;
if (result.isEmpty()) {
return null;
}
else {
boolean hasClasses = false;
for (PsiClass[] classes : result.values()) {
if (classes != null) {
hasClasses = true;
break;
}
}
return hasClasses ? result : null;
}
}
@Nullable
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2012 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.
@@ -13,25 +13,30 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.openapi.vcs.readOnlyHandler;
package com.intellij.refactoring.util;
import com.intellij.openapi.extensions.ExtensionPointName;
import com.intellij.ide.highlighter.JavaClassFileType;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.WritingAccessProvider;
import org.jetbrains.annotations.NotNull;
import java.util.Collection;
import java.util.Collections;
/**
* @author Dmitry Avdeev
* User: ksafonov
*/
public interface WritingAccessProvider {
public class ClsElementWritingAccessProvider extends WritingAccessProvider {
ExtensionPointName<WritingAccessProvider> EP_NAME = ExtensionPointName.create("com.intellij.writingAccessProvider");
/**
* @param files files to be checked
* @return set of files that cannot be accessed
*/
@NotNull
Collection<VirtualFile> requestWriting(VirtualFile... files);
@Override
public Collection<VirtualFile> requestWriting(final VirtualFile... files) {
return Collections.emptyList();
}
@Override
public boolean isPotentiallyWritable(@NotNull final VirtualFile file) {
// TODO make library class files readonly not by their file type but by location in library roots
return file.getFileType() != JavaClassFileType.INSTANCE;
}
}
@@ -27,8 +27,7 @@ import java.util.List;
* @since 5.1
*/
public abstract class HierarchicalMethodSignature extends MethodSignatureBackedByPsiMethod {
public HierarchicalMethodSignature(final MethodSignatureBackedByPsiMethod signature) {
public HierarchicalMethodSignature(@NotNull MethodSignatureBackedByPsiMethod signature) {
super(signature.getMethod(), signature.getSubstitutor(), signature.isRaw(),
signature.getParameterTypes(), signature.getTypeParameters());
}
@@ -38,7 +38,8 @@ public abstract class JavaRecursiveElementWalkingVisitor extends JavaElementVisi
protected void elementFinished(PsiElement element) {
}
@Override public void visitReferenceExpression(PsiReferenceExpression expression) {
@Override
public void visitReferenceExpression(PsiReferenceExpression expression) {
visitExpression(expression);
myWalkingState.startedWalking(); // do not traverse from scratch
visitReferenceElement(expression);
@@ -47,9 +47,11 @@ public interface PsiMethod extends PsiMember, PsiNameIdentifierOwner, PsiModifie
/**
* Returns the return type of the method.
*
* @return the method return type, or null if the method is a constructor.
*/
@Nullable PsiType getReturnType();
@Nullable
PsiType getReturnType();
/**
* Returns the type element for the return type of the method.
@@ -64,21 +66,24 @@ public interface PsiMethod extends PsiMember, PsiNameIdentifierOwner, PsiModifie
*
* @return the parameter list instance.
*/
@NotNull PsiParameterList getParameterList();
@NotNull
PsiParameterList getParameterList();
/**
* Returns the list of thrown exceptions for the method.
*
* @return the list of thrown exceptions instance.
*/
@NotNull PsiReferenceList getThrowsList();
@NotNull
PsiReferenceList getThrowsList();
/**
* Returns the body of the method.
*
* @return the method body, or null if the method belongs to a compiled class.
*/
@Nullable PsiCodeBlock getBody();
@Nullable
PsiCodeBlock getBody();
/**
* Checks if the method is a constructor.
@@ -101,7 +106,8 @@ public interface PsiMethod extends PsiMember, PsiNameIdentifierOwner, PsiModifie
* @param substitutor the substitutor.
* @return the method signature instance.
*/
@NotNull MethodSignature getSignature(@NotNull PsiSubstitutor substitutor);
@NotNull
MethodSignature getSignature(@NotNull PsiSubstitutor substitutor);
/**
* Returns the name identifier for the method.
@@ -109,7 +115,8 @@ public interface PsiMethod extends PsiMember, PsiNameIdentifierOwner, PsiModifie
* @return the name identifier instance.
*/
@Override
@Nullable PsiIdentifier getNameIdentifier();
@Nullable
PsiIdentifier getNameIdentifier();
/**
* Searches the superclasses and base interfaces of the containing class to find
@@ -120,7 +127,8 @@ public interface PsiMethod extends PsiMember, PsiNameIdentifierOwner, PsiModifie
*
* @return the array of super methods, or an empty array if no methods are found.
*/
@NotNull PsiMethod[] findSuperMethods();
@NotNull
PsiMethod[] findSuperMethods();
/**
* Searches the superclasses and base interfaces of the containing class to find
@@ -131,10 +139,11 @@ public interface PsiMethod extends PsiMember, PsiNameIdentifierOwner, PsiModifie
* overridden method is returned.
*
* @param checkAccess if false, the super methods are searched even if this method
* is private. If true, an empty result list is returned for private methods.
* is private. If true, an empty result list is returned for private methods.
* @return the array of super methods, or an empty array if no methods are found.
*/
@NotNull PsiMethod[] findSuperMethods(boolean checkAccess);
@NotNull
PsiMethod[] findSuperMethods(boolean checkAccess);
/**
* Searches the superclasses and base interfaces of the specified class to find
@@ -145,7 +154,8 @@ public interface PsiMethod extends PsiMember, PsiNameIdentifierOwner, PsiModifie
* @param parentClass the class to search for super methods.
* @return the array of super methods, or an empty array if no methods are found.
*/
@NotNull PsiMethod[] findSuperMethods(PsiClass parentClass);
@NotNull
PsiMethod[] findSuperMethods(PsiClass parentClass);
/**
* Searches the superclasses and base interfaces of the containing class to find
@@ -155,36 +165,43 @@ public interface PsiMethod extends PsiMember, PsiNameIdentifierOwner, PsiModifie
* overrides another method, only the directly overridden method is returned.
*
* @param checkAccess if false, the super methods are searched even if this method
* is private. If true, an empty result list is returned for private methods.
* is private. If true, an empty result list is returned for private methods.
* @return the array of matching method signatures, or an empty array if no methods are found.
*/
@NotNull List<MethodSignatureBackedByPsiMethod> findSuperMethodSignaturesIncludingStatic(boolean checkAccess);
@NotNull
List<MethodSignatureBackedByPsiMethod> findSuperMethodSignaturesIncludingStatic(boolean checkAccess);
/**
* Returns the method in the deepest base superclass or interface of the containing class which
* this method overrides or implements.
*
* @return the overridden or implemented method, or null if this method does not override
* or implement any other method.
* or implement any other method.
* @deprecated use {@link #findDeepestSuperMethods()} instead
*/
@Nullable PsiMethod findDeepestSuperMethod();
@Nullable
PsiMethod findDeepestSuperMethod();
@NotNull PsiMethod[] findDeepestSuperMethods();
@NotNull
PsiMethod[] findDeepestSuperMethods();
@Override
@NotNull PsiModifierList getModifierList();
@NotNull
PsiModifierList getModifierList();
@Override
@NotNull @NonNls
@NotNull
@NonNls
String getName();
@Override
PsiElement setName(@NonNls @NotNull String name) throws IncorrectOperationException;
@NotNull HierarchicalMethodSignature getHierarchicalMethodSignature();
@NotNull
HierarchicalMethodSignature getHierarchicalMethodSignature();
@Nullable PsiMethodReceiver getMethodReceiver();
@Nullable
PsiMethodReceiver getMethodReceiver();
@Nullable
PsiType getReturnTypeNoResolve();
@@ -26,10 +26,10 @@ public class MethodSignatureBackedByPsiMethod extends MethodSignatureBase {
private final boolean myIsRaw;
protected MethodSignatureBackedByPsiMethod(@NotNull PsiMethod method,
PsiSubstitutor substitutor,
@NotNull PsiSubstitutor substitutor,
boolean isRaw,
PsiType[] parameterTypes,
PsiTypeParameter[] methodTypeParameters) {
@NotNull PsiType[] parameterTypes,
@NotNull PsiTypeParameter[] methodTypeParameters) {
super(substitutor, parameterTypes, methodTypeParameters);
myIsRaw = isRaw;
if (!method.isValid()) {
@@ -67,11 +67,11 @@ public class MethodSignatureBackedByPsiMethod extends MethodSignatureBase {
return myMethod;
}
public static MethodSignatureBackedByPsiMethod create(PsiMethod method, PsiSubstitutor substitutor) {
public static MethodSignatureBackedByPsiMethod create(@NotNull PsiMethod method, @NotNull PsiSubstitutor substitutor) {
return create(method, substitutor, PsiUtil.isRawSubstitutor(method, substitutor));
}
public static MethodSignatureBackedByPsiMethod create(PsiMethod method, PsiSubstitutor substitutor, boolean isRaw) {
public static MethodSignatureBackedByPsiMethod create(@NotNull PsiMethod method, @NotNull PsiSubstitutor substitutor, boolean isRaw) {
PsiTypeParameter[] methodTypeParameters = method.getTypeParameters();
final PsiParameter[] parameters = method.getParameterList().getParameters();
PsiType[] parameterTypes = new PsiType[parameters.length];
@@ -27,7 +27,7 @@ public abstract class MethodSignatureBase implements MethodSignature {
private final PsiType[] myParameterTypes;
protected final PsiTypeParameter[] myTypeParameters;
protected MethodSignatureBase(PsiSubstitutor substitutor, @NotNull PsiType[] parameterTypes, @NotNull PsiTypeParameter[] typeParameters) {
protected MethodSignatureBase(@NotNull PsiSubstitutor substitutor, @NotNull PsiType[] parameterTypes, @NotNull PsiTypeParameter[] typeParameters) {
mySubstitutor = substitutor;
myParameterTypes = parameterTypes.length == 0 ? PsiType.EMPTY_ARRAY : new PsiType[parameterTypes.length];
for (int i = 0; i < parameterTypes.length; i++) {
@@ -233,7 +233,7 @@ public abstract class PsiJavaFileBaseImpl extends PsiFileImpl implements PsiJava
}
@Override
public <T> T getHint(final Key<T> hintKey) {
public <T> T getHint(@NotNull final Key<T> hintKey) {
return myDelegate.getHint(hintKey);
}
@@ -250,7 +250,7 @@ public abstract class PsiJavaFileBaseImpl extends PsiFileImpl implements PsiJava
}
@Override
public boolean execute(final PsiElement element, final ResolveState state) {
public boolean execute(@NotNull final PsiElement element, final ResolveState state) {
if (element instanceof PsiModifierListOwner && ((PsiModifierListOwner)element).hasModifierProperty(PsiModifier.STATIC)) {
if (element instanceof PsiNamedElement && myIsProcessingOnDemand) {
final String name = ((PsiNamedElement)element).getName();
@@ -25,6 +25,7 @@ import com.intellij.psi.infos.ClassCandidateInfo;
import com.intellij.psi.scope.*;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.util.SmartList;
import org.jetbrains.annotations.NotNull;
import java.util.Iterator;
import java.util.List;
@@ -210,7 +211,7 @@ public class ClassResolverProcessor extends BaseScopeProcessor implements NameHi
}
@Override
public boolean execute(PsiElement element, ResolveState state) {
public boolean execute(@NotNull PsiElement element, ResolveState state) {
if (!(element instanceof PsiClass)) return true;
final PsiClass aClass = (PsiClass)element;
final String name = aClass.getName();
@@ -308,7 +309,7 @@ public class ClassResolverProcessor extends BaseScopeProcessor implements NameHi
}
@Override
public <T> T getHint(Key<T> hintKey) {
public <T> T getHint(@NotNull Key<T> hintKey) {
if (hintKey == ElementClassHint.KEY || hintKey == NameHint.KEY) {
//noinspection unchecked
return (T)this;
@@ -21,6 +21,7 @@ import com.intellij.psi.infos.CandidateInfo;
import com.intellij.psi.scope.BaseScopeProcessor;
import com.intellij.psi.scope.NameHint;
import com.intellij.util.SmartList;
import org.jetbrains.annotations.NotNull;
import java.util.List;
import java.util.ListIterator;
@@ -38,7 +39,7 @@ public class StaticImportResolveProcessor extends BaseScopeProcessor implements
}
@Override
public boolean execute(final PsiElement candidate, final ResolveState state) {
public boolean execute(@NotNull final PsiElement candidate, final ResolveState state) {
if (candidate instanceof PsiMember && ((PsiModifierListOwner)candidate).hasModifierProperty(PsiModifier.STATIC)) {
if (candidate instanceof PsiField) {
if (checkDomination((PsiMember)candidate, myFieldResults)) return true;
@@ -90,7 +91,7 @@ public class StaticImportResolveProcessor extends BaseScopeProcessor implements
}
@Override
public <T> T getHint(final Key<T> hintKey) {
public <T> T getHint(@NotNull final Key<T> hintKey) {
if (hintKey == NameHint.KEY) {
//noinspection unchecked
return (T)this;
@@ -34,7 +34,7 @@ public class SymbolCollectingProcessor extends BaseScopeProcessor implements Ele
private PsiElement myCurrentFileContext = null;
@Override
public <T> T getHint(Key<T> hintKey) {
public <T> T getHint(@NotNull Key<T> hintKey) {
if (hintKey == ElementClassHint.KEY) {
//noinspection unchecked
return (T)this;
@@ -50,7 +50,7 @@ public class SymbolCollectingProcessor extends BaseScopeProcessor implements Ele
}
@Override
public boolean execute(PsiElement element, ResolveState state) {
public boolean execute(@NotNull PsiElement element, ResolveState state) {
if (element instanceof PsiNamedElement) {
PsiNamedElement named = (PsiNamedElement)element;
String name = named.getName();
@@ -29,6 +29,7 @@ import com.intellij.psi.scope.conflictResolvers.JavaVariableConflictResolver;
import com.intellij.psi.scope.processor.ConflictFilterProcessor;
import com.intellij.psi.util.PsiUtil;
import com.intellij.util.SmartList;
import org.jetbrains.annotations.NotNull;
/**
* @author ik, dsl
@@ -91,7 +92,7 @@ public class VariableResolverProcessor extends ConflictFilterProcessor implement
}
@Override
public boolean execute(PsiElement element, ResolveState state) {
public boolean execute(@NotNull PsiElement element, ResolveState state) {
if (!(element instanceof PsiField) && (myName == null || PsiUtil.checkName(element, myName, myPlace))) {
super.execute(element, state);
return myResults.isEmpty();
@@ -101,7 +102,7 @@ public class VariableResolverProcessor extends ConflictFilterProcessor implement
}
@Override
public <T> T getHint(Key<T> hintKey) {
public <T> T getHint(@NotNull Key<T> hintKey) {
if (hintKey == ElementClassHint.KEY) {
return (T)this;
}
@@ -102,7 +102,7 @@ public class PsiCodeBlockImpl extends LazyParseablePsiElement implements PsiCode
final Ref<Boolean> conflict = new Ref<Boolean>(Boolean.FALSE);
PsiScopesUtil.walkChildrenScopes(this, new BaseScopeProcessor() {
@Override
public boolean execute(PsiElement element, ResolveState state) {
public boolean execute(@NotNull PsiElement element, ResolveState state) {
if (element instanceof PsiLocalVariable) {
final PsiLocalVariable variable = (PsiLocalVariable)element;
final String name = variable.getName();
@@ -51,10 +51,7 @@ import com.intellij.psi.tree.IElementType;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.psi.util.PsiUtil;
import com.intellij.psi.util.TypeConversionUtil;
import com.intellij.util.CharTable;
import com.intellij.util.Function;
import com.intellij.util.IncorrectOperationException;
import com.intellij.util.NullableFunction;
import com.intellij.util.*;
import gnu.trove.THashSet;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -194,12 +191,13 @@ public class PsiReferenceExpressionImpl extends PsiReferenceExpressionBase imple
private static JavaResolveResult[] _resolve(boolean incompleteCode, PsiReferenceExpressionImpl expression) {
CompositeElement treeParent = expression.getTreeParent();
IElementType parentType = treeParent == null ? null : treeParent.getElementType();
expression.resolveAllQualifiers();
final JavaResolveResult[] result = expression.resolve(parentType);
if (incompleteCode && parentType != JavaElementType.REFERENCE_EXPRESSION && result.length == 0) {
return expression.resolve(JavaElementType.REFERENCE_EXPRESSION);
}
return result;
}
@@ -221,6 +219,38 @@ public class PsiReferenceExpressionImpl extends PsiReferenceExpressionBase imple
}
}
private void resolveAllQualifiers() {
// to avoid SOE
PsiElement qualifier = getQualifier();
if (qualifier == null) return;
final ResolveCache resolveCache = ResolveCache.getInstance(getProject());
//resolveCache.resolveWithCaching(this, OurGenericsResolver.INSTANCE, true, incompleteCode)
qualifier.accept(new JavaRecursiveElementWalkingVisitor() {
@Override
public void visitReferenceExpression(PsiReferenceExpression expression) {
if (!(expression instanceof PsiReferenceExpressionImpl) || resolveCache.isCached(expression, true, false)) {
return;
}
visitElement(expression);
}
@Override
protected void elementFinished(PsiElement element) {
if (!(element instanceof PsiReferenceExpressionImpl)) return;
PsiReferenceExpressionImpl expression = (PsiReferenceExpressionImpl)element;
//IElementType type = expression.getTreeParent().getElementType();
//expression.resolve();
ResolveResult[] results = resolveCache.resolveWithCaching(expression, OurGenericsResolver.INSTANCE, false, false);
//System.out.println("resolveWithCaching "+element);
//if (!resolveCache.isCached(expression, element.isPhysical(), false)) {
// assert resolveCache.isCached(expression, element.isPhysical(), false);
//}
assert results != null;
}
});
int i = 0;
}
@NotNull
private JavaResolveResult[] resolve(IElementType parentType) {
if (parentType == JavaElementType.REFERENCE_EXPRESSION) {
@@ -414,7 +444,7 @@ public class PsiReferenceExpressionImpl extends PsiReferenceExpressionBase imple
private final Set<String> myVarNames = new THashSet<String>();
@Override
public boolean execute(final PsiElement element, final ResolveState state) {
public boolean execute(@NotNull final PsiElement element, final ResolveState state) {
if (element instanceof PsiLocalVariable || element instanceof PsiParameter) {
myVarNames.add(((PsiVariable) element).getName());
}
@@ -48,7 +48,7 @@ public class ConflictFilterProcessor extends FilterScopeProcessor<CandidateInfo>
}
@Override
public boolean execute(PsiElement element, ResolveState state) {
public boolean execute(@NotNull PsiElement element, ResolveState state) {
if (myCachedResult != null && myCachedResult.length == 1 && myCachedResult[0].isAccessible()) {
return false;
}
@@ -103,7 +103,7 @@ public class ConflictFilterProcessor extends FilterScopeProcessor<CandidateInfo>
}
@Override
public <T> T getHint(Key<T> hintKey) {
public <T> T getHint(@NotNull Key<T> hintKey) {
if (hintKey == NameHint.KEY) {
//noinspection unchecked
return myName != null ? (T)this : null;
@@ -23,6 +23,7 @@ import com.intellij.psi.filters.ElementFilter;
import com.intellij.psi.scope.BaseScopeProcessor;
import com.intellij.psi.scope.PsiScopeProcessor;
import com.intellij.util.SmartList;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
@@ -66,7 +67,7 @@ public class FilterScopeProcessor<T> extends BaseScopeProcessor {
}
@Override
public boolean execute(PsiElement element, ResolveState state) {
public boolean execute(@NotNull PsiElement element, ResolveState state) {
if (myFilter.isAcceptable(element, myCurrentDeclarationHolder)) {
if (myProcessor != null) {
return myProcessor.execute(element, state);
@@ -82,7 +83,7 @@ public class FilterScopeProcessor<T> extends BaseScopeProcessor {
}
@Override
public <T> T getHint(Key<T> hintKey) {
public <T> T getHint(@NotNull Key<T> hintKey) {
if (myProcessor != null) {
return myProcessor.getHint(hintKey);
}
@@ -21,6 +21,7 @@ import com.intellij.psi.scope.JavaScopeProcessorEvent;
import com.intellij.psi.scope.PsiConflictResolver;
import com.intellij.psi.scope.conflictResolvers.JavaMethodsConflictResolver;
import com.intellij.util.SmartList;
import org.jetbrains.annotations.NotNull;
public class MethodResolverProcessor extends MethodCandidatesProcessor {
private boolean myStopAcceptingCandidates = false;
@@ -51,7 +52,7 @@ public class MethodResolverProcessor extends MethodCandidatesProcessor {
}
@Override
public boolean execute(PsiElement element, ResolveState state) {
public boolean execute(@NotNull PsiElement element, ResolveState state) {
return !myStopAcceptingCandidates && super.execute(element, state);
}
}
@@ -26,6 +26,7 @@ import com.intellij.psi.scope.JavaScopeProcessorEvent;
import com.intellij.psi.scope.PsiConflictResolver;
import com.intellij.psi.util.PsiUtil;
import com.intellij.util.SmartList;
import org.jetbrains.annotations.NotNull;
/**
* Created by IntelliJ IDEA.
@@ -116,7 +117,7 @@ public abstract class MethodsProcessor extends ConflictFilterProcessor implement
}
@Override
public <T> T getHint(Key<T> hintKey) {
public <T> T getHint(@NotNull Key<T> hintKey) {
if (hintKey == ElementClassHint.KEY) {
return (T)this;
}
@@ -0,0 +1,15 @@
import java.util.ArrayList;
public class TestCompletion {
public static void test() {
A<ArrayList<String>> ref = new A<>();
ref.set(new ArrayList<String>(<caret>) );
}
}
class A<V> {
A() {
}
void set(V v){}
}
@@ -0,0 +1,15 @@
import java.util.ArrayList;
public class TestCompletion {
public static void test() {
A<ArrayList<String>> ref = new A<>();
ref.set(new <caret> );
}
}
class A<V> {
A() {
}
void set(V v){}
}
@@ -46,6 +46,10 @@ public class SmartType17CompletionTest extends LightFixtureCompletionTestCase {
doTest();
}
public void testDiamondNotCollapsedNotApplicable() throws Exception {
doTest();
}
public void testDiamondNotCollapsedInCaseOfAnonymousClasses() throws Exception {
doTest();
}
@@ -29,6 +29,7 @@ import com.intellij.testFramework.PsiTestUtil;
import java.io.File;
import java.io.IOException;
@SuppressWarnings("ConstantConditions")
@PlatformTestCase.WrapInCommand
public class SrcRepositoryUseTest extends PsiTestCase{
private static final Logger LOG = Logger.getInstance("#com.intellij.psi.SrcRepositoryUseTest");
@@ -501,8 +502,9 @@ public class SrcRepositoryUseTest extends PsiTestCase{
setupLoadingFilter();
PsiClass aClass = myJavaFacade.findClass("pack.MyClass2", GlobalSearchScope.allScope(myProject));
PsiParameterList list = aClass.getMethods()[0].getParameterList();
assertNotNull(aClass);
PsiMethod[] methods = aClass.getMethods();
PsiParameterList list = methods[0].getParameterList();
PsiParameter[] parms = list.getParameters();
assertEquals(5, parms.length);
@@ -34,7 +34,7 @@ class InplaceRenameInvariantTest extends LightCodeInsightTestCase {
}
"""
doTestPositionInvariance(text, false)
doTestPositionInvariance(text, false, false)
}
public void "test middle caret position"() {
@@ -44,7 +44,7 @@ class InplaceRenameInvariantTest extends LightCodeInsightTestCase {
}
"""
doTestPositionInvariance(text, false)
doTestPositionInvariance(text, false, false)
}
public void "test end caret position"() {
@@ -54,7 +54,18 @@ class InplaceRenameInvariantTest extends LightCodeInsightTestCase {
}
"""
doTestPositionInvariance(text, false)
doTestPositionInvariance(text, false, false)
}
public void "test end caret position typing"() {
def text = """\
class Test {
Test<caret> myTest;
}
}
"""
doTestPositionInvariance(text, false, false)
}
@@ -65,7 +76,7 @@ class InplaceRenameInvariantTest extends LightCodeInsightTestCase {
}
"""
doTestPositionInvariance(text, true)
doTestPositionInvariance(text, true, false)
}
public void "test middle caret position preselect"() {
@@ -75,7 +86,7 @@ class InplaceRenameInvariantTest extends LightCodeInsightTestCase {
}
"""
doTestPositionInvariance(text, true)
doTestPositionInvariance(text, true, false)
}
public void "test end caret position preselect"() {
@@ -85,10 +96,10 @@ class InplaceRenameInvariantTest extends LightCodeInsightTestCase {
}
"""
doTestPositionInvariance(text, true)
doTestPositionInvariance(text, true, false)
}
private doTestPositionInvariance(String text, final boolean preselect) {
private doTestPositionInvariance(String text, final boolean preselect, final boolean checkTyping) {
configure text
TemplateManagerImpl templateManager = (TemplateManagerImpl)TemplateManager.getInstance(project)
def oldPreselectSetting = myEditor.settings.preselectRename
@@ -104,6 +115,11 @@ class InplaceRenameInvariantTest extends LightCodeInsightTestCase {
handler.doRename(element, editor, null);
if (checkTyping){
type '1'
offset++
}
assertEquals(offset, myEditor.caretModel.offset)
}
+13
View File
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="annotations" />
</component>
</module>
@@ -0,0 +1,8 @@
package org.jetbrains.jps.model;
/**
* @author nik
*/
public class DummyJpsElementProperties extends JpsElementProperties {
public static final DummyJpsElementProperties INSTANCE = new DummyJpsElementProperties();
}
@@ -0,0 +1,11 @@
package org.jetbrains.jps.model;
import org.jetbrains.annotations.NotNull;
/**
* @author nik
*/
public interface JpsCompositeElement extends JpsParentElement {
@NotNull
JpsElementContainer getContainer();
}
@@ -0,0 +1,18 @@
package org.jetbrains.jps.model;
import org.jetbrains.annotations.NotNull;
/**
* @author nik
*/
public interface JpsElement {
@NotNull
BulkModificationSupport<?> getBulkModificationSupport();
interface BulkModificationSupport<E extends JpsElement> extends JpsElement {
@NotNull
E createCopy(@NotNull JpsModel model, @NotNull JpsEventDispatcher eventDispatcher, JpsParentElement parent);
void applyChanges(@NotNull E modified);
}
}
@@ -0,0 +1,22 @@
package org.jetbrains.jps.model;
import org.jetbrains.annotations.NotNull;
import java.util.List;
/**
* @author nik
*/
public interface JpsElementCollection<E extends JpsElement> extends JpsParentElement {
List<E> getElements();
@NotNull
<P> E addChild(@NotNull JpsElementFactoryWithParameter<E,P> factory, @NotNull P param);
@NotNull
E addChild(@NotNull JpsElementFactory<E> factory);
E addChild(E element);
void removeChild(@NotNull E element);
}
@@ -0,0 +1,25 @@
package org.jetbrains.jps.model;
import org.jetbrains.annotations.NotNull;
/**
* @author nik
*/
public interface JpsElementContainer {
<T extends JpsElement>
T getChild(@NotNull JpsElementKind<T> kind);
@NotNull
<T extends JpsElement, K extends JpsElementKind<T>&JpsElementFactory<T>>
T setChild(@NotNull K kind);
@NotNull
<T extends JpsElement, P, K extends JpsElementKind<T>&JpsElementFactoryWithParameter<T, P>>
T setChild(@NotNull K kind, @NotNull P param);
<T extends JpsElement>
T setChild(JpsElementKind<T> kind, T child);
<T extends JpsElement>
void removeChild(@NotNull JpsElementKind<T> kind);
}
@@ -0,0 +1,12 @@
package org.jetbrains.jps.model;
import org.jetbrains.annotations.NotNull;
/**
* @author nik
*/
public interface JpsElementFactory<E extends JpsElement> {
@NotNull
E create(@NotNull JpsModel model, @NotNull JpsEventDispatcher eventDispatcher, JpsParentElement parent);
}
@@ -0,0 +1,11 @@
package org.jetbrains.jps.model;
import org.jetbrains.annotations.NotNull;
/**
* @author nik
*/
public interface JpsElementFactoryWithParameter<E extends JpsElement, P> {
@NotNull
E create(@NotNull JpsModel model, @NotNull JpsEventDispatcher eventDispatcher, JpsParentElement parent, @NotNull P param);
}
@@ -0,0 +1,15 @@
package org.jetbrains.jps.model;
import org.jetbrains.annotations.NotNull;
/**
* @author nik
*/
public class JpsElementKind<E extends JpsElement> {
public void fireElementAdded(@NotNull JpsEventDispatcher dispatcher, @NotNull E element) {
}
public void fireElementRemoved(@NotNull JpsEventDispatcher dispatcher, @NotNull E element) {
}
}
@@ -0,0 +1,7 @@
package org.jetbrains.jps.model;
/**
* @author nik
*/
public abstract class JpsElementProperties {
}
@@ -0,0 +1,11 @@
package org.jetbrains.jps.model;
import org.jetbrains.annotations.Nullable;
/**
* @author nik
*/
public interface JpsElementReference<T extends JpsElement> extends JpsElement {
@Nullable
T resolve();
}
@@ -0,0 +1,10 @@
package org.jetbrains.jps.model;
/**
* @author nik
*/
public abstract class JpsElementType<P extends JpsElementProperties> {
public abstract P createDefaultProperties();
public abstract P createCopy(P properties);
}
@@ -0,0 +1,23 @@
package org.jetbrains.jps.model;
import org.jetbrains.annotations.NotNull;
import java.util.EventListener;
/**
* @author nik
*/
public interface JpsEventDispatcher {
@NotNull
<T extends EventListener> T getPublisher(Class<T> listenerClass);
void fireElementRenamed(@NotNull JpsNamedElement element, @NotNull String oldName, @NotNull String newName);
void fireElementChanged(@NotNull JpsElement element);
<T extends JpsElement>
void fireElementAdded(@NotNull T element, @NotNull JpsElementKind<T> kind);
<T extends JpsElement>
void fireElementRemoved(@NotNull T element, @NotNull JpsElementKind<T> kind);
}
@@ -0,0 +1,15 @@
package org.jetbrains.jps.model;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jps.model.library.JpsLibrary;
import org.jetbrains.jps.model.library.JpsLibraryType;
/**
* @author nik
*/
public interface JpsGlobal extends JpsCompositeElement, JpsReferenceableElement<JpsGlobal> {
@NotNull
JpsLibrary addLibrary(@NotNull JpsLibraryType libraryType, final @NotNull String name);
}
@@ -0,0 +1,19 @@
package org.jetbrains.jps.model;
import org.jetbrains.annotations.NotNull;
/**
* @author nik
*/
public interface JpsModel {
@NotNull
JpsProject getProject();
@NotNull
JpsGlobal getGlobal();
@NotNull
JpsModel createModifiableModel(@NotNull JpsEventDispatcher eventDispatcher);
void commit();
}
@@ -0,0 +1,13 @@
package org.jetbrains.jps.model;
import org.jetbrains.annotations.NotNull;
/**
* @author nik
*/
public interface JpsNamedElement extends JpsElement {
@NotNull
String getName();
void setName(@NotNull String name);
}
@@ -0,0 +1,7 @@
package org.jetbrains.jps.model;
/**
* @author nik
*/
public interface JpsParentElement extends JpsElement {
}
@@ -0,0 +1,27 @@
package org.jetbrains.jps.model;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jps.model.library.JpsLibrary;
import org.jetbrains.jps.model.library.JpsLibraryType;
import org.jetbrains.jps.model.module.JpsModule;
import org.jetbrains.jps.model.module.JpsModuleType;
import java.util.List;
/**
* @author nik
*/
public interface JpsProject extends JpsCompositeElement, JpsReferenceableElement<JpsProject> {
@NotNull
JpsModule addModule(@NotNull JpsModuleType<?> moduleType, @NotNull String name);
@NotNull
JpsLibrary addLibrary(@NotNull JpsLibraryType<?> libraryType, @NotNull String name);
@NotNull
List<? extends JpsLibrary> getLibraries();
@NotNull
List<? extends JpsModule> getModules();
}
@@ -0,0 +1,11 @@
package org.jetbrains.jps.model;
import org.jetbrains.annotations.NotNull;
/**
* @author nik
*/
public interface JpsReferenceableElement<E extends JpsElement> {
@NotNull
JpsElementReference<E> createReference(JpsParentElement parent);
}
@@ -0,0 +1,16 @@
package org.jetbrains.jps.model;
import org.jetbrains.annotations.NotNull;
/**
* @author nik
*/
public interface JpsTypedData<P extends JpsElementProperties> extends JpsElement {
@NotNull
JpsElementType<P> getType();
@NotNull
P getProperties();
void setProperties(@NotNull P properties);
}
@@ -0,0 +1,17 @@
package org.jetbrains.jps.model;
import org.jetbrains.annotations.NotNull;
import java.util.List;
/**
* @author nik
*/
public interface JpsUrlList extends JpsElement {
@NotNull
List<String> getUrls();
void addUrl(@NotNull String url);
void removeUrl(@NotNull String url);
}
@@ -0,0 +1,12 @@
package org.jetbrains.jps.model;
import org.jetbrains.annotations.NotNull;
/**
* @author nik
*/
public interface JpsUrlListChangeListener<T extends JpsElement> {
void urlAdded(@NotNull T element, @NotNull String url);
void urlRemoved(@NotNull T element, @NotNull String url);
}
@@ -0,0 +1,13 @@
package org.jetbrains.jps.model;
import org.jetbrains.annotations.NotNull;
/**
* @author nik
*/
public interface SimpleJpsElement<P extends JpsElementProperties> extends JpsElement {
@NotNull
P getProperties();
void setProperties(@NotNull P properties);
}
@@ -0,0 +1,21 @@
package org.jetbrains.jps.model.java;
import org.jetbrains.jps.model.JpsElement;
/**
* @author nik
*/
public interface JavaModuleExtension extends JpsElement {
String getOutputUrl();
void setOutputUrl(String outputUrl);
String getTestOutputUrl();
void setTestOutputUrl(String testOutputUrl);
LanguageLevel getLanguageLevel();
void setLanguageLevel(LanguageLevel languageLevel);
}
@@ -0,0 +1,22 @@
package org.jetbrains.jps.model.java;
import org.jetbrains.jps.model.JpsElementProperties;
/**
* @author nik
*/
public class JavaSourceRootProperties extends JpsElementProperties {
private final String myPackagePrefix;
public JavaSourceRootProperties() {
myPackagePrefix = "";
}
public JavaSourceRootProperties(String packagePrefix) {
myPackagePrefix = packagePrefix;
}
public String getPackagePrefix() {
return myPackagePrefix;
}
}
@@ -0,0 +1,21 @@
package org.jetbrains.jps.model.java;
import org.jetbrains.jps.model.module.JpsModuleSourceRootType;
/**
* @author nik
*/
public class JavaSourceRootType extends JpsModuleSourceRootType<JavaSourceRootProperties> {
public static final JavaSourceRootType SOURCE = new JavaSourceRootType();
public static final JavaSourceRootType TEST_SOURCE = new JavaSourceRootType();
@Override
public JavaSourceRootProperties createDefaultProperties() {
return new JavaSourceRootProperties();
}
@Override
public JavaSourceRootProperties createCopy(JavaSourceRootProperties properties) {
return new JavaSourceRootProperties(properties.getPackagePrefix());
}
}
@@ -0,0 +1,21 @@
package org.jetbrains.jps.model.java;
import org.jetbrains.jps.model.DummyJpsElementProperties;
import org.jetbrains.jps.model.library.JpsLibraryType;
/**
* @author nik
*/
public class JpsJavaLibraryType extends JpsLibraryType<DummyJpsElementProperties> {
public static final JpsJavaLibraryType INSTANCE = new JpsJavaLibraryType();
@Override
public DummyJpsElementProperties createDefaultProperties() {
return DummyJpsElementProperties.INSTANCE;
}
@Override
public DummyJpsElementProperties createCopy(DummyJpsElementProperties properties) {
return DummyJpsElementProperties.INSTANCE;
}
}
@@ -0,0 +1,21 @@
package org.jetbrains.jps.model.java;
import org.jetbrains.jps.model.DummyJpsElementProperties;
import org.jetbrains.jps.model.module.JpsModuleType;
/**
* @author nik
*/
public class JpsJavaModuleType extends JpsModuleType<DummyJpsElementProperties> {
public static final JpsJavaModuleType INSTANCE = new JpsJavaModuleType();
@Override
public DummyJpsElementProperties createDefaultProperties() {
return DummyJpsElementProperties.INSTANCE;
}
@Override
public DummyJpsElementProperties createCopy(DummyJpsElementProperties properties) {
return DummyJpsElementProperties.INSTANCE;
}
}
@@ -0,0 +1,21 @@
package org.jetbrains.jps.model.java;
import org.jetbrains.jps.model.DummyJpsElementProperties;
import org.jetbrains.jps.model.library.JpsSdkType;
/**
* @author nik
*/
public class JpsJavaSdkType extends JpsSdkType<DummyJpsElementProperties> {
public static final JpsJavaSdkType INSTANCE = new JpsJavaSdkType();
@Override
public DummyJpsElementProperties createDefaultProperties() {
return DummyJpsElementProperties.INSTANCE;
}
@Override
public DummyJpsElementProperties createCopy(DummyJpsElementProperties properties) {
return DummyJpsElementProperties.INSTANCE;
}
}
@@ -0,0 +1,7 @@
package org.jetbrains.jps.model.java;
/**
* @author nik
*/
public enum LanguageLevel {
}
@@ -0,0 +1,26 @@
package org.jetbrains.jps.model.library;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jps.model.JpsNamedElement;
import org.jetbrains.jps.model.JpsParentElement;
import org.jetbrains.jps.model.JpsReferenceableElement;
import java.util.List;
/**
* @author nik
*/
public interface JpsLibrary extends JpsNamedElement, JpsReferenceableElement<JpsLibrary> {
@NotNull
List<String> getUrls(@NotNull JpsLibraryRootType rootType);
void addUrl(@NotNull String url, @NotNull JpsLibraryRootType rootType);
void removeUrl(@NotNull String url, @NotNull JpsLibraryRootType rootType);
void delete();
@NotNull
JpsLibraryReference createReference(JpsParentElement parent);
}
@@ -0,0 +1,13 @@
package org.jetbrains.jps.model.library;
import org.jetbrains.annotations.NotNull;
import java.util.EventListener;
/**
* @author nik
*/
public interface JpsLibraryListener extends EventListener {
void libraryAdded(@NotNull JpsLibrary library);
void libraryRemoved(@NotNull JpsLibrary library);
}
@@ -0,0 +1,12 @@
package org.jetbrains.jps.model.library;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jps.model.JpsElementReference;
/**
* @author nik
*/
public interface JpsLibraryReference extends JpsElementReference<JpsLibrary> {
@NotNull
String getLibraryName();
}
@@ -0,0 +1,18 @@
package org.jetbrains.jps.model.library;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jps.model.JpsElement;
/**
* @author nik
*/
public interface JpsLibraryRoot extends JpsElement {
@NotNull
JpsLibraryRootType getRootType();
@NotNull
String getUrl();
@NotNull
JpsLibrary getLibrary();
}
@@ -0,0 +1,13 @@
package org.jetbrains.jps.model.library;
import org.jetbrains.annotations.NotNull;
import java.util.EventListener;
/**
* @author nik
*/
public interface JpsLibraryRootListener extends EventListener {
void rootAdded(@NotNull JpsLibraryRoot root);
void rootRemoved(@NotNull JpsLibraryRoot root);
}
@@ -0,0 +1,24 @@
package org.jetbrains.jps.model.library;
/**
* @author nik
*/
public class JpsLibraryRootType {
public static final JpsLibraryRootType COMPILED = new JpsLibraryRootType(JpsOrderRootType.COMPILED, false);
public static final JpsLibraryRootType SOURCES = new JpsLibraryRootType(JpsOrderRootType.SOURCES, false);
private final boolean myJarDirectory;
private final JpsOrderRootType myType;
public JpsLibraryRootType(JpsOrderRootType type, boolean jarDirectory) {
myType = type;
myJarDirectory = jarDirectory;
}
public boolean isJarDirectory() {
return myJarDirectory;
}
public JpsOrderRootType getType() {
return myType;
}
}
@@ -0,0 +1,10 @@
package org.jetbrains.jps.model.library;
import org.jetbrains.jps.model.JpsElementProperties;
import org.jetbrains.jps.model.JpsElementType;
/**
* @author nik
*/
public abstract class JpsLibraryType<P extends JpsElementProperties> extends JpsElementType<P> {
}
@@ -0,0 +1,13 @@
package org.jetbrains.jps.model.library;
/**
* @author nik
*/
public abstract class JpsOrderRootType {
public static final JpsOrderRootType COMPILED = new JpsOrderRootType() {
};
public static final JpsOrderRootType SOURCES = new JpsOrderRootType() {
};
public static final JpsOrderRootType DOCUMENTATION = new JpsOrderRootType() {
};
}
@@ -0,0 +1,9 @@
package org.jetbrains.jps.model.library;
import org.jetbrains.jps.model.JpsElementProperties;
/**
* @author nik
*/
public abstract class JpsSdkType<P extends JpsElementProperties> extends JpsLibraryType<P> {
}
@@ -0,0 +1,26 @@
package org.jetbrains.jps.model.module;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jps.model.JpsElement;
import org.jetbrains.jps.model.library.JpsLibrary;
import org.jetbrains.jps.model.library.JpsSdkType;
import java.util.List;
/**
* @author nik
*/
public interface JpsDependenciesList extends JpsElement {
@NotNull
JpsModuleDependency addModuleDependency(@NotNull JpsModule module);
@NotNull
JpsLibraryDependency addLibraryDependency(@NotNull JpsLibrary libraryElement);
void addModuleSourceDependency();
void addSdkDependency(@NotNull JpsSdkType<?> sdkType);
@NotNull
List<? extends JpsDependencyElement> getDependencies();
}
@@ -0,0 +1,10 @@
package org.jetbrains.jps.model.module;
import org.jetbrains.jps.model.JpsElement;
/**
* @author nik
*/
public interface JpsDependencyElement extends JpsElement {
void remove();
}
@@ -0,0 +1,12 @@
package org.jetbrains.jps.model.module;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jps.model.library.JpsLibraryReference;
/**
* @author nik
*/
public interface JpsLibraryDependency extends JpsDependencyElement {
@NotNull
JpsLibraryReference getLibraryReference();
}
@@ -0,0 +1,44 @@
package org.jetbrains.jps.model.module;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jps.model.*;
import java.util.List;
/**
* @author nik
*/
public interface JpsModule extends JpsNamedElement, JpsReferenceableElement<JpsModule> {
@NotNull
JpsUrlList getContentRootsList();
@NotNull
JpsUrlList getExcludeRootsList();
@NotNull
List<? extends JpsModuleSourceRoot> getSourceRoots();
@NotNull
<P extends JpsElementProperties>
JpsModuleSourceRoot addSourceRoot(@NotNull JpsModuleSourceRootType<P> rootType, @NotNull String url);
@NotNull
<P extends JpsElementProperties>
JpsModuleSourceRoot addSourceRoot(@NotNull JpsModuleSourceRootType<P> rootType, @NotNull String url, @NotNull P properties);
void removeSourceRoot(@NotNull JpsModuleSourceRootType rootType, @NotNull String url);
JpsDependenciesList getDependenciesList();
@NotNull
JpsElementContainer getContainer();
@NotNull
JpsModuleReference createReference(JpsParentElement parent);
void delete();
@NotNull
JpsSdkReferencesTable getSdkReferencesTable();
}
@@ -0,0 +1,9 @@
package org.jetbrains.jps.model.module;
import org.jetbrains.jps.model.JpsUrlListChangeListener;
/**
* @author nik
*/
public interface JpsModuleContentRootsListener extends JpsUrlListChangeListener<JpsModule> {
}
@@ -0,0 +1,11 @@
package org.jetbrains.jps.model.module;
import org.jetbrains.annotations.NotNull;
/**
* @author nik
*/
public interface JpsModuleDependency extends JpsDependencyElement {
@NotNull
JpsModuleReference getModuleReference();
}
@@ -0,0 +1,9 @@
package org.jetbrains.jps.model.module;
import org.jetbrains.jps.model.JpsUrlListChangeListener;
/**
* @author nik
*/
public interface JpsModuleExcludeRootsListener extends JpsUrlListChangeListener<JpsModule> {
}
@@ -0,0 +1,14 @@
package org.jetbrains.jps.model.module;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jps.model.module.JpsModule;
import java.util.EventListener;
/**
* @author nik
*/
public interface JpsModuleListener extends EventListener {
void moduleAdded(@NotNull JpsModule module);
void moduleRemoved(@NotNull JpsModule module);
}
@@ -0,0 +1,12 @@
package org.jetbrains.jps.model.module;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jps.model.JpsElementReference;
/**
* @author nik
*/
public interface JpsModuleReference extends JpsElementReference<JpsModule> {
@NotNull
String getModuleName();
}
@@ -0,0 +1,23 @@
package org.jetbrains.jps.model.module;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jps.model.JpsElement;
import org.jetbrains.jps.model.JpsElementProperties;
/**
* @author nik
*/
public interface JpsModuleSourceRoot extends JpsElement {
@NotNull
JpsModuleSourceRootType<?> getRootType();
@Nullable
<P extends JpsElementProperties> P getProperties(@NotNull JpsModuleSourceRootType<P> type);
<P extends JpsElementProperties>
void setProperties(JpsModuleSourceRootType<P> type, P properties);
@NotNull
String getUrl();
}
@@ -0,0 +1,14 @@
package org.jetbrains.jps.model.module;
import org.jetbrains.annotations.NotNull;
import java.util.EventListener;
/**
* @author nik
*/
public interface JpsModuleSourceRootListener extends EventListener {
void sourceRootAdded(@NotNull JpsModuleSourceRoot root);
void sourceRootRemoved(@NotNull JpsModuleSourceRoot root);
void sourceRootChanged(@NotNull JpsModuleSourceRoot root);
}
@@ -0,0 +1,10 @@
package org.jetbrains.jps.model.module;
import org.jetbrains.jps.model.JpsElementProperties;
import org.jetbrains.jps.model.JpsElementType;
/**
* @author nik
*/
public abstract class JpsModuleSourceRootType<P extends JpsElementProperties> extends JpsElementType<P> {
}
@@ -0,0 +1,11 @@
package org.jetbrains.jps.model.module;
import org.jetbrains.jps.model.JpsElementProperties;
import org.jetbrains.jps.model.JpsElementType;
/**
* @author nik
*/
public abstract class JpsModuleType<P extends JpsElementProperties> extends JpsElementType<P> {
}
@@ -0,0 +1,17 @@
package org.jetbrains.jps.model.module;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jps.model.library.JpsLibrary;
import org.jetbrains.jps.model.library.JpsSdkType;
/**
* @author nik
*/
public interface JpsSdkDependency extends JpsDependencyElement {
@NotNull
JpsSdkType<?> getSdkType();
@Nullable
JpsLibrary resolveSdk();
}
@@ -0,0 +1,18 @@
package org.jetbrains.jps.model.module;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jps.model.JpsCompositeElement;
import org.jetbrains.jps.model.library.JpsLibrary;
import org.jetbrains.jps.model.library.JpsLibraryReference;
import org.jetbrains.jps.model.library.JpsSdkType;
/**
* @author nik
*/
public interface JpsSdkReferencesTable extends JpsCompositeElement {
@Nullable
JpsLibraryReference getSdkReference(@NotNull JpsSdkType<?> type);
void setSdkReference(@NotNull JpsSdkType<?> type, @NotNull JpsLibrary sdk);
}
+16
View File
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/testSrc" isTestSource="true" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="util" />
<orderEntry type="module" module-name="jps-model-api" />
<orderEntry type="module" module-name="testFramework" scope="TEST" />
</component>
</module>
@@ -0,0 +1,35 @@
package org.jetbrains.jps.model.impl;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jps.model.*;
/**
* @author nik
*/
public abstract class JpsCompositeElementBase<Self extends JpsCompositeElementBase<Self>> extends JpsElementBase<Self> implements JpsCompositeElement {
protected final JpsElementContainerImpl myContainer;
protected final JpsModel myModel;
protected JpsCompositeElementBase(JpsModel model, JpsEventDispatcher eventDispatcher, JpsParentElement parent) {
super(eventDispatcher, parent);
myModel = model;
myContainer = new JpsElementContainerImpl(model, eventDispatcher, this);
}
protected JpsCompositeElementBase(JpsCompositeElementBase<Self> original, JpsModel model, JpsEventDispatcher dispatcher,
JpsParentElement parent) {
super(original, dispatcher, parent);
myModel = model;
myContainer = new JpsElementContainerImpl(original.myContainer, model, dispatcher, this);
}
public void applyChanges(@NotNull Self element) {
myContainer.applyChanges(element.myContainer);
}
@Override
@NotNull
public JpsElementContainerImpl getContainer() {
return myContainer;
}
}
@@ -0,0 +1,41 @@
package org.jetbrains.jps.model.impl;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jps.model.*;
/**
* @author nik
*/
public abstract class JpsElementBase<Self extends JpsElementBase<Self>> implements JpsElement, JpsElement.BulkModificationSupport<Self> {
private JpsEventDispatcher myEventDispatcher;
protected JpsParentElement myParent;
protected JpsElementBase(JpsEventDispatcher eventDispatcher, JpsParentElement parent) {
myEventDispatcher = eventDispatcher;
myParent = parent;
}
public JpsElementBase(JpsElementBase original, JpsEventDispatcher eventDispatcher, JpsParentElement parent) {
myEventDispatcher = eventDispatcher;
myParent = parent;
}
protected JpsEventDispatcher getEventDispatcher() {
return myEventDispatcher;
}
@NotNull
@Override
public BulkModificationSupport<?> getBulkModificationSupport() {
return this;
}
@NotNull
public abstract Self createCopy(@NotNull JpsModel model, @NotNull JpsEventDispatcher eventDispatcher, JpsParentElement parent);
public abstract void applyChanges(@NotNull Self modified);
public JpsParentElement getParent() {
return myParent;
}
}
@@ -0,0 +1,107 @@
package org.jetbrains.jps.model.impl;
import com.intellij.util.SmartList;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jps.model.*;
import java.util.*;
/**
* @author nik
*/
public class JpsElementCollectionImpl<E extends JpsElement> extends JpsElementBase<JpsElementCollectionImpl<E>> implements JpsElementCollection<E> {
private final List<E> myElements;
private final JpsModel myModel;
private final Map<E, E> myCopyToOriginal;
private final JpsElementKind<E> myKind;
public JpsElementCollectionImpl(JpsElementKind<E> kind, JpsModel model, JpsEventDispatcher eventDispatcher, JpsParentElement parent) {
super(eventDispatcher, parent);
myKind = kind;
myModel = model;
myElements = new SmartList<E>();
myCopyToOriginal = null;
}
public JpsElementCollectionImpl(JpsElementCollectionImpl<E> original,
JpsModel model,
JpsEventDispatcher eventDispatcher,
JpsParentElement parent) {
super(original, eventDispatcher, parent);
myKind = original.myKind;
myModel = model;
myElements = new SmartList<E>();
myCopyToOriginal = new HashMap<E, E>();
for (E e : original.myElements) {
//noinspection unchecked
final E copy = (E)e.getBulkModificationSupport().createCopy(model, eventDispatcher, parent);
myElements.add(copy);
myCopyToOriginal.put(copy, e);
}
}
@Override
public List<E> getElements() {
return myElements;
}
@NotNull
@Override
public <P> E addChild(@NotNull JpsElementFactoryWithParameter<E, P> factory, @NotNull P param) {
return addChild(factory.create(myModel, getEventDispatcher(), myParent, param));
}
@NotNull
@Override
public E addChild(@NotNull JpsElementFactory<E> factory) {
return addChild(factory.create(myModel, getEventDispatcher(), myParent));
}
@Override
public E addChild(E element) {
myElements.add(element);
getEventDispatcher().fireElementAdded(element, myKind);
return element;
}
@Override
public void removeChild(@NotNull E element) {
final boolean removed = myElements.remove(element);
if (removed) {
getEventDispatcher().fireElementRemoved(element, myKind);
}
}
@NotNull
@Override
public JpsElementCollectionImpl<E> createCopy(@NotNull JpsModel model,
@NotNull JpsEventDispatcher eventDispatcher,
JpsParentElement parent) {
return new JpsElementCollectionImpl<E>(this, model, eventDispatcher, parent);
}
public void applyChanges(@NotNull JpsElementCollectionImpl<E> modified) {
Set<E> toRemove = new LinkedHashSet<E>(myElements);
List<E> toAdd = new ArrayList<E>();
final Map<E, E> copyToOriginal = modified.myCopyToOriginal;
for (E element : modified.myElements) {
final E original = copyToOriginal != null ? copyToOriginal.get(element) : null;
if (original != null) {
//noinspection unchecked
((BulkModificationSupport<E>)original.getBulkModificationSupport()).applyChanges(element);
toRemove.remove(original);
}
else {
//noinspection unchecked
final E copy = (E)element.getBulkModificationSupport().createCopy(myModel, getEventDispatcher(), myParent);
toAdd.add(copy);
}
}
for (E e : toRemove) {
removeChild(e);
}
for (E e : toAdd) {
addChild(e);
}
}
}
@@ -0,0 +1,24 @@
package org.jetbrains.jps.model.impl;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jps.model.*;
/**
* @author nik
*/
public class JpsElementCollectionKind<E extends JpsElement> extends JpsElementKind<JpsElementCollectionImpl<E>>
implements JpsElementFactory<JpsElementCollectionImpl<E>> {
private final JpsElementKind<E> myElementKind;
public JpsElementCollectionKind(JpsElementKind<E> elementKind) {
myElementKind = elementKind;
}
@NotNull
@Override
public JpsElementCollectionImpl<E> create(@NotNull JpsModel model,
@NotNull JpsEventDispatcher eventDispatcher,
JpsParentElement parent) {
return new JpsElementCollectionImpl<E>(myElementKind, model, eventDispatcher, parent);
}
}
@@ -0,0 +1,98 @@
package org.jetbrains.jps.model.impl;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jps.model.*;
import java.util.HashMap;
import java.util.Map;
/**
* @author nik
*/
public class JpsElementContainerImpl implements JpsElementContainer {
private final Map<JpsElementKind<?>, JpsElement> myElements = new HashMap<JpsElementKind<?>, JpsElement>();
private final @NotNull JpsModel myModel;
private final @NotNull JpsEventDispatcher myEventDispatcher;
private final @NotNull JpsParentElement myParent;
public JpsElementContainerImpl(@NotNull JpsModel model,
@NotNull JpsEventDispatcher eventDispatcher, JpsParentElement parent) {
myModel = model;
myEventDispatcher = eventDispatcher;
myParent = parent;
}
public JpsElementContainerImpl(@NotNull JpsElementContainerImpl original, @NotNull JpsModel model,
@NotNull JpsEventDispatcher eventDispatcher, JpsParentElement parent) {
myModel = model;
myEventDispatcher = eventDispatcher;
myParent = parent;
for (Map.Entry<JpsElementKind<?>, JpsElement> entry : original.myElements.entrySet()) {
final JpsElementKind kind = entry.getKey();
myElements.put(kind, entry.getValue().getBulkModificationSupport().createCopy(myModel, myEventDispatcher, myParent));
}
}
@Override
public <T extends JpsElement> T getChild(@NotNull JpsElementKind<T> kind) {
//noinspection unchecked
return (T)myElements.get(kind);
}
@NotNull
@Override
public <T extends JpsElement, P, K extends JpsElementKind<T> & JpsElementFactoryWithParameter<T, P>> T setChild(@NotNull K kind,
@NotNull P param) {
final T child = kind.create(myModel, myEventDispatcher, myParent, param);
return setChild(kind, child);
}
@NotNull
@Override
public <T extends JpsElement, K extends JpsElementKind<T> & JpsElementFactory<T>> T setChild(@NotNull K kind) {
final T child = kind.create(myModel, myEventDispatcher, myParent);
return setChild(kind, child);
}
@Override
public <T extends JpsElement> T setChild(JpsElementKind<T> kind, T child) {
myElements.put(kind, child);
myEventDispatcher.fireElementAdded(child, kind);
return child;
}
@Override
public <T extends JpsElement> void removeChild(@NotNull JpsElementKind<T> kind) {
//noinspection unchecked
final T removed = (T)myElements.remove(kind);
myEventDispatcher.fireElementRemoved(removed, kind);
}
public void applyChanges(@NotNull JpsElementContainerImpl modified) {
for (JpsElementKind<?> kind : myElements.keySet()) {
applyChanges(kind, modified);
}
for (JpsElementKind<?> kind : modified.myElements.keySet()) {
if (!myElements.containsKey(kind)) {
applyChanges(kind, modified);
}
}
}
private <T extends JpsElement> void applyChanges(JpsElementKind<T> kind, JpsElementContainerImpl modified) {
final T child = getChild(kind);
final T modifiedChild = modified.getChild(kind);
if (child != null && modifiedChild != null) {
final JpsElement.BulkModificationSupport modificationSupport = child.getBulkModificationSupport();
//noinspection unchecked
modificationSupport.applyChanges(modifiedChild);
}
else if (modifiedChild == null) {
removeChild(kind);
}
else {
//noinspection unchecked
setChild(kind, (T)modifiedChild.getBulkModificationSupport().createCopy(myModel, myEventDispatcher, myParent));
}
}
}
@@ -0,0 +1,40 @@
package org.jetbrains.jps.model.impl;
import com.intellij.util.EventDispatcher;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jps.model.JpsElement;
import org.jetbrains.jps.model.JpsElementKind;
import org.jetbrains.jps.model.JpsEventDispatcher;
import java.util.EventListener;
import java.util.HashMap;
import java.util.Map;
/**
* @author nik
*/
public abstract class JpsEventDispatcherBase implements JpsEventDispatcher {
private Map<Class<?>, EventDispatcher<?>> myDispatchers = new HashMap<Class<?>, EventDispatcher<?>>();
@NotNull
@Override
public <T extends EventListener> T getPublisher(Class<T> listenerClass) {
EventDispatcher<?> dispatcher = myDispatchers.get(listenerClass);
if (dispatcher == null) {
dispatcher = EventDispatcher.create(listenerClass);
myDispatchers.put(listenerClass, dispatcher);
}
//noinspection unchecked
return (T)dispatcher.getMulticaster();
}
@Override
public <T extends JpsElement> void fireElementAdded(@NotNull T element, @NotNull JpsElementKind<T> kind) {
kind.fireElementAdded(this, element);
}
@Override
public <T extends JpsElement> void fireElementRemoved(@NotNull T element, @NotNull JpsElementKind<T> kind) {
kind.fireElementRemoved(this, element);
}
}

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