本文整理汇总了Java中com.intellij.psi.PsiNewExpression类的典型用法代码示例。如果您正苦于以下问题:Java PsiNewExpression类的具体用法?Java PsiNewExpression怎么用?Java PsiNewExpression使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PsiNewExpression类属于com.intellij.psi包,在下文中一共展示了PsiNewExpression类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: isBuildingChildScope
import com.intellij.psi.PsiNewExpression; //导入依赖的package包/类
private PsiElement isBuildingChildScope(PsiMethodCallExpression call) {
try {
// Dot
PsiElement nextSibling = call.getNextSibling();
// Parenthesis
nextSibling = nextSibling.getNextSibling();
// Chained method name
nextSibling = nextSibling.getParent();
// Chained method
PsiElement chainedMethod = nextSibling.getParent();
if (chainedMethod instanceof PsiMethodCallExpression) {
PsiExpressionList list = ((PsiMethodCallExpression) chainedMethod).getArgumentList();
// If chained method is taking an argument that returns an instance of something
// (such as a new Module), it is probably safe to assume that the user is building a
// child scope
if (list.getFirstChild() != null
&& list.getFirstChild().getNextSibling() instanceof PsiNewExpression) {
return chainedMethod;
}
}
} catch (Exception e) {
// A for effort
}
return null;
}
开发者ID:bgogetap,项目名称:Scoper,代码行数:26,代码来源:IncorrectChildScopeBuilding.java
示例2: apply
import com.intellij.psi.PsiNewExpression; //导入依赖的package包/类
@Override
public void apply(Editor editor, JavaSmartEnterProcessor processor, PsiElement psiElement) throws IncorrectOperationException {
if (!(psiElement instanceof PsiNewExpression)) return;
PsiNewExpression expr = (PsiNewExpression)psiElement;
int count = 0;
for (PsiElement element : expr.getChildren()) {
if (element.getNode().getElementType() == JavaTokenType.LBRACKET) {
count++;
} else if (element.getNode().getElementType() == JavaTokenType.RBRACKET) {
count--;
}
}
if (count > 0) {
editor.getDocument().insertString(psiElement.getTextRange().getEndOffset(), "]");
}
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:MissingArrayConstructorBracketFixer.java
示例3: visitArrayInitializerExpression
import com.intellij.psi.PsiNewExpression; //导入依赖的package包/类
@Override
public void visitArrayInitializerExpression(
PsiArrayInitializerExpression expression) {
super.visitArrayInitializerExpression(expression);
final PsiExpression[] initializers = expression.getInitializers();
if (initializers.length > 0) {
return;
}
if (expression.getParent() instanceof PsiNewExpression) {
return;
}
if (ExpressionUtils.isDeclaredConstant(expression)) {
return;
}
registerError(expression);
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:ZeroLengthArrayInitializationInspectionBase.java
示例4: isResourceCreation
import com.intellij.psi.PsiNewExpression; //导入依赖的package包/类
@Override
protected boolean isResourceCreation(PsiExpression expression) {
if (expression instanceof PsiMethodCallExpression) {
final PsiMethodCallExpression methodCallExpression = (PsiMethodCallExpression)expression;
final PsiReferenceExpression methodExpression = methodCallExpression.getMethodExpression();
@NonNls final String methodName = methodExpression.getReferenceName();
if (!"accept".equals(methodName)) {
return false;
}
final PsiExpression qualifier = methodExpression.getQualifierExpression();
if (qualifier == null || !TypeUtils.expressionHasTypeOrSubtype(qualifier, "java.net.ServerSocket")) {
return false;
}
return TypeUtils.expressionHasTypeOrSubtype(methodCallExpression, "java.net.Socket");
}
else if (expression instanceof PsiNewExpression) {
return TypeUtils.expressionHasTypeOrSubtype(expression, "java.net.Socket", "java.net.DatagramSocket", "java.net.ServerSocket") != null;
}
return false;
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:SocketResourceInspection.java
示例5: visitExpressionStatement
import com.intellij.psi.PsiNewExpression; //导入依赖的package包/类
@Override
public void visitExpressionStatement(@NotNull PsiExpressionStatement statement) {
super.visitExpressionStatement(statement);
final PsiExpression expression = statement.getExpression();
if (!(expression instanceof PsiNewExpression)) {
return;
}
final PsiNewExpression newExpression = (PsiNewExpression)expression;
final PsiExpression[] arrayDimensions = newExpression.getArrayDimensions();
if (arrayDimensions.length != 0) {
return;
}
if (newExpression.getArrayInitializer() != null) {
return;
}
registerNewExpressionError(newExpression);
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:ResultOfObjectAllocationIgnoredInspection.java
示例6: visitNewExpression
import com.intellij.psi.PsiNewExpression; //导入依赖的package包/类
@Override
public void visitNewExpression(@NotNull PsiNewExpression expression) {
super.visitNewExpression(expression);
if (!ExpressionUtils.hasType(expression, "java.text.SimpleDateFormat")) {
return;
}
final PsiExpressionList argumentList = expression.getArgumentList();
if (argumentList == null) {
return;
}
final PsiExpression[] arguments = argumentList.getExpressions();
for (PsiExpression argument : arguments) {
if (ExpressionUtils.hasType(argument, "java.util.Locale")) {
return;
}
}
registerNewExpressionError(expression);
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:SimpleDateFormatWithoutLocaleInspection.java
示例7: visitNewExpression
import com.intellij.psi.PsiNewExpression; //导入依赖的package包/类
@Override
public void visitNewExpression(@NotNull PsiNewExpression expression) {
super.visitNewExpression(expression);
final PsiType type = expression.getType();
if (type == null) {
return;
}
if (!CollectionUtils.isCollectionWithInitialCapacity(type)) {
return;
}
final PsiExpressionList argumentList = expression.getArgumentList();
if (argumentList == null) {
return;
}
final PsiExpression[] parameters = argumentList.getExpressions();
if (parameters.length != 0) {
return;
}
registerError(expression);
}
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:22,代码来源:CollectionsMustHaveInitialCapacityInspection.java
示例8: visitNewExpression
import com.intellij.psi.PsiNewExpression; //导入依赖的package包/类
@Override
public void visitNewExpression(@NotNull PsiNewExpression expression) {
super.visitNewExpression(expression);
if (!ExpressionUtils.hasType(expression, "java.text.SimpleDateFormat")) {
return;
}
final PsiExpressionList argumentList = expression.getArgumentList();
if (argumentList == null) {
return;
}
final PsiExpression[] arguments = argumentList.getExpressions();
for (PsiExpression argument : arguments) {
if (ExpressionUtils.hasType(argument, "java.util.Locale")) {
return;
}
}
registerError(expression);
}
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:19,代码来源:SimpleDateFormatWithoutLocaleInspection.java
示例9: isUnusedInAnonymousClass
import com.intellij.psi.PsiNewExpression; //导入依赖的package包/类
private static boolean isUnusedInAnonymousClass(@NotNull PsiMethod method)
{
PsiClass containingClass = method.getContainingClass();
if(!(containingClass instanceof PsiAnonymousClass))
{
return false;
}
if(containingClass.getParent() instanceof PsiNewExpression && containingClass.getParent().getParent() instanceof PsiVariable && !method.getHierarchicalMethodSignature().getSuperSignatures()
.isEmpty())
{
// references outside anonymous class can still resolve to this method, see com.intellij.psi.scope.util.PsiScopesUtil.setupAndRunProcessor()
return false;
}
return MethodReferencesSearch.search(method, new LocalSearchScope(containingClass), false).findFirst() == null;
}
开发者ID:consulo,项目名称:consulo-java,代码行数:18,代码来源:InferenceFromSourceUtil.java
示例10: visitArrayInitializerExpression
import com.intellij.psi.PsiNewExpression; //导入依赖的package包/类
@Override
public void visitArrayInitializerExpression(PsiArrayInitializerExpression expression)
{
super.visitArrayInitializerExpression(expression);
final PsiExpression[] initializers = expression.getInitializers();
if(initializers.length > 0)
{
return;
}
if(expression.getParent() instanceof PsiNewExpression)
{
return;
}
if(ExpressionUtils.isDeclaredConstant(expression))
{
return;
}
registerError(expression);
}
开发者ID:consulo,项目名称:consulo-java,代码行数:20,代码来源:ZeroLengthArrayInitializationInspectionBase.java
示例11: visitNewExpression
import com.intellij.psi.PsiNewExpression; //导入依赖的package包/类
@Override
public void visitNewExpression(@NotNull PsiNewExpression newExpression) {
if (passed) {
return;
}
super.visitNewExpression(newExpression);
final PsiExpressionList argumentList = newExpression.getArgumentList();
if (argumentList == null) {
return;
}
final PsiExpression[] arguments = argumentList.getExpressions();
for (PsiExpression argument : arguments) {
if (VariableAccessUtils.mayEvaluateToVariable(argument, variable)) {
passed = true;
break;
}
}
}
开发者ID:consulo,项目名称:consulo-java,代码行数:19,代码来源:VariablePassedAsArgumentVisitor.java
示例12: apply
import com.intellij.psi.PsiNewExpression; //导入依赖的package包/类
@Override
public void apply(Editor editor, JavaSmartEnterProcessor processor, PsiElement psiElement) throws IncorrectOperationException
{
if(!(psiElement instanceof PsiNewExpression))
{
return;
}
PsiNewExpression expr = (PsiNewExpression) psiElement;
int count = 0;
for(PsiElement element : expr.getChildren())
{
if(element.getNode().getElementType() == JavaTokenType.LBRACKET)
{
count++;
}
else if(element.getNode().getElementType() == JavaTokenType.RBRACKET)
{
count--;
}
}
if(count > 0)
{
editor.getDocument().insertString(psiElement.getTextRange().getEndOffset(), "]");
}
}
开发者ID:consulo,项目名称:consulo-java,代码行数:26,代码来源:MissingArrayConstructorBracketFixer.java
示例13: visitNewExpression
import com.intellij.psi.PsiNewExpression; //导入依赖的package包/类
@Override
public void visitNewExpression(@NotNull PsiNewExpression expression)
{
super.visitNewExpression(expression);
if(myIgnoreFields && expression.getParent() instanceof PsiField)
{
return;
}
final PsiType type = expression.getType();
if(!isCollectionWithInitialCapacity(type))
{
return;
}
final PsiExpressionList argumentList = expression.getArgumentList();
if(argumentList == null || argumentList.getExpressions().length != 0)
{
return;
}
registerNewExpressionError(expression);
}
开发者ID:consulo,项目名称:consulo-java,代码行数:22,代码来源:CollectionsMustHaveInitialCapacityInspection.java
示例14: visitNewExpression
import com.intellij.psi.PsiNewExpression; //导入依赖的package包/类
@Override
public void visitNewExpression(PsiNewExpression expression) {
super.visitNewExpression(expression);
PsiMethod constructor = expression.resolveConstructor();
if (constructor == null) return;
JavaEvaluator evaluator = mContext.getEvaluator();
PsiClass cls = constructor.getContainingClass();
boolean isView = evaluator.extendsClass(cls, CLASS_VIEW, true);
if (!isView) return;
Location location = this.mContext.getLocation(expression);
PsiElement psiElement = expression.getParent();
//创建的变量没有赋值给本地变量,无法指定注解
if (!(psiElement instanceof PsiLocalVariable)) {
this.mContext.report(DynamicNewViewDetector.ISSUE, expression, location, "检测到动态创建view操作,new 操作的结果需要赋值给本地变量");
return;
}
PsiLocalVariable localVariable = (PsiLocalVariable) psiElement;
PsiModifierList modifierList = localVariable.getModifierList();
if (modifierList == null) {
this.mContext.report(DynamicNewViewDetector.ISSUE, expression, location, "检测到动态创建view操作,确认是否为view指定了唯一标识");
return;
}
PsiAnnotation[] annotations = modifierList.getAnnotations();
for (PsiAnnotation annotation : annotations) {
String fullName = annotation.getQualifiedName();
if (IDENTIFIER_ANNOTATION.equals(fullName)) {
return;
}
}
this.mContext.report(DynamicNewViewDetector.ISSUE, expression, location, "检测到动态创建view操作,确认是否为view指定了唯一标识");
}
开发者ID:jessie345,项目名称:CustomLintRules,代码行数:40,代码来源:DynamicNewViewDetector.java
示例15: isApplicableTo
import com.intellij.psi.PsiNewExpression; //导入依赖的package包/类
@Override
public boolean isApplicableTo(PsiElement e) {
if (e instanceof PsiArrayInitializerExpression) {
final PsiElement gParent = e.getParent();
if (gParent instanceof PsiNewExpression && gParent.getParent() instanceof PsiVariable) {
return true;
}
}
return false;
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:12,代码来源:JavaArrayInitializerUnwrapper.java
示例16: isAvailableOnElementInEditorAndFile
import com.intellij.psi.PsiNewExpression; //导入依赖的package包/类
protected boolean isAvailableOnElementInEditorAndFile(@NotNull final PsiElement element, @NotNull final Editor editor, @NotNull PsiFile file, @NotNull DataContext context) {
final PsiElement targetElement = file.findElementAt(editor.getCaretModel().getOffset());
if (PsiTreeUtil.getParentOfType(targetElement, PsiAnonymousClass.class) != null) {
return true;
}
if (PsiTreeUtil.getParentOfType(element, PsiAnonymousClass.class) != null) {
return true;
}
final PsiNewExpression newExpression = PsiTreeUtil.getParentOfType(element, PsiNewExpression.class);
return newExpression != null && newExpression.getAnonymousClass() != null;
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:12,代码来源:AnonymousToInnerAction.java
示例17: getQualifier
import com.intellij.psi.PsiNewExpression; //导入依赖的package包/类
PsiExpression getQualifier () {
PsiElement element = getElement();
if (element instanceof PsiReferenceExpression) {
return ((PsiReferenceExpression)element).getQualifierExpression();
}
else if (element instanceof PsiNewExpression) return ((PsiNewExpression)element).getQualifier();
return null;
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:10,代码来源:InternalUsageInfo.java
示例18: visitNewExpression
import com.intellij.psi.PsiNewExpression; //导入依赖的package包/类
@Override
public void visitNewExpression(@NotNull PsiNewExpression expression) {
super.visitNewExpression(expression);
if (!TypeUtils.expressionHasTypeOrSubtype(expression,
"java.lang.ClassLoader")) {
return;
}
registerNewExpressionError(expression);
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:10,代码来源:ClassLoaderInstantiationInspection.java
示例19: visitNewExpression
import com.intellij.psi.PsiNewExpression; //导入依赖的package包/类
@Override
public void visitNewExpression(
@NotNull PsiNewExpression expression) {
super.visitNewExpression(expression);
if (!ExpressionUtils.isZeroLengthArrayConstruction(expression)) {
return;
}
if (ExpressionUtils.isDeclaredConstant(expression)) {
return;
}
registerError(expression);
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:13,代码来源:ZeroLengthArrayInitializationInspectionBase.java
示例20: visitNewExpression
import com.intellij.psi.PsiNewExpression; //导入依赖的package包/类
@Override
public void visitNewExpression(
@NotNull PsiNewExpression newExpression) {
super.visitNewExpression(newExpression);
final PsiType type = newExpression.getType();
if (type == null) {
return;
}
@NonNls final String typeString = type.getCanonicalText();
if (!"java.lang.ProcessBuilder".equals(typeString)) {
return;
}
registerNewExpressionError(newExpression);
}
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:15,代码来源:UseOfProcessBuilderInspection.java
注:本文中的com.intellij.psi.PsiNewExpression类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论