Skip to content

Commit

Permalink
Merge remote branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Iris24 committed Feb 1, 2013
2 parents 7b183e2 + 16a8fa4 commit abc44fa
Show file tree
Hide file tree
Showing 11 changed files with 101 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ public IFileElementType(@NonNls @NotNull final String debugName, @Nullable final
super(debugName, language);
}

public IFileElementType(@NonNls @NotNull final String debugName, @Nullable final Language language, boolean register) {
super(debugName, language, register);
}

@Nullable
@Override
public ASTNode parseContents(final ASTNode chameleon) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -389,31 +389,24 @@ public void printToHistory(@NotNull final List<Pair<String, TextAttributes>> att
final boolean scrollToEnd = shouldScrollHistoryToEnd();
final int[] offsets = new int[attributedText.size() + 1];
int i = 0;
offsets[i] = 0;
final StringBuilder sb = new StringBuilder();
final Document history = myHistoryViewer.getDocument();
offsets[i] = history.getTextLength();
for (final Pair<String, TextAttributes> pair : attributedText) {
final String str = StringUtil.convertLineSeparators(pair.getFirst());
final int lastOffset = offsets[i];
offsets[++i] = lastOffset + str.length();
sb.append(str);
appendToHistoryDocument(history, str);
offsets[++i] = history.getTextLength();
}
LOG.debug("printToHistory(): text processed");
final Document history = myHistoryViewer.getDocument();
final MarkupModel markupModel = DocumentMarkupModel.forDocument(history, myProject, true);
final int oldHistoryLength = history.getTextLength();
appendToHistoryDocument(history, sb.toString());
if ((oldHistoryLength + offsets[i]) != history.getTextLength()) {
assert false : "Last offset - " + offsets[i] + " history length: old " + oldHistoryLength + ", new - " + history.getTextLength()
+ ", history - " + history;
}
LOG.debug("printToHistory(): text added");
i = 0;
for (final Pair<String, TextAttributes> pair : attributedText) {
markupModel.addRangeHighlighter(oldHistoryLength + offsets[i],
oldHistoryLength + offsets[i+1],
HighlighterLayer.SYNTAX,
pair.getSecond(),
HighlighterTargetArea.EXACT_RANGE);
markupModel.addRangeHighlighter(
offsets[i],
offsets[i+1],
HighlighterLayer.SYNTAX,
pair.getSecond(),
HighlighterTargetArea.EXACT_RANGE
);
++i;
}
LOG.debug("printToHistory(): markup added");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,8 @@ public void propertyChanged(final VirtualFilePropertyEvent event) {

VirtualFile parent = vFile.getParent();
final PsiDirectory parentDir = getCachedDirectory(parent);
if (parentDir == null) {
// do not suppress reparse request for light files
if (parentDir == null && !FileContentUtil.FORCE_RELOAD_REQUESTOR.equals(event.getRequestor())) {
boolean fire = VirtualFile.PROP_NAME.equals(propertyName) && vFile.isDirectory();
if (fire) {
PsiDirectory psiDir = myFileManager.getCachedDirectory(vFile);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,15 +271,15 @@ protected void checkResult(@TestDataFile @NonNls String targetDataName, final St
doCheckResult(myFullDataPath, targetDataName, text);
}

private static void doCheckResult(String myFullDataPath, String targetDataName, String text) throws IOException {
public static void doCheckResult(String fullPath, String targetDataName, String text) throws IOException {
text = text.trim();
String expectedFileName = myFullDataPath + File.separatorChar + targetDataName;
String expectedFileName = fullPath + File.separatorChar + targetDataName;
if (OVERWRITE_TESTDATA) {
VfsTestUtil.overwriteTestData(expectedFileName, text);
System.out.println("File " + expectedFileName + " created.");
}
try {
String expectedText = doLoadFile(myFullDataPath, targetDataName);
String expectedText = doLoadFile(fullPath, targetDataName);
if (!Comparing.equal(expectedText, text)) {
throw new FileComparisonFailure(targetDataName, expectedText, text, expectedFileName);
}
Expand All @@ -304,7 +304,7 @@ private static String doLoadFile(String myFullDataPath, String name) throws IOEx
return text;
}

private static void ensureParsed(PsiFile file) {
public static void ensureParsed(PsiFile file) {
file.accept(new PsiElementVisitor() {
@Override
public void visitElement(PsiElement element) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ public class JavaFxCommonClassNames {
@NonNls public static final String JAVAFX_EVENT_EVENT_HANDLER = "javafx.event.EventHandler";
@NonNls public static final String JAVAFX_SCENE_NODE = "javafx.scene.Node";
@NonNls public static final String JAVAFX_SCENE_PAINT = "javafx.scene.paint.Paint";
@NonNls public static final String JAVAFX_FXML_BUILDER = "javafx.util.Builder";
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.*;
import com.intellij.psi.impl.source.PostprocessReformattingAspect;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.util.InheritanceUtil;
import com.intellij.psi.util.PropertyUtil;
import com.intellij.psi.util.PsiTreeUtil;
Expand Down Expand Up @@ -82,7 +83,11 @@ public static String getInstructionTarget(String instructionName, XmlProcessingI
}

public static PsiClass findPsiClass(String name, XmlTag tag) {
return findPsiClass(name, parseImports((XmlFile)tag.getContainingFile()), tag, tag.getProject());
final Project project = tag.getProject();
if (!StringUtil.getShortName(name).equals(name)) {
return JavaPsiFacade.getInstance(project).findClass(name, GlobalSearchScope.allScope(project));
}
return findPsiClass(name, parseImports((XmlFile)tag.getContainingFile()), tag, project);
}

private static PsiClass findPsiClass(String name, List<String> imports, XmlTag tag, Project project) {
Expand Down Expand Up @@ -155,7 +160,11 @@ public static PsiClassType getPropertyClassType(PsiElement field) {

public static boolean isClassTag(String name) {
final String shortName = StringUtil.getShortName(name);
return StringUtil.isCapitalized(name) && name.equals(shortName);
final boolean capitalized = StringUtil.isCapitalized(name);
if (name.equals(shortName)) {
return capitalized;
}
return !capitalized;
}

public static PsiMethod findPropertySetter(String attributeName, XmlTag context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,22 @@
import com.intellij.codeInsight.daemon.Validator;
import com.intellij.codeInsight.daemon.impl.analysis.GenericsHighlightUtil;
import com.intellij.codeInsight.daemon.impl.analysis.HighlightUtil;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.*;
import com.intellij.psi.impl.source.xml.XmlAttributeImpl;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.search.searches.ClassInheritorsSearch;
import com.intellij.psi.util.InheritanceUtil;
import com.intellij.psi.util.PropertyUtil;
import com.intellij.psi.util.PsiUtil;
import com.intellij.psi.util.TypeConversionUtil;
import com.intellij.psi.xml.XmlAttribute;
import com.intellij.psi.xml.XmlTag;
import com.intellij.util.ArrayUtil;
import com.intellij.util.Function;
import com.intellij.util.Processor;
import com.intellij.xml.XmlAttributeDescriptor;
import com.intellij.xml.XmlElementDescriptor;
import com.intellij.xml.XmlElementsGroup;
Expand Down Expand Up @@ -279,6 +284,31 @@ public void validate(@NotNull XmlTag context, @NotNull ValidationHost host) {
}
}
validateTagAccordingToFieldType(context, parentTag, host);
if (myPsiClass != null && myPsiClass.isValid()) {
if(myPsiClass.getConstructors().length > 0) {
final Project project = myPsiClass.getProject();
final PsiMethod noArgConstructor = myPsiClass
.findMethodBySignature(JavaPsiFacade.getElementFactory(project).createConstructor(myPsiClass.getName()), false);
if (noArgConstructor == null) {
final PsiClass builderClass = JavaPsiFacade.getInstance(project).findClass(JavaFxCommonClassNames.JAVAFX_FXML_BUILDER,
GlobalSearchScope.allScope(project));
if (builderClass != null) {
//todo cache this info
final PsiTypeParameter typeParameter = builderClass.getTypeParameters()[0];
if (ClassInheritorsSearch.search(builderClass).forEach(new Processor<PsiClass>() {
@Override
public boolean process(PsiClass aClass) {
final PsiType initType =
TypeConversionUtil.getSuperClassSubstitutor(builderClass, aClass, PsiSubstitutor.EMPTY).substitute(typeParameter);
return !Comparing.equal(myPsiClass, PsiUtil.resolveClassInClassTypeOnly(initType));
}
})) {
host.addMessage(context, "Unable to instantiate", ValidationHost.ErrorType.ERROR);
}
}
}
}
}
}

private void validateTagAccordingToFieldType(XmlTag context, XmlTag parentTag, ValidationHost host) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@
*/
package org.jetbrains.plugins.javaFX.fxml.refs;

import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiReference;
import com.intellij.psi.PsiReferenceBase;
import com.intellij.psi.PsiReferenceProvider;
import com.intellij.psi.*;
import com.intellij.psi.xml.XmlAttribute;
import com.intellij.psi.xml.XmlAttributeValue;
import com.intellij.util.ArrayUtil;
import com.intellij.util.ProcessingContext;
import com.intellij.xml.XmlAttributeDescriptor;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.plugins.javaFX.fxml.descriptors.JavaFxPropertyAttributeDescriptor;

/**
Expand All @@ -39,7 +38,20 @@ public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNu
if (parent instanceof XmlAttribute) {
final XmlAttributeDescriptor descriptor = ((XmlAttribute)parent).getDescriptor();
if (descriptor instanceof JavaFxPropertyAttributeDescriptor && descriptor.isEnumerated()) {
return new PsiReference[] {new PsiReferenceBase.Immediate<XmlAttributeValue>(xmlAttributeValue, ((JavaFxPropertyAttributeDescriptor)descriptor).getEnumConstant(xmlAttributeValue.getValue()))};
final PsiField enumConstant = ((JavaFxPropertyAttributeDescriptor)descriptor).getEnumConstant(xmlAttributeValue.getValue());
return new PsiReference[] {new PsiReferenceBase<XmlAttributeValue>(xmlAttributeValue){
@Nullable
@Override
public PsiElement resolve() {
return enumConstant;
}

@NotNull
@Override
public Object[] getVariants() {
return ArrayUtil.EMPTY_OBJECT_ARRAY;
}
}};
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions plugins/javaFX/testData/highlighting/fQNtagNames.fxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>

<javafx.scene.layout.AnchorPane xmlns:fx="http://javafx.com/fxml">
</javafx.scene.layout.AnchorPane>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?import javafx.scene.layout.GridPane?>
<?import java.io.File?>
<?import javafx.scene.control.Label?>
<GridPane xmlns:fx="http://javafx.com/fxml">
<fx:define>
<<error descr="Unable to instantiate">File</error>/>
<Label/>
</fx:define>
</GridPane>
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,14 @@ public void testValueOfAcceptance() throws Exception {
doTest();
}

public void testInstantiationAcceptance() throws Exception {
doTest();
}

public void testFQNtagNames() throws Exception {
doTest();
}

@NotNull
@Override
protected String getTestDataPath() {
Expand Down

0 comments on commit abc44fa

Please sign in to comment.