Java 类org.eclipse.jdt.core.Flags 实例源码

项目:Migrate-Skeletal-Implementation-to-Interface-Refactoring    文件:SourceMethodBodyAnalysisVisitor.java   
@Override
public boolean visit(MethodInvocation node) {
    // check for calls to particular java.lang.Object
    // methods #144.
    IMethodBinding methodBinding = node.resolveMethodBinding();

    if (methodBinding != null && methodBinding.getDeclaringClass().getQualifiedName().equals("java.lang.Object")) {
        IMethod calledObjectMethod = (IMethod) methodBinding.getJavaElement();

        try {
            if (Flags.isProtected(calledObjectMethod.getFlags())) {
                this.methodContainsCallToProtectedObjectMethod = true;
                this.calledProtectedObjectMethodSet.add(calledObjectMethod);
            }
        } catch (JavaModelException e) {
            throw new RuntimeException(e);
        }
    }
    return super.visit(node);
}
项目:vertigo-chroma-kspplugin    文件:ServiceManager.java   
private void handleType(IType type, IFile file, List<ServiceImplementation> serviceImplementations) throws JavaModelException {
    /* Parcourt les méthodes. */
    for (IMethod method : type.getMethods()) {
        /* Filtre pour ne garder que les méthodes publiques d'instance */
        if (method.isConstructor() || Flags.isStatic(method.getFlags()) || Flags.isPrivate(method.getFlags())) {
            continue;
        }

        /* Créé le ServiceImplementation. */
        String javaName = method.getElementName();
        ISourceRange nameRange = method.getNameRange();
        FileRegion fileRegion = new FileRegion(file, nameRange.getOffset(), nameRange.getLength());
        ServiceImplementation serviceImplementation = new ServiceImplementation(fileRegion, javaName);
        serviceImplementations.add(serviceImplementation);
    }
}
项目:vertigo-chroma-kspplugin    文件:DaoManager.java   
private void handleType(IType type, IFile file, List<DaoImplementation> daoImplementations) throws JavaModelException {
    /* Parcourt les méthodes. */
    for (IMethod method : type.getMethods()) {
        /* Filtre pour ne garder que les méthodes publiques d'instance */
        if (method.isConstructor() || Flags.isStatic(method.getFlags()) || Flags.isPrivate(method.getFlags())) {
            continue;
        }

        /* Créé le DaoImplementation. */
        String javaName = method.getElementName();
        ISourceRange nameRange = method.getNameRange();
        FileRegion fileRegion = new FileRegion(file, nameRange.getOffset(), nameRange.getLength());
        DaoImplementation daoImplementation = new DaoImplementation(fileRegion, javaName);
        daoImplementations.add(daoImplementation);
    }
}
项目:vertigo-chroma-kspplugin    文件:DtoUtils.java   
private static void parseVertigoDtoField(IMethod method, List<DtoField> fields) {
    try {
        if (method.isConstructor() || !Flags.isPublic(method.getFlags())) {
            return;
        }
        IAnnotation fieldAnnotation = JdtUtils.getAnnotation(method, FIELD_ANNOTATION_NAME);
        if (fieldAnnotation == null) {
            return;
        }
        String domain = (String) JdtUtils.getMemberValue(fieldAnnotation, DOMAIN_FIELD_NAME);

        /* Cas d'un champ de composition DTO/DTC : on filtre. */
        if (domain == null || domain.startsWith(DTO_DOMAIN_PREFIX)) {
            return;
        }

        String constantCaseName = StringUtils.toConstantCase(KspStringUtils.getFieldNameFromGetter(method.getElementName()));
        String label = (String) JdtUtils.getMemberValue(fieldAnnotation, LABEL_FIELD_NAME);
        Boolean persistent = (Boolean) JdtUtils.getMemberValue(fieldAnnotation, PERSISTENT_FIELD_NAME);

        DtoField field = new DtoField(constantCaseName, label, domain, persistent);
        fields.add(field);
    } catch (JavaModelException e) {
        ErrorUtils.handle(e);
    }
}
项目:vertigo-chroma-kspplugin    文件:JdtUtils.java   
/**
 * Indique si le type donné est un DtObject Kasper 3.
 * 
 * @param type Type JDT.
 * @return <code>true</code> si le type est un DtObject.
 */
public static boolean isKasper3DtoType(IType type) {
    try {
        /* Vérifie que c'est une classe publique. */
        if (!type.isClass() || !Flags.isPublic(type.getFlags())) {
            return false;
        }
        /* Vérifie que la classe hérite de SuperDtObject */
        if (type.getSuperclassName() == null) {
            return false;
        }
        return "SuperDtObject".equals(type.getSuperclassName()) || "kasper.model.SuperDtObject".equals(type.getSuperclassName());

    } catch (JavaModelException e) {
        ErrorUtils.handle(e);
    }
    return false;
}
项目:vertigo-chroma-kspplugin    文件:JdtUtils.java   
/**
 * Indique si le type donné est un DtObject Kasper 4 ou 5.
 * 
 * @param type Type JDT.
 * @return <code>true</code> si le type est un DtObject.
 */
public static boolean isKasper345DtoType(IType type) {
    try {
        /* Vérifie que c'est une classe publique. */
        if (!type.isClass() || !Flags.isPublic(type.getFlags())) {
            return false;
        }
        /* Vérifie que la classe hérite d'un abstract de même nom préfixé ou suffixé par Abstract */
        String superclassName = type.getSuperclassName();
        if (superclassName == null) {
            return false;
        }
        String prefixedName = "Abstract" + type.getElementName();
        String suffixedName = type.getElementName() + "Abstract";

        return superclassName.equals(prefixedName) || superclassName.equals(suffixedName);

    } catch (JavaModelException e) {
        ErrorUtils.handle(e);
    }
    return false;
}
项目:vertigo-chroma-kspplugin    文件:JdtUtils.java   
/**
 * Indique si le type donné est une sous-classe direct d'un type parmi une liste.
 * 
 * @param type Type JDT.
 * @param parentClasses Liste des classes parentes candidates.
 * @return <code>true</code> si le type est une sous-classe.
 */
public static boolean isSubclass(IType type, List<String> parentClasses) {
    if (parentClasses == null || parentClasses.isEmpty()) {
        return false;
    }
    try {
        /* Vérifie que c'est une classe publique. */
        if (!type.isClass() || !Flags.isPublic(type.getFlags())) {
            return false;
        }
        /* Vérifie que la classe hérite d'une classe (autre que Object) */
        String superclassName = type.getSuperclassName();
        if (superclassName == null) {
            return false;
        }

        /* Vérifie que la classe parente est parmi les candidates. */
        return parentClasses.contains(superclassName);

    } catch (JavaModelException e) {
        ErrorUtils.handle(e);
    }
    return false;
}
项目:pandionj    文件:ObjectModel.java   
public List<IMethod> getInstanceMethods() {
    if(jType == null)
        return Collections.emptyList();

    try {
        List<IMethod> list = new ArrayList<>();
        IMethod[] methods = jType.getMethods();
        for(IMethod m : methods)

            if(!m.isConstructor() && !Flags.isStatic(m.getFlags()) && isMethodVisible(m))
                list.add(m);
        return list;
    } catch (JavaModelException e) {
        e.printStackTrace();
        return Collections.emptyList();
    }
    //      return info.getMethods(EnumSet.of(VisibilityInfo.PUBLIC));
}
项目:pandionj    文件:StaticInvocationWidget.java   
private void addRefCombovalues(Combo combo, String paramType) {
    if(!PrimitiveType.isPrimitiveSig(paramType)) {
        combo.add("null");
        IType owner = (IType) method.getParent();
        try {
            IField[] fields = owner.getFields();
            for(IField f : fields)
                if(Flags.isStatic(f.getFlags()) && f.getTypeSignature().equals(paramType))
                    combo.add(f.getElementName());


        } catch (JavaModelException e1) {
            e1.printStackTrace();
        }
    }
}
项目:pandionj    文件:StaticInvocationWidget.java   
private void addCombovalues(Combo combo, String paramType) {
    if(!PrimitiveType.isPrimitiveSig(paramType)) {
        String sel = combo.getText();
        combo.removeAll();
        combo.add("null");
        IType owner = (IType) method.getParent();
        try {
            IField[] fields = owner.getFields();
            for(IField f : fields)
                if(Flags.isStatic(f.getFlags()) && f.getTypeSignature().equals(paramType))
                    combo.add(f.getElementName());


        } catch (JavaModelException e1) {
            e1.printStackTrace();
        }
        if(sel.isEmpty())
            combo.select(0);
        else
            combo.setText(sel);
    }
}
项目:eclipse.jdt.ls    文件:CompletionProposalDescriptionProvider.java   
/**
 * Appends the parameter list to <code>buffer</code>.
 *
 * @param buffer the buffer to append to
 * @param methodProposal the method proposal
 * @return the modified <code>buffer</code>
 */
private StringBuilder appendUnboundedParameterList(StringBuilder buffer, CompletionProposal methodProposal) {
    // TODO remove once https://bugs.eclipse.org/bugs/show_bug.cgi?id=85293
    // gets fixed.
    char[] signature= SignatureUtil.fix83600(methodProposal.getSignature());
    char[][] parameterNames= methodProposal.findParameterNames(null);
    char[][] parameterTypes= Signature.getParameterTypes(signature);

    for (int i= 0; i < parameterTypes.length; i++) {
        parameterTypes[i]= createTypeDisplayName(SignatureUtil.getLowerBound(parameterTypes[i]));
    }

    if (Flags.isVarargs(methodProposal.getFlags())) {
        int index= parameterTypes.length - 1;
        parameterTypes[index]= convertToVararg(parameterTypes[index]);
    }
    return appendParameterSignature(buffer, parameterTypes, parameterNames);
}
项目:eclipse.jdt.ls    文件:GetterSetterCompletionProposal.java   
/**
 * @param document
 * @param offset
 * @param importRewrite
 * @param completionSnippetsSupported
 * @return
 * @throws CoreException
 * @throws BadLocationException
 */
public String updateReplacementString(IDocument document, int offset, ImportRewrite importRewrite, boolean completionSnippetsSupported) throws CoreException, BadLocationException {
    int flags= Flags.AccPublic | (fField.getFlags() & Flags.AccStatic);

    String stub;
    if (fIsGetter) {
        String getterName= GetterSetterUtil.getGetterName(fField, null);
        stub = GetterSetterUtil.getGetterStub(fField, getterName, true, flags);
    } else {
        String setterName= GetterSetterUtil.getSetterName(fField, null);
        stub = GetterSetterUtil.getSetterStub(fField, setterName, true, flags);
    }

    // use the code formatter
    String lineDelim= TextUtilities.getDefaultLineDelimiter(document);
    String replacement = CodeFormatterUtil.format(CodeFormatter.K_CLASS_BODY_DECLARATIONS, stub, 0, lineDelim, fField.getJavaProject());

    if (replacement.endsWith(lineDelim)) {
        replacement = replacement.substring(0, replacement.length() - lineDelim.length());
    }

    return replacement;
}
项目:eclipse.jdt.ls    文件:OrganizeImportsOperation.java   
private boolean isVisible(TypeNameMatch curr) {
    int flags= curr.getModifiers();
    if (Flags.isPrivate(flags)) {
        return false;
    }
    boolean isPublic;
    try {
        isPublic= JdtFlags.isPublic(curr.getType());
    } catch (JavaModelException e) {
        isPublic= Flags.isPublic(flags);
    }
    if (isPublic || Flags.isProtected(flags)) {
        return true;
    }
    return curr.getPackageName().equals(fCurrPackage.getElementName());
}
项目:Migrate-Skeletal-Implementation-to-Interface-Refactoring    文件:MigrateSkeletalImplementationToInterfaceRefactoringProcessor.java   
private RefactoringStatus checkDestinationInterfaceTargetMethods(IMethod sourceMethod) throws JavaModelException {
    RefactoringStatus status = new RefactoringStatus();

    logInfo("Checking destination interface target methods...");

    // Ensure that target methods are not already default methods.
    // For each method to move, add a warning if the associated target
    // method is already default.
    IMethod targetMethod = getTargetMethod(sourceMethod, Optional.empty());

    if (targetMethod != null) {
        int targetMethodFlags = targetMethod.getFlags();

        if (Flags.isDefaultMethod(targetMethodFlags)) {
            RefactoringStatusEntry entry = addError(status, sourceMethod,
                    PreconditionFailure.TargetMethodIsAlreadyDefault, targetMethod);
            addUnmigratableMethod(sourceMethod, entry);
        }
    }
    return status;
}
项目:junit-tools    文件:JDTUtils.java   
/**
 * Returns the method modifier as String.
 * 
 * @param method
 * @return method modifier
 * @throws JavaModelException
 */
public static String getMethodModifier(IMethod method)
        throws JavaModelException {
    int methodFlags = method.getFlags();

    if (Flags.isPublic(methodFlags)) {
        return MOD_PUBLIC;
    } else if (Flags.isProtected(methodFlags)) {
        return MOD_PROTECTED;
    } else if (Flags.isPrivate(methodFlags)) {
        return MOD_PRIVATE;
    } else if (Flags.isPackageDefault(methodFlags)) {
        return MOD_PACKAGE;
    }

    return ""; //$NON-NLS-1$
}
项目:Constants-to-Enum-Eclipse-Plugin    文件:Util.java   
public static int getConsistentVisibility(Collection col)
        throws JavaModelException {
    if (col.isEmpty())
        return -1;

    // They should already be consistent.
    final IMember firstElem = (IMember) col.iterator().next();
    if (Flags.isPublic(firstElem.getFlags()))
        return Flags.AccPublic;
    else if (Flags.isPackageDefault(firstElem.getFlags()))
        return Flags.AccDefault;
    else if (Flags.isPrivate(firstElem.getFlags()))
        return Flags.AccPrivate;
    else if (Flags.isProtected(firstElem.getFlags()))
        return Flags.AccProtected;
    else
        throw new IllegalArgumentException(
                Messages.Util_InvalidMemberVisibility);
}
项目:jenerate    文件:DialogFactoryHelperImpl.java   
@Override
public boolean isOverriddenInSuperclass(IType objectClass, String methodName,
        String[] methodParameterTypeSignatures, String originalClassFullyQualifiedName) throws JavaModelException {
    ITypeHierarchy typeHierarchy = objectClass.newSupertypeHierarchy(null);
    IType[] superclasses = typeHierarchy.getAllSuperclasses(objectClass);

    if (superclasses.length == 0) {
        return false;
    }

    for (IType superclass : superclasses) {
        if (superclass.getFullyQualifiedName().equals(originalClassFullyQualifiedName)) {
            return false;
        }

        IMethod method = superclass.getMethod(methodName, methodParameterTypeSignatures);
        if (method.exists()) {
            return !Flags.isAbstract(method.getFlags());
        }
    }

    return false;
}
项目:che    文件:CompletionProposalLabelProvider.java   
/**
 * Appends the parameter list to <code>buffer</code>.
 *
 * @param buffer the buffer to append to
 * @param methodProposal the method proposal
 * @return the modified <code>buffer</code>
 */
private StyledString appendUnboundedParameterList(
    StyledString buffer, CompletionProposal methodProposal) {
  // TODO remove once https://bugs.eclipse.org/bugs/show_bug.cgi?id=85293
  // gets fixed.
  char[] signature = SignatureUtil.fix83600(methodProposal.getSignature());
  char[][] parameterNames = methodProposal.findParameterNames(null);
  char[][] parameterTypes = Signature.getParameterTypes(signature);

  for (int i = 0; i < parameterTypes.length; i++)
    parameterTypes[i] = createTypeDisplayName(SignatureUtil.getLowerBound(parameterTypes[i]));

  if (Flags.isVarargs(methodProposal.getFlags())) {
    int index = parameterTypes.length - 1;
    parameterTypes[index] = convertToVararg(parameterTypes[index]);
  }
  return appendParameterSignature(buffer, parameterTypes, parameterNames);
}
项目:che    文件:MethodOverrideTester.java   
/**
 * Finds an overriding method in a type.
 *
 * @param overridingType The type to find methods in
 * @param overridden The overridden method
 * @return The overriding method or <code>null</code> if no method is overriding.
 * @throws JavaModelException if a problem occurs
 */
public IMethod findOverridingMethodInType(IType overridingType, IMethod overridden)
    throws JavaModelException {
  int flags = overridden.getFlags();
  if (Flags.isPrivate(flags) || Flags.isStatic(flags) || overridden.isConstructor()) return null;
  IMethod[] overridingMethods = overridingType.getMethods();
  for (int i = 0; i < overridingMethods.length; i++) {
    IMethod overriding = overridingMethods[i];
    flags = overriding.getFlags();
    if (Flags.isPrivate(flags) || Flags.isStatic(flags) || overriding.isConstructor()) continue;
    if (isSubsignature(overriding, overridden)) {
      return overriding;
    }
  }
  return null;
}
项目:che    文件:StubUtility2.java   
private static IMethodBinding[] getDelegateCandidates(
    ITypeBinding binding, ITypeBinding hierarchy) {
  List<IMethodBinding> allMethods = new ArrayList<IMethodBinding>();
  boolean isInterface = binding.isInterface();
  IMethodBinding[] typeMethods = binding.getDeclaredMethods();
  for (int index = 0; index < typeMethods.length; index++) {
    final int modifiers = typeMethods[index].getModifiers();
    if (!typeMethods[index].isConstructor()
        && !Modifier.isStatic(modifiers)
        && (isInterface || Modifier.isPublic(modifiers))) {
      IMethodBinding result =
          Bindings.findOverriddenMethodInHierarchy(hierarchy, typeMethods[index]);
      if (result != null && Flags.isFinal(result.getModifiers())) continue;
      ITypeBinding[] parameterBindings = typeMethods[index].getParameterTypes();
      boolean upper = false;
      for (int offset = 0; offset < parameterBindings.length; offset++) {
        if (parameterBindings[offset].isWildcardType()
            && parameterBindings[offset].isUpperbound()) upper = true;
      }
      if (!upper) allMethods.add(typeMethods[index]);
    }
  }
  return allMethods.toArray(new IMethodBinding[allMethods.size()]);
}
项目:che    文件:JUnit4TestRunner.java   
@Override
public boolean isTestMethod(IMethod method, ICompilationUnit compilationUnit) {
  try {
    int flags = method.getFlags();
    // 'V' is void signature
    return !(method.isConstructor()
            || !Flags.isPublic(flags)
            || Flags.isAbstract(flags)
            || Flags.isStatic(flags)
            || !"V".equals(method.getReturnType()))
        && javaTestFinder.isTest(
            method, compilationUnit, JavaTestAnnotations.JUNIT4X_TEST.getName());

  } catch (JavaModelException ignored) {
    return false;
  }
}
项目:che    文件:ChangeSignatureProcessor.java   
public String getOldMethodSignature() throws JavaModelException {
  StringBuffer buff = new StringBuffer();

  int flags = getMethod().getFlags();
  buff.append(getVisibilityString(flags));
  if (Flags.isStatic(flags)) {
    buff.append("static "); // $NON-NLS-1$
  } else if (Flags.isDefaultMethod(flags)) {
    buff.append("default "); // $NON-NLS-1$
  }
  if (!getMethod().isConstructor()) buff.append(fReturnTypeInfo.getOldTypeName()).append(' ');

  buff.append(
      JavaElementLabels.getElementLabel(
          fMethod.getParent(), JavaElementLabels.ALL_FULLY_QUALIFIED));
  buff.append('.');
  buff.append(fMethod.getElementName())
      .append(Signature.C_PARAM_START)
      .append(getOldMethodParameters())
      .append(Signature.C_PARAM_END);

  buff.append(getOldMethodThrows());

  return BasicElementLabels.getJavaCodeString(buff.toString());
}
项目:che    文件:ChangeSignatureProcessor.java   
public String getNewMethodSignature() throws JavaModelException {
  StringBuffer buff = new StringBuffer();

  buff.append(getVisibilityString(fVisibility));
  int flags = getMethod().getFlags();
  if (Flags.isStatic(flags)) {
    buff.append("static "); // $NON-NLS-1$
  } else if (Flags.isDefaultMethod(flags)) {
    buff.append("default "); // $NON-NLS-1$
  }
  if (!getMethod().isConstructor()) buff.append(getReturnTypeString()).append(' ');

  buff.append(getMethodName())
      .append(Signature.C_PARAM_START)
      .append(getMethodParameters())
      .append(Signature.C_PARAM_END);

  buff.append(getMethodThrows());

  return BasicElementLabels.getJavaCodeString(buff.toString());
}
项目:jenerate    文件:DialogFactoryHelperImpl.java   
private IField[] getNonStaticNonCacheFields(IType objectClass, PreferencesManager preferencesManager)
        throws JavaModelException {
    Set<String> cacheFields = new HashSet<>();
    cacheFields.add(preferencesManager.getCurrentPreferenceValue(JeneratePreferences.HASHCODE_CACHING_FIELD));
    cacheFields.add(preferencesManager.getCurrentPreferenceValue(JeneratePreferences.TOSTRING_CACHING_FIELD));

    IField[] fields;
    fields = objectClass.getFields();

    List<IField> result = new ArrayList<>();

    for (int i = 0, size = fields.length; i < size; i++) {
        if (!Flags.isStatic(fields[i].getFlags()) && !cacheFields.contains(fields[i].getElementName())) {
            result.add(fields[i]);
        }
    }

    return result.toArray(new IField[result.size()]);
}
项目:che    文件:RefactoringAvailabilityTester.java   
public static boolean isMoveStaticAvailable(final IMember member) throws JavaModelException {
  if (!member.exists()) return false;
  final int type = member.getElementType();
  if (type != IJavaElement.METHOD && type != IJavaElement.FIELD && type != IJavaElement.TYPE)
    return false;
  if (JdtFlags.isEnum(member) && type != IJavaElement.TYPE) return false;
  final IType declaring = member.getDeclaringType();
  if (declaring == null) return false;
  if (!Checks.isAvailable(member)) return false;
  if (type == IJavaElement.METHOD && declaring.isInterface()) {
    boolean is18OrHigher = JavaModelUtil.is18OrHigher(member.getJavaProject());
    if (!is18OrHigher || !Flags.isStatic(member.getFlags())) return false;
  }
  if (type == IJavaElement.METHOD && !JdtFlags.isStatic(member)) return false;
  if (type == IJavaElement.METHOD && ((IMethod) member).isConstructor()) return false;
  if (type == IJavaElement.TYPE && !JdtFlags.isStatic(member)) return false;
  if (!declaring.isInterface() && !JdtFlags.isStatic(member)) return false;
  return true;
}
项目:che    文件:InlineMethodRefactoring.java   
private void checkOverridden(RefactoringStatus status, IProgressMonitor pm)
    throws JavaModelException {
  pm.beginTask("", 9); // $NON-NLS-1$
  pm.setTaskName(RefactoringCoreMessages.InlineMethodRefactoring_checking_overridden);
  MethodDeclaration decl = fSourceProvider.getDeclaration();
  IMethod method = (IMethod) decl.resolveBinding().getJavaElement();
  if (method == null || Flags.isPrivate(method.getFlags())) {
    pm.worked(8);
    return;
  }
  IType type = method.getDeclaringType();
  ITypeHierarchy hierarchy = type.newTypeHierarchy(new SubProgressMonitor(pm, 6));
  checkSubTypes(status, method, hierarchy.getAllSubtypes(type), new SubProgressMonitor(pm, 1));
  checkSuperClasses(
      status, method, hierarchy.getAllSuperclasses(type), new SubProgressMonitor(pm, 1));
  checkSuperInterfaces(
      status, method, hierarchy.getAllSuperInterfaces(type), new SubProgressMonitor(pm, 1));
  pm.setTaskName(""); // $NON-NLS-1$
}
项目:che    文件:ReplaceInvocationsRefactoring.java   
private void checkOverridden(RefactoringStatus status, IProgressMonitor pm)
    throws JavaModelException {
  pm.beginTask("", 9); // $NON-NLS-1$
  pm.setTaskName(RefactoringCoreMessages.InlineMethodRefactoring_checking_overridden);
  MethodDeclaration decl = fSourceProvider.getDeclaration();
  IMethod method = (IMethod) decl.resolveBinding().getJavaElement();
  if (method == null || Flags.isPrivate(method.getFlags())) {
    pm.worked(8);
    return;
  }
  IType type = method.getDeclaringType();
  ITypeHierarchy hierarchy = type.newTypeHierarchy(new SubProgressMonitor(pm, 6));
  checkSubTypes(status, method, hierarchy.getAllSubtypes(type), new SubProgressMonitor(pm, 1));
  checkSuperClasses(
      status, method, hierarchy.getAllSuperclasses(type), new SubProgressMonitor(pm, 1));
  checkSuperInterfaces(
      status, method, hierarchy.getAllSuperInterfaces(type), new SubProgressMonitor(pm, 1));
  pm.setTaskName(""); // $NON-NLS-1$
}
项目:che    文件:StubCreator.java   
protected void appendFlags(final IMember member) throws JavaModelException {
  if (member instanceof IAnnotatable)
    for (IAnnotation annotation : ((IAnnotatable) member).getAnnotations()) {
      appendAnnotation(annotation);
    }

  int flags = member.getFlags();
  final int kind = member.getElementType();
  if (kind == IJavaElement.TYPE) {
    flags &= ~Flags.AccSuper;
    final IType type = (IType) member;
    if (!type.isMember()) flags &= ~Flags.AccPrivate;
    if (Flags.isEnum(flags)) flags &= ~Flags.AccAbstract;
  }
  if (Flags.isEnum(flags)) flags &= ~Flags.AccFinal;
  if (kind == IJavaElement.METHOD) {
    flags &= ~Flags.AccVarargs;
    flags &= ~Flags.AccBridge;
  }
  if (flags != 0) fBuffer.append(Flags.toString(flags));
}
项目:gwt-eclipse-plugin    文件:JsniMethodBodyCompletionProposalComputer.java   
private static JavaCompletionProposal createProposal(int flags,
    String replacementString, int replacementOffset, int numCharsFilled, 
    int numCharsToOverwrite, String displayString) {
  Image image;
  GWTPlugin plugin = GWTPlugin.getDefault();
  if (Flags.isPublic(flags)) {
    image = plugin.getImage(GWTImages.JSNI_PUBLIC_METHOD_SMALL);
  } else if (Flags.isPrivate(flags)) {
    image = plugin.getImage(GWTImages.JSNI_PRIVATE_METHOD_SMALL);
  } else if (Flags.isProtected(flags)) {
    image = plugin.getImage(GWTImages.JSNI_PROTECTED_METHOD_SMALL);
  } else {
    image = plugin.getImage(GWTImages.JSNI_DEFAULT_METHOD_SMALL);
  }
  replacementString = replacementString.substring(numCharsFilled);
  return new JavaCompletionProposal(replacementString, replacementOffset,
      numCharsToOverwrite, image, "/*-{ " + displayString + " }-*/;", 0);
}
项目:che    文件:SelfEncapsulateFieldRefactoring.java   
@Override
public RefactoringStatus checkInitialConditions(IProgressMonitor pm) throws CoreException {
  if (fVisibility < 0)
    fVisibility = (fField.getFlags() & (Flags.AccPublic | Flags.AccProtected | Flags.AccPrivate));
  RefactoringStatus result = new RefactoringStatus();
  result.merge(Checks.checkAvailability(fField));
  if (result.hasFatalError()) return result;
  fRoot =
      new RefactoringASTParser(ASTProvider.SHARED_AST_LEVEL)
          .parse(fField.getCompilationUnit(), true, pm);
  ISourceRange sourceRange = fField.getNameRange();
  ASTNode node = NodeFinder.perform(fRoot, sourceRange.getOffset(), sourceRange.getLength());
  if (node == null) {
    return mappingErrorFound(result, node);
  }
  fFieldDeclaration =
      (VariableDeclarationFragment) ASTNodes.getParent(node, VariableDeclarationFragment.class);
  if (fFieldDeclaration == null) {
    return mappingErrorFound(result, node);
  }
  if (fFieldDeclaration.resolveBinding() == null) {
    if (!processCompilerError(result, node))
      result.addFatalError(RefactoringCoreMessages.SelfEncapsulateField_type_not_resolveable);
    return result;
  }
  computeUsedNames();
  return result;
}
项目:che    文件:GetterSetterCorrectionSubProcessor.java   
public TextFileChange getChange(IFile file) throws CoreException {
  final SelfEncapsulateFieldRefactoring refactoring =
      new SelfEncapsulateFieldRefactoring(fField);
  refactoring.setVisibility(Flags.AccPublic);
  refactoring.setConsiderVisibility(
      false); // private field references are just searched in local file
  refactoring.checkInitialConditions(new NullProgressMonitor());
  refactoring.checkFinalConditions(new NullProgressMonitor());
  Change createdChange = refactoring.createChange(new NullProgressMonitor());
  if (createdChange instanceof CompositeChange) {
    Change[] children = ((CompositeChange) createdChange).getChildren();
    for (int i = 0; i < children.length; i++) {
      Change curr = children[i];
      if (curr instanceof TextFileChange && ((TextFileChange) curr).getFile().equals(file)) {
        return (TextFileChange) curr;
      }
    }
  }
  return null;
}
项目:che    文件:ChangeMethodSignatureArguments.java   
/** {@inheritDoc} */
public String toString() {
  StringBuffer buf = new StringBuffer("change signature to "); // $NON-NLS-1$
  buf.append("\n\tvisibility: ").append(Flags.toString(fNewVisibility)); // $NON-NLS-1$
  buf.append("\n\treturn type sig: ").append(fNewReturnType); // $NON-NLS-1$
  buf.append("\n\tnew name: ").append(fNewName); // $NON-NLS-1$
  buf.append("\n\tkeep original: ").append(fKeepOriginal); // $NON-NLS-1$
  for (int i = 0; i < fNewParameters.length; i++) {
    buf.append("\n\tparameter ")
        .append(i)
        .append(": ")
        .append(fNewParameters[i]); // $NON-NLS-1$ //$NON-NLS-2$
  }
  for (int i = 0; i < fThrownExceptions.length; i++) {
    buf.append("\n\texception ")
        .append(i)
        .append(": ")
        .append(fThrownExceptions[i]); // $NON-NLS-1$ //$NON-NLS-2$
  }
  return buf.toString();
}
项目:che    文件:JavaModelUtil.java   
/**
 * Evaluates if a member in the focus' element hierarchy is visible from elements in a package.
 *
 * @param member The member to test the visibility for
 * @param pack The package of the focus element focus
 * @return returns <code>true</code> if the member is visible from the package
 * @throws JavaModelException thrown when the member can not be accessed
 */
public static boolean isVisibleInHierarchy(IMember member, IPackageFragment pack)
    throws JavaModelException {
  int type = member.getElementType();
  if (type == IJavaElement.INITIALIZER
      || (type == IJavaElement.METHOD
          && member.getElementName().startsWith("<"))) { // $NON-NLS-1$
    return false;
  }

  int otherflags = member.getFlags();

  IType declaringType = member.getDeclaringType();
  if (Flags.isPublic(otherflags)
      || Flags.isProtected(otherflags)
      || (declaringType != null && isInterfaceOrAnnotation(declaringType))) {
    return true;
  } else if (Flags.isPrivate(otherflags)) {
    return false;
  }

  IPackageFragment otherpack =
      (IPackageFragment) member.getAncestor(IJavaElement.PACKAGE_FRAGMENT);
  return (pack != null && pack.equals(otherpack));
}
项目:che    文件:JavaModelUtil.java   
/**
 * Evaluates if a member (possible from another package) is visible from elements in a package.
 *
 * @param member The member to test the visibility for
 * @param pack The package in focus
 * @return returns <code>true</code> if the member is visible from the package
 * @throws JavaModelException thrown when the member can not be accessed
 */
public static boolean isVisible(IMember member, IPackageFragment pack) throws JavaModelException {

  int type = member.getElementType();
  if (type == IJavaElement.INITIALIZER
      || (type == IJavaElement.METHOD
          && member.getElementName().startsWith("<"))) { // $NON-NLS-1$
    return false;
  }

  int otherflags = member.getFlags();
  IType declaringType = member.getDeclaringType();
  if (Flags.isPublic(otherflags)
      || (declaringType != null && isInterfaceOrAnnotation(declaringType))) {
    return true;
  } else if (Flags.isPrivate(otherflags)) {
    return false;
  }

  IPackageFragment otherpack =
      (IPackageFragment) member.getAncestor(IJavaElement.PACKAGE_FRAGMENT);
  return (pack != null && otherpack != null && isSamePackage(pack, otherpack));
}
项目:codelens-eclipse    文件:JavaCodeLensProvider.java   
private void collectCodeLenses(ITypeRoot unit, IJavaElement[] elements, List<ICodeLens> lenses,
        IProgressMonitor monitor) throws JavaModelException {
    for (IJavaElement element : elements) {
        if (monitor.isCanceled()) {
            return;
        }
        if (element.getElementType() == IJavaElement.TYPE) {
            collectCodeLenses(unit, ((IType) element).getChildren(), lenses, monitor);
        } else if (element.getElementType() != IJavaElement.METHOD || JDTUtils.isHiddenGeneratedElement(element)) {
            continue;
        }

        // if (preferenceManager.getPreferences().isReferencesCodeLensEnabled()) {
        ICodeLens lens = getCodeLens(REFERENCES_TYPE, element, unit);
        lenses.add(lens);
        // }
        // if (preferenceManager.getPreferences().isImplementationsCodeLensEnabled() &&
        // element instanceof IType) {
        if (element instanceof IType) {
            IType type = (IType) element;
            if (type.isInterface() || Flags.isAbstract(type.getFlags())) {
                lens = getCodeLens(IMPLEMENTATION_TYPE, element, unit);
                lenses.add(lens);
            }
        }
    }
}
项目:Hydrograph    文件:ClassDetails.java   
private void addMethodsToClass(IMethod iMethod) throws JavaModelException {
    if (iMethod.isConstructor() || iMethod.isMainMethod() || isMethodDepricated(iMethod)) {
        return;
    } else {
        if (Flags.isPublic(iMethod.getFlags()) && Flags.isStatic(iMethod.getFlags())) {
            if (StringUtils.isBlank(iMethod.getSource())) {
                methodList.add(new MethodDetails(iMethod,cName, false));
            } else
                methodList.add(new MethodDetails(iMethod,cName, true));
        }
    }
}
项目:vertigo-chroma-kspplugin    文件:WsRouteManager.java   
private void handleMethod(IMethod method, String pathPrefix, IFile file, List<WsRoute> wsRoutes) throws JavaModelException {
    /* Filtre pour ne garder que les méthodes publiques d'instance */
    if (method.isConstructor() || Flags.isStatic(method.getFlags()) || Flags.isPrivate(method.getFlags())) {
        return;
    }

    /* Parcourt les verbes HTTP */
    for (String verb : HTTP_VERBS) {

        /* Extrait l'annotation du verbe. */
        IAnnotation verbAnnotation = JdtUtils.getAnnotation(method, verb);
        if (verbAnnotation == null) {
            continue;
        }

        /* Extrait la route partielle. */
        String routePatternSuffix = JdtUtils.getMemberValue(verbAnnotation);

        /* Calcule la route complète. */
        String routePattern = pathPrefix + routePatternSuffix;

        /* Créé la WsRoute. */
        String javaName = method.getElementName();
        ISourceRange nameRange = method.getNameRange();
        FileRegion fileRegion = new FileRegion(file, nameRange.getOffset(), nameRange.getLength());
        WsRoute wsRoute = new WsRoute(fileRegion, javaName, routePattern, verb);
        wsRoutes.add(wsRoute);
    }
}
项目:vertigo-chroma-kspplugin    文件:DtoUtils.java   
private static void parseKasper5DtoField(IMethod method, List<DtoField> fields) {
    try {
        if (method.isConstructor() || !Flags.isPublic(method.getFlags())) {
            return;
        }
        IAnnotation fieldAnnotation = JdtUtils.getAnnotation(method, FIELD_ANNOTATION_NAME);
        if (fieldAnnotation == null) {
            return;
        }
        String domain = (String) JdtUtils.getMemberValue(fieldAnnotation, DOMAIN_FIELD_NAME);

        /* Cas d'un champ de composition DTO/DTC : on filtre. */
        if (domain == null || domain.startsWith(DTO_DOMAIN_PREFIX)) {
            return;
        }

        IAnnotation columnAnnotation = JdtUtils.getAnnotation(method, COLUMN_ANNOTATION_NAME);
        if (columnAnnotation == null) {
            return;
        }

        String constantCaseName = (String) JdtUtils.getMemberValue(columnAnnotation, NAME_FIELD_NAME);
        String label = (String) JdtUtils.getMemberValue(fieldAnnotation, LABEL_FIELD_NAME);
        Boolean persistent = (Boolean) JdtUtils.getMemberValue(fieldAnnotation, PERSISTENT_FIELD_NAME);

        DtoField field = new DtoField(constantCaseName, label, domain, persistent);
        fields.add(field);
    } catch (JavaModelException e) {
        ErrorUtils.handle(e);
    }
}
项目:vertigo-chroma-kspplugin    文件:DtoUtils.java   
private static DtoField parseKasper3BeanFieldGetter(IMethod method) throws JavaModelException {
    if (method.isConstructor() || !Flags.isPublic(method.getFlags()) || !Flags.isFinal(method.getFlags())) {
        return null;
    }
    String methodName = method.getElementName();
    if (!methodName.startsWith("get")) {
        return null;
    }

    String constantCaseName = StringUtils.toConstantCase(KspStringUtils.getFieldNameFromGetter(method.getElementName()));
    String label = "Unknown";
    Boolean persistent = false;

    return new DtoField(constantCaseName, label, "Unknown", persistent);
}
项目:vertigo-chroma-kspplugin    文件:JdtUtils.java   
/**
 * Indique si le type donné est un DtObject Vertigo.
 * 
 * @param type Type JDT.
 * @return <code>true</code> si le type est un DtObject.
 */
public static boolean isVertigoDtoType(IType type) {
    try {
        /* Vérifie que c'est une classe publique final. */
        if (!type.isClass() || !Flags.isPublic(type.getFlags()) || !Flags.isFinal(type.getFlags())) {
            return false;
        }
        /* Vérifie les interfaces. */
        return hasVertigoDtoTypeInterface(type);
    } catch (JavaModelException e) {
        ErrorUtils.handle(e);
    }
    return false;
}