Merge remote branch 'origin/master'

This commit is contained in:
Dmitry Jemerov
2012-02-08 20:15:35 +01:00
49 changed files with 1442 additions and 235 deletions
@@ -19,11 +19,13 @@ import com.intellij.codeInsight.lookup.*;
import com.intellij.featureStatistics.FeatureUsageTracker;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.util.ClassConditionKey;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.*;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.psi.util.PsiTreeUtil;
import gnu.trove.THashSet;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Set;
@@ -65,7 +67,16 @@ public class JavaChainLookupElement extends LookupElementDecorator<LookupElement
}
private String maybeAddParentheses(String s) {
return myQualifier.getObject() instanceof PsiMethod ? s + "()" : s;
return getQualifierObject() instanceof PsiMethod ? s + "()" : s;
}
@Nullable
private Object getQualifierObject() {
Object qObject = myQualifier.getObject();
if (qObject instanceof ResolveResult) {
qObject = ((ResolveResult)qObject).getElement();
}
return qObject;
}
@Override
@@ -76,6 +87,10 @@ public class JavaChainLookupElement extends LookupElementDecorator<LookupElement
String name = maybeAddParentheses(qualifierPresentation.getItemText());
final String qualifierText = myQualifier.as(CastingLookupElementDecorator.CLASS_CONDITION_KEY) != null ? "(" + name + ")" : name;
presentation.setItemText(qualifierText + "." + presentation.getItemText());
if (getQualifierObject() instanceof PsiClass) {
presentation.setTailText(StringUtil.notNullize(presentation.getTailText()) + qualifierPresentation.getTailText());
}
}
@Override
@@ -99,7 +114,7 @@ public class JavaChainLookupElement extends LookupElementDecorator<LookupElement
CompletionUtil.emulateInsertion(getDelegate(), context.getTailOffset(), context);
}
private static boolean shouldParenthesizeQualifier(final PsiFile file, final int startOffset, final int endOffset) {
protected boolean shouldParenthesizeQualifier(final PsiFile file, final int startOffset, final int endOffset) {
PsiElement element = file.findElementAt(startOffset);
if (element == null) {
return false;
@@ -57,7 +57,8 @@ public class JavaClassNameCompletionContributor extends CompletionContributor {
}
CompletionResultSet result = _result.withPrefixMatcher(CompletionUtil.findReferenceOrAlphanumericPrefix(parameters));
addAllClasses(parameters, JavaCompletionSorting.addJavaSorting(parameters, result), parameters.getInvocationCount() <= 1, new Consumer<LookupElement>() {
addAllClasses(parameters, parameters.getInvocationCount() <= 1,
JavaCompletionSorting.addJavaSorting(parameters, result).getPrefixMatcher(), new Consumer<LookupElement>() {
@Override
public void consume(LookupElement element) {
_result.addElement(element);
@@ -68,8 +69,8 @@ public class JavaClassNameCompletionContributor extends CompletionContributor {
}
public static void addAllClasses(CompletionParameters parameters,
final CompletionResultSet result,
final boolean filterByScope,
@NotNull final PrefixMatcher matcher,
@NotNull final Consumer<LookupElement> consumer) {
final PsiElement insertedElement = parameters.getPosition();
@@ -110,7 +111,7 @@ public class JavaClassNameCompletionContributor extends CompletionContributor {
}
final boolean lookingForAnnotations = PsiJavaPatterns.psiElement().afterLeaf("@").accepts(insertedElement);
AllClassesGetter.processJavaClasses(parameters, result.getPrefixMatcher(), filterByScope, new Consumer<PsiClass>() {
AllClassesGetter.processJavaClasses(parameters, matcher, filterByScope, new Consumer<PsiClass>() {
@Override
public void consume(PsiClass psiClass) {
if (lookingForAnnotations && !psiClass.isAnnotationType()) return;
@@ -106,7 +106,7 @@ public class JavaCompletionContributor extends CompletionContributor {
withParent(or(psiElement(PsiResourceVariable.class), psiElement(PsiResourceList.class)))));
@Nullable
private static ElementFilter getReferenceFilter(PsiElement position) {
public static ElementFilter getReferenceFilter(PsiElement position) {
// Completion after extends in interface, type parameter and implements in class
final PsiClass containingClass = PsiTreeUtil.getParentOfType(position, PsiClass.class, false, PsiCodeBlock.class, PsiMethod.class, PsiExpressionList.class, PsiVariable.class);
if (containingClass != null && psiElement().afterLeaf(PsiKeyword.EXTENDS, PsiKeyword.IMPLEMENTS, ",", "&").accepts(position)) {
@@ -239,7 +239,7 @@ public class JavaCompletionContributor extends CompletionContributor {
if (!isClassNamePossible(parameters.getPosition()) || !mayStartClassName(result, parameters.isRelaxedMatching())) return;
if (mayShowAllClasses(parameters)) {
JavaClassNameCompletionContributor.addAllClasses(parameters, result, parameters.getInvocationCount() <= 2, new Consumer<LookupElement>() {
JavaClassNameCompletionContributor.addAllClasses(parameters, parameters.getInvocationCount() <= 2, result.getPrefixMatcher(), new Consumer<LookupElement>() {
@Override
public void consume(LookupElement element) {
if (!inheritors.alreadyProcessed(element)) {
@@ -346,6 +346,9 @@ public class JavaCompletionUtil {
@Nullable
private static PsiType getPsiType(final Object o) {
if (o instanceof ResolveResult) {
return getPsiType(((ResolveResult)o).getElement());
}
if (o instanceof PsiVariable) {
return ((PsiVariable)o).getType();
}
@@ -15,10 +15,21 @@
*/
package com.intellij.codeInsight.completion;
import com.intellij.codeInsight.completion.impl.CamelHumpMatcher;
import com.intellij.codeInsight.lookup.AutoCompletionPolicy;
import com.intellij.codeInsight.lookup.LookupElement;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiJavaCodeReferenceElement;
import com.intellij.psi.PsiReferenceExpression;
import com.intellij.psi.PsiType;
import com.intellij.psi.filters.ElementFilter;
import com.intellij.util.CollectConsumer;
import com.intellij.util.Consumer;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.Set;
/**
* @author peter
*/
@@ -26,29 +37,87 @@ public class JavaNoVariantsDelegator extends NoVariantsDelegator {
@Override
protected void delegate(CompletionParameters parameters, CompletionResultSet result, Consumer<CompletionResult> passResult) {
if (parameters.getCompletionType() == CompletionType.BASIC &&
parameters.getInvocationCount() <= 1 &&
JavaCompletionContributor.mayStartClassName(result, false) &&
JavaCompletionContributor.isClassNamePossible(parameters.getPosition())) {
final ClassByNameMerger merger = new ClassByNameMerger(parameters.getInvocationCount() == 0, result);
if (parameters.getCompletionType() == CompletionType.BASIC) {
PsiElement position = parameters.getPosition();
if (parameters.getInvocationCount() <= 1 &&
JavaCompletionContributor.mayStartClassName(result, false) &&
JavaCompletionContributor.isClassNamePossible(position)) {
suggestNonImportedClasses(parameters, result);
return;
}
JavaClassNameCompletionContributor.addAllClasses(parameters, JavaCompletionSorting.addJavaSorting(parameters, result),
true, new Consumer<LookupElement>() {
@Override
public void consume(LookupElement element) {
JavaPsiClassReferenceElement classElement = element.as(JavaPsiClassReferenceElement.CLASS_CONDITION_KEY);
if (classElement != null) {
classElement.setAutoCompletionPolicy(AutoCompletionPolicy.NEVER_AUTOCOMPLETE);
}
suggestChainedCalls(parameters, result, position);
}
merger.consume(classElement);
}
});
merger.finishedClassProcessing();
} else if (parameters.getCompletionType() == CompletionType.SMART && parameters.getInvocationCount() == 2) {
if (parameters.getCompletionType() == CompletionType.SMART && parameters.getInvocationCount() == 2) {
result.runRemainingContributors(parameters.withInvocationCount(3), passResult);
}
}
private static void suggestChainedCalls(CompletionParameters parameters, CompletionResultSet result, PsiElement position) {
PsiElement parent = position.getParent();
if (!(parent instanceof PsiJavaCodeReferenceElement)) {
return;
}
PsiElement qualifier = ((PsiJavaCodeReferenceElement)parent).getQualifier();
if (!(qualifier instanceof PsiJavaCodeReferenceElement) ||
((PsiJavaCodeReferenceElement)qualifier).isQualified() ||
((PsiJavaCodeReferenceElement)qualifier).resolve() != null) {
return;
}
String fullPrefix = position.getContainingFile().getText().substring(parent.getTextRange().getStartOffset(), parameters.getOffset());
CompletionResultSet qualifiedCollector = result.withPrefixMatcher(fullPrefix);
ElementFilter filter = JavaCompletionContributor.getReferenceFilter(position);
for (LookupElement base : suggestQualifierItems(parameters, (PsiJavaCodeReferenceElement)qualifier, filter)) {
PsiType type = JavaCompletionUtil.getLookupElementType(base);
if (type != null && !PsiType.VOID.equals(type)) {
PsiReferenceExpression ref = ReferenceExpressionCompletionContributor.createMockReference(position, type, base);
for (final LookupElement item : JavaSmartCompletionContributor.completeReference(position, ref, filter, true, true, parameters,
result.getPrefixMatcher())) {
qualifiedCollector.addElement(new JavaChainLookupElement(base, item));
}
}
}
}
private static Set<LookupElement> suggestQualifierItems(CompletionParameters parameters,
PsiJavaCodeReferenceElement qualifier,
ElementFilter filter) {
String referenceName = qualifier.getReferenceName();
if (referenceName == null) {
return Collections.emptySet();
}
PrefixMatcher qMatcher = new CamelHumpMatcher(referenceName);
Set<LookupElement> plainVariants =
JavaSmartCompletionContributor.completeReference(qualifier, qualifier, filter, true, true, parameters, qMatcher);
if (!plainVariants.isEmpty()) {
return plainVariants;
}
final Set<LookupElement> allClasses = new LinkedHashSet<LookupElement>();
JavaClassNameCompletionContributor.addAllClasses(parameters.withPosition(qualifier.getReferenceNameElement(), qualifier.getTextRange().getEndOffset()),
true, qMatcher, new CollectConsumer<LookupElement>(allClasses));
return allClasses;
}
private static void suggestNonImportedClasses(CompletionParameters parameters, CompletionResultSet result) {
final ClassByNameMerger merger = new ClassByNameMerger(parameters.getInvocationCount() == 0, result);
JavaClassNameCompletionContributor.addAllClasses(parameters,
true, JavaCompletionSorting.addJavaSorting(parameters, result).getPrefixMatcher(), new Consumer<LookupElement>() {
@Override
public void consume(LookupElement element) {
JavaPsiClassReferenceElement classElement = element.as(JavaPsiClassReferenceElement.CLASS_CONDITION_KEY);
if (classElement != null) {
classElement.setAutoCompletionPolicy(AutoCompletionPolicy.NEVER_AUTOCOMPLETE);
}
merger.consume(classElement);
}
});
merger.finishedClassProcessing();
}
}
@@ -155,14 +155,15 @@ public class JavaSmartCompletionContributor extends CompletionContributor {
final ElementFilter filter = getReferenceFilter(element);
if (filter != null) {
final List<ExpectedTypeInfo> infos = Arrays.asList(getExpectedTypes(parameters));
for (final LookupElement item : completeReference(element, reference, filter, true, parameters)) {
for (final LookupElement item : completeReference(element, reference, filter, true, false, parameters, result.getPrefixMatcher())) {
if (item.getObject() instanceof PsiClass) {
result.addElement(decorate(LookupElementDecorator.withInsertHandler((LookupItem)item, ConstructorInsertHandler.SMART_INSTANCE), infos));
}
}
}
else if (INSIDE_TYPECAST_EXPRESSION.accepts(element)) {
for (final LookupElement item : completeReference(element, reference, new GeneratorFilter(AssignableToFilter.class, new CastTypeGetter()), false, parameters)) {
for (final LookupElement item : completeReference(element, reference, new GeneratorFilter(AssignableToFilter.class, new CastTypeGetter()), false, true, parameters,
result.getPrefixMatcher())) {
result.addElement(item);
}
}
@@ -182,7 +183,7 @@ public class JavaSmartCompletionContributor extends CompletionContributor {
final PsiElement element = parameters.getPosition();
final PsiReference reference = element.getContainingFile().findReferenceAt(parameters.getOffset());
assert reference != null;
for (final LookupElement item : completeReference(element, reference, THROWABLES_FILTER, true, parameters)) {
for (final LookupElement item : completeReference(element, reference, THROWABLES_FILTER, true, false, parameters, result.getPrefixMatcher())) {
result.addElement(item);
}
}
@@ -456,7 +457,12 @@ public class JavaSmartCompletionContributor extends CompletionContributor {
return ExpectedTypesProvider.getExpectedTypes(expression, true, parameters.getCompletionType() == CompletionType.SMART, false);
}
static Set<LookupElement> completeReference(final PsiElement element, PsiReference reference, final ElementFilter filter, final boolean acceptClasses, CompletionParameters parameters) {
static Set<LookupElement> completeReference(final PsiElement element,
PsiReference reference,
final ElementFilter filter,
final boolean acceptClasses,
final boolean acceptMembers,
CompletionParameters parameters, @Nullable final PrefixMatcher matcher) {
if (reference instanceof PsiMultiReference) {
reference = ContainerUtil.findInstance(((PsiMultiReference) reference).getReferences(), PsiJavaReference.class);
}
@@ -470,15 +476,18 @@ public class JavaSmartCompletionContributor extends CompletionContributor {
}
public boolean isClassAcceptable(Class hintClass) {
if (acceptClasses) {
return ReflectionCache.isAssignable(PsiClass.class, hintClass);
if (ReflectionCache.isAssignable(PsiClass.class, hintClass)) {
return acceptClasses;
}
return ReflectionCache.isAssignable(PsiVariable.class, hintClass) ||
ReflectionCache.isAssignable(PsiMethod.class, hintClass) ||
ReflectionCache.isAssignable(CandidateInfo.class, hintClass);
if (ReflectionCache.isAssignable(PsiVariable.class, hintClass) ||
ReflectionCache.isAssignable(PsiMethod.class, hintClass) ||
ReflectionCache.isAssignable(CandidateInfo.class, hintClass)) {
return acceptMembers;
}
return false;
}
}, true, parameters.getInvocationCount() <= 1, null, parameters);
}, true, parameters.getInvocationCount() <= 1, matcher, parameters);
}
return Collections.emptySet();
@@ -33,8 +33,11 @@ import com.intellij.psi.codeStyle.JavaCodeStyleManager;
import com.intellij.psi.filters.*;
import com.intellij.psi.filters.element.ModifierFilter;
import com.intellij.psi.filters.types.AssignableFromFilter;
import com.intellij.psi.impl.FakePsiElement;
import com.intellij.psi.impl.light.LightVariableBuilder;
import com.intellij.psi.impl.source.PostprocessReformattingAspect;
import com.intellij.psi.infos.CandidateInfo;
import com.intellij.psi.scope.PsiScopeProcessor;
import com.intellij.psi.util.InheritanceUtil;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.psi.util.PsiUtil;
@@ -122,7 +125,7 @@ public class ReferenceExpressionCompletionContributor {
final boolean secondTime = parameters.getParameters().getInvocationCount() >= 2;
final Set<LookupElement> base =
JavaSmartCompletionContributor.completeReference(element, reference, filter, false, parameters.getParameters());
JavaSmartCompletionContributor.completeReference(element, reference, filter, false, true, parameters.getParameters(), null);
for (final LookupElement item : base) {
addSingleArrayElementAccess(element, item, parameters, result);
}
@@ -177,7 +180,7 @@ public class ReferenceExpressionCompletionContributor {
public boolean isClassAcceptable(Class hintClass) {
return true;
}
}), false, parameters.getParameters());
}), false, true, parameters.getParameters(), null);
for (LookupElement lookupElement : elements) {
if (lookupElement.getObject() instanceof PsiMethod) {
final JavaMethodCallElement item = lookupElement.as(JavaMethodCallElement.CLASS_CONDITION_KEY);
@@ -419,32 +422,43 @@ public class ReferenceExpressionCompletionContributor {
final Consumer<LookupElement> result,
PsiType qualifierType,
final PsiType expectedType, JavaSmartCompletionParameters parameters) throws IncorrectOperationException {
final JavaCodeFragmentFactory factory = JavaCodeFragmentFactory.getInstance(place.getProject());
PsiType varType = qualifierType;
if (varType instanceof PsiEllipsisType) {
varType = ((PsiEllipsisType)varType).getComponentType();
}
if (varType instanceof PsiWildcardType || varType instanceof PsiCapturedWildcardType) {
varType = TypeConversionUtil.erasure(expectedType);
}
final String typeText = varType.getCanonicalText();
final JavaCodeFragment block = factory.createCodeBlockCodeFragment(typeText + " xxx;xxx.xxx;", place, false);
final PsiElement secondChild = block.getChildren()[1];
if (!(secondChild instanceof PsiExpressionStatement)) {
LOG.error(typeText + " of " + varType.getClass());
}
final PsiExpressionStatement expressionStatement = (PsiExpressionStatement)secondChild;
final PsiReferenceExpression mockRef = (PsiReferenceExpression) expressionStatement.getExpression();
final PsiReferenceExpression mockRef = createMockReference(place, qualifierType, qualifierItem);
final ElementFilter filter = getReferenceFilter(place, true);
for (final LookupElement item : completeFinalReference(place, mockRef, filter, parameters)) {
if (shoudChain(place, varType, expectedType, item)) {
if (shoudChain(place, qualifierType, expectedType, item)) {
result.consume(new JavaChainLookupElement(qualifierItem, item));
}
}
}
public static PsiReferenceExpression createMockReference(final PsiElement place, @NotNull PsiType qualifierType, LookupElement qualifierItem) {
PsiElementFactory factory = JavaPsiFacade.getElementFactory(place.getProject());
if (qualifierItem.getObject() instanceof PsiClass) {
return (PsiReferenceExpression)factory
.createExpressionFromText(((PsiClass)qualifierItem.getObject()).getQualifiedName() + ".xxx", place);
}
return (PsiReferenceExpression) factory.createExpressionFromText("xxx.xxx", createContextWithXxxVariable(place, qualifierType));
}
public static FakePsiElement createContextWithXxxVariable(final PsiElement place, final PsiType varType) {
return new FakePsiElement() {
@Override
public boolean processDeclarations(@NotNull PsiScopeProcessor processor,
@NotNull ResolveState state,
PsiElement lastParent,
@NotNull PsiElement place) {
return processor.execute(new LightVariableBuilder("xxx", varType, place), ResolveState.initial());
}
@Override
public PsiElement getParent() {
return place;
}
};
}
private static boolean shoudChain(PsiElement element, PsiType qualifierType, PsiType expectedType, LookupElement item) {
if (item.getObject() instanceof PsiMethod) {
final PsiMethod method = (PsiMethod)item.getObject();
@@ -122,6 +122,7 @@ public class PullAsAbstractUpFix extends LocalQuickFixAndIntentionActionOnPsiEle
}
private static void pullUp(PsiMethod method, PsiClass containingClass, PsiClass baseClass) {
if (!CodeInsightUtilBase.prepareFileForWrite(baseClass.getContainingFile())) return;
final MemberInfo memberInfo = new MemberInfo(method);
memberInfo.setChecked(true);
memberInfo.setToAbstract(true);
@@ -45,6 +45,7 @@ import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.List;
/**
@@ -85,8 +86,10 @@ public class JavaVariableInplaceIntroducer extends InplaceVariableIntroducer<Psi
myPointer = declarationStatement != null ? SmartPointerManager.getInstance(project).createSmartPsiElementPointer(declarationStatement) : null;
editor.putUserData(ReassignVariableUtil.DECLARATION_KEY, myPointer);
if (occurrenceMarkers != null) {
final ArrayList<RangeMarker> rangeMarkers = new ArrayList<RangeMarker>(occurrenceMarkers);
rangeMarkers.add(exprMarker);
editor.putUserData(ReassignVariableUtil.OCCURRENCES_KEY,
occurrenceMarkers.toArray(new RangeMarker[occurrenceMarkers.size()]));
rangeMarkers.toArray(new RangeMarker[rangeMarkers.size()]));
}
myExpression = expression;
final PsiType defaultType = elementToRename.getType();
@@ -24,6 +24,7 @@ import com.intellij.openapi.project.Project;
import com.intellij.psi.*;
import com.intellij.psi.impl.file.JavaDirectoryServiceImpl;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.util.PsiUtil;
import com.intellij.psi.util.PsiUtilBase;
import com.intellij.refactoring.move.MoveCallback;
import com.intellij.util.ArrayUtil;
@@ -76,9 +77,12 @@ public class JavaMoveFilesOrDirectoriesHandler extends MoveFilesOrDirectoriesHan
@Override
protected void run(Result<PsiElement[]> result) throws Throwable {
final List<PsiElement> adjustedElements = new ArrayList<PsiElement>();
for (PsiElement element : elements) {
for (int i = 0, length = elements.length; i < length; i++) {
PsiElement element = elements[i];
if (element instanceof PsiClass) {
final PsiFile containingFile = obtainContainingFile(element, elements);
final PsiClass topLevelClass = PsiUtil.getTopLevelClass(element);
elements[i] = topLevelClass;
final PsiFile containingFile = obtainContainingFile(topLevelClass, elements);
if (containingFile != null && !adjustedElements.contains(containingFile)) {
adjustedElements.add(containingFile);
}
@@ -32,6 +32,7 @@ import java.util.ArrayList;
import java.util.List;
public class CommandLineWrapper {
private static final String PREFIX = "-D";
public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException,
IllegalAccessException, IOException, InstantiationException {
@@ -54,9 +55,41 @@ public class CommandLineWrapper {
reader.close();
}
file.delete();
String progClass = args[1];
String[] progArgs = new String[args.length - 2];
System.arraycopy(args, 2, progArgs, 0, progArgs.length);
int startArgsIdx = 2;
if (args[1].equals("@vm_params")) {
startArgsIdx = 4;
final File vmParamsFile = new File(args[2]);
final BufferedReader vmParamsReader = new BufferedReader(new FileReader(vmParamsFile));
try {
while (vmParamsReader.ready()) {
final String vmParam = vmParamsReader.readLine().trim();
final int eqIdx = vmParam.indexOf("=");
String vmParamName;
String vmParamValue;
if (eqIdx > -1 && eqIdx < vmParam.length() - 1) {
vmParamName = vmParam.substring(0, eqIdx);
vmParamValue = vmParam.substring(eqIdx + 1);
} else {
vmParamName = vmParam;
vmParamValue = "";
}
vmParamName = vmParamName.trim();
if (vmParamName.startsWith(PREFIX)) {
vmParamName = vmParamName.substring(PREFIX.length());
System.setProperty(vmParamName, vmParamValue);
}
}
}
finally {
vmParamsReader.close();
}
vmParamsFile.delete();
}
String progClass = args[startArgsIdx - 1];
String[] progArgs = new String[args.length - startArgsIdx];
System.arraycopy(args, startArgsIdx, progArgs, 0, progArgs.length);
ClassLoader loader = new URLClassLoader((URL[])urls.toArray(new URL[urls.size()]), null);
final String classloader = System.getProperty("java.system.class.loader");
if (classloader != null) {
@@ -1221,4 +1221,16 @@ class Foo {{
myFixture.checkResult 'class Foo { int foo() { re(<caret>) }}'
}
public void testAmbiguousClassQualifier() {
myFixture.addClass("package foo; public class Util { public static void foo() {} }")
myFixture.addClass("package bar; public class Util { public static void bar() {} }")
myFixture.configureByText 'a.java', 'class Foo {{ <caret> }}'
type 'Util.'
assert myFixture.lookupElementStrings == ['Util.bar', 'Util.foo']
type 'fo\n'
myFixture.checkResult '''import foo.Util;
class Foo {{ Util.foo();<caret> }}'''
}
}
@@ -35,10 +35,18 @@ public class Mappings {
private boolean myIsDifferentiated = false;
private final List<DependencyContext.S> myChangedClasses;
private final List<DependencyContext.S> myChangedFiles;
private void addChangedClass(final DependencyContext.S it) {
assert (myChangedClasses != null);
assert (myChangedClasses != null && myChangedFiles != null);
myChangedClasses.add(it);
final DependencyContext.S file = myClassToSourceFile.get(it);
if (file != null) {
myChangedFiles.add(it);
}
myIsDifferentiated = true;
}
@@ -46,6 +54,10 @@ public class Mappings {
return myChangedClasses;
}
private Collection<DependencyContext.S> getChangedFiles() {
return myChangedFiles;
}
private boolean isDifferentiated() {
return myIsDifferentiated;
}
@@ -110,6 +122,7 @@ public class Mappings {
private Mappings(final Mappings base) throws IOException {
myIsDelta = true;
myChangedClasses = new LinkedList<DependencyContext.S>();
myChangedFiles = new LinkedList<DependencyContext.S>();
myDeltaIsTransient = base.myDeltaIsTransient;
myRootDir = new File(FileUtil.toSystemIndependentName(base.myRootDir.getAbsolutePath()) + File.separatorChar + "delta");
myContext = base.myContext;
@@ -121,6 +134,7 @@ public class Mappings {
public Mappings(final File rootDir, final boolean transientDelta) throws IOException {
myIsDelta = false;
myChangedClasses = null;
myChangedFiles = null;
myDeltaIsTransient = transientDelta;
myRootDir = rootDir;
createImplementation();
@@ -1579,9 +1593,32 @@ public class Mappings {
myClassToSourceFile.putAll(delta.myClassToSourceFile);
}
mySourceFileToClasses.putAll(delta.mySourceFileToClasses);
mySourceFileToUsages.putAll(delta.mySourceFileToUsages);
mySourceFileToAnnotationUsages.putAll(delta.mySourceFileToAnnotationUsages);
if (delta.isDifferentiated()) {
for (DependencyContext.S f : delta.getChangedFiles()) {
mySourceFileToClasses.remove(f);
final Collection<ClassRepr> classes = delta.mySourceFileToClasses.get(f);
if (classes != null){
mySourceFileToClasses.put(f, classes);
}
mySourceFileToUsages.remove(f);
final Collection<UsageRepr.Cluster> clusters = delta.mySourceFileToUsages.get(f);
if (clusters != null){
mySourceFileToUsages.put(f, clusters);
}
mySourceFileToAnnotationUsages.remove(f);
final Collection<UsageRepr.Usage> usages = delta.mySourceFileToAnnotationUsages.get(f);
if (usages != null){
mySourceFileToAnnotationUsages.put(f, usages);
}
}
}
else {
mySourceFileToClasses.putAll(delta.mySourceFileToClasses);
mySourceFileToUsages.putAll(delta.mySourceFileToUsages);
mySourceFileToAnnotationUsages.putAll(delta.mySourceFileToAnnotationUsages);
}
final Collection<DependencyContext.S> compiledSet = new HashSet<DependencyContext.S>(compiled.size());
@@ -1684,8 +1721,21 @@ public class Mappings {
}
@Override
public void registerImports(Collection<String> imports, String rootClass) {
//To change body of implemented methods use File | Settings | File Templates.
public void registerImports(final Collection<String> imports, final String rootClass) {
final DependencyContext.S rootClassName = myContext.get(rootClass);
final DependencyContext.S fileName = myClassToSourceFile.get(rootClassName);
for (final String i : imports) {
final DependencyContext.S iname = myContext.get(i);
myClassToClassDependency.put(rootClassName, iname);
if (fileName != null) {
final UsageRepr.Cluster cluster = new UsageRepr.Cluster();
cluster.addUsage(rootClassName, UsageRepr.createClassUsage(myContext, iname));
mySourceFileToUsages.put(fileName, cluster);
}
}
}
};
}
@@ -100,4 +100,8 @@ public class CompletionParameters {
public boolean isRelaxedMatching() {
return myRelaxedMatching;
}
public CompletionParameters withPosition(PsiElement element, int offset) {
return new CompletionParameters(element, myOriginalFile, myCompletionType, offset, myInvocationCount, myLookup, myRelaxedMatching);
}
}
@@ -167,4 +167,10 @@ public class LookupElementPresentation {
public void setTypeGrayed(boolean typeGrayed) {
myTypeGrayed = typeGrayed;
}
public static LookupElementPresentation renderElement(LookupElement element) {
LookupElementPresentation presentation = new LookupElementPresentation();
element.renderElement(presentation);
return presentation;
}
}
@@ -40,6 +40,7 @@ import org.jetbrains.annotations.Nullable;
import java.io.*;
import java.nio.charset.Charset;
import java.nio.charset.UnsupportedCharsetException;
import java.util.List;
import java.util.jar.Attributes;
import java.util.jar.JarFile;
import java.util.jar.Manifest;
@@ -147,32 +148,13 @@ public class JdkUtil {
commandLine.setExePath(exePath);
ParametersList parametersList = javaParameters.getVMParametersList();
commandLine.addParameters(parametersList.getList());
// Value of -Dfile.encoding and charset of GeneralCommandLine should be in sync in order process's input and output be correctly handled.
String encoding = parametersList.getPropertyValue("file.encoding");
if (encoding == null) {
Charset charset = javaParameters.getCharset();
if (charset == null) charset = EncodingManager.getInstance().getDefaultCharset();
if (charset == null) charset = CharsetToolkit.getDefaultSystemCharset();
commandLine.addParameter("-Dfile.encoding=" + charset.name());
commandLine.setCharset(charset);
}
else {
try {
Charset charset = Charset.forName(encoding);
commandLine.setCharset(charset);
}
catch (UnsupportedCharsetException ignore) {
}
}
commandLine.setEnvParams(javaParameters.getEnv());
commandLine.setPassParentEnvs(javaParameters.isPassParentEnvs());
final Class commandLineWrapper;
if (forceDynamicClasspath && (commandLineWrapper = getCommandLineWrapperClass()) != null) {
File classpathFile = null;
File vmParamsFile = null;
if(!parametersList.hasParameter("-classpath") && !parametersList.hasParameter("-cp")){
try {
classpathFile = FileUtil.createTempFile("classpath", null);
@@ -199,16 +181,55 @@ public class JdkUtil {
catch (IOException e) {
LOG.error(e);
}
try {
vmParamsFile = FileUtil.createTempFile("vm_params", null);
final PrintWriter writer = new PrintWriter(vmParamsFile);
try {
for (String param : parametersList.getList()) {
if (param.startsWith("-D")) {
writer.println(param);
}
}
}
finally {
writer.close();
}
}
catch (IOException e) {
LOG.error(e);
}
}
final List<String> list = parametersList.getList();
if (vmParamsFile == null) {
commandLine.addParameters(list);
} else {
for (String param : list) {
if (!param.trim().startsWith("-D")) {
commandLine.addParameter(param);
}
}
}
appendEncoding(javaParameters, commandLine, parametersList);
if (classpathFile != null) {
commandLine.addParameter(commandLineWrapper.getName());
commandLine.addParameter(classpathFile.getAbsolutePath());
}
if (vmParamsFile != null) {
commandLine.addParameter("@vm_params");
commandLine.addParameter(vmParamsFile.getAbsolutePath());
}
}
else if(!parametersList.hasParameter("-classpath") && !parametersList.hasParameter("-cp")){
else if (!parametersList.hasParameter("-classpath") && !parametersList.hasParameter("-cp")){
commandLine.addParameters(parametersList.getList());
appendEncoding(javaParameters, commandLine, parametersList);
commandLine.addParameter("-classpath");
commandLine.addParameter(javaParameters.getClassPath().getPathsString());
} else {
commandLine.addParameters(parametersList.getList());
appendEncoding(javaParameters, commandLine, parametersList);
}
final String mainClass = javaParameters.getMainClass();
@@ -220,6 +241,26 @@ public class JdkUtil {
return commandLine;
}
private static void appendEncoding(SimpleJavaParameters javaParameters, GeneralCommandLine commandLine, ParametersList parametersList) {
// Value of -Dfile.encoding and charset of GeneralCommandLine should be in sync in order process's input and output be correctly handled.
String encoding = parametersList.getPropertyValue("file.encoding");
if (encoding == null) {
Charset charset = javaParameters.getCharset();
if (charset == null) charset = EncodingManager.getInstance().getDefaultCharset();
if (charset == null) charset = CharsetToolkit.getDefaultSystemCharset();
commandLine.addParameter("-Dfile.encoding=" + charset.name());
commandLine.setCharset(charset);
}
else {
try {
Charset charset = Charset.forName(encoding);
commandLine.setCharset(charset);
}
catch (UnsupportedCharsetException ignore) {
}
}
}
@Nullable
private static Class getCommandLineWrapperClass() {
try {
@@ -617,6 +617,7 @@ public abstract class LogConsoleBase extends AdditionalTabComponent implements L
myAlarm.addRequest(this, 100);
}
};
if (myAlarm.isDisposed()) return;
myAlarm.addRequest(runnable, 10);
}
@@ -39,6 +39,7 @@ import com.intellij.openapi.project.DumbAwareRunnable;
import com.intellij.openapi.project.DumbService;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.startup.StartupManager;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.ui.MessageType;
import com.intellij.openapi.ui.popup.Balloon;
import com.intellij.openapi.ui.popup.JBPopupFactory;
@@ -2186,6 +2187,9 @@ public final class ToolWindowManagerImpl extends ToolWindowManagerEx implements
if (root != null) {
JComponent toFocus = IdeFocusTraversalPolicy.getPreferredFocusedComponent(root);
if (toFocus != null) {
if (DialogWrapper.findInstance(toFocus) != null) {
return new ActionCallback.Done(); //IDEA-80929
}
return IdeFocusManager.findInstanceByComponent(toFocus).requestFocus(toFocus, forced);
}
}
@@ -443,7 +443,6 @@
<completion.skip implementation="com.intellij.codeInsight.template.impl.LiveTemplateCompletionContributor$Skipper" id="skipLiveTemplate"/>
<completion.contributor language="TEXT" implementationClass="com.intellij.openapi.vcs.CommitCompletionContributor" id="commitCompletion" order="first, before liveTemplates"/>
<completion.contributor language="JAVA" implementationClass="com.intellij.codeInspection.magicConstant.MagicCompletionContributor" id="magicCompletion" order="first, before liveTemplates"/>
<applicationService serviceInterface="com.intellij.execution.console.ConsoleFoldingSettings" serviceImplementation="com.intellij.execution.console.ConsoleFoldingSettings"/>
<console.folding implementation="com.intellij.execution.console.SubstringConsoleFolding"/>
@@ -653,7 +652,7 @@
<fileIconProvider implementation="com.intellij.ide.FileIconPatcherImpl"/>
<renameHandler implementation="com.intellij.refactoring.rename.inplace.VariableInplaceRenameHandler"/>
<renameHandler implementation="com.intellij.refactoring.rename.inplace.MemberInplaceRenameHandler"/>
<completion.contributor language="any" implementationClass="com.intellij.refactoring.rename.inplace.CompletionContributorForInplaceRename" order="first"/>
<completion.contributor language="any" implementationClass="com.intellij.refactoring.rename.inplace.CompletionContributorForInplaceRename" order="first, before liveTemplates"/>
<projectService serviceInterface="com.intellij.openapi.vcs.changes.ui.ChangesFileNameDecorator"
serviceImplementation="com.intellij.openapi.vcs.changes.ui.WolfChangesFileNameDecorator"/>
@@ -698,7 +697,6 @@
serviceImplementation="com.intellij.openapi.vcs.impl.CodeSmellDetectorImpl"/>
<editorTabTitleProvider implementation="com.intellij.openapi.fileEditor.impl.UniqueNameEditorTabTitleProvider"/>
<applicationService serviceImplementation="com.intellij.execution.JavaRunConfigurationExtensionManager"/>
<projectService serviceInterface="com.intellij.psi.util.PsiModificationTracker"
serviceImplementation="com.intellij.psi.impl.PsiModificationTrackerImpl"/>
@@ -22,6 +22,8 @@
<orderEntry type="module" module-name="spellchecker" />
<orderEntry type="module" module-name="android" />
<orderEntry type="module" module-name="ui-designer-new" />
<orderEntry type="module" module-name="dom-impl" />
<orderEntry type="module" module-name="dom-openapi" />
</component>
</module>
@@ -2,9 +2,16 @@
<name>Android Designer</name>
<id>com.intellij.android-designer</id>
<vendor logo="/general/ijLogo.png">JetBrains</vendor>
<resource-bundle>messages.AndroidDesignerBundle</resource-bundle>
<depends>com.intellij.java-i18n</depends>
<depends>com.intellij.properties</depends>
<depends>org.jetbrains.android</depends>
<depends>com.intellij.ui-designer-new</depends>
<extensions defaultExtensionNs="com.intellij">
<fileEditorProvider implementation="com.intellij.android.designer.AndroidDesignerEditorProvider"/>
</extensions>
</idea-plugin>
@@ -0,0 +1,50 @@
/*
* 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.android.designer;
import com.intellij.CommonBundle;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.PropertyKey;
import java.lang.ref.Reference;
import java.lang.ref.SoftReference;
import java.util.ResourceBundle;
/**
* @author yole
*/
public class AndroidDesignerBundle {
private static Reference<ResourceBundle> ourBundle;
@NonNls private static final String BUNDLE = "messages.AndroidDesignerBundle";
private AndroidDesignerBundle() {
}
public static String message(@PropertyKey(resourceBundle = BUNDLE) String key, Object... params) {
return CommonBundle.message(getBundle(), key, params);
}
private static ResourceBundle getBundle() {
ResourceBundle bundle = null;
if (ourBundle != null) bundle = ourBundle.get();
if (bundle == null) {
bundle = ResourceBundle.getBundle(BUNDLE);
ourBundle = new SoftReference<ResourceBundle>(bundle);
}
return bundle;
}
}
@@ -0,0 +1,65 @@
/*
* 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.android.designer;
import com.intellij.openapi.fileEditor.FileEditorState;
import com.intellij.openapi.fileEditor.FileEditorStateLevel;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.uiDesigner.DesignerEditor;
import org.jetbrains.annotations.NotNull;
/**
* @author Alexander Lobas
*/
public final class AndroidDesignerEditor extends DesignerEditor {
public AndroidDesignerEditor(Project project, VirtualFile file) {
super(project, file);
}
@NotNull
@Override
public String getName() {
return AndroidDesignerBundle.message("editor.tab.title");
}
@Override
public boolean isValid() {
return true; // TODO: Auto-generated method stub
}
@NotNull
@Override
public FileEditorState getState(@NotNull FileEditorStateLevel level) {
// TODO: Auto-generated method stub
return new FileEditorState() {
@Override
public boolean canBeMergedWith(FileEditorState otherState, FileEditorStateLevel level) {
return false;
}
};
}
@Override
public void setState(@NotNull FileEditorState state) {
// TODO: Auto-generated method stub
}
@Override
public boolean isModified() {
return false;
}
}
@@ -0,0 +1,87 @@
/*
* 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.android.designer;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.fileEditor.*;
import com.intellij.openapi.project.DumbAware;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiDocumentManager;
import com.intellij.psi.PsiFile;
import com.intellij.psi.xml.XmlFile;
import org.jdom.Element;
import org.jetbrains.android.dom.layout.LayoutDomFileDescription;
import org.jetbrains.android.facet.AndroidFacet;
import org.jetbrains.annotations.NotNull;
/**
* @author Alexander Lobas
*/
public final class AndroidDesignerEditorProvider implements FileEditorProvider, DumbAware {
@Override
public boolean accept(@NotNull Project project, @NotNull VirtualFile file) {
Document document = FileDocumentManager.getInstance().getDocument(file);
if (document != null) {
PsiFile psiFile = PsiDocumentManager.getInstance(project).getPsiFile(document);
return psiFile instanceof XmlFile &&
AndroidFacet.getInstance(psiFile) != null &&
LayoutDomFileDescription.isLayoutFile((XmlFile)psiFile);
}
return false;
}
@NotNull
@Override
public FileEditor createEditor(@NotNull Project project, @NotNull VirtualFile file) {
return new AndroidDesignerEditor(project, file);
}
@Override
public void disposeEditor(@NotNull FileEditor editor) {
Disposer.dispose(editor);
}
@NotNull
@Override
public FileEditorState readState(@NotNull Element sourceElement, @NotNull Project project, @NotNull VirtualFile file) {
// TODO: Auto-generated method stub
return new FileEditorState() {
@Override
public boolean canBeMergedWith(FileEditorState otherState, FileEditorStateLevel level) {
return false;
}
};
}
@Override
public void writeState(@NotNull FileEditorState state, @NotNull Project project, @NotNull Element targetElement) {
// TODO: Auto-generated method stub
}
@NotNull
@Override
public String getEditorTypeId() {
return "android-designer";
}
@NotNull
@Override
public FileEditorPolicy getPolicy() {
return FileEditorPolicy.PLACE_BEFORE_DEFAULT_EDITOR;
}
}
@@ -0,0 +1 @@
editor.tab.title=Design
@@ -45,6 +45,7 @@ import com.intellij.util.PairConsumer;
import com.intellij.util.ProcessingContext;
import gnu.trove.THashSet;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.plugins.groovy.GroovyBundle;
import org.jetbrains.plugins.groovy.lang.psi.GrReferenceElement;
import org.jetbrains.plugins.groovy.lang.psi.GroovyFile;
@@ -64,18 +65,18 @@ import org.jetbrains.plugins.groovy.lang.psi.api.toplevel.imports.GrImportStatem
import org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement;
import org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeElement;
import org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeParameterList;
import org.jetbrains.plugins.groovy.lang.psi.impl.statements.expressions.CompleteReferenceExpression;
import org.jetbrains.plugins.groovy.lang.psi.util.GroovyPropertyUtils;
import org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil;
import org.jetbrains.plugins.groovy.refactoring.DefaultGroovyVariableNameValidator;
import org.jetbrains.plugins.groovy.refactoring.GroovyNameSuggestionUtil;
import org.jetbrains.plugins.groovy.refactoring.inline.InlineMethodConflictSolver;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.*;
import static com.intellij.patterns.PlatformPatterns.psiElement;
import static com.intellij.patterns.PsiJavaPatterns.elementType;
import static com.intellij.util.containers.CollectionFactory.arrayList;
import static com.intellij.util.containers.CollectionFactory.hashMap;
import static org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes.*;
import static org.jetbrains.plugins.groovy.lang.lexer.TokenSets.SEPARATORS;
@@ -176,18 +177,20 @@ public class GroovyCompletionContributor extends CompletionContributor {
private static void addAllClasses(CompletionParameters parameters, final CompletionResultSet result, final InheritorsHolder inheritors) {
addAllClasses(parameters, result, new Consumer<LookupElement>() {
addAllClasses(parameters, new Consumer<LookupElement>() {
@Override
public void consume(LookupElement element) {
result.addElement(element);
}
}, inheritors);
}, inheritors, result.getPrefixMatcher());
}
public static void addAllClasses(CompletionParameters parameters, CompletionResultSet result, final Consumer<LookupElement> consumer, final InheritorsHolder inheritors) {
public static void addAllClasses(CompletionParameters parameters,
final Consumer<LookupElement> consumer,
final InheritorsHolder inheritors, final PrefixMatcher matcher) {
final PsiElement position = parameters.getPosition();
final ElementFilter filter = getClassFilter(position);
AllClassesGetter.processJavaClasses(parameters, result.getPrefixMatcher(), parameters.getInvocationCount() <= 1,
AllClassesGetter.processJavaClasses(parameters, matcher, parameters.getInvocationCount() <= 1,
new Consumer<PsiClass>() {
@Override
public void consume(PsiClass psiClass) {
@@ -310,21 +313,21 @@ public class GroovyCompletionContributor extends CompletionContributor {
addUnfinishedMethodTypeParameters(position, result);
final PsiElement parent = position.getParent();
GrReferenceElement reference;
if (parent instanceof GrReferenceElement) {
reference = (GrReferenceElement)parent;
if (reference.getParent() instanceof GrImportStatement && reference.getQualifier() != null) {
result.addElement(LookupElementBuilder.create("*"));
}
} else if (couldContainReference(position)) {
reference = GroovyPsiElementFactory.getInstance(position.getProject()).createReferenceElementFromText("Foo", position);
} else {
GrReferenceElement reference = findGroovyReference(position);
if (reference == null) {
return;
}
if (reference.getParent() instanceof GrImportStatement && reference.getQualifier() != null) {
result.addElement(LookupElementBuilder.create("*"));
}
InheritorsHolder inheritors = new InheritorsHolder(position, result);
completeReference(parameters, result, reference, inheritors);
if (GroovySmartCompletionContributor.AFTER_NEW.accepts(position)) {
GroovySmartCompletionContributor.generateInheritorVariants(parameters, result.getPrefixMatcher(), inheritors);
}
result.addAllElements(completeReference(parameters, reference, inheritors, result.getPrefixMatcher()));
if (reference.getQualifier() == null) {
GroovySmartCompletionContributor.addExpectedClassMembers(parameters, result);
@@ -361,6 +364,17 @@ public class GroovyCompletionContributor extends CompletionContributor {
}
@Nullable private static GrReferenceElement findGroovyReference(PsiElement position) {
final PsiElement parent = position.getParent();
if (parent instanceof GrReferenceElement) {
return (GrReferenceElement)parent;
}
if (couldContainReference(position)) {
return GroovyPsiElementFactory.getInstance(position.getProject()).createReferenceElementFromText("Foo", position);
}
return null;
}
private static boolean couldContainReference(PsiElement position) {
return IN_CATCH_TYPE.accepts(position) ||
AFTER_AT.accepts(position) ||
@@ -408,31 +422,31 @@ public class GroovyCompletionContributor extends CompletionContributor {
super.fillCompletionVariants(parameters, result);
}
private static void completeReference(final CompletionParameters parameters,
final CompletionResultSet result,
GrReferenceElement reference, final InheritorsHolder inheritorsHolder) {
static LinkedHashSet<LookupElement> completeReference(final CompletionParameters parameters,
GrReferenceElement reference, final InheritorsHolder inheritorsHolder, final PrefixMatcher matcher) {
final PsiElement position = parameters.getPosition();
if (GroovySmartCompletionContributor.AFTER_NEW.accepts(position)) {
GroovySmartCompletionContributor.generateInheritorVariants(parameters, result.getPrefixMatcher(), inheritorsHolder);
}
final int invocationCount = parameters.getInvocationCount();
final boolean firstCompletionInvoked = invocationCount < 2;
final String prefix = result.getPrefixMatcher().getPrefix();
final boolean skipAccessors = firstCompletionInvoked && !prefix.startsWith("g") && !prefix.startsWith("s") && !prefix.startsWith("i");
result.restartCompletionOnPrefixChange("g");
result.restartCompletionOnPrefixChange("i");
result.restartCompletionOnPrefixChange("s");
final Map<PsiModifierListOwner, LookupElement> staticMembers = hashMap();
final PsiElement qualifier = reference.getQualifier();
final PsiType qualifierType = qualifier instanceof GrExpression ? ((GrExpression)qualifier).getType() : null;
LinkedHashSet<LookupElement> result = new LinkedHashSet<LookupElement>();
if (reference instanceof GrReferenceExpression && (qualifier instanceof GrExpression || qualifier == null)) {
for (String string : CompleteReferenceExpression.getVariantsWithSameQualifier(matcher, (GrExpression)qualifier, (GrReferenceExpression)reference)) {
result.add(GroovyCompletionUtil.getLookupElement(string));
}
if (parameters.getInvocationCount() < 2 && qualifier != null && qualifierType == null) {
if (parameters.getInvocationCount() == 1) {
showInfo();
}
return result;
}
}
final ElementFilter classFilter = getClassFilter(position);
reference.processVariants(result.getPrefixMatcher(), parameters, new Consumer<Object>() {
final List<LookupElement> items = arrayList();
reference.processVariants(matcher, parameters, new Consumer<Object>() {
public void consume(Object element) {
if (element instanceof PsiClass && inheritorsHolder.alreadyProcessed((PsiClass)element)) {
return;
@@ -445,15 +459,11 @@ public class GroovyCompletionContributor extends CompletionContributor {
element = ((LookupElement)element).getObject();
}
final LookupElement lookupElement = element instanceof PsiClass
? GroovyCompletionUtil.createClassLookupItem(CompletionUtil.getOriginalOrSelf((PsiClass)element))
: GroovyCompletionUtil.getLookupElement(element);
LookupElement lookupElement = element instanceof PsiClass
? GroovyCompletionUtil.createClassLookupItem(CompletionUtil.getOriginalOrSelf((PsiClass)element))
: GroovyCompletionUtil.getLookupElement(element);
Object object = lookupElement.getObject();
PsiSubstitutor substitutor = null;
GroovyResolveResult resolveResult = null;
if (object instanceof GroovyResolveResult) {
resolveResult = (GroovyResolveResult)object;
substitutor = resolveResult.getSubstitutor();
object = ((GroovyResolveResult)object).getElement();
}
@@ -461,44 +471,9 @@ public class GroovyCompletionContributor extends CompletionContributor {
return;
}
final boolean autopopup = parameters.getInvocationCount() == 0;
//skip default groovy methods
if (firstCompletionInvoked &&
object instanceof GrGdkMethod &&
GroovyCompletionUtil.skipDefGroovyMethod((GrGdkMethod)object, substitutor, qualifierType)) {
if (!autopopup) {
showInfo();
}
return;
}
//skip operator methods
if (firstCompletionInvoked &&
object instanceof PsiMethod &&
GroovyCompletionUtil.OPERATOR_METHOD_NAMES.contains(((PsiMethod)object).getName())) {
if (!checkForIterator((PsiMethod)object)) {
if (!autopopup) {
showInfo();
}
return;
}
}
//skip accessors if there is no get, set, is prefix
if (skipAccessors && object instanceof PsiMethod && GroovyPropertyUtils.isSimplePropertyAccessor((PsiMethod)object)) {
if (!autopopup) {
showInfo();
}
return;
}
//skip inaccessible elements
if (firstCompletionInvoked && resolveResult != null && !resolveResult.isAccessible()) {
if (!autopopup) {
showInfo();
}
return;
}
int priority = assignPriority(lookupElement, qualifierType);
lookupElement = JavaCompletionUtil.highlightIfNeeded(qualifierType,
PrioritizedLookupElement.withPriority(lookupElement, priority), object);
if ((object instanceof PsiMethod || object instanceof PsiField) &&
((PsiModifierListOwner)object).hasModifierProperty(PsiModifier.STATIC)) {
@@ -510,7 +485,8 @@ public class GroovyCompletionContributor extends CompletionContributor {
if (object instanceof PsiClass && !classFilter.isAcceptable(object, position)) {
return;
}
result.addElement(JavaCompletionUtil.highlightIfNeeded(qualifierType, lookupElement, object));
items.add(lookupElement);
}
});
@@ -522,7 +498,7 @@ public class GroovyCompletionContributor extends CompletionContributor {
member = ((GrAccessorMethod)member).getProperty();
}
final String name = member.getName();
if (name == null || !result.getPrefixMatcher().prefixMatches(name)) {
if (name == null || !matcher.prefixMatches(name)) {
staticMembers.remove(member);
return;
}
@@ -532,7 +508,26 @@ public class GroovyCompletionContributor extends CompletionContributor {
});
}
result.addAllElements(staticMembers.values());
items.addAll(staticMembers.values());
for (Iterator<LookupElement> iterator = items.iterator(); iterator.hasNext(); ) {
LookupElement element = iterator.next();
PrioritizedLookupElement prio = element.as(PrioritizedLookupElement.CLASS_CONDITION_KEY);
if (prio == null || prio.getPriority() >= 0) {
result.add(element);
iterator.remove();
}
}
result.addAll(items);
return result;
}
private static void showInfo() {
if (StringUtil.isEmpty(CompletionService.getCompletionService().getAdvertisementText())) {
CompletionService.getCompletionService()
.setAdvertisementText(GroovyBundle.message("invoke.completion.second.time.to.show.skipped.methods"));
}
}
private static boolean checkForIterator(PsiMethod method) {
@@ -545,11 +540,39 @@ public class GroovyCompletionContributor extends CompletionContributor {
return InheritanceUtil.isInheritorOrSelf(containingClass, iterator, true);
}
private static void showInfo() {
if (StringUtil.isEmpty(CompletionService.getCompletionService().getAdvertisementText())) {
CompletionService.getCompletionService()
.setAdvertisementText(GroovyBundle.message("invoke.completion.second.time.to.show.skipped.methods"));
private static int assignPriority(LookupElement lookupElement, PsiType qualifierType) {
Object object = lookupElement.getObject();
PsiSubstitutor substitutor = null;
GroovyResolveResult resolveResult = null;
if (object instanceof GroovyResolveResult) {
resolveResult = (GroovyResolveResult)object;
substitutor = resolveResult.getSubstitutor();
object = ((GroovyResolveResult)object).getElement();
}
// default groovy methods
if (object instanceof GrGdkMethod &&
GroovyCompletionUtil.skipDefGroovyMethod((GrGdkMethod)object, substitutor, qualifierType)) {
return -1;
}
// operator methods
if (object instanceof PsiMethod &&
GroovyCompletionUtil.OPERATOR_METHOD_NAMES.contains(((PsiMethod)object).getName()) && !checkForIterator((PsiMethod)object)) {
return -3;
}
// accessors if there is no get, set, is prefix
if (object instanceof PsiMethod && GroovyPropertyUtils.isSimplePropertyAccessor((PsiMethod)object)) {
return -1;
}
// inaccessible elements
if (resolveResult != null && !resolveResult.isAccessible()) {
return -2;
}
return 0;
}
static StaticMemberProcessor completeStaticMembers(CompletionParameters parameters) {
@@ -16,9 +16,21 @@
package org.jetbrains.plugins.groovy.lang.completion;
import com.intellij.codeInsight.completion.*;
import com.intellij.codeInsight.completion.impl.CamelHumpMatcher;
import com.intellij.codeInsight.lookup.AutoCompletionPolicy;
import com.intellij.codeInsight.lookup.LookupElement;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiType;
import com.intellij.util.Consumer;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.plugins.groovy.lang.psi.GrReferenceElement;
import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.Set;
/**
* @author peter
@@ -27,27 +39,114 @@ public class GroovyNoVariantsDelegator extends NoVariantsDelegator {
@Override
protected void delegate(CompletionParameters parameters, CompletionResultSet result, Consumer<CompletionResult> passResult) {
if (parameters.getCompletionType() == CompletionType.BASIC &&
parameters.getInvocationCount() <= 1 &&
JavaCompletionContributor.mayStartClassName(result, false) &&
GroovyCompletionContributor.isClassNamePossible(parameters.getPosition()) &&
!MapArgumentCompletionProvider.isMapKeyCompletion(parameters)) {
final ClassByNameMerger merger = new ClassByNameMerger(parameters.getInvocationCount() == 0, result);
GroovyCompletionContributor.addAllClasses(parameters, result,
new Consumer<LookupElement>() {
@Override
public void consume(LookupElement element) {
JavaPsiClassReferenceElement classElement = element.as(JavaPsiClassReferenceElement.CLASS_CONDITION_KEY);
if (classElement != null) {
classElement.setAutoCompletionPolicy(AutoCompletionPolicy.NEVER_AUTOCOMPLETE);
}
merger.consume(classElement);
}
}, new InheritorsHolder(parameters.getPosition(), result));
merger.finishedClassProcessing();
if (parameters.getCompletionType() == CompletionType.BASIC) {
if (parameters.getInvocationCount() <= 1 &&
JavaCompletionContributor.mayStartClassName(result, false) &&
GroovyCompletionContributor.isClassNamePossible(parameters.getPosition()) &&
!MapArgumentCompletionProvider.isMapKeyCompletion(parameters)) {
suggestNonImportedClasses(parameters, result);
}
suggestChainedCalls(parameters, result);
}
}
private static void suggestNonImportedClasses(CompletionParameters parameters, CompletionResultSet result) {
final ClassByNameMerger merger = new ClassByNameMerger(parameters.getInvocationCount() == 0, result);
GroovyCompletionContributor.addAllClasses(parameters, new Consumer<LookupElement>() {
@Override
public void consume(LookupElement element) {
JavaPsiClassReferenceElement classElement =
element.as(JavaPsiClassReferenceElement.CLASS_CONDITION_KEY);
if (classElement != null) {
classElement.setAutoCompletionPolicy(AutoCompletionPolicy.NEVER_AUTOCOMPLETE);
}
merger.consume(classElement);
}
}, new InheritorsHolder(parameters.getPosition(), result), result.getPrefixMatcher());
merger.finishedClassProcessing();
}
private static void suggestChainedCalls(CompletionParameters parameters, CompletionResultSet result) {
PsiElement position = parameters.getPosition();
PsiElement parent = position.getParent();
if (!(parent instanceof GrReferenceElement)) {
return;
}
PsiElement qualifier = ((GrReferenceElement)parent).getQualifier();
if (!(qualifier instanceof GrReferenceElement) ||
((GrReferenceElement)qualifier).getQualifier() != null ||
((GrReferenceElement)qualifier).resolve() != null) {
return;
}
String fullPrefix = position.getContainingFile().getText().substring(parent.getTextRange().getStartOffset(), parameters.getOffset());
final CompletionResultSet qualifiedCollector = result.withPrefixMatcher(fullPrefix);
InheritorsHolder inheritors = new InheritorsHolder(position, result);
for (final LookupElement base : suggestQualifierItems(parameters, (GrReferenceElement)qualifier, inheritors)) {
final PsiType type = JavaCompletionUtil.getLookupElementType(base);
if (type != null && !PsiType.VOID.equals(type)) {
GrReferenceElement ref = createMockReference(position, type, base);
PsiElement refName = ref.getReferenceNameElement();
assert refName != null;
for (LookupElement element : GroovyCompletionContributor.completeReference(
parameters.withPosition(refName, refName.getTextRange().getStartOffset()), ref, inheritors, result.getPrefixMatcher())) {
qualifiedCollector.addElement(new JavaChainLookupElement(base, element) {
@Override
protected boolean shouldParenthesizeQualifier(PsiFile file, int startOffset, int endOffset) {
return false;
}
});
}
}
}
}
private static GrReferenceElement createMockReference(final PsiElement place, @NotNull PsiType qualifierType, LookupElement qualifierItem) {
GroovyPsiElementFactory factory = GroovyPsiElementFactory.getInstance(place.getProject());
if (qualifierItem.getObject() instanceof PsiClass) {
return factory
.createReferenceExpressionFromText(((PsiClass)qualifierItem.getObject()).getQualifiedName() + ".xxx", place);
}
return factory.createReferenceExpressionFromText("xxx.xxx",
ReferenceExpressionCompletionContributor
.createContextWithXxxVariable(place, qualifierType));
}
private static Set<LookupElement> suggestQualifierItems(CompletionParameters _parameters,
GrReferenceElement qualifier,
InheritorsHolder inheritors) {
CompletionParameters parameters =
_parameters.withPosition(qualifier.getReferenceNameElement(), qualifier.getTextRange().getEndOffset());
String referenceName = qualifier.getReferenceName();
if (referenceName == null) {
return Collections.emptySet();
}
final PrefixMatcher qMatcher = new CamelHumpMatcher(referenceName);
final Set<LookupElement> variants = new LinkedHashSet<LookupElement>();
for (LookupElement element : GroovyCompletionContributor.completeReference(parameters, qualifier, inheritors, qMatcher)) {
if (qMatcher.prefixMatches(element)) {
variants.add(element);
}
}
if (variants.isEmpty()) {
GroovyCompletionContributor.addAllClasses(parameters, new Consumer<LookupElement>() {
@Override
public void consume(LookupElement element) {
if (qMatcher.prefixMatches(element)) {
variants.add(element);
}
}
}, inheritors, qMatcher);
}
return variants;
}
}
@@ -25,7 +25,6 @@ import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.util.InheritanceUtil;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.psi.util.TypeConversionUtil;
import com.intellij.util.ArrayUtil;
import com.intellij.util.Consumer;
import com.intellij.util.containers.hash.HashSet;
import org.jetbrains.annotations.NotNull;
@@ -48,7 +47,6 @@ import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrRe
import org.jetbrains.plugins.groovy.lang.psi.impl.GroovyPsiManager;
import org.jetbrains.plugins.groovy.lang.psi.impl.GroovyResolveResultImpl;
import org.jetbrains.plugins.groovy.lang.psi.impl.PsiImplUtil;
import org.jetbrains.plugins.groovy.lang.psi.util.GrClassImplUtil;
import org.jetbrains.plugins.groovy.lang.psi.util.PsiUtil;
import org.jetbrains.plugins.groovy.lang.resolve.ClosureMissingMethodContributor;
import org.jetbrains.plugins.groovy.lang.resolve.ResolveUtil;
@@ -88,7 +86,6 @@ public class CompleteReferenceExpression {
private static void getVariantsImpl(PrefixMatcher matcher, GrReferenceExpression refExpr, CompleteReferenceProcessor processor) {
GrExpression qualifier = refExpr.getQualifierExpression();
getVariantsWithSameQualifier(matcher, qualifier, refExpr, processor);
if (qualifier == null) {
ResolveUtil.treeWalkUp(refExpr, processor, true);
@@ -228,7 +225,8 @@ public class CompleteReferenceExpression {
return;
}
}
getVariantsFromQualifierType(refExpr, processor, GrClassImplUtil.getGroovyObjectType(refExpr), project);
getVariantsFromQualifierType(refExpr, processor,
PsiType.getJavaLangObject(refExpr.getManager(), qualifier.getResolveScope()), project);
}
else if (qualifierType instanceof PsiIntersectionType) {
for (PsiType conjunct : ((PsiIntersectionType)qualifierType).getConjuncts()) {
@@ -256,20 +254,19 @@ public class CompleteReferenceExpression {
}
}
private static String[] getVariantsWithSameQualifier(PrefixMatcher matcher,GrExpression qualifier, GrReferenceExpression refExpr, CompleteReferenceProcessor processor) {
if (qualifier != null && qualifier.getType() != null) return ArrayUtil.EMPTY_STRING_ARRAY;
public static Set<String> getVariantsWithSameQualifier(PrefixMatcher matcher, @Nullable GrExpression qualifier, GrReferenceExpression refExpr) {
if (qualifier != null && qualifier.getType() != null) return Collections.emptySet();
final PsiElement scope = PsiTreeUtil.getParentOfType(refExpr, GrMember.class, PsiFile.class);
Set<String> result = new LinkedHashSet<String>();
addVariantsWithSameQualifier(matcher, scope, refExpr, qualifier, result, processor);
return ArrayUtil.toStringArray(result);
addVariantsWithSameQualifier(matcher, scope, refExpr, qualifier, result);
return result;
}
private static void addVariantsWithSameQualifier(PrefixMatcher matcher, PsiElement element,
GrReferenceExpression patternExpression,
GrExpression patternQualifier,
Set<String> result,
CompleteReferenceProcessor processor) {
Set<String> result) {
if (element instanceof GrReferenceExpression && element != patternExpression && !PsiUtil.isLValue((GroovyPsiElement)element)) {
final GrReferenceExpression refExpr = (GrReferenceExpression)element;
final String refName = refExpr.getReferenceName();
@@ -279,21 +276,19 @@ public class CompleteReferenceExpression {
if (PsiEquivalenceUtil.areElementsEquivalent(hisQualifier, patternQualifier)) {
if (refExpr.resolve() == null) {
result.add(refName);
processor.consume(refName);
}
}
}
else if (hisQualifier == null && patternQualifier == null) {
if (refExpr.resolve() == null) {
result.add(refName);
processor.consume(refName);
}
}
}
}
for (PsiElement child = element.getFirstChild(); child != null; child = child.getNextSibling()) {
addVariantsWithSameQualifier(matcher, child, patternExpression, patternQualifier, result, processor);
addVariantsWithSameQualifier(matcher, child, patternExpression, patternQualifier, result);
}
}
@@ -170,7 +170,67 @@ toString
wait
wait
wait
with\
with
getThisProp
setThisProp
getSuperProp
setSuperProp
addShutdownHook
any
any
asBoolean
asType
collect
collect
dump
each
eachWithIndex
every
every
find
findAll
findIndexOf
findIndexOf
findIndexValues
findIndexValues
findLastIndexOf
findLastIndexOf
getAt
getClass
getMetaClass
getMetaPropertyValues
getProperties
grep
hasPerInstanceMetaClass
hasProperty
identity
inject
inspect
is
isCase
iterator
metaClass
primitiveArrayGet
primitiveArrayGet
primitiveArrayGet
primitiveArrayPut
print
print
printf
printf
println
println
println
putAt
respondsTo
respondsTo
setMetaClass
split
sprintf
sprintf
use
use
use\
""".split('\n')
}
@@ -56,7 +56,7 @@ class GroovyAutoPopupTest extends CompletionAutoPopupTestCase {
public void testNoLookupFocusOnUnresolvedQualifier() {
myFixture.configureByText("a.groovy", """xxx.<caret>""")
type 'h' //hashCode
assert !lookup.focused
assert !lookup
}
public void testNoLookupFocusOnUntypedQualifier() {
@@ -65,7 +65,7 @@ class GroovyAutoPopupTest extends CompletionAutoPopupTestCase {
xxx.<caret>
}""")
type 'h'
assert !lookup.focused
assert !lookup
}
public void testPossibleClosureParameter() {
@@ -891,16 +891,6 @@ class B extends A {
checkCompletion "asse<caret>x", ' ', 'assert <caret>x'
}
public void testDontShowAccessors() {
assertNull doContainsTest("getFoo", """
class MyClass {
def foo
}
def a = new MyClass()
a.<caret>""")
}
public void testPreferInstanceof() {
caseSensitiveNone()
@@ -1072,7 +1062,7 @@ class X {
}
public void testSortOrder0() {
doVariantableTest 'se', 'setMetaClass', 'setProperty', 'setSe'
doVariantableTest 'se', 'setProperty', 'setMetaClass', 'setSe'
}
public void testPrimitiveCastOverwrite() {
@@ -1118,9 +1108,29 @@ public class KeyVO {
checkSingleItemCompletion 'class Foo impl<caret> {}', 'class Foo implements <caret> {}'
}
public void testAmbiguousClassQualifier() {
myFixture.addClass("package foo; public class Util { public static void foo() {} }")
myFixture.addClass("package bar; public class Util { public static void bar() {} }")
myFixture.configureByText 'a.groovy', 'Util.<caret>'
myFixture.completeBasic()
assert myFixture.lookupElementStrings[0..1] == ['Util.bar', 'Util.foo']
def presentation = LookupElementPresentation.renderElement(myFixture.lookupElements[0])
assert 'Util.bar' == presentation.itemText
assert '() (bar)' == presentation.tailText
assert !presentation.tailGrayed
myFixture.type 'f\n'
myFixture.checkResult '''import foo.Util
Util.foo()<caret>'''
}
public void testPreferInterfacesInImplements() {
myFixture.addClass('interface FooIntf {}')
myFixture.addClass('class FooClass {}')
doVariantableTest('FooIntf', 'FooClass')
}
public void testPropertyChain() { doBasicTest() }
}
@@ -50,7 +50,7 @@ class GroovyTransformationsTest extends LightCodeInsightFixtureTestCase {
public void testVetoableTransform() throws Throwable { doPlainTest() }
public void testNewifyTransform1() throws Throwable { doVariantsTest('newInstance', 'new', 'new', 'newInstance') }
public void testNewifyTransform1() throws Throwable { doVariantsTest('newInstance', 'new', 'new', 'newInstance', 'negative', 'next') }
public void testNewifyTransform2() throws Throwable { doVariantsTest('Leaf', 'Leaf', 'Leaf') }
@@ -0,0 +1,8 @@
class A {
File myFile;
def foo() {
myf.cap<caret>
}
}
@@ -0,0 +1,8 @@
class A {
File myFile;
def foo() {
myFile.canonicalPath<caret>
}
}
@@ -1,4 +1,3 @@
def (street, home, postCode)
def s = street.toS<caret>
-----
toString
-----
@@ -1,3 +1,2 @@
unknown.metaCl<caret>
-----
metaClass
-----
@@ -1,8 +1,17 @@
<idea-plugin version="2">
<name>UI Designer</name>
<name>UI Designer (Core)</name>
<id>com.intellij.ui-designer-new</id>
<vendor logo="/general/ijLogo.png">JetBrains</vendor>
<resource-bundle>messages.UIDesignerBundle</resource-bundle>
<depends>com.intellij.java-i18n</depends>
<depends>com.intellij.properties</depends>
<project-components>
<component>
<implementation-class>com.intellij.uiDesigner.UIDesignerToolWindowManager</implementation-class>
</component>
</project-components>
</idea-plugin>
@@ -0,0 +1,97 @@
/*
* 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.uiDesigner;
import com.intellij.codeHighlighting.BackgroundEditorHighlighter;
import com.intellij.ide.structureView.StructureViewBuilder;
import com.intellij.openapi.fileEditor.FileEditor;
import com.intellij.openapi.fileEditor.FileEditorLocation;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleUtil;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.UserDataHolderBase;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.testFramework.LightVirtualFile;
import com.intellij.uiDesigner.designSurface.DesignerEditorPanel;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
import java.beans.PropertyChangeListener;
/**
* @author Alexander Lobas
*/
public abstract class DesignerEditor extends UserDataHolderBase implements FileEditor {
private final DesignerEditorPanel myDesignerPanel;
public DesignerEditor(Project project, VirtualFile file) {
if (file instanceof LightVirtualFile) {
file = ((LightVirtualFile)file).getOriginalFile();
}
Module module = ModuleUtil.findModuleForFile(file, project);
if (module == null) {
throw new IllegalArgumentException("No module for file " + file + " in project " + project);
}
myDesignerPanel = new DesignerEditorPanel(module, file);
}
@NotNull
@Override
public JComponent getComponent() {
return myDesignerPanel;
}
@Override
public JComponent getPreferredFocusedComponent() {
return myDesignerPanel.getPreferredFocusedComponent();
}
@Override
public void dispose() {
myDesignerPanel.dispose();
}
@Override
public void selectNotify() {
}
@Override
public void deselectNotify() {
}
@Override
public void addPropertyChangeListener(@NotNull PropertyChangeListener listener) {
}
@Override
public void removePropertyChangeListener(@NotNull PropertyChangeListener listener) {
}
@Override
public BackgroundEditorHighlighter getBackgroundHighlighter() {
return null;
}
@Override
public FileEditorLocation getCurrentLocation() {
return null;
}
@Override
public StructureViewBuilder getStructureViewBuilder() {
return null;
}
}
@@ -0,0 +1,50 @@
/*
* 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.uiDesigner;
import com.intellij.CommonBundle;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.PropertyKey;
import java.lang.ref.Reference;
import java.lang.ref.SoftReference;
import java.util.ResourceBundle;
/**
* @author yole
*/
public class UIDesignerBundle {
private static Reference<ResourceBundle> ourBundle;
@NonNls private static final String BUNDLE = "messages.UIDesignerBundle";
private UIDesignerBundle() {
}
public static String message(@PropertyKey(resourceBundle = BUNDLE) String key, Object... params) {
return CommonBundle.message(getBundle(), key, params);
}
private static ResourceBundle getBundle() {
ResourceBundle bundle = null;
if (ourBundle != null) bundle = ourBundle.get();
if (bundle == null) {
bundle = ResourceBundle.getBundle(BUNDLE);
ourBundle = new SoftReference<ResourceBundle>(bundle);
}
return bundle;
}
}
@@ -0,0 +1,52 @@
/*
* 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.uiDesigner;
import com.intellij.openapi.components.ProjectComponent;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
/**
* @author Alexander Lobas
*/
public final class UIDesignerToolWindowManager implements ProjectComponent {
@Override
public void projectOpened() {
// TODO: Auto-generated method stub
}
@Override
public void projectClosed() {
// TODO: Auto-generated method stub
}
@Override
public void initComponent() {
// TODO: Auto-generated method stub
}
@Override
public void disposeComponent() {
// TODO: Auto-generated method stub
}
@NotNull
@NonNls
@Override
public String getComponentName() {
return "UIDesignerToolWindowManager2";
}
}
@@ -0,0 +1,30 @@
/*
* 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.uiDesigner.componentTree;
import com.intellij.openapi.actionSystem.DataProvider;
import com.intellij.ui.treeStructure.Tree;
import org.jetbrains.annotations.NonNls;
/**
* @author Alexander Lobas
*/
public final class ComponentTree extends Tree implements DataProvider {
@Override
public Object getData(@NonNls String dataId) {
return null; //To change body of implemented methods use File | Settings | File Templates.
}
}
@@ -0,0 +1,48 @@
/*
* 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.uiDesigner.designSurface;
import com.intellij.openapi.actionSystem.DataProvider;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
import java.awt.*;
/**
* @author Alexander Lobas
*/
public final class DesignerEditorPanel extends JPanel implements DataProvider {
public DesignerEditorPanel(@NotNull Module module, @NotNull VirtualFile file) {
setLayout(new BorderLayout());
add(new JLabel("Design Surface"), BorderLayout.CENTER);
}
@Override
public Object getData(@NonNls String dataId) {
return null; //To change body of implemented methods use File | Settings | File Templates.
}
public void dispose() {
// TODO: Auto-generated method stub
}
public JComponent getPreferredFocusedComponent() {
return null; // TODO: Auto-generated method stub
}
}
@@ -0,0 +1,47 @@
/*
* 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.uiDesigner.model;
import com.intellij.uiDesigner.propertyTable.Property;
import java.util.List;
/**
* @author Alexander Lobas
*/
public abstract class RadComponent {
private RadComponent myParent;
public RadComponent getRoot() {
return myParent == null ? this : myParent.getRoot();
}
public final RadComponent getParent() {
return myParent;
}
public final void setParent(RadComponent parent) {
myParent = parent;
}
public List<RadComponent> getChildren() {
return null;
}
public List<Property> getProperties() {
return null;
}
}
@@ -0,0 +1,60 @@
/*
* 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.uiDesigner.propertyTable;
import com.intellij.uiDesigner.model.RadComponent;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
/**
* @author Alexander Lobas
*/
public abstract class Property {
private final Property myParent;
@NotNull private final String myName;
public Property(Property parent, @NotNull @NonNls String name) {
myParent = parent;
myName = name;
}
public final Property getParent() {
return myParent;
}
@NotNull
public final String getName() {
return myName;
}
public List<Property> getChildren(RadComponent component) {
return null;
}
public Object getValue(RadComponent component) {
return null;
}
@NotNull
public abstract PropertyRenderer getRenderer();
@Nullable
public abstract PropertyEditor getEditor();
}
@@ -0,0 +1,29 @@
/*
* 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.uiDesigner.propertyTable;
import com.intellij.uiDesigner.model.RadComponent;
import javax.swing.*;
/**
* @author Alexander Lobas
*/
public interface PropertyEditor {
JComponent getComponent(RadComponent component, Object value);
Object getValue();
}
@@ -0,0 +1,41 @@
/*
* 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.uiDesigner.propertyTable;
import com.intellij.uiDesigner.model.RadComponent;
import javax.swing.*;
/**
* @author Alexander Lobas
*/
public interface PropertyRenderer {
/**
* @return <code>JComponent</code> to represent the <code>value</code>
* somewhere in UI (for example in the JList of in the JTree). To be
* consistent with other UI additional parameter abount selection and
* focus are also passed.
*/
JComponent getComponent(RadComponent component, Object value, boolean selected, boolean hasFocus);
/**
* Renderer should update UI of all its internal components to fit current
* IDEA Look And Feel. We cannot directly update UI of the component
* that is returned by {@link #getComponent } method
* because hidden component that are not in the Swing tree can exist.
*/
void updateUI();
}
@@ -0,0 +1,30 @@
/*
* 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.uiDesigner.propertyTable;
import com.intellij.openapi.actionSystem.DataProvider;
import com.intellij.ui.table.JBTable;
import org.jetbrains.annotations.NonNls;
/**
* @author Alexander Lobas
*/
public final class PropertyTable extends JBTable implements DataProvider {
@Override
public Object getData(@NonNls String dataId) {
return null; //To change body of implemented methods use File | Settings | File Templates.
}
}
@@ -0,0 +1,29 @@
/*
* 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.uiDesigner.propertyTable;
import javax.swing.*;
import java.awt.*;
/**
* @author Alexander Lobas
*/
public final class PropertyTablePanel extends JPanel {
public PropertyTablePanel() {
setLayout(new BorderLayout());
add(new JLabel("Design Surface"), BorderLayout.CENTER);
}
}
+6 -2
View File
@@ -213,10 +213,12 @@
<completion.confidence language="JAVA" implementationClass="com.intellij.codeInsight.completion.AlwaysFocusLookup" id="javaTrue" order="last"/>
<completion.confidence language="JAVA" implementationClass="com.intellij.codeInsight.completion.SkipAutopopupInStrings" id="javaSkipAutopopupInStrings"/>
<completion.contributor language="JAVA" implementationClass="com.intellij.codeInspection.magicConstant.MagicCompletionContributor"
id="magicCompletion, after javaBasic2ClassName"/>
<completion.contributor language="JAVA" implementationClass="com.intellij.codeInsight.completion.JavaNoVariantsDelegator" id="javaBasic2ClassName"
order="first, before javaMemberName, after liveTemplates"/>
order="before javaMemberName, before javaLegacy, after liveTemplates"/>
<completion.contributor language="XML" implementationClass="com.intellij.codeInsight.completion.XmlBasicToClassNameDelegator" id="basic2ClassName"
order="first, after xml"/>
order="after xml"/>
<completion.contributor language="JAVA" implementationClass="com.intellij.codeInsight.completion.JavaCompletionContributor" id="javaLegacy"
order="last, before legacy, before default, before javaClassName"/>
<completion.contributor language="any" implementationClass="com.intellij.codeInsight.completion.JavaClassReferenceCompletionContributor"
@@ -1212,6 +1214,8 @@
<wizardMode implementation="com.intellij.ide.util.newProjectWizard.modes.CreateModuleFromSourcesMode" id="CreateModuleFromSourcesMode" order="after CreateProjectFromSourcesMode"/>
<projectStructureDetector implementation="com.intellij.ide.util.projectWizard.importSources.impl.JavaProjectStructureDetector" order="first"/>
<applicationService serviceImplementation="com.intellij.execution.JavaRunConfigurationExtensionManager"/>
<regExpLanguageHost forClass="com.intellij.psi.impl.source.tree.java.PsiLiteralExpressionImpl"
implementationClass="com.intellij.psi.impl.JavaRegExpHost"/>
</extensions>