Java 类com.intellij.lang.java.JavaLanguage 实例源码

项目:intellij-spring-assistant    文件:YamlDocumentationProvider.java   
@Override
public PsiElement getDocumentationElementForLookupItem(PsiManager psiManager, Object object,
    @Nullable PsiElement element) {
  if (object instanceof Suggestion) {
    Suggestion suggestion = Suggestion.class.cast(object);
    MetadataNode target = suggestion.getRef();
    boolean requestedForTargetValue = suggestion.isReferringToValue();
    String text = null;
    if (element != null) {
      text = element.getText();
    }
    return new DocumentationProxyElement(psiManager, JavaLanguage.INSTANCE, target,
        requestedForTargetValue, text);
  }
  return super.getDocumentationElementForLookupItem(psiManager, object, element);
}
项目:intellij-spring-assistant    文件:PropertiesDocumentationProvider.java   
@Override
public PsiElement getDocumentationElementForLookupItem(PsiManager psiManager, Object object,
    @Nullable PsiElement element) {
  if (object instanceof Suggestion) {
    Suggestion suggestion = Suggestion.class.cast(object);
    MetadataNode target = suggestion.getRef();
    boolean requestedForTargetValue = suggestion.isReferringToValue();
    String text = null;
    if (element != null) {
      text = element.getText();
    }
    return new DocumentationProxyElement(psiManager, JavaLanguage.INSTANCE, target,
        requestedForTargetValue, text);
  }
  return super.getDocumentationElementForLookupItem(psiManager, object, element);
}
项目:intellij-ce-playground    文件:Intention.java   
@Nullable
PsiElement findMatchingElement(@Nullable PsiElement element, Editor editor) {
  while (element != null) {
    if (!JavaLanguage.INSTANCE.equals(element.getLanguage())) {
      break;
    }
    if (predicate instanceof PsiElementEditorPredicate) {
      if (((PsiElementEditorPredicate)predicate).satisfiedBy(element, editor)) {
        return element;
      }
    }
    else if (predicate.satisfiedBy(element)) {
      return element;
    }
    element = element.getParent();
    if (element instanceof PsiFile) {
      break;
    }
  }
  return null;
}
项目:intellij-ce-playground    文件:JavaMoveClassToInnerHandler.java   
@Override
public PsiClass moveClass(@NotNull PsiClass aClass, @NotNull PsiClass targetClass) {
  if (aClass.getLanguage() != JavaLanguage.INSTANCE) {
    return null;
  }

  ChangeContextUtil.encodeContextInfo(aClass, true);
  PsiClass newClass = (PsiClass)targetClass.addBefore(aClass, targetClass.getRBrace());
  if (targetClass.isInterface()) {
    PsiUtil.setModifierProperty(newClass, PsiModifier.PACKAGE_LOCAL, true);
  }
  else {
    PsiUtil.setModifierProperty(newClass, PsiModifier.STATIC, true);
  }
  return (PsiClass)ChangeContextUtil.decodeContextInfo(newClass, null, null);
}
项目:intellij-ce-playground    文件:JavaInvertBooleanDelegate.java   
public void collectRefsToInvert(PsiElement namedElement, Collection<PsiElement> elementsToInvert) {
  final Query<PsiReference> query = namedElement instanceof PsiMethod ?
                                    MethodReferencesSearch.search((PsiMethod)namedElement) :
                                    ReferencesSearch.search(namedElement);
  final Collection<PsiReference> refs = query.findAll();

  for (PsiReference ref : refs) {
    final PsiElement element = ref.getElement();
    PsiElement refElement = getElementToInvert(namedElement, element);
    if (refElement == null) {
      refElement = getForeignElementToInvert(namedElement, element, JavaLanguage.INSTANCE);
    }
    if (refElement != null) {
      elementsToInvert.add(refElement);
    }
  }
}
项目:intellij-ce-playground    文件:JavadocFormatterTest.java   
public void testReturnTagAlignment() throws Exception {
  getSettings().getRootSettings().ENABLE_JAVADOC_FORMATTING = true;
  getSettings().RIGHT_MARGIN = 80;
  getSettings().getRootSettings().JD_LEADING_ASTERISKS_ARE_ENABLED = true;
  getSettings().getRootSettings().WRAP_COMMENTS = true;
  getSettings().getRootSettings().getCommonSettings(JavaLanguage.INSTANCE).WRAP_LONG_LINES = true;

  String before = "    /**\n" +
                  "     * @return this is a return value documentation with a very long description that is longer than the right margin. It is more than 200 characters long, not including the comment indent and the asterisk characters, which should be greater than any sane right margin.\n" +
                  "     */\n" +
                  "    public int method(int parameter) {\n" +
                  "        return 0;\n" +
                  "    }\n";

  String after = "/**\n" +
                 " * @return this is a return value documentation with a very long description\n" +
                 " * that is longer than the right margin. It is more than 200 characters\n" +
                 " * long, not including the comment indent and the asterisk characters, which\n" +
                 " * should be greater than any sane right margin.\n" +
                 " */\n" +
                 "public int method(int parameter) {\n" +
                 "    return 0;\n" +
                 "}\n";

  doClassTest(before, after);
}
项目:intellij-ce-playground    文件:JavadocFormatterTest.java   
public void testDummyDeprecatedTagAlignment() throws Exception {
  getSettings().getRootSettings().ENABLE_JAVADOC_FORMATTING = true;
  getSettings().RIGHT_MARGIN = 80;
  getSettings().getRootSettings().JD_LEADING_ASTERISKS_ARE_ENABLED = true;
  getSettings().getRootSettings().WRAP_COMMENTS = true;
  getSettings().getRootSettings().getCommonSettings(JavaLanguage.INSTANCE).WRAP_LONG_LINES = true;

  String before = "    /**\n" +
                  "     * @deprecated this is an additional documentation with a very long description that is longer than the right margin. It is more than 200 characters long, not including the comment indent and the asterisk characters which should be greater than any sane right margin\n" +
                  "     */\n" +
                  "    public int method(int parameter) {\n" +
                  "        return 0;\n" +
                  "    }";

  String after = "/**\n" +
                 " * @deprecated this is an additional documentation with a very long\n" +
                 " * description that is longer than the right margin. It is more than 200\n" +
                 " * characters long, not including the comment indent and the asterisk\n" +
                 " * characters which should be greater than any sane right margin\n" +
                 " */\n" +
                 "public int method(int parameter) {\n" +
                 "    return 0;\n" +
                 "}";

  doClassTest(before, after);
}
项目:intellij-ce-playground    文件:TestOnlyInspection.java   
private static void validate(@NotNull PsiElement reference, @Nullable PsiMember member, ProblemsHolder h) {
  if (member == null || !isAnnotatedAsTestOnly(member)) return;
  if (isInsideTestOnlyMethod(reference)) return;
  if (isInsideTestClass(reference)) return;
  if (isUnderTestSources(reference)) return;

  PsiAnnotation anno = findVisibleForTestingAnnotation(member);
  if (anno != null) {
    String modifier = getAccessModifierWithoutTesting(anno);
    if (modifier == null) {
      modifier = member.hasModifierProperty(PsiModifier.PUBLIC) ? PsiModifier.PROTECTED :
                 member.hasModifierProperty(PsiModifier.PROTECTED) ? PsiModifier.PACKAGE_LOCAL :
                 PsiModifier.PRIVATE;
    }

    LightModifierList modList = new LightModifierList(member.getManager(), JavaLanguage.INSTANCE, modifier);
    if (JavaResolveUtil.isAccessible(member, member.getContainingClass(), modList, reference, null, null)) {
      return;
    }
  }

  reportProblem(reference, member, h);
}
项目:intellij-ce-playground    文件:CommentFormatter.java   
/**
 * Computes indentation of PsiClass, PsiMethod and PsiField elements after formatting
 * @param element PsiClass or PsiMethod or PsiField
 * @return indentation size
 */
private int getIndentSpecial(@NotNull PsiElement element) {
  if (element instanceof PsiDocComment) {
    return 0;
  }
  LOG.assertTrue(element instanceof PsiClass ||
                 element instanceof PsiField ||
                 element instanceof PsiMethod);

  int indentSize = mySettings.getIndentSize(JavaFileType.INSTANCE);
  boolean doNotIndentTopLevelClassMembers = mySettings.getCommonSettings(JavaLanguage.INSTANCE).DO_NOT_INDENT_TOP_LEVEL_CLASS_MEMBERS;

  int indent = 0;
  PsiClass top = PsiUtil.getTopLevelClass(element);
  while (top != null && !element.isEquivalentTo(top)) {
    if (doNotIndentTopLevelClassMembers && element.getParent().isEquivalentTo(top)) {
      break;
    }
    element = element.getParent();
    indent += indentSize;
  }

  return indent;
}
项目:intellij-ce-playground    文件:SuppressFix.java   
@Override
@Nullable
public PsiDocCommentOwner getContainer(final PsiElement context) {
  if (context == null || !context.getManager().isInProject(context)) {
    return null;
  }
  final PsiFile containingFile = context.getContainingFile();
  if (containingFile == null) {
    // for PsiDirectory
    return null;
  }
  if (!containingFile.getLanguage().isKindOf(JavaLanguage.INSTANCE) || context instanceof PsiFile) {
    return null;
  }
  PsiElement container = context;
  while (container instanceof PsiAnonymousClass || !(container instanceof PsiDocCommentOwner) || container instanceof PsiTypeParameter) {
    container = PsiTreeUtil.getParentOfType(container, PsiDocCommentOwner.class);
    if (container == null) return null;
  }
  return (PsiDocCommentOwner)container;
}
项目:intellij-ce-playground    文件:SetupSDKNotificationProvider.java   
@Override
public EditorNotificationPanel createNotificationPanel(@NotNull VirtualFile file, @NotNull FileEditor fileEditor) {
  if (file.getFileType() == JavaClassFileType.INSTANCE) return null;

  final PsiFile psiFile = PsiManager.getInstance(myProject).findFile(file);
  if (psiFile == null) {
    return null;
  }

  if (psiFile.getLanguage() != JavaLanguage.INSTANCE) {
    return null;
  }

  Module module = ModuleUtilCore.findModuleForPsiElement(psiFile);
  if (module == null) {
    return null;
  }

  Sdk sdk = ModuleRootManager.getInstance(module).getSdk();
  if (sdk != null) {
    return null;
  }

  return createPanel(myProject, psiFile);
}
项目:intellij-ce-playground    文件:TabPostFormatProcessor.java   
@NotNull
private static TextRange doProcess(@NotNull PsiElement source, @NotNull TextRange range, @NotNull CodeStyleSettings settings) {
  ASTNode node = source.getNode();
  if (node == null) {
    return range;
  }

  Language language = source.getLanguage();
  if (language != JavaLanguage.INSTANCE) {
    // We had the only complaint for tabs not being converted to spaces for now. It was for the java code which has
    // a single block for the multi-line comment. This check should be removed if it is decided to generalize
    // this logic to other languages as well.
    return range;
  }

  if (!source.isValid()) return range;
  PsiFile file = source.getContainingFile();
  CommonCodeStyleSettings.IndentOptions indentOptions = settings.getIndentOptionsByFile(file, range);

  boolean useTabs = indentOptions.USE_TAB_CHARACTER;
  boolean smartTabs = indentOptions.SMART_TABS;
  int tabWidth = indentOptions.TAB_SIZE;
  return processViaPsi(node, range, new TreeHelperImpl(), useTabs, smartTabs, tabWidth);
}
项目:intellij-ce-playground    文件:JoinLinesTest.java   
public void testUnwrapCodeBlock1() throws Exception {
  CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject());
  boolean use_tab_character = settings.useTabCharacter(null);
  boolean smart_tabs = settings.isSmartTabs(null);
  int old = settings.IF_BRACE_FORCE;
  try {
    settings.getIndentOptions(StdFileTypes.JAVA).USE_TAB_CHARACTER = true;
    settings.getIndentOptions(StdFileTypes.JAVA).SMART_TABS = true;
    settings.getCommonSettings(JavaLanguage.INSTANCE).IF_BRACE_FORCE = CommonCodeStyleSettings.FORCE_BRACES_IF_MULTILINE;
    doTest();
  } finally {
    settings.getIndentOptions(StdFileTypes.JAVA).USE_TAB_CHARACTER = use_tab_character;
    settings.getIndentOptions(StdFileTypes.JAVA).SMART_TABS = smart_tabs;
    settings.getCommonSettings(JavaLanguage.INSTANCE).IF_BRACE_FORCE = old;
  }
}
项目:intellij-ce-playground    文件:MakeInferredAnnotationExplicit.java   
@Override
public boolean isAvailable(@NotNull final Project project, Editor editor, PsiFile file) {
  final PsiElement leaf = file.findElementAt(editor.getCaretModel().getOffset());
  final PsiModifierListOwner owner = ExternalAnnotationsLineMarkerProvider.getAnnotationOwner(leaf);
  if (owner != null && !(owner instanceof PsiCompiledElement) && owner.getLanguage().isKindOf(JavaLanguage.INSTANCE) &&
      ModuleUtilCore.findModuleForPsiElement(file) != null &&
      PsiUtil.getLanguageLevel(file).isAtLeast(LanguageLevel.JDK_1_5)) {
    final PsiAnnotation[] annotations = InferredAnnotationsManager.getInstance(project).findInferredAnnotations(owner);
    if (annotations.length > 0) {
      final String annos = StringUtil.join(annotations, new Function<PsiAnnotation, String>() {
        @Override
        public String fun(PsiAnnotation annotation) {
          final PsiJavaCodeReferenceElement nameRef = correctAnnotation(annotation).getNameReferenceElement();
          final String name = nameRef != null ? nameRef.getReferenceName() : annotation.getQualifiedName();
          return "@" + name + annotation.getParameterList().getText();
        }
      }, " ");
      setText("Insert '" + annos + "'");
      return true;
    }
  }

  return false;
}
项目:intellij-ce-playground    文件:JavaReferenceImporter.java   
@Override
public boolean autoImportReferenceAt(@NotNull Editor editor, @NotNull PsiFile file, int offset) {
  if (!file.getViewProvider().getLanguages().contains(JavaLanguage.INSTANCE)) {
    return false;
  }

  PsiReference element = file.findReferenceAt(offset);
  if (element instanceof PsiJavaCodeReferenceElement) {
    PsiJavaCodeReferenceElement ref = (PsiJavaCodeReferenceElement)element;
    if (ref.multiResolve(true).length == 0) {
      new ImportClassFix(ref).doFix(editor, false, true);
      return true;
    }
  }

  return false;
}
项目:intellij-ce-playground    文件:DefineParamsDefaultValueAction.java   
@Override
public boolean isAvailable(@NotNull Project project, Editor editor, @NotNull PsiElement element) {
  if (!JavaLanguage.INSTANCE.equals(element.getLanguage())) {
    return false;
  }
  final PsiElement parent = PsiTreeUtil.getParentOfType(element, PsiMethod.class, PsiCodeBlock.class);
  if (!(parent instanceof PsiMethod)) {
    return false;
  }
  final PsiMethod method = (PsiMethod)parent;
  final PsiParameterList parameterList = method.getParameterList();
  if (parameterList.getParametersCount() == 0) {
    return false;
  }
  final PsiClass containingClass = method.getContainingClass();
  if (containingClass == null || (containingClass.isInterface() && !PsiUtil.isLanguageLevel8OrHigher(method))) {
    return false;
  }
  setText("Generate overloaded " + (method.isConstructor() ? "constructor" : "method") + " with default parameter values");
  return true;
}
项目:intellij-ce-playground    文件:SurroundAutoCloseableAction.java   
@Override
public boolean isAvailable(@NotNull Project project, Editor editor, @NotNull PsiElement element) {
  if (!element.getLanguage().isKindOf(JavaLanguage.INSTANCE)) return false;
  if (!PsiUtil.getLanguageLevel(element).isAtLeast(LanguageLevel.JDK_1_7)) return false;

  final PsiLocalVariable variable = PsiTreeUtil.getParentOfType(element, PsiLocalVariable.class);
  if (variable == null) return false;
  final PsiExpression initializer = variable.getInitializer();
  if (initializer == null) return false;
  final PsiElement declaration = variable.getParent();
  if (!(declaration instanceof PsiDeclarationStatement)) return false;
  final PsiElement codeBlock = declaration.getParent();
  if (!(codeBlock instanceof PsiCodeBlock)) return false;

  return InheritanceUtil.isInheritor(variable.getType(), CommonClassNames.JAVA_LANG_AUTO_CLOSEABLE);
}
项目:intellij-ce-playground    文件:SplitDeclarationAction.java   
@Override
public boolean isAvailable(@NotNull Project project, Editor editor, @NotNull PsiElement element) {

  if (element instanceof PsiCompiledElement) return false;
  if (!element.getManager().isInProject(element)) return false;
  if (!element.getLanguage().isKindOf(JavaLanguage.INSTANCE)) return false;

  final PsiElement context = PsiTreeUtil.getParentOfType(element, PsiDeclarationStatement.class, PsiClass.class);
  if (context instanceof PsiDeclarationStatement) {
    return isAvailableOnDeclarationStatement((PsiDeclarationStatement)context, element);
  }

  PsiField field = PsiTreeUtil.getParentOfType(element, PsiField.class);
  if (field != null && PsiTreeUtil.getParentOfType(element, PsiDocComment.class) == null && isAvailableOnField(field)) {
    setText(CodeInsightBundle.message("intention.split.declaration.text"));
    return true;
  }
  return false;
}
项目:intellij-ce-playground    文件:JavadocFormatterTest.java   
public void testDummySinceTagAlignment() throws Exception {
  getSettings().getRootSettings().ENABLE_JAVADOC_FORMATTING = true;
  getSettings().RIGHT_MARGIN = 80;
  getSettings().getRootSettings().JD_LEADING_ASTERISKS_ARE_ENABLED = true;
  getSettings().getRootSettings().WRAP_COMMENTS = true;
  getSettings().getRootSettings().getCommonSettings(JavaLanguage.INSTANCE).WRAP_LONG_LINES = true;

  String before = "    /**\n" +
                  "     * @since this is an additional documentation with a very long description that is longer than the right margin. It is more than 200 characters long, not including the comment indent and the asterisk characters which should be greater than any sane right margin\n" +
                  "     */\n" +
                  "    public int method(int parameter) {\n" +
                  "        return 0;\n" +
                  "    }";

  String after = "/**\n" +
                 " * @since this is an additional documentation with a very long description\n" +
                 " * that is longer than the right margin. It is more than 200 characters\n" +
                 " * long, not including the comment indent and the asterisk characters which\n" +
                 " * should be greater than any sane right margin\n" +
                 " */\n" +
                 "public int method(int parameter) {\n" +
                 "    return 0;\n" +
                 "}";

  doClassTest(before, after);
}
项目:intellij-ce-playground    文件:JavaFormatterTest.java   
public void testCommentAfterDeclaration() throws Exception {
  CodeStyleSettings codeStyleSettings = CodeStyleSettingsManager.getSettings(getProject());
  CommonCodeStyleSettings javaSettings = codeStyleSettings.getCommonSettings(JavaLanguage.INSTANCE);

  int oldMargin = codeStyleSettings.getDefaultRightMargin();
  int oldWrap = javaSettings.ASSIGNMENT_WRAP;

  try {
    codeStyleSettings.setDefaultRightMargin(20);
    javaSettings.ASSIGNMENT_WRAP = CommonCodeStyleSettings.WRAP_AS_NEEDED;
    doMethodTest(
      "int i=0; //comment comment",
      "int i =\n" +
      "        0; //comment comment"
    );

  }
  finally {
    codeStyleSettings.setDefaultRightMargin(oldMargin);
    javaSettings.ASSIGNMENT_WRAP = oldWrap;
  }
}
项目:intellij-ce-playground    文件:JavaNavBarExtension.java   
@Nullable
@Override
public PsiElement adjustElement(final PsiElement psiElement) {
  final ProjectFileIndex index = ProjectRootManager.getInstance(psiElement.getProject()).getFileIndex();
  final PsiFile containingFile = psiElement.getContainingFile();
  if (containingFile != null) {
    final VirtualFile file = containingFile.getVirtualFile();
    if (file != null &&
        (index.isUnderSourceRootOfType(file, JavaModuleSourceRootTypes.SOURCES) || index.isInLibraryClasses(file) || index.isInLibrarySource(file))) {
      if (psiElement instanceof PsiJavaFile) {
        final PsiJavaFile psiJavaFile = (PsiJavaFile)psiElement;
        if (psiJavaFile.getViewProvider().getBaseLanguage() == JavaLanguage.INSTANCE) {
          final PsiClass[] psiClasses = psiJavaFile.getClasses();
          if (psiClasses.length == 1) {
            return psiClasses[0];
          }
        }
      }
      if (psiElement instanceof PsiClass) {
        return psiElement;
      }
    }
    return containingFile;
  }
  return psiElement;
}
项目:intellij-ce-playground    文件:JavaFormatterInEditorTest.java   
public void testCaretPositionOnLongLineWrapping() throws IOException {
  // Inspired by IDEA-70242
  CommonCodeStyleSettings javaCommonSettings = getCurrentCodeStyleSettings().getCommonSettings(JavaLanguage.INSTANCE);
  javaCommonSettings.WRAP_LONG_LINES = true;
  javaCommonSettings.RIGHT_MARGIN = 40;
  doTest(
    "import static java.util.concurrent.atomic.AtomicInteger.*;\n" +
    "\n" +
    "class <caret>Test {\n" +
    "}",

    "import static java.util.concurrent\n" +
    "        .atomic.AtomicInteger.*;\n" +
    "\n" +
    "class <caret>Test {\n" +
    "}"
  );
}
项目:intellij-ce-playground    文件:JavaAnchorProvider.java   
@Override
public PsiElement getAnchor(@NotNull PsiElement element) {
  if (!element.getLanguage().isKindOf(JavaLanguage.INSTANCE) || !element.isPhysical()) {
    return null;
  }

  if (element instanceof PsiClass) {
    if (element instanceof PsiAnonymousClass) {
      return ((PsiAnonymousClass)element).getBaseClassReference().getReferenceNameElement();
    } else {
      return ((PsiClass)element).getNameIdentifier();
    }
  } else if (element instanceof PsiMethod) {
    return ((PsiMethod)element).getNameIdentifier();
  } else if (element instanceof PsiVariable) {
    return ((PsiVariable)element).getNameIdentifier();
  }
  return null;
}
项目:RIBs    文件:GenerateAction.java   
/**
 * Writes a source file generated by a {@link Generator} to disk.
 *
 * @param project to write file in.
 * @param generator to generate file with.
 * @param directory to write file to.
 */
private static void createSourceFile(
    Project project, Generator generator, PsiDirectory directory) {
  PsiFile file =
      PsiFileFactory.getInstance(project)
          .createFileFromText(
              String.format("%s.java", generator.getClassName()),
              JavaLanguage.INSTANCE,
              generator.generate());
  directory.add(file);
}
项目:cup-plugin    文件:CupJavaInjector.java   
@Override
public void getLanguagesToInject(@NotNull PsiLanguageInjectionHost host, @NotNull InjectedLanguagePlaces injectionPlacesRegistrar) {

    if (!(host instanceof CupJavaImpl) || !(settings.ENABLE_JAVA_INJECTION)) {
        return;
    }
    final CupJavaImpl cupJavaCode = (CupJavaImpl) host;
    final String text = cupJavaCode.getText();
    if (!(text.startsWith(PREFIX) && text.endsWith(SUFFIX))) {
        return;
    }
    injectionPlacesRegistrar.addPlace(JavaLanguage.INSTANCE, new TextRange(SUFFIX.length(), text.length() - SUFFIX.length()), "public class Dummy { public void dummyMethod(){", "}}");
}
项目:camel-idea-plugin    文件:GutterTestUtil.java   
static List<GotoRelatedItem> getGutterNavigationDestinationElements(LineMarkerInfo.LineMarkerGutterIconRenderer gutter) {
    LineMarkerProvider lineMarkerProvider1 = LineMarkersPass.getMarkerProviders(JavaLanguage.INSTANCE, gutter
        .getLineMarkerInfo()
        .getElement().getProject())
        .stream()
        .filter(lineMarkerProvider -> lineMarkerProvider instanceof CamelRouteLineMarkerProvider).findAny()
        .get();
    List<RelatedItemLineMarkerInfo> result = new ArrayList<>();
    ((CamelRouteLineMarkerProvider) lineMarkerProvider1).collectNavigationMarkers(gutter.getLineMarkerInfo().getElement(), result);
    return (List<GotoRelatedItem>) result.get(0).createGotoRelatedItems();
}
项目:intellij-ce-playground    文件:DataBindingUtil.java   
private void createStaticMethods(PsiElementFactory factory, PsiMethod[] outPsiMethods, int index) {
  PsiClassType myType = factory.createType(this);
  PsiClassType viewGroupType = PsiType
    .getTypeByName(SdkConstants.CLASS_VIEWGROUP, myInfo.getProject(),
                   myFacet.getModule().getModuleWithDependenciesAndLibrariesScope(true));
  PsiClassType layoutInflaterType = PsiType.getTypeByName(SdkConstants.CLASS_LAYOUT_INFLATER, myInfo.getProject(),
                                                          myFacet.getModule().getModuleWithDependenciesAndLibrariesScope(true));
  PsiClassType viewType = PsiType
    .getTypeByName(SdkConstants.CLASS_VIEW, myInfo.getProject(), myFacet.getModule().getModuleWithDependenciesAndLibrariesScope(true));
  PsiParameter layoutInflaterParam = factory.createParameter("inflater", layoutInflaterType);
  PsiParameter rootParam = factory.createParameter("root", viewGroupType);
  PsiParameter attachToRootParam = factory.createParameter("attachToRoot", PsiType.BOOLEAN);
  PsiParameter viewParam = factory.createParameter("view", viewType);

  PsiMethod inflate3Arg = factory.createMethod("inflate", myType);
  inflate3Arg.getParameterList().add(layoutInflaterParam);
  inflate3Arg.getParameterList().add(rootParam);
  inflate3Arg.getParameterList().add(attachToRootParam);

  PsiMethod inflate1Arg = factory.createMethod("inflate", myType);
  inflate1Arg.getParameterList().add(layoutInflaterParam);

  PsiMethod bind = factory.createMethod("bind", myType);
  bind.getParameterList().add(viewParam);

  PsiMethod[] methods = new PsiMethod[]{inflate1Arg, inflate3Arg, bind};
  PsiManager psiManager = PsiManager.getInstance(myInfo.getProject());
  for (PsiMethod method : methods) {
    PsiUtil.setModifierProperty(method, PsiModifier.PUBLIC, true);
    PsiUtil.setModifierProperty(method, PsiModifier.STATIC, true);
    //noinspection ConstantConditions
    outPsiMethods[index++] =
      new LightDataBindingMethod(myInfo.getPsiFile(), psiManager, method, this, JavaLanguage.INSTANCE);
  }
}
项目:intellij-ce-playground    文件:LightClassReference.java   
private LightClassReference(@NotNull PsiManager manager, @NotNull @NonNls String text, @NotNull @NonNls String className, PsiSubstitutor substitutor, @NotNull GlobalSearchScope resolveScope) {
  super(manager, JavaLanguage.INSTANCE);
  myText = text;
  myClassName = className;
  myResolveScope = resolveScope;

  myContext = null;
  myRefClass = null;
  mySubstitutor = substitutor;
}
项目:intellij-ce-playground    文件:LightClassReference.java   
public LightClassReference(@NotNull PsiManager manager, @NotNull @NonNls String text, @NotNull @NonNls String className, PsiSubstitutor substitutor, @NotNull PsiElement context) {
  super(manager, JavaLanguage.INSTANCE);
  myText = text;
  myClassName = className;
  mySubstitutor = substitutor;
  myContext = context;
  myResolveScope = context.getResolveScope();
  myRefClass = null;
}
项目:intellij-ce-playground    文件:TypeMigrationTest.java   
public void testT127() {
  CommonCodeStyleSettings javaSettings = getCurrentCodeStyleSettings().getCommonSettings(JavaLanguage.INSTANCE);
  javaSettings.ALIGN_MULTILINE_PARAMETERS = true;
  javaSettings.ALIGN_MULTILINE_PARAMETERS_IN_CALLS = true;
  doTestMethodType("test234",
                   myFactory.createTypeFromText("int", null),
                   myFactory.createTypeFromText("long", null));
}
项目:intellij-ce-playground    文件:CreateFieldFromUsageTest.java   
public void testWithAlignment() throws Exception {
  final CommonCodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject()).getCommonSettings(JavaLanguage.INSTANCE);
  boolean old = settings.ALIGN_GROUP_FIELD_DECLARATIONS;
  try {
    settings.ALIGN_GROUP_FIELD_DECLARATIONS = true;
    doSingleTest();
  }
  finally {
    settings.ALIGN_GROUP_FIELD_DECLARATIONS = old;
  }
}
项目:intellij-ce-playground    文件:OverrideImplement15Test.java   
public void testLongFinalParameterList() {
  CodeStyleSettings codeStyleSettings = CodeStyleSettingsManager.getSettings(getProject()).clone();
  try {
    CommonCodeStyleSettings javaSettings = codeStyleSettings.getCommonSettings(JavaLanguage.INSTANCE);
    javaSettings.RIGHT_MARGIN = 80;
    javaSettings.KEEP_LINE_BREAKS = true;
    codeStyleSettings.GENERATE_FINAL_PARAMETERS = true;
    javaSettings.METHOD_PARAMETERS_WRAP = CommonCodeStyleSettings.WRAP_ON_EVERY_ITEM;
    CodeStyleSettingsManager.getInstance(getProject()).setTemporarySettings(codeStyleSettings);
    doTest(false);
  }
  finally {
    CodeStyleSettingsManager.getInstance(getProject()).dropTemporarySettings();
  }
}
项目:intellij-ce-playground    文件:JavaScratchConfigurationProducer.java   
@Override
protected boolean setupConfigurationFromContext(JavaScratchConfiguration configuration, ConfigurationContext context, Ref<PsiElement> sourceElement) {
  final Location location = context.getLocation();
  if (location != null) {
    final VirtualFile vFile = location.getVirtualFile();
    if (vFile instanceof VirtualFileWithId && vFile.getFileType() == ScratchFileType.INSTANCE) {
      final PsiFile psiFile = location.getPsiElement().getContainingFile();
      if (psiFile != null && psiFile.getLanguage() == JavaLanguage.INSTANCE) {
        configuration.SCRATCH_FILE_ID = ((VirtualFileWithId)vFile).getId();
        return super.setupConfigurationFromContext(configuration, context, sourceElement);
      }
    }
  }
  return false;
}
项目:intellij-ce-playground    文件:SmartCompletionDecorator.java   
private static void replaceMethodCallIfNeeded(InsertionContext context) {
  PsiFile file = context.getFile();
  PsiElement element = file.findElementAt(context.getTailOffset());
  if (element instanceof PsiWhiteSpace &&
      (!element.textContains('\n') ||
       CodeStyleSettingsManager.getSettings(file.getProject()).getCommonSettings(JavaLanguage.INSTANCE).METHOD_PARAMETERS_LPAREN_ON_NEXT_LINE
      )) {
    element = file.findElementAt(element.getTextRange().getEndOffset());
  }
  if (element != null && PsiUtilCore.getElementType(element) == JavaTokenType.LPARENTH && element.getParent() instanceof PsiExpressionList) {
    context.getDocument().deleteString(context.getTailOffset(), element.getParent().getTextRange().getEndOffset());
  }
}
项目:intellij-ce-playground    文件:AntLikePropertySelectionHandler.java   
@Override
public boolean canSelect(PsiElement e) {
  Language l = e.getLanguage();
  if (!(l.equals(JavaLanguage.INSTANCE)
        || l.equals(StdLanguages.XML)
        || l.equals(StdLanguages.ANT))) {
    return false;
  }

  return PsiTreeUtil.getParentOfType(e, PsiComment.class) == null;
}
项目:intellij-ce-playground    文件:InvertIfConditionTest.java   
@Override
protected void beforeActionStarted(final String testName, final String contents) {
  super.beforeActionStarted(testName, contents);
  final CommonCodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject()).getCommonSettings(JavaLanguage.INSTANCE);
  myElseOnNewLine = settings.ELSE_ON_NEW_LINE;
  settings.ELSE_ON_NEW_LINE = !contents.contains("else on the same line");
}
项目:intellij-ce-playground    文件:JavaCodeContextType.java   
@Override
public boolean isInContext(@NotNull final PsiFile file, final int offset) {
  if (PsiUtilCore.getLanguageAtOffset(file, offset).isKindOf(JavaLanguage.INSTANCE)) {
    PsiElement element = file.findElementAt(offset);
    if (element instanceof PsiWhiteSpace) {
      return false;
    }
    return element != null && isInContext(element);
  }

  return false;
}
项目:intellij-ce-playground    文件:JavaParsingTestCase.java   
@Override
protected void setUp() throws Exception {
  super.setUp();
  myLanguageLevel = LanguageLevel.JDK_1_6;
  getProject().registerService(LanguageLevelProjectExtension.class, new LanguageLevelProjectExtensionImpl(getProject()));
  addExplicitExtension(LanguageASTFactory.INSTANCE, JavaLanguage.INSTANCE, new JavaASTFactory());
}
项目:intellij-ce-playground    文件:JoinDeclarationAndAssignmentAction.java   
@Override
public boolean isAvailable(@NotNull Project project, Editor editor, @NotNull PsiElement element) {

  if (element instanceof PsiCompiledElement) return false;
  if (!element.getManager().isInProject(element)) return false;
  if (!element.getLanguage().isKindOf(JavaLanguage.INSTANCE)) return false;

  if (getPair(element) != null) {
    setText(CodeInsightBundle.message("intention.join.declaration.text"));
    return true;
  }
  return false;
}
项目:intellij-ce-playground    文件:CreateFieldFromParameterAction.java   
@Override
protected boolean isAvailable(PsiParameter psiParameter) {
  final PsiType type = getSubstitutedType(psiParameter);
  final PsiClass targetClass = PsiTreeUtil.getParentOfType(psiParameter, PsiClass.class);
  return FieldFromParameterUtils.isAvailable(psiParameter, type, targetClass) &&
         psiParameter.getLanguage().isKindOf(JavaLanguage.INSTANCE);
}