Java 类com.intellij.psi.impl.JavaPsiFacadeEx 实例源码

项目:intellij-ce-playground    文件:ShortenClassReferencesTest.java   
public void testSCR22368_1() {
  JavaPsiFacadeEx facade = JavaPsiFacadeEx.getInstanceEx(getProject());
  PsiElementFactory factory = facade.getElementFactory();
  PsiClass aClass = factory.createClass("X");
  PsiMethod methodFromText = factory.createMethodFromText("void method() {\n" +
                                                          "    IntelliJIDEARulezz<\n" +
                                                          "}", null);
  PsiMethod method = (PsiMethod)aClass.add(methodFromText);
  PsiCodeBlock body = method.getBody();
  assertNotNull(body);
  PsiDeclarationStatement declarationStatement = (PsiDeclarationStatement)body.getStatements()[0];
  PsiJavaCodeReferenceElement referenceElement = (PsiJavaCodeReferenceElement)declarationStatement.getFirstChild().getFirstChild();
  PsiClass javaUtilListClass = facade.findClass(CommonClassNames.JAVA_UTIL_LIST);
  assertNotNull(javaUtilListClass);
  PsiElement resultingElement = referenceElement.bindToElement(javaUtilListClass);
  assertEquals("List<", resultingElement.getText());
  assertEquals("void method() {\n" +
               "    List<\n" +
               "}", method.getText());
}
项目:intellij-ce-playground    文件:TypesTest.java   
public void testRawTypes() throws Exception {
  final JavaPsiFacadeEx psiManager = getJavaFacade();
  final PsiElementFactory factory = psiManager.getElementFactory();
  final PsiClass classA = psiManager.findClass("A");
  assertNotNull(classA);

  final PsiMethod method = classA.getMethods()[0];
  final PsiStatement[] methodStatements = method.getBody().getStatements();
  final PsiDeclarationStatement declarationStatement = (PsiDeclarationStatement) methodStatements[0];
  final PsiVariable varList = (PsiVariable) declarationStatement.getDeclaredElements()[0];
  final PsiType typeFromText = factory.createTypeFromText("test.List", null);
  assertEquals(varList.getType(), typeFromText);

  final PsiReferenceExpression methodExpression = ((PsiMethodCallExpression) ((PsiExpressionStatement) methodStatements[1]).getExpression()).getMethodExpression();
  final JavaResolveResult resolveResult = methodExpression.advancedResolve(false);
  assertTrue(resolveResult.getElement() instanceof PsiMethod);
  final PsiMethod methodFromList = (PsiMethod) resolveResult.getElement();
  final PsiType typeOfFirstParameterOfAdd = methodFromList.getParameterList().getParameters()[0].getType();
  final PsiType substitutedType = resolveResult.getSubstitutor().substitute(typeOfFirstParameterOfAdd);
  assertEquals(PsiType.getJavaLangObject(getPsiManager(), method.getResolveScope()), substitutedType);

  final PsiType methodCallType = ((PsiExpressionStatement) methodStatements[2]).getExpression().getType();
  final PsiType rawIteratorType = factory.createTypeFromText("test.Iterator", null);
  assertEquals(rawIteratorType, methodCallType);
}
项目:intellij-ce-playground    文件:TypesTest.java   
public void testBoundedParams() throws Exception {
  final JavaPsiFacadeEx psiManager = getJavaFacade();
  final PsiElementFactory factory = psiManager.getElementFactory();
  final PsiClass classA = psiManager.findClass("A");
  assertNotNull(classA);

  final PsiMethod method = classA.getMethods()[0];
  final PsiStatement[] statements = method.getBody().getStatements();

  final PsiVariable var = (PsiVariable) ((PsiDeclarationStatement) statements[0]).getDeclaredElements()[0];
  final PsiType varType = var.getType();
  final PsiType typeRawIterator = factory.createTypeFromText("test.Iterator", null);
  assertEquals(varType, typeRawIterator);

  final PsiType initializerType = var.getInitializer().getType();
  assertEquals(initializerType, typeRawIterator);
  assertTrue(varType.isAssignableFrom(initializerType));
}
项目:intellij-ce-playground    文件:TypesTest.java   
public void testRawTypeExtension() throws Exception {
  final JavaPsiFacadeEx psiManager = getJavaFacade();
  final PsiElementFactory factory = psiManager.getElementFactory();
  final PsiClass classA = psiManager.findClass("A");
  assertNotNull(classA);

  final PsiMethod method = classA.getMethods()[0];
  final PsiStatement[] statements = method.getBody().getStatements();

  final PsiVariable var = (PsiVariable) ((PsiDeclarationStatement) statements[0]).getDeclaredElements()[0];
  final PsiType varType = var.getType();
  final PsiType typeRawIterator = factory.createTypeFromText("test.Iterator", null);
  assertEquals(varType, typeRawIterator);

  final PsiType initializerType = var.getInitializer().getType();
  assertEquals(initializerType, typeRawIterator);
  assertTrue(varType.isAssignableFrom(initializerType));
}
项目:intellij-ce-playground    文件:TypesTest.java   
public void testTypesInGenericClass() {
  final JavaPsiFacadeEx psiManager = getJavaFacade();
  final PsiElementFactory factory = psiManager.getElementFactory();
  final PsiClass classA = psiManager.findClass("A");
  assertNotNull(classA);

  final PsiTypeParameter parameterT = classA.getTypeParameters()[0];
  assertEquals("T", parameterT.getName());

  final PsiMethod method = classA.findMethodsByName("method", false)[0];
  final PsiType type = ((PsiExpressionStatement) method.getBody().getStatements()[0]).getExpression().getType();
  final PsiClassType typeT = factory.createType(parameterT);
  assertEquals("T", typeT.getPresentableText());

  assertEquals(typeT, type);
}
项目:intellij-ce-playground    文件:TypesTest.java   
public void testComplexInheritance() throws Exception {
  final JavaPsiFacadeEx psiManager = getJavaFacade();
  final PsiElementFactory factory = psiManager.getElementFactory();
  final PsiClass classA = psiManager.findClass("A");
  assertNotNull(classA);

  final PsiMethod method = classA.findMethodsByName("method", false)[0];
  final PsiExpression expression = ((PsiExpressionStatement) method.getBody().getStatements()[1]).getExpression();
  assertEquals("l.get(0)", expression.getText());

  final PsiType type = expression.getType();
  final PsiType listOfInteger = factory.createTypeFromText("test.List<java.lang.Integer>", null);
  assertEquals(listOfInteger, type);
  final PsiType collectionOfInteger = factory.createTypeFromText("test.Collection<java.lang.Integer>", null);
  assertTrue(collectionOfInteger.isAssignableFrom(type));
}
项目:intellij-ce-playground    文件:TypesTest.java   
public void testListListInheritance() throws Exception {
  final JavaPsiFacadeEx psiManager = getJavaFacade();
  final PsiElementFactory factory = psiManager.getElementFactory();
  final PsiClass classA = psiManager.findClass("A");
  assertNotNull(classA);

  final PsiMethod method = classA.findMethodsByName("method", false)[0];

  final PsiExpression expression1 = ((PsiExpressionStatement) method.getBody().getStatements()[1]).getExpression();
  assertEquals("l.get(0)", expression1.getText());
  final PsiType type1 = expression1.getType();
  final PsiType typeListOfInteger = factory.createTypeFromText("test.List<java.lang.Integer>", null);
  assertEquals(typeListOfInteger, type1);
  assertTrue(typeListOfInteger.isAssignableFrom(type1));

  final PsiExpression expression2 = ((PsiExpressionStatement) method.getBody().getStatements()[3]).getExpression();
  assertEquals("b.get(0)", expression2.getText());
  final PsiType type2 = expression2.getType();
  assertEquals(typeListOfInteger, type2);
}
项目:tools-idea    文件:ShortenClassReferencesTest.java   
public void testSCR22368_1() {
  JavaPsiFacadeEx facade = JavaPsiFacadeEx.getInstanceEx(getProject());
  PsiElementFactory factory = facade.getElementFactory();
  PsiClass aClass = factory.createClass("X");
  PsiMethod methodFromText = factory.createMethodFromText("void method() {\n" +
                                                          "    IntelliJIDEARulezz<\n" +
                                                          "}", null);
  PsiMethod method = (PsiMethod)aClass.add(methodFromText);
  PsiCodeBlock body = method.getBody();
  assertNotNull(body);
  PsiDeclarationStatement declarationStatement = (PsiDeclarationStatement)body.getStatements()[0];
  PsiJavaCodeReferenceElement referenceElement = (PsiJavaCodeReferenceElement)declarationStatement.getFirstChild().getFirstChild();
  PsiClass javaUtilListClass = facade.findClass(CommonClassNames.JAVA_UTIL_LIST);
  assertNotNull(javaUtilListClass);
  PsiElement resultingElement = referenceElement.bindToElement(javaUtilListClass);
  assertEquals("List<", resultingElement.getText());
  assertEquals("void method() {\n" +
               "    List<\n" +
               "}", method.getText());
}
项目:tools-idea    文件:TypesTest.java   
public void testRawTypes() throws Exception {
  final JavaPsiFacadeEx psiManager = getJavaFacade();
  final PsiElementFactory factory = psiManager.getElementFactory();
  final PsiClass classA = psiManager.findClass("A");
  assertNotNull(classA);

  final PsiMethod method = classA.getMethods()[0];
  final PsiStatement[] methodStatements = method.getBody().getStatements();
  final PsiDeclarationStatement declarationStatement = (PsiDeclarationStatement) methodStatements[0];
  final PsiVariable varList = (PsiVariable) declarationStatement.getDeclaredElements()[0];
  final PsiType typeFromText = factory.createTypeFromText("test.List", null);
  assertEquals(varList.getType(), typeFromText);

  final PsiReferenceExpression methodExpression = ((PsiMethodCallExpression) ((PsiExpressionStatement) methodStatements[1]).getExpression()).getMethodExpression();
  final JavaResolveResult resolveResult = methodExpression.advancedResolve(false);
  assertTrue(resolveResult.getElement() instanceof PsiMethod);
  final PsiMethod methodFromList = (PsiMethod) resolveResult.getElement();
  final PsiType typeOfFirstParameterOfAdd = methodFromList.getParameterList().getParameters()[0].getType();
  final PsiType substitutedType = resolveResult.getSubstitutor().substitute(typeOfFirstParameterOfAdd);
  assertEquals(PsiType.getJavaLangObject(getPsiManager(), method.getResolveScope()), substitutedType);

  final PsiType methodCallType = ((PsiExpressionStatement) methodStatements[2]).getExpression().getType();
  final PsiType rawIteratorType = factory.createTypeFromText("test.Iterator", null);
  assertEquals(rawIteratorType, methodCallType);
}
项目:tools-idea    文件:TypesTest.java   
public void testBoundedParams() throws Exception {
  final JavaPsiFacadeEx psiManager = getJavaFacade();
  final PsiElementFactory factory = psiManager.getElementFactory();
  final PsiClass classA = psiManager.findClass("A");
  assertNotNull(classA);

  final PsiMethod method = classA.getMethods()[0];
  final PsiStatement[] statements = method.getBody().getStatements();

  final PsiVariable var = (PsiVariable) ((PsiDeclarationStatement) statements[0]).getDeclaredElements()[0];
  final PsiType varType = var.getType();
  final PsiType typeRawIterator = factory.createTypeFromText("test.Iterator", null);
  assertEquals(varType, typeRawIterator);

  final PsiType initializerType = var.getInitializer().getType();
  assertEquals(initializerType, typeRawIterator);
  assertTrue(varType.isAssignableFrom(initializerType));
}
项目:tools-idea    文件:TypesTest.java   
public void testRawTypeExtension() throws Exception {
  final JavaPsiFacadeEx psiManager = getJavaFacade();
  final PsiElementFactory factory = psiManager.getElementFactory();
  final PsiClass classA = psiManager.findClass("A");
  assertNotNull(classA);

  final PsiMethod method = classA.getMethods()[0];
  final PsiStatement[] statements = method.getBody().getStatements();

  final PsiVariable var = (PsiVariable) ((PsiDeclarationStatement) statements[0]).getDeclaredElements()[0];
  final PsiType varType = var.getType();
  final PsiType typeRawIterator = factory.createTypeFromText("test.Iterator", null);
  assertEquals(varType, typeRawIterator);

  final PsiType initializerType = var.getInitializer().getType();
  assertEquals(initializerType, typeRawIterator);
  assertTrue(varType.isAssignableFrom(initializerType));
}
项目:tools-idea    文件:TypesTest.java   
public void testTypesInGenericClass() {
  final JavaPsiFacadeEx psiManager = getJavaFacade();
  final PsiElementFactory factory = psiManager.getElementFactory();
  final PsiClass classA = psiManager.findClass("A");
  assertNotNull(classA);

  final PsiTypeParameter parameterT = classA.getTypeParameters()[0];
  assertEquals("T", parameterT.getName());

  final PsiMethod method = classA.findMethodsByName("method", false)[0];
  final PsiType type = ((PsiExpressionStatement) method.getBody().getStatements()[0]).getExpression().getType();
  final PsiClassType typeT = factory.createType(parameterT);
  assertEquals("T", typeT.getPresentableText());

  assertEquals(typeT, type);
}
项目:tools-idea    文件:TypesTest.java   
public void testComplexInheritance() throws Exception {
  final JavaPsiFacadeEx psiManager = getJavaFacade();
  final PsiElementFactory factory = psiManager.getElementFactory();
  final PsiClass classA = psiManager.findClass("A");
  assertNotNull(classA);

  final PsiMethod method = classA.findMethodsByName("method", false)[0];
  final PsiExpression expression = ((PsiExpressionStatement) method.getBody().getStatements()[1]).getExpression();
  assertEquals("l.get(0)", expression.getText());

  final PsiType type = expression.getType();
  final PsiType listOfInteger = factory.createTypeFromText("test.List<java.lang.Integer>", null);
  assertEquals(listOfInteger, type);
  final PsiType collectionOfInteger = factory.createTypeFromText("test.Collection<java.lang.Integer>", null);
  assertTrue(collectionOfInteger.isAssignableFrom(type));
}
项目:tools-idea    文件:TypesTest.java   
public void testListListInheritance() throws Exception {
  final JavaPsiFacadeEx psiManager = getJavaFacade();
  final PsiElementFactory factory = psiManager.getElementFactory();
  final PsiClass classA = psiManager.findClass("A");
  assertNotNull(classA);

  final PsiMethod method = classA.findMethodsByName("method", false)[0];

  final PsiExpression expression1 = ((PsiExpressionStatement) method.getBody().getStatements()[1]).getExpression();
  assertEquals("l.get(0)", expression1.getText());
  final PsiType type1 = expression1.getType();
  final PsiType typeListOfInteger = factory.createTypeFromText("test.List<java.lang.Integer>", null);
  assertEquals(typeListOfInteger, type1);
  assertTrue(typeListOfInteger.isAssignableFrom(type1));

  final PsiExpression expression2 = ((PsiExpressionStatement) method.getBody().getStatements()[3]).getExpression();
  assertEquals("b.get(0)", expression2.getText());
  final PsiType type2 = expression2.getType();
  assertEquals(typeListOfInteger, type2);
}
项目:consulo-java    文件:ShortenClassReferencesTest.java   
public void testSCR22368_1() {
  JavaPsiFacadeEx facade = JavaPsiFacadeEx.getInstanceEx(getProject());
  PsiElementFactory factory = facade.getElementFactory();
  PsiClass aClass = factory.createClass("X");
  PsiMethod methodFromText = factory.createMethodFromText("void method() {\n" +
                                                          "    IntelliJIDEARulezz<\n" +
                                                          "}", null);
  PsiMethod method = (PsiMethod)aClass.add(methodFromText);
  PsiCodeBlock body = method.getBody();
  assertNotNull(body);
  PsiDeclarationStatement declarationStatement = (PsiDeclarationStatement)body.getStatements()[0];
  PsiJavaCodeReferenceElement referenceElement = (PsiJavaCodeReferenceElement)declarationStatement.getFirstChild().getFirstChild();
  PsiClass javaUtilListClass = facade.findClass(CommonClassNames.JAVA_UTIL_LIST);
  assertNotNull(javaUtilListClass);
  PsiElement resultingElement = referenceElement.bindToElement(javaUtilListClass);
  assertEquals("List<", resultingElement.getText());
  assertEquals("void method() {\n" +
               "    List<\n" +
               "}", method.getText());
}
项目:consulo-java    文件:TypesTest.java   
public void testRawTypes() throws Exception {
  final JavaPsiFacadeEx psiManager = getJavaFacade();
  final PsiElementFactory factory = psiManager.getElementFactory();
  final PsiClass classA = psiManager.findClass("A");
  assertNotNull(classA);

  final PsiMethod method = classA.getMethods()[0];
  final PsiStatement[] methodStatements = method.getBody().getStatements();
  final PsiDeclarationStatement declarationStatement = (PsiDeclarationStatement) methodStatements[0];
  final PsiVariable varList = (PsiVariable) declarationStatement.getDeclaredElements()[0];
  final PsiType typeFromText = factory.createTypeFromText("test.List", null);
  assertEquals(varList.getType(), typeFromText);

  final PsiReferenceExpression methodExpression = ((PsiMethodCallExpression) ((PsiExpressionStatement) methodStatements[1]).getExpression()).getMethodExpression();
  final JavaResolveResult resolveResult = methodExpression.advancedResolve(false);
  assertTrue(resolveResult.getElement() instanceof PsiMethod);
  final PsiMethod methodFromList = (PsiMethod) resolveResult.getElement();
  final PsiType typeOfFirstParameterOfAdd = methodFromList.getParameterList().getParameters()[0].getType();
  final PsiType substitutedType = resolveResult.getSubstitutor().substitute(typeOfFirstParameterOfAdd);
  assertEquals(PsiType.getJavaLangObject(getPsiManager(), method.getResolveScope()), substitutedType);

  final PsiType methodCallType = ((PsiExpressionStatement) methodStatements[2]).getExpression().getType();
  final PsiType rawIteratorType = factory.createTypeFromText("test.Iterator", null);
  assertEquals(rawIteratorType, methodCallType);
}
项目:consulo-java    文件:TypesTest.java   
public void testBoundedParams() throws Exception {
  final JavaPsiFacadeEx psiManager = getJavaFacade();
  final PsiElementFactory factory = psiManager.getElementFactory();
  final PsiClass classA = psiManager.findClass("A");
  assertNotNull(classA);

  final PsiMethod method = classA.getMethods()[0];
  final PsiStatement[] statements = method.getBody().getStatements();

  final PsiVariable var = (PsiVariable) ((PsiDeclarationStatement) statements[0]).getDeclaredElements()[0];
  final PsiType varType = var.getType();
  final PsiType typeRawIterator = factory.createTypeFromText("test.Iterator", null);
  assertEquals(varType, typeRawIterator);

  final PsiType initializerType = var.getInitializer().getType();
  assertEquals(initializerType, typeRawIterator);
  assertTrue(varType.isAssignableFrom(initializerType));
}
项目:consulo-java    文件:TypesTest.java   
public void testRawTypeExtension() throws Exception {
  final JavaPsiFacadeEx psiManager = getJavaFacade();
  final PsiElementFactory factory = psiManager.getElementFactory();
  final PsiClass classA = psiManager.findClass("A");
  assertNotNull(classA);

  final PsiMethod method = classA.getMethods()[0];
  final PsiStatement[] statements = method.getBody().getStatements();

  final PsiVariable var = (PsiVariable) ((PsiDeclarationStatement) statements[0]).getDeclaredElements()[0];
  final PsiType varType = var.getType();
  final PsiType typeRawIterator = factory.createTypeFromText("test.Iterator", null);
  assertEquals(varType, typeRawIterator);

  final PsiType initializerType = var.getInitializer().getType();
  assertEquals(initializerType, typeRawIterator);
  assertTrue(varType.isAssignableFrom(initializerType));
}
项目:consulo-java    文件:TypesTest.java   
public void testTypesInGenericClass() {
  final JavaPsiFacadeEx psiManager = getJavaFacade();
  final PsiElementFactory factory = psiManager.getElementFactory();
  final PsiClass classA = psiManager.findClass("A");
  assertNotNull(classA);

  final PsiTypeParameter parameterT = classA.getTypeParameters()[0];
  assertEquals("T", parameterT.getName());

  final PsiMethod method = classA.findMethodsByName("method", false)[0];
  final PsiType type = ((PsiExpressionStatement) method.getBody().getStatements()[0]).getExpression().getType();
  final PsiClassType typeT = factory.createType(parameterT);
  assertEquals("T", typeT.getPresentableText());

  assertEquals(typeT, type);
}
项目:consulo-java    文件:TypesTest.java   
public void testComplexInheritance() throws Exception {
  final JavaPsiFacadeEx psiManager = getJavaFacade();
  final PsiElementFactory factory = psiManager.getElementFactory();
  final PsiClass classA = psiManager.findClass("A");
  assertNotNull(classA);

  final PsiMethod method = classA.findMethodsByName("method", false)[0];
  final PsiExpression expression = ((PsiExpressionStatement) method.getBody().getStatements()[1]).getExpression();
  assertEquals("l.get(0)", expression.getText());

  final PsiType type = expression.getType();
  final PsiType listOfInteger = factory.createTypeFromText("test.List<java.lang.Integer>", null);
  assertEquals(listOfInteger, type);
  final PsiType collectionOfInteger = factory.createTypeFromText("test.Collection<java.lang.Integer>", null);
  assertTrue(collectionOfInteger.isAssignableFrom(type));
}
项目:consulo-java    文件:TypesTest.java   
public void testListListInheritance() throws Exception {
  final JavaPsiFacadeEx psiManager = getJavaFacade();
  final PsiElementFactory factory = psiManager.getElementFactory();
  final PsiClass classA = psiManager.findClass("A");
  assertNotNull(classA);

  final PsiMethod method = classA.findMethodsByName("method", false)[0];

  final PsiExpression expression1 = ((PsiExpressionStatement) method.getBody().getStatements()[1]).getExpression();
  assertEquals("l.get(0)", expression1.getText());
  final PsiType type1 = expression1.getType();
  final PsiType typeListOfInteger = factory.createTypeFromText("test.List<java.lang.Integer>", null);
  assertEquals(typeListOfInteger, type1);
  assertTrue(typeListOfInteger.isAssignableFrom(type1));

  final PsiExpression expression2 = ((PsiExpressionStatement) method.getBody().getStatements()[3]).getExpression();
  assertEquals("b.get(0)", expression2.getText());
  final PsiType type2 = expression2.getType();
  assertEquals(typeListOfInteger, type2);
}
项目:intellij-ce-playground    文件:DaemonAnalyzerTestCase.java   
@NotNull
protected Collection<HighlightInfo> checkHighlighting(@NotNull final ExpectedHighlightingData data) {
  data.init();
  PsiDocumentManager.getInstance(myProject).commitAllDocuments();

  //to load text
  ApplicationManager.getApplication().runWriteAction(new Runnable() {
    @Override
    public void run() {
      TreeUtil.clearCaches((TreeElement)myFile.getNode());
    }
  });


  //to initialize caches
  if (!DumbService.isDumb(getProject())) {
    CacheManager.SERVICE.getInstance(myProject).getFilesWithWord("XXX", UsageSearchContext.IN_COMMENTS, GlobalSearchScope.allScope(myProject), true);
  }
  final JavaPsiFacadeEx facade = getJavaFacade();
  if (facade != null) {
    facade.setAssertOnFileLoadingFilter(myVirtualFileFilter, myTestRootDisposable); // check repository work
  }

  try {
    Collection<HighlightInfo> infos = doHighlighting();

    String text = myEditor.getDocument().getText();
    data.checkLineMarkers(DaemonCodeAnalyzerImpl.getLineMarkers(getDocument(getFile()), getProject()), text);
    data.checkResult(infos, text);
    return infos;
  }
  finally {
    if (facade != null) {
      facade.setAssertOnFileLoadingFilter(VirtualFileFilter.NONE, myTestRootDisposable);
    }
  }
}
项目:intellij-ce-playground    文件:IdeaTestCase.java   
@Override
protected void setUp() throws Exception {
  super.setUp();
  myJavaFacade = JavaPsiFacadeEx.getInstanceEx(myProject);
  VirtualFilePointerManagerImpl filePointerManager = (VirtualFilePointerManagerImpl)VirtualFilePointerManager.getInstance();
  filePointerManager.storePointers();
}
项目:intellij-ce-playground    文件:TypesTest.java   
public void testSimpleStuff() throws Exception {
  final JavaPsiFacadeEx psiManager = getJavaFacade();
  final PsiElementFactory factory = psiManager.getElementFactory();
  final PsiClass classA = psiManager.findClass("A");
  assertNotNull(classA);

  final PsiMethod method = classA.getMethods()[0];
  final PsiStatement[] methodStatements = method.getBody().getStatements();
  final PsiDeclarationStatement declarationStatement = (PsiDeclarationStatement) methodStatements[0];
  final PsiVariable varList = (PsiVariable) declarationStatement.getDeclaredElements()[0];
  final PsiType typeListOfA = factory.createTypeFromText("test.List<java.lang.String>", null);
  assertEquals(varList.getType(), typeListOfA);
  final PsiType typeListOfObject = factory.createTypeFromText("test.List<java.lang.Object>", null);
  assertFalse(varList.getType().equals(typeListOfObject));

  final PsiReferenceExpression methodExpression
          = ((PsiMethodCallExpression) ((PsiExpressionStatement) methodStatements[1]).getExpression()).getMethodExpression();
  final JavaResolveResult resolveResult = methodExpression.advancedResolve(false);
  assertTrue(resolveResult.getElement() instanceof PsiMethod);
  final PsiMethod methodFromList = (PsiMethod) resolveResult.getElement();
  final PsiType typeOfFirstParameterOfAdd = methodFromList.getParameterList().getParameters()[0].getType();
  final PsiType substitutedType = resolveResult.getSubstitutor().substitute(typeOfFirstParameterOfAdd);
  final PsiClassType typeA = factory.createTypeByFQClassName("java.lang.String");
  assertEquals(typeA, substitutedType);
  assertTrue(typeA.equalsToText("java.lang.String"));

  final PsiType aListIteratorType = ((PsiExpressionStatement) methodStatements[2]).getExpression().getType();
  final PsiType aIteratorType = factory.createTypeFromText("test.Iterator<java.lang.String>", null);
  assertEquals(aIteratorType, aListIteratorType);
  final PsiType objectIteratorType = factory.createTypeFromText("test.Iterator<java.lang.Object>", null);
  assertFalse(objectIteratorType.equals(aListIteratorType));
}
项目:intellij-ce-playground    文件:TypesTest.java   
public void testSubstWithInheritor() throws Exception {
  final JavaPsiFacadeEx psiManager = getJavaFacade();
  final PsiElementFactory factory = psiManager.getElementFactory();
  final PsiClass classA = psiManager.findClass("A");
  assertNotNull(classA);

  final PsiMethod method = classA.getMethods()[0];
  final PsiStatement[] methodStatements = method.getBody().getStatements();
  final PsiDeclarationStatement declarationStatement = (PsiDeclarationStatement) methodStatements[0];
  final PsiVariable varList = (PsiVariable) declarationStatement.getDeclaredElements()[0];
  final PsiType typeFromText = factory.createTypeFromText("test.IntList", null);
  assertEquals(varList.getType(), typeFromText);

  final PsiReferenceExpression methodExpression
          = ((PsiMethodCallExpression) ((PsiExpressionStatement) methodStatements[1]).getExpression()).getMethodExpression();
  final JavaResolveResult resolveResult = methodExpression.advancedResolve(false);
  assertTrue(resolveResult.getElement() instanceof PsiMethod);
  final PsiMethod methodFromList = (PsiMethod) resolveResult.getElement();
  final PsiType typeOfFirstParameterOfAdd = methodFromList.getParameterList().getParameters()[0].getType();
  final PsiType substitutedType = resolveResult.getSubstitutor().substitute(typeOfFirstParameterOfAdd);
  final PsiType javaLangInteger = factory.createTypeFromText("java.lang.Integer", null);
  assertEquals(javaLangInteger, substitutedType);

  final PsiType intListIteratorReturnType = ((PsiExpressionStatement) methodStatements[2]).getExpression().getType();
  final PsiType integerIteratorType = factory.createTypeFromText("test.Iterator<java.lang.Integer>", null);
  assertEquals(integerIteratorType, intListIteratorReturnType);
  final PsiType objectIteratorType = factory.createTypeFromText("test.Iterator<java.lang.Object>", null);
  assertFalse(objectIteratorType.equals(integerIteratorType));
}
项目:intellij-ce-playground    文件:TypesTest.java   
public void testSimpleRawTypeInMethodArg() throws Exception {
  final JavaPsiFacadeEx psiManager = getJavaFacade();
  final PsiElementFactory factory = psiManager.getElementFactory();
  final PsiClass classA = psiManager.findClass("A");
  assertNotNull(classA);

  final PsiMethod method = classA.getMethods()[0];
  final PsiStatement[] methodStatements = method.getBody().getStatements();

  final PsiVariable variable = (PsiVariable) ((PsiDeclarationStatement) methodStatements[0]).getDeclaredElements()[0];
  final PsiClassType type = (PsiClassType) variable.getType();
  final PsiClassType.ClassResolveResult resolveClassTypeResult = type.resolveGenerics();
  assertNotNull(resolveClassTypeResult.getElement());

  final PsiReferenceExpression methodExpression
          = ((PsiMethodCallExpression) ((PsiExpressionStatement) methodStatements[2]).getExpression()).getMethodExpression();
  final PsiExpression qualifierExpression = methodExpression.getQualifierExpression();
  final PsiClassType qualifierType = (PsiClassType) qualifierExpression.getType();
  assertFalse(qualifierType.hasParameters());
  final PsiType typeFromText = factory.createTypeFromText("test.List", null);
  assertEquals(qualifierType, typeFromText);

  final PsiElement psiElement = ((PsiReferenceExpression) qualifierExpression).resolve();
  assertTrue(psiElement instanceof PsiVariable);
  final JavaResolveResult resolveResult = methodExpression.advancedResolve(false);
  assertTrue(resolveResult.getElement() instanceof PsiMethod);
  final PsiMethod methodFromList = (PsiMethod) resolveResult.getElement();
  assertEquals("add", methodFromList.getName());
  assertEquals("test.List", methodFromList.getContainingClass().getQualifiedName());
}
项目:intellij-ce-playground    文件:TypesTest.java   
public void testAssignableSubInheritor() throws Exception {
  final JavaPsiFacadeEx psiManager = getJavaFacade();
  final PsiElementFactory factory = psiManager.getElementFactory();
  final PsiClass classCollection = psiManager.findClass("test.Collection");
  final PsiClass classList = psiManager.findClass("test.List");
  final PsiType collectionType = factory.createType(classCollection, PsiSubstitutor.EMPTY);
  final PsiType listType = factory.createType(classList, PsiSubstitutor.EMPTY);
  assertEquals(collectionType.getCanonicalText(), "test.Collection<E>");
  assertEquals(listType.getCanonicalText(), "test.List<T>");

  final PsiType typeListOfString = factory.createTypeFromText("test.List<java.lang.String>", null);
  final PsiType typeCollectionOfString = factory.createTypeFromText("test.Collection<java.lang.String>", null);
  assertTrue(typeCollectionOfString.isAssignableFrom(typeListOfString));
}
项目:intellij-ce-playground    文件:TypesTest.java   
public void testSpaceInTypeParameterList() throws Exception {
  final JavaPsiFacadeEx psiManager = getJavaFacade();
  final PsiElementFactory factory = psiManager.getElementFactory();
  final PsiClass classA = psiManager.findClass("A");
  assertNotNull(classA);

  final PsiMethod method = classA.findMethodsByName("method", false)[0];

  final PsiVariable variable = (PsiVariable) ((PsiDeclarationStatement) method.getBody().getStatements()[0]).getDeclaredElements()[0];
  final PsiType type = variable.getType();
  final PsiType typeListOfListOfInteger = factory.createTypeFromText("test.List<test.List<java.lang.Integer>>", null);
  assertEquals(typeListOfListOfInteger, type);
}
项目:intellij-ce-playground    文件:TypesTest.java   
public void testMethodTypeParameter() throws Exception {
  final JavaPsiFacadeEx psiManager = getJavaFacade();
  final PsiElementFactory factory = psiManager.getElementFactory();
  final PsiClass classA = psiManager.findClass("A");
  assertNotNull(classA);

  final PsiMethod method = classA.findMethodsByName("method", false)[0];
  final PsiStatement[] statements = method.getBody().getStatements();

  final PsiMethodCallExpression methodCallExpression = (PsiMethodCallExpression) ((PsiExpressionStatement) statements[1]).getExpression();
  isCollectionUtilSort(methodCallExpression, factory.createTypeFromText("java.lang.Integer", null));

  final PsiMethodCallExpression methodCallExpression1 = (PsiMethodCallExpression) ((PsiExpressionStatement) statements[3]).getExpression();
  isCollectionUtilSort(methodCallExpression1, null);
}
项目:intellij-ce-playground    文件:TypesTest.java   
public void testRawArrayTypes() throws Exception {
  final JavaPsiFacadeEx psiManager = getJavaFacade();
  final PsiElementFactory factory = psiManager.getElementFactory();
  final PsiClass classA = psiManager.findClass("A");
  assertNotNull(classA);

  final PsiMethod method = classA.findMethodsByName("method", false)[0];
  final PsiStatement[] statements = method.getBody().getStatements();

  final PsiDeclarationStatement declarationStatement = (PsiDeclarationStatement) statements[0];
  final PsiClassType typeOfL = (PsiClassType) ((PsiVariable) declarationStatement.getDeclaredElements()[0]).getType();
  final PsiType typeRawList = factory.createTypeFromText("test.List", null);
  assertTrue(Comparing.equal(typeOfL, typeRawList));
  final PsiSubstitutor typeOfLSubstitutor = typeOfL.resolveGenerics().getSubstitutor();

  final PsiMethodCallExpression exprGetArray = (PsiMethodCallExpression) ((PsiExpressionStatement) statements[1]).getExpression();
  final PsiType typeOfGetArrayCall = exprGetArray.getType();
  final PsiType objectArrayType = factory.createTypeFromText("java.lang.Object[]", null);
  assertTrue(Comparing.equal(typeOfGetArrayCall, objectArrayType));
  final PsiMethod methodGetArray = (PsiMethod) exprGetArray.getMethodExpression().resolve();
  final PsiType subtitutedGetArrayReturnType = typeOfLSubstitutor.substitute(methodGetArray.getReturnType());
  assertTrue(Comparing.equal(subtitutedGetArrayReturnType, objectArrayType));


  final PsiMethodCallExpression exprGetListOfArray = (PsiMethodCallExpression) ((PsiExpressionStatement) statements[2]).getExpression();
  final PsiMethod methodGetListOfArray = (PsiMethod) exprGetListOfArray.getMethodExpression().resolve();
  final PsiType returnType = methodGetListOfArray.getReturnType();
  final PsiType substitutedReturnType = typeOfLSubstitutor.substitute(returnType);
  assertTrue(Comparing.equal(substitutedReturnType, typeRawList));

  final PsiType typeOfGetListOfArrayCall = exprGetListOfArray.getType();
  assertTrue(Comparing.equal(typeOfGetListOfArrayCall, typeRawList));
}
项目:tools-idea    文件:DaemonAnalyzerTestCase.java   
@NotNull
protected Collection<HighlightInfo> checkHighlighting(@NotNull final ExpectedHighlightingData data) {
  data.init();
  PsiDocumentManager.getInstance(myProject).commitAllDocuments();

  //to load text
  ApplicationManager.getApplication().runWriteAction(new Runnable() {
    @Override
    public void run() {
      TreeUtil.clearCaches((TreeElement)myFile.getNode());
    }
  });


  //to initialize caches
  if (!DumbService.isDumb(getProject())) {
    CacheManager.SERVICE.getInstance(myProject).getFilesWithWord("XXX", UsageSearchContext.IN_COMMENTS, GlobalSearchScope.allScope(myProject), true);
  }
  final JavaPsiFacadeEx facade = getJavaFacade();
  if (facade != null) {
    facade.setAssertOnFileLoadingFilter(myFileTreeAccessFilter); // check repository work
  }

  Collection<HighlightInfo> infos = doHighlighting();

  if (facade != null) {
    facade.setAssertOnFileLoadingFilter(VirtualFileFilter.NONE);
  }

  String text = myEditor.getDocument().getText();
  data.checkLineMarkers(DaemonCodeAnalyzerImpl.getLineMarkers(getDocument(getFile()), getProject()), text);
  data.checkResult(infos, text);
  return infos;
}
项目:tools-idea    文件:IdeaTestCase.java   
@Override
protected void setUp() throws Exception {
  super.setUp();
  myJavaFacade = JavaPsiFacadeEx.getInstanceEx(myProject);
  VirtualFilePointerManagerImpl filePointerManager = (VirtualFilePointerManagerImpl)VirtualFilePointerManager.getInstance();
  filePointerManager.storePointers();
}
项目:tools-idea    文件:TypesTest.java   
public void testSimpleStuff() throws Exception {
  final JavaPsiFacadeEx psiManager = getJavaFacade();
  final PsiElementFactory factory = psiManager.getElementFactory();
  final PsiClass classA = psiManager.findClass("A");
  assertNotNull(classA);

  final PsiMethod method = classA.getMethods()[0];
  final PsiStatement[] methodStatements = method.getBody().getStatements();
  final PsiDeclarationStatement declarationStatement = (PsiDeclarationStatement) methodStatements[0];
  final PsiVariable varList = (PsiVariable) declarationStatement.getDeclaredElements()[0];
  final PsiType typeListOfA = factory.createTypeFromText("test.List<java.lang.String>", null);
  assertEquals(varList.getType(), typeListOfA);
  final PsiType typeListOfObject = factory.createTypeFromText("test.List<java.lang.Object>", null);
  assertFalse(varList.getType().equals(typeListOfObject));

  final PsiReferenceExpression methodExpression
          = ((PsiMethodCallExpression) ((PsiExpressionStatement) methodStatements[1]).getExpression()).getMethodExpression();
  final JavaResolveResult resolveResult = methodExpression.advancedResolve(false);
  assertTrue(resolveResult.getElement() instanceof PsiMethod);
  final PsiMethod methodFromList = (PsiMethod) resolveResult.getElement();
  final PsiType typeOfFirstParameterOfAdd = methodFromList.getParameterList().getParameters()[0].getType();
  final PsiType substitutedType = resolveResult.getSubstitutor().substitute(typeOfFirstParameterOfAdd);
  final PsiClassType typeA = factory.createTypeByFQClassName("java.lang.String");
  assertEquals(typeA, substitutedType);
  assertTrue(typeA.equalsToText("java.lang.String"));

  final PsiType aListIteratorType = ((PsiExpressionStatement) methodStatements[2]).getExpression().getType();
  final PsiType aIteratorType = factory.createTypeFromText("test.Iterator<java.lang.String>", null);
  assertEquals(aIteratorType, aListIteratorType);
  final PsiType objectIteratorType = factory.createTypeFromText("test.Iterator<java.lang.Object>", null);
  assertFalse(objectIteratorType.equals(aListIteratorType));
}
项目:tools-idea    文件:TypesTest.java   
public void testSubstWithInheritor() throws Exception {
  final JavaPsiFacadeEx psiManager = getJavaFacade();
  final PsiElementFactory factory = psiManager.getElementFactory();
  final PsiClass classA = psiManager.findClass("A");
  assertNotNull(classA);

  final PsiMethod method = classA.getMethods()[0];
  final PsiStatement[] methodStatements = method.getBody().getStatements();
  final PsiDeclarationStatement declarationStatement = (PsiDeclarationStatement) methodStatements[0];
  final PsiVariable varList = (PsiVariable) declarationStatement.getDeclaredElements()[0];
  final PsiType typeFromText = factory.createTypeFromText("test.IntList", null);
  assertEquals(varList.getType(), typeFromText);

  final PsiReferenceExpression methodExpression
          = ((PsiMethodCallExpression) ((PsiExpressionStatement) methodStatements[1]).getExpression()).getMethodExpression();
  final JavaResolveResult resolveResult = methodExpression.advancedResolve(false);
  assertTrue(resolveResult.getElement() instanceof PsiMethod);
  final PsiMethod methodFromList = (PsiMethod) resolveResult.getElement();
  final PsiType typeOfFirstParameterOfAdd = methodFromList.getParameterList().getParameters()[0].getType();
  final PsiType substitutedType = resolveResult.getSubstitutor().substitute(typeOfFirstParameterOfAdd);
  final PsiType javaLangInteger = factory.createTypeFromText("java.lang.Integer", null);
  assertEquals(javaLangInteger, substitutedType);

  final PsiType intListIteratorReturnType = ((PsiExpressionStatement) methodStatements[2]).getExpression().getType();
  final PsiType integerIteratorType = factory.createTypeFromText("test.Iterator<java.lang.Integer>", null);
  assertEquals(integerIteratorType, intListIteratorReturnType);
  final PsiType objectIteratorType = factory.createTypeFromText("test.Iterator<java.lang.Object>", null);
  assertFalse(objectIteratorType.equals(integerIteratorType));
}
项目:tools-idea    文件:TypesTest.java   
public void testSimpleRawTypeInMethodArg() throws Exception {
  final JavaPsiFacadeEx psiManager = getJavaFacade();
  final PsiElementFactory factory = psiManager.getElementFactory();
  final PsiClass classA = psiManager.findClass("A");
  assertNotNull(classA);

  final PsiMethod method = classA.getMethods()[0];
  final PsiStatement[] methodStatements = method.getBody().getStatements();

  final PsiVariable variable = (PsiVariable) ((PsiDeclarationStatement) methodStatements[0]).getDeclaredElements()[0];
  final PsiClassType type = (PsiClassType) variable.getType();
  final PsiClassType.ClassResolveResult resolveClassTypeResult = type.resolveGenerics();
  assertNotNull(resolveClassTypeResult.getElement());

  final PsiReferenceExpression methodExpression
          = ((PsiMethodCallExpression) ((PsiExpressionStatement) methodStatements[2]).getExpression()).getMethodExpression();
  final PsiExpression qualifierExpression = methodExpression.getQualifierExpression();
  final PsiClassType qualifierType = (PsiClassType) qualifierExpression.getType();
  assertFalse(qualifierType.hasParameters());
  final PsiType typeFromText = factory.createTypeFromText("test.List", null);
  assertEquals(qualifierType, typeFromText);

  final PsiElement psiElement = ((PsiReferenceExpression) qualifierExpression).resolve();
  assertTrue(psiElement instanceof PsiVariable);
  final JavaResolveResult resolveResult = methodExpression.advancedResolve(false);
  assertTrue(resolveResult.getElement() instanceof PsiMethod);
  final PsiMethod methodFromList = (PsiMethod) resolveResult.getElement();
  assertEquals("add", methodFromList.getName());
  assertEquals("test.List", methodFromList.getContainingClass().getQualifiedName());
}
项目:tools-idea    文件:TypesTest.java   
public void testAssignableSubInheritor() throws Exception {
  final JavaPsiFacadeEx psiManager = getJavaFacade();
  final PsiElementFactory factory = psiManager.getElementFactory();
  final PsiClass classCollection = psiManager.findClass("test.Collection");
  final PsiClass classList = psiManager.findClass("test.List");
  final PsiType collectionType = factory.createType(classCollection, PsiSubstitutor.EMPTY);
  final PsiType listType = factory.createType(classList, PsiSubstitutor.EMPTY);
  assertEquals(collectionType.getCanonicalText(), "test.Collection<E>");
  assertEquals(listType.getCanonicalText(), "test.List<T>");

  final PsiType typeListOfString = factory.createTypeFromText("test.List<java.lang.String>", null);
  final PsiType typeCollectionOfString = factory.createTypeFromText("test.Collection<java.lang.String>", null);
  assertTrue(typeCollectionOfString.isAssignableFrom(typeListOfString));
}
项目:tools-idea    文件:TypesTest.java   
public void testSpaceInTypeParameterList() throws Exception {
  final JavaPsiFacadeEx psiManager = getJavaFacade();
  final PsiElementFactory factory = psiManager.getElementFactory();
  final PsiClass classA = psiManager.findClass("A");
  assertNotNull(classA);

  final PsiMethod method = classA.findMethodsByName("method", false)[0];

  final PsiVariable variable = (PsiVariable) ((PsiDeclarationStatement) method.getBody().getStatements()[0]).getDeclaredElements()[0];
  final PsiType type = variable.getType();
  final PsiType typeListOfListOfInteger = factory.createTypeFromText("test.List<test.List<java.lang.Integer>>", null);
  assertEquals(typeListOfListOfInteger, type);
}
项目:tools-idea    文件:TypesTest.java   
public void testMethodTypeParameter() throws Exception {
  final JavaPsiFacadeEx psiManager = getJavaFacade();
  final PsiElementFactory factory = psiManager.getElementFactory();
  final PsiClass classA = psiManager.findClass("A");
  assertNotNull(classA);

  final PsiMethod method = classA.findMethodsByName("method", false)[0];
  final PsiStatement[] statements = method.getBody().getStatements();

  final PsiMethodCallExpression methodCallExpression = (PsiMethodCallExpression) ((PsiExpressionStatement) statements[1]).getExpression();
  isCollectionUtilSort(methodCallExpression, factory.createTypeFromText("java.lang.Integer", null));

  final PsiMethodCallExpression methodCallExpression1 = (PsiMethodCallExpression) ((PsiExpressionStatement) statements[3]).getExpression();
  isCollectionUtilSort(methodCallExpression1, null);
}
项目:tools-idea    文件:TypesTest.java   
public void testRawArrayTypes() throws Exception {
  final JavaPsiFacadeEx psiManager = getJavaFacade();
  final PsiElementFactory factory = psiManager.getElementFactory();
  final PsiClass classA = psiManager.findClass("A");
  assertNotNull(classA);

  final PsiMethod method = classA.findMethodsByName("method", false)[0];
  final PsiStatement[] statements = method.getBody().getStatements();

  final PsiDeclarationStatement declarationStatement = (PsiDeclarationStatement) statements[0];
  final PsiClassType typeOfL = (PsiClassType) ((PsiVariable) declarationStatement.getDeclaredElements()[0]).getType();
  final PsiType typeRawList = factory.createTypeFromText("test.List", null);
  assertTrue(Comparing.equal(typeOfL, typeRawList));
  final PsiSubstitutor typeOfLSubstitutor = typeOfL.resolveGenerics().getSubstitutor();

  final PsiMethodCallExpression exprGetArray = (PsiMethodCallExpression) ((PsiExpressionStatement) statements[1]).getExpression();
  final PsiType typeOfGetArrayCall = exprGetArray.getType();
  final PsiType objectArrayType = factory.createTypeFromText("java.lang.Object[]", null);
  assertTrue(Comparing.equal(typeOfGetArrayCall, objectArrayType));
  final PsiMethod methodGetArray = (PsiMethod) exprGetArray.getMethodExpression().resolve();
  final PsiType subtitutedGetArrayReturnType = typeOfLSubstitutor.substitute(methodGetArray.getReturnType());
  assertTrue(Comparing.equal(subtitutedGetArrayReturnType, objectArrayType));


  final PsiMethodCallExpression exprGetListOfArray = (PsiMethodCallExpression) ((PsiExpressionStatement) statements[2]).getExpression();
  final PsiMethod methodGetListOfArray = (PsiMethod) exprGetListOfArray.getMethodExpression().resolve();
  final PsiType returnType = methodGetListOfArray.getReturnType();
  final PsiType substitutedReturnType = typeOfLSubstitutor.substitute(returnType);
  assertTrue(Comparing.equal(substitutedReturnType, typeRawList));

  final PsiType typeOfGetListOfArrayCall = exprGetListOfArray.getType();
  assertTrue(Comparing.equal(typeOfGetListOfArrayCall, typeRawList));
}
项目:consulo-java    文件:DaemonAnalyzerTestCase.java   
@NotNull
protected Collection<HighlightInfo> checkHighlighting(@NotNull final ExpectedHighlightingData data)
{
    data.init();
    PsiDocumentManager.getInstance(myProject).commitAllDocuments();

    //to load text
    ApplicationManager.getApplication().runWriteAction(new Runnable()
    {
        @Override
        public void run()
        {
            TreeUtil.clearCaches((TreeElement) myFile.getNode());
        }
    });


    //to initialize caches
    if(!DumbService.isDumb(getProject()))
    {
        CacheManager.getInstance(myProject).getFilesWithWord("XXX", UsageSearchContext.IN_COMMENTS, GlobalSearchScope.allScope(myProject), true);
    }
    final JavaPsiFacadeEx facade = getJavaFacade();
    if(facade != null)
    {
        facade.setAssertOnFileLoadingFilter(myFileTreeAccessFilter, null); // check repository work
    }

    Collection<HighlightInfo> infos = doHighlighting();

    if(facade != null)
    {
        facade.setAssertOnFileLoadingFilter(VirtualFileFilter.NONE, null);
    }

    String text = myEditor.getDocument().getText();
    data.checkLineMarkers(DaemonCodeAnalyzerImpl.getLineMarkers(getDocument(getFile()), getProject()), text);
    data.checkResult(infos, text);
    return infos;
}