本文整理汇总了Java中com.intellij.lang.java.JavaLanguage类的典型用法代码示例。如果您正苦于以下问题:Java JavaLanguage类的具体用法?Java JavaLanguage怎么用?Java JavaLanguage使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JavaLanguage类属于com.intellij.lang.java包,在下文中一共展示了JavaLanguage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getDocumentationElementForLookupItem
import com.intellij.lang.java.JavaLanguage; //导入依赖的package包/类
@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);
}
示例2: findMatchingElement
import com.intellij.lang.java.JavaLanguage; //导入依赖的package包/类
@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;
}
示例3: moveClass
import com.intellij.lang.java.JavaLanguage; //导入依赖的package包/类
@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);
}
示例4: collectRefsToInvert
import com.intellij.lang.java.JavaLanguage; //导入依赖的package包/类
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);
}
}
}
示例5: testReturnTagAlignment
import com.intellij.lang.java.JavaLanguage; //导入依赖的package包/类
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);
}
示例6: testDummyDeprecatedTagAlignment
import com.intellij.lang.java.JavaLanguage; //导入依赖的package包/类
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);
}
示例7: validate
import com.intellij.lang.java.JavaLanguage; //导入依赖的package包/类
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);
}
示例8: getIndentSpecial
import com.intellij.lang.java.JavaLanguage; //导入依赖的package包/类
/**
* 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;
}
示例9: getContainer
import com.intellij.lang.java.JavaLanguage; //导入依赖的package包/类
@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;
}
示例10: createNotificationPanel
import com.intellij.lang.java.JavaLanguage; //导入依赖的package包/类
@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);
}
示例11: doProcess
import com.intellij.lang.java.JavaLanguage; //导入依赖的package包/类
@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);
}
示例12: testUnwrapCodeBlock1
import com.intellij.lang.java.JavaLanguage; //导入依赖的package包/类
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;
}
}
示例13: isAvailable
import com.intellij.lang.java.JavaLanguage; //导入依赖的package包/类
@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;
}
示例14: autoImportReferenceAt
import com.intellij.lang.java.JavaLanguage; //导入依赖的package包/类
@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;
}
示例15: isAvailable
import com.intellij.lang.java.JavaLanguage; //导入依赖的package包/类
@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;
}