Package org.eclipse.jdt.core

Examples of org.eclipse.jdt.core.IField


          comparator);

      final Map annotationToQualifiedNameMap = new HashMap();

      for (final Iterator cit = constants.iterator(); cit.hasNext();) {
        final IField constantField = (IField) cit.next();
        final FieldDeclaration originalFieldDeclaration = (FieldDeclaration) this.removedFieldNodes
            .get(constantField);

        // Get annotations.
        final Collection annotationCollection = new LinkedHashSet();
        for (final Iterator mit = originalFieldDeclaration.modifiers()
            .iterator(); mit.hasNext();) {
          final Object o = mit.next();
          if (o instanceof Annotation) {
            final Annotation oldAnnotation = (Annotation) o;
            final Annotation newAnnotation = (Annotation) ASTNode
                .copySubtree(ast, oldAnnotation);
            annotationToQualifiedNameMap.put(newAnnotation,
                oldAnnotation.resolveTypeBinding()
                    .getQualifiedName());
            annotationCollection.add(newAnnotation);
          }
        }

        // Get the javadoc.
        final Javadoc originalJavadoc = originalFieldDeclaration
            .getJavadoc();
        final Javadoc newJavadoc = (Javadoc) ASTNode.copySubtree(ast,
            originalJavadoc);

        final EnumConstantDeclaration constDecl = createNewEnumConstantDeclarataion(
            ast, ast.newSimpleName(constantField.getElementName()),
            newJavadoc, annotationCollection);

        newEnumConstantToOldConstantFieldMap.put(constDecl, constantField);
        enumConstantDeclarationCollection.add(constDecl);
      }
View Full Code Here


  private RefactoringStatus reportNonEnumerizableInputConstants() {
    final RefactoringStatus ret = new RefactoringStatus();
    final Collection enumerizableElements = Util
        .flattenForest(this.computer.getEnumerizationForest());
    for (final Iterator it = this.fieldsToRefactor.iterator(); it.hasNext();) {
      final IField field = (IField) it.next();
      if (!enumerizableElements.contains(field)) {
        String message = Messages.ConvertConstantsToEnumRefactoring_RefactoringNotPossible;
        ret.addWarning(MessageFormat.format(message, new Object[] {field.getElementName()}));
      }
    }
    return ret;
  }
View Full Code Here

    if (!(o2 instanceof EnumConstantDeclaration && o2 instanceof EnumConstantDeclaration)) {
      String message = Messages.EnumConstantComparator_BothObjectsMustMatch;
      throw new IllegalArgumentException(MessageFormat.format(message, new Object[]{EnumConstantDeclaration.class.getName()}));
    }

    final IField f1 = (IField) this.newEnumConstantToOldConstantFieldMap.get(o1);
    final IField f2 = (IField) this.newEnumConstantToOldConstantFieldMap.get(o2);

    Object v1 = null;
    Object v2 = null;

    try {
      v1 = f1.getConstant();
      v2 = f2.getConstant();
    } catch (final JavaModelException E) {
      final ClassCastException ce = new ClassCastException(
          Messages.EnumConstantComparator_CannotCompare);
      ce.initCause(E);
      throw ce;
View Full Code Here

            + o);
      break;
    }

    case IJavaElement.FIELD: {
      final IField f = (IField) o;
      final String sig = f.getTypeSignature();
      if (!isValidTypeSignature(sig))
        throw new IllegalArgumentException(Messages.Worklist_IllegalWorklistElement
            + o);
      break;
    }
View Full Code Here

      boolean allProtected = true;

      for (final Iterator jit = set.iterator(); jit.hasNext();) {
        final IJavaElement elem = (IJavaElement) jit.next();
        if (elem.getElementType() == IJavaElement.FIELD) {
          final IField field = (IField) elem;
          final Object constValue = field.getConstant();
          if (constValue != null) {
            allPublic &= Flags.isPublic(field.getFlags());
            allPrivate &= Flags.isPrivate(field.getFlags());
            allProtected &= Flags.isProtected(field.getFlags());
            allPackage &= Flags.isPackageDefault(field.getFlags());
          }
        }
      }
      if (!(allPublic || allPrivate || allPackage || allProtected))
        ret.remove(set);
View Full Code Here

      final Collection set = (Collection) it.next();
      final Collection constValues = new ArrayList();
      for (final Iterator jit = set.iterator(); jit.hasNext();) {
        final IJavaElement elem = (IJavaElement) jit.next();
        if (elem.getElementType() == IJavaElement.FIELD) {
          final IField field = (IField) elem;
          final Object constValue = field.getConstant();
          if (constValue != null)
            constValues.add(constValue);
        }
      }
View Full Code Here

      final Collection set = (Collection) it.next();
      final Collection constNames = new ArrayList();
      for (final Iterator jit = set.iterator(); jit.hasNext();) {
        final IJavaElement elem = (IJavaElement) jit.next();
        if (elem.getElementType() == IJavaElement.FIELD) {
          final IField field = (IField) elem;
          final Object constValue = field.getConstant();
          if (constValue != null)
            constNames.add(field.getElementName());
        }
      }
      if (!distinct(constNames))
        ret.remove(set);
    }
View Full Code Here

    });
    fNameField.setLayoutData(new GridData(GridData.FILL, GridData.CENTER, true, false));
    IField[] fields = (IField[]) getConvertToEnumRefactoring().getFieldsToRefactor().toArray(new IField[] {});
    List fieldList = new ArrayList(fields.length);
    for (int i = 0; i < fields.length; i++) {
      IField field = fields[i];
      fieldList.add(field.getElementName());
    }
    String suggestedName = getSuggestedEnumTypeName((String[]) fieldList.toArray(new String[]{}));
    fNameField.setText(suggestedName);
  }
View Full Code Here

     
      String packageName = Util.getPackageName(name);
      if ( packageName.isEmpty() && !getConvertToEnumRefactoring().getFieldsToRefactor().isEmpty() ) {
        //assign package to be the package of the first constant.
        //TODO [rk]: Done just to avoid default package for now.
        IField field = (IField) getConvertToEnumRefactoring().getFieldsToRefactor().iterator().next();
        IType parent = (IType) field.getParent();
        String fullyQualifiedName = parent.getFullyQualifiedName();
        packageName = Util.getPackageName(fullyQualifiedName);
      }
       
      getConvertToEnumRefactoring().setPackageName(packageName);
View Full Code Here

    throws InvocationTargetException, InterruptedException {
      if((javaElement != null) && (newVisiblityKindLiteral != null)) {
        IContainerService contH = getContainerService();
        if(contH instanceof IASTNodeService<?, ?>) {
          if(javaElement instanceof IField) {
            IField field = (IField)javaElement;
            try {
              SelfEncapsulateFieldRefactoring r =
                new SelfEncapsulateFieldRefactoring(field);
              int visiblityInt = VisibilityKind.PRIVATE;
              if(
                  newVisiblityKindLiteral.equals(
                      VisibilityKind
                      .PRIVATE_LITERAL
                      .getLiteral()
                  )
              ) {
                visiblityInt = Flags.AccPrivate;
              }
              else if(
                  newVisiblityKindLiteral.equals(
                      VisibilityKind
                      .PROTECTED_LITERAL
                      .getLiteral()
                  )
              ) {
                visiblityInt = Flags.AccProtected;
              }
              else if(
                  newVisiblityKindLiteral.equals(
                      VisibilityKind
                      .PUBLIC_LITERAL
                      .getLiteral()
                  )
              ) {
                visiblityInt = Flags.AccPublic;
              }
              r.setVisibility(visiblityInt);
              r.setGetterName(
                  Resources.getCodeConstant(
                      "constants.getterPrefix"
                  )
                  + field.getElementName()
              );
              r.setSetterName(
                  Resources.getCodeConstant(
                      "constants.setterPrefix"
                  )
                  + field.getElementName()
              );
              r.setGenerateJavadoc(true);
              PerformRefactoringOperation op =
                new PerformRefactoringOperation(
                    r,
View Full Code Here

TOP

Related Classes of org.eclipse.jdt.core.IField

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.