Java 类com.intellij.psi.CommonClassNames 实例源码

项目:intellij-ce-playground    文件:ConvertGStringToStringIntention.java   
private static String prepareExpression(GrExpression expr) {
  if (PsiUtil.isThisOrSuperRef(expr)) return expr.getText();
  String text = expr.getText();

  final PsiType type = expr.getType();
  if (type != null && CommonClassNames.JAVA_LANG_STRING.equals(type.getCanonicalText())) {
    if (expr instanceof GrBinaryExpression && GroovyTokenTypes.mPLUS.equals(((GrBinaryExpression)expr).getOperationTokenType())) {
      return '(' + text + ')';
    }
    else {
      return text;
    }
  }
  else {
    return "String.valueOf(" + text + ")";
  }
}
项目:intellij-ce-playground    文件:ClassRenderer.java   
@Nullable
public static String getEnumConstantName(@NotNull ObjectReference objRef, ClassType classType) {
  do {
    if (!classType.isPrepared()) {
      return null;
    }
    classType = classType.superclass();
    if (classType == null) {
      return null;
    }
  }
  while (!(CommonClassNames.JAVA_LANG_ENUM.equals(classType.name())));
  //noinspection HardCodedStringLiteral
  final Field field = classType.fieldByName("name");
  if (field == null) {
    return null;
  }
  final Value value = objRef.getValue(field);
  if (!(value instanceof StringReference)) {
    return null;
  }
  return ((StringReference)value).value();
}
项目:intellij-ce-playground    文件:GroovyWaitCallNotInLoopInspection.java   
@Override
public void visitMethodCallExpression(GrMethodCallExpression grMethodCallExpression) {
  super.visitMethodCallExpression(grMethodCallExpression);
  final GrExpression methodExpression = grMethodCallExpression.getInvokedExpression();
  if (!(methodExpression instanceof GrReferenceExpression)) {
    return;
  }
  final GrReferenceExpression reference = (GrReferenceExpression) methodExpression;
  final String name = reference.getReferenceName();
  if (!"wait".equals(name)) {
    return;
  }
  final PsiMethod method = grMethodCallExpression.resolveMethod();
  if (method == null) {
    return;
  }
  final PsiClass containingClass = method.getContainingClass();
  if (containingClass == null || !CommonClassNames.JAVA_LANG_OBJECT.equals(containingClass.getQualifiedName())) {
    return;
  }
  if (ControlFlowUtils.isInLoop(grMethodCallExpression)) {
    return;
  }
  registerMethodCallError(grMethodCallExpression);
}
项目:intellij-ce-playground    文件:NonFinalFieldOfExceptionInspection.java   
@Override
public void visitField(PsiField field) {
  super.visitField(field);
  if (field.hasModifierProperty(PsiModifier.FINAL)) {
    return;
  }
  final PsiClass containingClass = field.getContainingClass();
  if (containingClass == null) {
    return;
  }
  if (!InheritanceUtil.isInheritor(containingClass,
                                   CommonClassNames.JAVA_LANG_EXCEPTION)) {
    return;
  }
  registerFieldError(field, field);
}
项目:intellij-ce-playground    文件:ConvertInterfaceToClassPredicate.java   
public boolean satisfiedBy(PsiElement element) {
  final PsiElement parent = element.getParent();
  if (!(parent instanceof PsiClass)) {
    return false;
  }
  final PsiClass aClass = (PsiClass)parent;
  if (!aClass.isInterface() || aClass.isAnnotationType()) {
    return false;
  }
  final PsiElement leftBrace = aClass.getLBrace();
  final int offsetInParent = element.getStartOffsetInParent();
  if (leftBrace == null ||
      offsetInParent >= leftBrace.getStartOffsetInParent()) {
    return false;
  }
  final SearchScope useScope = aClass.getUseScope();
  for (PsiClass inheritor :
    ClassInheritorsSearch.search(aClass, useScope, true)) {
    if (inheritor.isInterface()) {
      return false;
    }
  }
  return !AnnotationUtil.isAnnotated(aClass, CommonClassNames.JAVA_LANG_FUNCTIONAL_INTERFACE, false, true);
}
项目:intellij-ce-playground    文件:GrTupleType.java   
@Override
public boolean isAssignableFrom(@NotNull PsiType type) {
  if (type instanceof GrTupleType) {
    PsiType[] otherComponents = ((GrTupleType)type).getComponentTypes();
    PsiType[] componentTypes = getComponentTypes();
    for (int i = 0; i < Math.min(componentTypes.length, otherComponents.length); i++) {
      PsiType componentType = componentTypes[i];
      PsiType otherComponent = otherComponents[i];
      if (otherComponent == null) {
        if (componentType != null && !TypesUtil.isClassType(componentType, CommonClassNames.JAVA_LANG_OBJECT)) return false;
      }
      else if (componentType != null && !componentType.isAssignableFrom(otherComponent)) return false;
    }
    return true;
  }

  return super.isAssignableFrom(type);
}
项目:intellij-ce-playground    文件:DPropertyElement.java   
@Override
@NotNull
public PsiVariable getPsi(PsiManager manager, final String containingClassName) {
  if (myPsi != null) return myPsi;

  Boolean isStatic = isStatic();

  String type = getType();
  if (type == null || type.trim().isEmpty()) {
    type = CommonClassNames.JAVA_LANG_OBJECT;
  }
  myPsi = new GrDynamicImplicitProperty(manager, getName(), type, containingClassName);

  if (isStatic != null && isStatic.booleanValue()) {
    myPsi.getModifierList().addModifier(PsiModifier.STATIC);
  }

  return myPsi;
}
项目:intellij-ce-playground    文件:GroovyConditionalCanBeElvisInspection.java   
private static boolean checkForListIsEmpty(GrExpression condition, GrExpression elseBranch) {
  if (condition instanceof GrMethodCall) condition = ((GrMethodCall)condition).getInvokedExpression();
  if (!(condition instanceof GrReferenceExpression)) return false;

  final GrExpression qualifier = ((GrReferenceExpression)condition).getQualifier();
  if (qualifier == null) return false;

  if (!PsiEquivalenceUtil.areElementsEquivalent(qualifier, elseBranch)) return false;

  final PsiType type = qualifier.getType();
  if (type == null) return false;
  if (!InheritanceUtil.isInheritor(type, CommonClassNames.JAVA_UTIL_LIST)) return false;

  final PsiElement resolved = ((GrReferenceExpression)condition).resolve();

  return resolved instanceof PsiMethod &&
         "isEmpty".equals(((PsiMethod)resolved).getName()) &&
         ((PsiMethod)resolved).getParameterList().getParametersCount() == 0;
}
项目:intellij-ce-playground    文件:AndroidSdkResolveScopeProvider.java   
@Override
public int compare(@NotNull VirtualFile file1, @NotNull VirtualFile file2) {
  final boolean inSources1 = myIndex.isInLibrarySource(file1);

  if (inSources1 != myIndex.isInLibrarySource(file2)) {
    //Consider class A implements Runnable in project source.
    //Super class Object for class A is found in cls, super interface Runnable is found in cls as well (class A resolve scope is simple modules scope with dependencies).
    //Super class of cls Runnable isn't explicitly specified in the cls psi, so PsiClassImplUtil.getSuperClass/getSuperTypes return java.lang.Object
    //found via file's resolve scope (this one). So for the two hierarchies to meet in one place we should return cls Object here.
    //By default this resolve scope prefers sdk sources, so we need to override this behavior for Object.

    //The problem doesn't arise for other super class references inside Android sdk cls (e.g. A extends B implements C, where B implements C and both are inside android sdk),
    //because these references (C) are explicit and resolved via ClsJavaCodeReferenceElementImpl#resolveClassPreferringMyJar which returns cls classes despite custom Android sdk scope.
    if (!CommonClassNames.JAVA_LANG_OBJECT_SHORT.equals(file1.getNameWithoutExtension())) {
      return inSources1 ? 1 : -1;
    }
  }
  return super.compare(file1, file2);
}
项目:intellij-ce-playground    文件:AbstractClassExtendsConcreteClassInspection.java   
@Override
public void visitClass(@NotNull PsiClass aClass) {
  // no call to super, so that it doesn't drill down to inner classes
  if (aClass.isInterface() || aClass.isAnnotationType()) {
    return;
  }
  if (!aClass.hasModifierProperty(PsiModifier.ABSTRACT)) {
    return;
  }
  final PsiClass superClass = aClass.getSuperClass();
  if (superClass == null) {
    return;
  }
  if (superClass.hasModifierProperty(PsiModifier.ABSTRACT)) {
    return;
  }
  final String superclassName = superClass.getQualifiedName();
  if (CommonClassNames.JAVA_LANG_OBJECT.equals(superclassName)) {
    return;
  }
  registerClassError(aClass);
}
项目:intellij-ce-playground    文件:ExceptionNameDoesntEndWithExceptionInspectionBase.java   
@Override
public void visitClass(@NotNull PsiClass aClass) {
  // no call to super, so it doesn't drill down into inner classes
  if (aClass instanceof PsiTypeParameter) {
    return;
  }
  final String className = aClass.getName();
  if (className == null) {
    return;
  }
  @NonNls final String exception = "Exception";
  if (className.endsWith(exception)) {
    return;
  }
  if (!InheritanceUtil.isInheritor(aClass,
                                   CommonClassNames.JAVA_LANG_EXCEPTION)) {
    return;
  }
  registerClassError(aClass);
}
项目:intellij-ce-playground    文件:NonExceptionNameEndsWithExceptionInspectionBase.java   
@Override
public void visitClass(@NotNull PsiClass aClass) {
  // no call to super, so it doesn't drill down into inner classes
  final String className = aClass.getName();
  if (className == null) {
    return;
  }
  @NonNls final String exception = "Exception";
  if (!className.endsWith(exception)) {
    return;
  }
  if (InheritanceUtil.isInheritor(aClass,
                                  CommonClassNames.JAVA_LANG_EXCEPTION)) {
    return;
  }
  registerClassError(aClass, className,
                     Boolean.valueOf(isOnTheFly()));
}
项目:intellij-ce-playground    文件:GroovyPatterns.java   
public static GroovyElementPattern.Capture<GrArgumentLabel> namedArgumentLabel(@Nullable final ElementPattern<? extends String> namePattern) {
  return new GroovyElementPattern.Capture<GrArgumentLabel>(new InitialPatternCondition<GrArgumentLabel>(GrArgumentLabel.class) {
    @Override
    public boolean accepts(@Nullable final Object o, final ProcessingContext context) {
      if (o instanceof GrArgumentLabel) {
        PsiElement nameElement = ((GrArgumentLabel)o).getNameElement();
        if (nameElement instanceof LeafPsiElement) {
          IElementType elementType = ((LeafPsiElement)nameElement).getElementType();
          if (elementType == GroovyTokenTypes.mIDENT ||
              CommonClassNames.JAVA_LANG_STRING.equals(TypesUtil.getBoxedTypeName(elementType))) {
            return namePattern == null || namePattern.accepts(((GrArgumentLabel)o).getName());
          }
        }
      }

      return false;
    }
  });
}
项目:intellij-ce-playground    文件:GroovyConditionalCanBeElvisInspection.java   
/**
 * checks for the case string.isEmpty() ? something_else : string
 */
private static boolean checkForStringIsEmpty(GrExpression condition, GrExpression elseBranch) {
  if (condition instanceof GrMethodCall) condition = ((GrMethodCall)condition).getInvokedExpression();
  if (!(condition instanceof GrReferenceExpression)) return false;

  final GrExpression qualifier = ((GrReferenceExpression)condition).getQualifier();
  if (qualifier == null) return false;

  if (!PsiEquivalenceUtil.areElementsEquivalent(qualifier, elseBranch)) return false;

  final PsiType type = qualifier.getType();
  if (type == null) return false;
  if (!type.equalsToText(CommonClassNames.JAVA_LANG_STRING)) return false;

  final PsiElement resolved = ((GrReferenceExpression)condition).resolve();

  return resolved instanceof PsiMethod &&
         "isEmpty".equals(((PsiMethod)resolved).getName()) &&
         ((PsiMethod)resolved).getParameterList().getParametersCount() == 0;
}
项目:intellij-ce-playground    文件:DateToStringInspection.java   
@Override
public void visitMethodCallExpression(
  @NotNull PsiMethodCallExpression expression) {
  super.visitMethodCallExpression(expression);
  final String methodName = MethodCallUtils.getMethodName(expression);
  if (!HardcodedMethodConstants.TO_STRING.equals(methodName)) {
    return;
  }
  final PsiType targetType = MethodCallUtils.getTargetType(expression);
  if (!TypeUtils.typeEquals(CommonClassNames.JAVA_UTIL_DATE,
                            targetType)) {
    return;
  }
  final PsiExpressionList argumentList = expression.getArgumentList();
  if (argumentList.getExpressions().length != 0) {
    return;
  }
  if (NonNlsUtils.isNonNlsAnnotatedUse(expression)) {
    return;
  }
  registerMethodCallError(expression);
}
项目:intellij-ce-playground    文件:SignatureParsing.java   
private static PsiTypeParameterStub parseTypeParameter(CharacterIterator iterator, PsiTypeParameterListStub parent) throws ClsFormatException {
  StringBuilder name = new StringBuilder();
  while (iterator.current() != ':' && iterator.current() != CharacterIterator.DONE) {
    name.append(iterator.current());
    iterator.next();
  }
  if (iterator.current() == CharacterIterator.DONE) {
    throw new ClsFormatException();
  }

  //todo parse annotations on type param
  PsiTypeParameterStub parameterStub = new PsiTypeParameterStubImpl(parent, StringRef.fromString(name.toString()));

  // postpone list allocation till a second bound is seen; ignore sole Object bound
  List<String> bounds = null;
  boolean jlo = false;
  while (iterator.current() == ':') {
    iterator.next();
    String bound = parseTopLevelClassRefSignature(iterator);
    if (bound == null) continue;
    if (bounds == null) {
      if (CommonClassNames.JAVA_LANG_OBJECT.equals(bound)) {
        jlo = true;
        continue;
      }
      bounds = ContainerUtil.newSmartList();
      if (jlo) {
        bounds.add(CommonClassNames.JAVA_LANG_OBJECT);
      }
    }
    bounds.add(bound);
  }

  StubBuildingVisitor.newReferenceList(JavaStubElementTypes.EXTENDS_BOUND_LIST, parameterStub, ArrayUtil.toStringArray(bounds));

  return parameterStub;
}
项目:intellij-ce-playground    文件:BoxingEvaluator.java   
public Object evaluate(EvaluationContextImpl context) throws EvaluateException {
  final Object result = myOperand.evaluate(context);
  if (result == null || result instanceof ObjectReference) {
    return result;
  }

  if (result instanceof BooleanValue) {
    return convertToWrapper(context, (BooleanValue)result, CommonClassNames.JAVA_LANG_BOOLEAN);
  }
  if (result instanceof ByteValue) {
    return convertToWrapper(context, (ByteValue)result, CommonClassNames.JAVA_LANG_BYTE);
  }
  if (result instanceof CharValue) {
    return convertToWrapper(context, (CharValue)result, CommonClassNames.JAVA_LANG_CHARACTER);
  }
  if (result instanceof ShortValue) {
    return convertToWrapper(context, (ShortValue)result, CommonClassNames.JAVA_LANG_SHORT);
  }
  if (result instanceof IntegerValue) {
    return convertToWrapper(context, (IntegerValue)result, CommonClassNames.JAVA_LANG_INTEGER);
  }
  if (result instanceof LongValue) {
    return convertToWrapper(context, (LongValue)result, CommonClassNames.JAVA_LANG_LONG);
  }
  if (result instanceof FloatValue) {
    return convertToWrapper(context, (FloatValue)result, CommonClassNames.JAVA_LANG_FLOAT);
  }
  if (result instanceof DoubleValue) {
    return convertToWrapper(context, (DoubleValue)result, CommonClassNames.JAVA_LANG_DOUBLE);
  }
  throw new EvaluateException("Cannot perform boxing conversion for a value of type " + ((Value)result).type().name());
}
项目:intellij-ce-playground    文件:ToStringRenderer.java   
@SuppressWarnings({"HardCodedStringLiteral"})
private static boolean overridesToString(Type type) {
  if(type instanceof ClassType) {
    final List<Method> methods = ((ClassType)type).methodsByName("toString", "()Ljava/lang/String;");
    for (Method method : methods) {
      if (!(method.declaringType().name()).equals(CommonClassNames.JAVA_LANG_OBJECT)) {
        return true;
      }
    }
  }
  return false;
}
项目:intellij-ce-playground    文件:UncheckedExceptionClassInspection.java   
@Override
public void visitClass(@NotNull PsiClass aClass) {
  if (!InheritanceUtil.isInheritor(aClass, CommonClassNames.JAVA_LANG_RUNTIME_EXCEPTION)) {
    return;
  }
  registerClassError(aClass);
}
项目:intellij-ce-playground    文件:NodeRendererSettings.java   
public Renderer createRenderer(final String rendererId) {
  if (ClassRenderer.UNIQUE_ID.equals(rendererId)) {
    return myClassRenderer;
  }
  else if (ArrayRenderer.UNIQUE_ID.equals(rendererId)) {
    return myArrayRenderer;
  }
  else if (PrimitiveRenderer.UNIQUE_ID.equals(rendererId)) {
    return myPrimitiveRenderer;
  }
  else if(HexRenderer.UNIQUE_ID.equals(rendererId)) {
    return myHexRenderer;
  }
  else if(rendererId.equals(ExpressionChildrenRenderer.UNIQUE_ID)) {
    return new ExpressionChildrenRenderer();
  }
  else if(rendererId.equals(LabelRenderer.UNIQUE_ID)) {
    return new LabelRenderer();
  }
  else if(rendererId.equals(EnumerationChildrenRenderer.UNIQUE_ID)) {
    return new EnumerationChildrenRenderer();
  }
  else if(rendererId.equals(ToStringRenderer.UNIQUE_ID)) {
    return myToStringRenderer;
  }
  else if(rendererId.equals(CompoundNodeRenderer.UNIQUE_ID) || rendererId.equals(REFERENCE_RENDERER)) {
    return createCompoundReferenceRenderer("unnamed", CommonClassNames.JAVA_LANG_OBJECT, null, null);
  }
  return null;
}
项目:intellij-ce-playground    文件:NodeRendererSettings.java   
public ListObjectRenderer(NodeRendererSettings rendererSettings) {
  super(rendererSettings,
        "List",
        createLabelRenderer(" size = ", "size()", null),
        createExpressionChildrenRenderer("toArray()", "!isEmpty()"));
  setClassName(CommonClassNames.JAVA_UTIL_LIST);
}
项目:intellij-ce-playground    文件:FormatPostfixTemplate.java   
@Override
public boolean value(PsiElement expr) {
  if (!(expr instanceof PsiExpression)) {
    return false;
  }
  PsiType type = ((PsiExpression)expr).getType();
  return type != null && CommonClassNames.JAVA_LANG_STRING.equals(type.getCanonicalText());
}
项目:intellij-ce-playground    文件:GroovyMapPutCanBeKeyedAccessInspection.java   
@Override
public void visitMethodCallExpression(GrMethodCallExpression grMethodCallExpression) {
  super.visitMethodCallExpression(grMethodCallExpression);
  final GrArgumentList args = grMethodCallExpression.getArgumentList();
  if (args == null) {
    return;
  }
  if (args.getExpressionArguments().length != 2) {
    return;
  }
  if (PsiImplUtil.hasNamedArguments(args)) {
    return;
  }
  final GrExpression methodExpression = grMethodCallExpression.getInvokedExpression();
  if (!(methodExpression instanceof GrReferenceExpression)) {
    return;
  }
  final GrReferenceExpression referenceExpression = (GrReferenceExpression) methodExpression;
  final String name = referenceExpression.getReferenceName();
  if (!"put".equals(name)) {
    return;
  }
  final GrExpression qualifier = referenceExpression.getQualifierExpression();

  if (qualifier == null || PsiUtil.isThisOrSuperRef(qualifier)) {
    return;
  }
  if (referenceExpression.getDotTokenType() == GroovyTokenTypes.mOPTIONAL_DOT) return;
  final PsiType type = qualifier.getType();
  if (!InheritanceUtil.isInheritor(type, CommonClassNames.JAVA_UTIL_MAP)) {
    return;
  }
  registerMethodCallError(grMethodCallExpression);
}
项目:intellij-ce-playground    文件:FindJarFix.java   
@Override
public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) {
  return myRef.isValid()
         && JavaPsiFacade.getInstance(project).findClass(CommonClassNames.JAVA_LANG_OBJECT, file.getResolveScope()) != null
         && myModule != null
         && isFqnsOk(project, getPossibleFqns(myRef));
}
项目:intellij-ce-playground    文件:ExpectedTypeInfoTest.java   
public void testIntersectStrictStrict2() throws Exception {
  ExpectedTypeInfo info1 = createInfo("java.lang.Exception", ExpectedTypeInfo.TYPE_STRICTLY);
  ExpectedTypeInfo info2 = createInfo(CommonClassNames.JAVA_LANG_OBJECT, ExpectedTypeInfo.TYPE_STRICTLY);

  ExpectedTypeInfo[] result = info1.intersect(info2);
  assertEquals(result.length, 0);
}
项目:intellij-ce-playground    文件:ExpectedTypeInfoTest.java   
public void testIntersectStrictSubtype2() throws Exception {
  ExpectedTypeInfo info1 = createInfo(CommonClassNames.JAVA_LANG_OBJECT, ExpectedTypeInfo.TYPE_STRICTLY);
  ExpectedTypeInfo info2 = createInfo("java.lang.Exception", ExpectedTypeInfo.TYPE_OR_SUBTYPE);

  ExpectedTypeInfo[] result = info1.intersect(info2);
  assertEquals(result.length, 0);
}
项目:intellij-ce-playground    文件:GeneratorClassNameProvider.java   
@Override
public String getQualifiedClassName(PsiClass psiClass, @Nullable PsiElement context) {
  if (context != null && psiClass != null) {
    psiClass = GenerationUtil.findAccessibleSuperClass(context, psiClass);
  }
  if (psiClass == null) {
    return CommonClassNames.JAVA_LANG_OBJECT;
  }

  final String name = psiClass.getQualifiedName();
  if (name != null) return name;
  return psiClass.getName();
}
项目:intellij-ce-playground    文件:GroovyMapGetCanBeKeyedAccessInspection.java   
@Override
public void visitMethodCallExpression(GrMethodCallExpression grMethodCallExpression) {
  super.visitMethodCallExpression(grMethodCallExpression);
  final GrArgumentList args = grMethodCallExpression.getArgumentList();
  if (args == null) {
    return;
  }
  if (args.getExpressionArguments().length != 1) {
    return;
  }
  if (PsiImplUtil.hasNamedArguments(args)) {
    return;
  }
  final GrExpression methodExpression = grMethodCallExpression.getInvokedExpression();
  if (!(methodExpression instanceof GrReferenceExpression)) {
    return;
  }
  final GrReferenceExpression referenceExpression = (GrReferenceExpression) methodExpression;
  final String name = referenceExpression.getReferenceName();
  if (!"get".equals(name)) {
    return;
  }
  final GrExpression qualifier = referenceExpression.getQualifierExpression();

  if (qualifier == null || PsiUtil.isThisOrSuperRef(qualifier)) {
    return;
  }

  if (referenceExpression.getDotTokenType() == GroovyTokenTypes.mOPTIONAL_DOT) return;
  final PsiType type = qualifier.getType();
  if (!InheritanceUtil.isInheritor(type, CommonClassNames.JAVA_UTIL_MAP)) {
    return;
  }
  registerMethodCallError(grMethodCallExpression);
}
项目:intellij-ce-playground    文件:GroovyNotifyWhileNotSynchronizedInspection.java   
@Override
public void visitMethodCallExpression(GrMethodCallExpression grMethodCallExpression) {
  super.visitMethodCallExpression(grMethodCallExpression);
  final GrExpression methodExpression = grMethodCallExpression.getInvokedExpression();
  if (!(methodExpression instanceof GrReferenceExpression)) {
    return;
  }
  final GrReferenceExpression reference = (GrReferenceExpression) methodExpression;
  final String name = reference.getReferenceName();
  if (!"notify".equals(name) && !"notifyAll".equals(name)) {
    return;
  }
  final PsiMethod method = grMethodCallExpression.resolveMethod();
  if (method == null) {
    return;
  }
  final PsiClass containingClass = method.getContainingClass();
  if (containingClass == null || !CommonClassNames.JAVA_LANG_OBJECT.equals(containingClass.getQualifiedName())) {
    return;
  }
  final GrMethod containingMethod = PsiTreeUtil.getParentOfType(grMethodCallExpression, GrMethod.class);
  if (containingMethod != null && containingMethod.hasModifierProperty(PsiModifier.SYNCHRONIZED)) {
    return;
  }
  final GrStatement parent = PsiTreeUtil.getParentOfType(grMethodCallExpression, GrSynchronizedStatement.class, GrClosableBlock.class);
  if (parent instanceof GrSynchronizedStatement) {
    return;
  }
  registerMethodCallError(grMethodCallExpression);
}
项目:intellij-ce-playground    文件:GrEnumConverter.java   
@Nullable
@Override
public ConversionResult isConvertibleEx(@NotNull PsiType targetType,
                                        @NotNull PsiType actualType,
                                        @NotNull GroovyPsiElement context,
                                        @NotNull ApplicableTo currentPosition) {
  if (!isEnum(targetType)) return null;
  if (InheritanceUtil.isInheritor(actualType, GroovyCommonClassNames.GROOVY_LANG_GSTRING) ||
      InheritanceUtil.isInheritor(actualType, CommonClassNames.JAVA_LANG_STRING)) {
    return GroovyConfigUtils.getInstance().isVersionAtLeast(context, GroovyConfigUtils.GROOVY1_8)
           ? ConversionResult.OK
           : ConversionResult.ERROR;
  }
  return null;
}
项目:intellij-ce-playground    文件:GrMapTypeImpl.java   
@Override
@NotNull
protected PsiType[] getAllKeyTypes() {
  Set<PsiType> result = new HashSet<PsiType>();
  if (!myStringEntries.isEmpty()) {
    result.add(GroovyPsiManager.getInstance(myFacade.getProject()).createTypeByFQClassName(CommonClassNames.JAVA_LANG_STRING, getResolveScope()));
  }
  for (Couple<PsiType> entry : myOtherEntries) {
    result.add(entry.first);
  }
  result.remove(null);
  return result.toArray(createArray(result.size()));
}
项目:intellij-ce-playground    文件:GroovyListSetCanBeKeyedAccessInspection.java   
@Override
public void visitMethodCallExpression(GrMethodCallExpression grMethodCallExpression) {
  super.visitMethodCallExpression(grMethodCallExpression);
  final GrArgumentList args = grMethodCallExpression.getArgumentList();
  if (args == null) {
    return;
  }
  if (args.getExpressionArguments().length != 2) {
    return;
  }
  if (PsiImplUtil.hasNamedArguments(args)) {
    return;
  }
  final GrExpression methodExpression = grMethodCallExpression.getInvokedExpression();
  if (!(methodExpression instanceof GrReferenceExpression)) {
    return;
  }
  final GrReferenceExpression referenceExpression = (GrReferenceExpression) methodExpression;
  final String name = referenceExpression.getReferenceName();
  if (!"set".equals(name)) {
    return;
  }
  final GrExpression qualifier = referenceExpression.getQualifierExpression();

  if (qualifier == null || PsiUtil.isThisOrSuperRef(qualifier)) {
    return;
  }
  if (referenceExpression.getDotTokenType() == GroovyTokenTypes.mOPTIONAL_DOT) return;
  final PsiType type = qualifier.getType();
  if (!InheritanceUtil.isInheritor(type, CommonClassNames.JAVA_UTIL_LIST)) {
    return;
  }
  registerMethodCallError(grMethodCallExpression);
}
项目:intellij-ce-playground    文件:GrMapTypeFromNamedArgs.java   
@NotNull
@Override
protected PsiType[] getAllKeyTypes() {
  Set<PsiType> result = ContainerUtil.newHashSet();
  if (!myStringEntries.isEmpty()) {
    result.add(GroovyPsiManager.getInstance(myFacade.getProject()).createTypeByFQClassName(CommonClassNames.JAVA_LANG_STRING, getResolveScope()));
  }
  for (Couple<GrExpression> entry : myOtherEntries) {
    result.add(inferTypePreventingRecursion(entry.first));
  }
  result.remove(null);
  return result.toArray(createArray(result.size()));
}
项目:intellij-ce-playground    文件:GroovyListGetCanBeKeyedAccessInspection.java   
@Override
public void visitMethodCallExpression(GrMethodCallExpression grMethodCallExpression) {
  super.visitMethodCallExpression(grMethodCallExpression);
  final GrArgumentList args = grMethodCallExpression.getArgumentList();
  if (args == null) {
    return;
  }
  if (args.getExpressionArguments().length != 1) {
    return;
  }
  if (PsiImplUtil.hasNamedArguments(args)) {
    return;
  }
  final GrExpression methodExpression = grMethodCallExpression.getInvokedExpression();
  if (!(methodExpression instanceof GrReferenceExpression)) {
    return;
  }
  final GrReferenceExpression referenceExpression = (GrReferenceExpression) methodExpression;
  final String name = referenceExpression.getReferenceName();
  if (!"get".equals(name)) {
    return;
  }
  final GrExpression qualifier = referenceExpression.getQualifierExpression();

  if (qualifier == null || PsiUtil.isThisOrSuperRef(qualifier)) {
    return;
  }
  if (referenceExpression.getDotTokenType() == GroovyTokenTypes.mOPTIONAL_DOT) return;
  final PsiType type = qualifier.getType();
  if (!InheritanceUtil.isInheritor(type, CommonClassNames.JAVA_UTIL_LIST)) {
    return;
  }
  registerMethodCallError(grMethodCallExpression);
}
项目:intellij-ce-playground    文件:GrStringConverter.java   
@Nullable
@Override
public ConversionResult isConvertibleEx(@NotNull PsiType lType,
                                        @NotNull PsiType rType,
                                        @NotNull GroovyPsiElement context,
                                        @NotNull ApplicableTo currentPosition) {
  if (!TypesUtil.isClassType(lType, CommonClassNames.JAVA_LANG_STRING)) return null;
  if (currentPosition == ApplicableTo.EXPLICIT_CAST) {
    return TypesUtil.isClassType(rType, GroovyCommonClassNames.GROOVY_LANG_GSTRING)
           ? ConversionResult.OK
           : null;
  }
  return ConversionResult.OK;
}
项目:intellij-ce-playground    文件:ExtendsThrowableInspection.java   
@Override
public void visitClass(@NotNull PsiClass aClass) {
  if (aClass.isInterface() || aClass.isAnnotationType() || aClass.isEnum() || aClass instanceof PsiTypeParameter) {
    return;
  }
  final PsiClass superClass = aClass.getSuperClass();
  if (superClass == null) {
    return;
  }
  final String superclassName = superClass.getQualifiedName();
  if (!CommonClassNames.JAVA_LANG_THROWABLE.equals(superclassName)) {
    return;
  }
  registerClassError(aClass, aClass);
}
项目:intellij-ce-playground    文件:GroovyUnconditionalWaitInspection.java   
private void checkBody(GrCodeBlock body) {
  final GrStatement[] statements = body.getStatements();
  if (statements.length == 0) {
    return;
  }
  for (final GrStatement statement : statements) {
    if (isConditional(statement)) {
      return;
    }

    if (!(statement instanceof GrMethodCallExpression)) {
      continue;
    }
    final GrMethodCallExpression methodCallExpression =
        (GrMethodCallExpression) statement;
    final GrExpression methodExpression = methodCallExpression.getInvokedExpression();
    if (!(methodExpression instanceof GrReferenceExpression)) {
      return;
    }
    final GrReferenceExpression reference = (GrReferenceExpression) methodExpression;
    final String name = reference.getReferenceName();
    if (!"wait".equals(name)) {
      return;
    }
    final PsiMethod method = methodCallExpression.resolveMethod();
    if (method == null) {
      return;
    }
    final PsiClass containingClass = method.getContainingClass();
    if (containingClass == null || !CommonClassNames.JAVA_LANG_OBJECT.equals(containingClass.getQualifiedName())) {
      return;
    }
    registerMethodCallError(methodCallExpression);
  }
}
项目:intellij-ce-playground    文件:GroovyWaitWhileNotSynchronizedInspection.java   
@Override
public void visitMethodCallExpression(GrMethodCallExpression grMethodCallExpression) {
    super.visitMethodCallExpression(grMethodCallExpression);
    final GrExpression methodExpression = grMethodCallExpression.getInvokedExpression();
    if (!(methodExpression instanceof GrReferenceExpression)) {
        return;
    }
    final GrReferenceExpression reference = (GrReferenceExpression) methodExpression;
    final String name = reference.getReferenceName();
    if (!"wait".equals(name)) {
        return;
    }
    final PsiMethod method = grMethodCallExpression.resolveMethod();
    if (method == null) {
        return;
    }
    final PsiClass containingClass = method.getContainingClass();
    if (containingClass == null || !CommonClassNames.JAVA_LANG_OBJECT.equals(containingClass.getQualifiedName())) {
        return;
    }
    final GrMethod containingMethod = PsiTreeUtil.getParentOfType(grMethodCallExpression, GrMethod.class);
    if(containingMethod!=null && containingMethod.hasModifierProperty(PsiModifier.SYNCHRONIZED))
    {
        return;
    }
    final GrStatement parent = PsiTreeUtil.getParentOfType(grMethodCallExpression, GrSynchronizedStatement.class, GrClosableBlock.class);
    if (parent instanceof GrSynchronizedStatement) {
        return;
    }
    registerMethodCallError(grMethodCallExpression);
}
项目:intellij-ce-playground    文件:ComparatorNotSerializableInspection.java   
@Override
public void visitClass(PsiClass aClass) {
  if (aClass instanceof PsiAnonymousClass || !InheritanceUtil.isInheritor(aClass, CommonClassNames.JAVA_UTIL_COMPARATOR) ||
      SerializationUtils.isSerializable(aClass)) {
    return;
  }
  registerClassError(aClass, aClass);
}
项目:intellij-ce-playground    文件:AbstractMethodOverridesConcreteMethodInspection.java   
@Override
public void visitMethod(@NotNull PsiMethod method) {
  //no call to super, so we don't drill into anonymous classes
  if (method.isConstructor()) {
    return;
  }
  final PsiClass containingClass = method.getContainingClass();
  if (containingClass == null) {
    return;
  }
  if (containingClass.isInterface() ||
      containingClass.isAnnotationType()) {
    return;
  }
  if (!method.hasModifierProperty(PsiModifier.ABSTRACT)) {
    return;
  }
  final PsiMethod[] superMethods = method.findSuperMethods();
  for (final PsiMethod superMethod : superMethods) {
    final PsiClass superClass = superMethod.getContainingClass();
    if (superClass == null) {
      continue;
    }
    final String superClassName = superClass.getQualifiedName();
    if (!superClass.isInterface() &&
        !CommonClassNames.JAVA_LANG_OBJECT.equals(superClassName) &&
        !superMethod.hasModifierProperty(PsiModifier.ABSTRACT)) {
      registerMethodError(method);
      return;
    }
  }
}