Java Code Examples for org.eclipse.jdt.core.Flags#AccPublic

The following examples show how to use org.eclipse.jdt.core.Flags#AccPublic . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GetterSetterCompletionProposal.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * @param document
 * @param offset
 * @param importRewrite
 * @param completionSnippetsSupported
 * @param addComments
 * @return
 * @throws CoreException
 * @throws BadLocationException
 */
public String updateReplacementString(IDocument document, int offset, ImportRewrite importRewrite, boolean completionSnippetsSupported, boolean addComments) 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, addComments, flags);
	} else {
		String setterName= GetterSetterUtil.getSetterName(fField, null);
		stub = GetterSetterUtil.getSetterStub(fField, setterName, addComments, 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;
}
 
Example 2
Source File: SelfEncapsulateFieldRefactoring.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
@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;
}
 
Example 3
Source File: SelfEncapsulateFieldInputPage.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private Object[] createData(int visibility) {
	String pub= RefactoringMessages.SelfEncapsulateFieldInputPage_public;
	String pro= RefactoringMessages.SelfEncapsulateFieldInputPage_protected;
	String def= RefactoringMessages.SelfEncapsulateFieldInputPage_default;
	String priv= RefactoringMessages.SelfEncapsulateFieldInputPage_private;

	String[] labels= null;
	Integer[] data= null;
	if (Flags.isPrivate(visibility)) {
		labels= new String[] { pub, pro, def, priv };
		data= new Integer[] {new Integer(Flags.AccPublic), new Integer(Flags.AccProtected), new Integer(0), new Integer(Flags.AccPrivate) };
	} else if (Flags.isProtected(visibility)) {
		labels= new String[] { pub, pro };
		data= new Integer[] {new Integer(Flags.AccPublic), new Integer(Flags.AccProtected)};
	} else {
		labels= new String[] { pub, def };
		data= new Integer[] {new Integer(Flags.AccPublic), new Integer(0)};
	}
	return new Object[] {labels, data};
}
 
Example 4
Source File: GroovyDocumentUtil.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
public static void refreshUserLibrary(Repository repository) {
    try {
        FunctionsRepositoryFactory.getUserFunctionCatgory().removeAllFunctions();
        GroovyRepositoryStore store = repository.getRepositoryStore(GroovyRepositoryStore.class);
        IJavaProject javaProject = repository.getJavaProject();
        for (IRepositoryFileStore artifact : store.getChildren()) {
            IType type = javaProject.findType(artifact.getDisplayName().replace("/", "."));
            if (type != null) {
                for (IMethod m : type.getMethods()) {
                    if (m.getFlags() == (Flags.AccStatic | Flags.AccPublic)) {
                        FunctionsRepositoryFactory.getUserFunctionCatgory()
                                .addFunction(new GroovyFunction(m, FunctionsRepositoryFactory.getUserFunctionCatgory()));
                    }
                }
            }
        }
    } catch (Exception e) {
        GroovyPlugin.logError(e);
    }
}
 
Example 5
Source File: XbaseImages.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected int toFlags(JvmVisibility visibility) {
	switch (visibility) {
		case PRIVATE:
			return Flags.AccPrivate;
		case PROTECTED:
			return Flags.AccProtected;
		case PUBLIC:
			return Flags.AccPublic;
		default:
			return Flags.AccDefault;
	}
}
 
Example 6
Source File: XbaseImages2.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected int toFlags(JvmVisibility visibility) {
	switch (visibility) {
		case PRIVATE:
			return Flags.AccPrivate;
		case PROTECTED:
			return Flags.AccProtected;
		case PUBLIC:
			return Flags.AccPublic;
		default:
			return Flags.AccDefault;
	}
}
 
Example 7
Source File: SelfEncapsulateFieldRefactoring.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
@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(IASTSharedValues.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 = 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;
}
 
Example 8
Source File: MemberVisibilityAdjustor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Converts a given modifier keyword into a visibility flag.
 *
 * @param keyword the keyword to convert
 * @return the visibility flag
 */
private static int keywordToVisibility(final ModifierKeyword keyword) {
	int visibility= 0;
	if (keyword == ModifierKeyword.PUBLIC_KEYWORD)
		visibility= Flags.AccPublic;
	else if (keyword == ModifierKeyword.PRIVATE_KEYWORD)
		visibility= Flags.AccPrivate;
	else if (keyword == ModifierKeyword.PROTECTED_KEYWORD)
		visibility= Flags.AccProtected;
	return visibility;
}
 
Example 9
Source File: GetterSetterCompletionProposal.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected boolean updateReplacementString(IDocument document, char trigger, int offset, ImportRewrite impRewrite) throws CoreException, BadLocationException {

	CodeGenerationSettings settings= JavaPreferencesSettings.getCodeGenerationSettings(fField.getJavaProject());
	boolean addComments= settings.createComments;
	int flags= Flags.AccPublic | (fField.getFlags() & Flags.AccStatic);

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

	// use the code formatter
	String lineDelim= TextUtilities.getDefaultLineDelimiter(document);

	IRegion region= document.getLineInformationOfOffset(getReplacementOffset());
	int lineStart= region.getOffset();
	int indent= Strings.computeIndentUnits(document.get(lineStart, getReplacementOffset() - lineStart), settings.tabWidth, settings.indentWidth);

	String replacement= CodeFormatterUtil.format(CodeFormatter.K_CLASS_BODY_DECLARATIONS, stub, indent, lineDelim, fField.getJavaProject());

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

	setReplacementString(Strings.trimLeadingTabsAndSpaces(replacement));
	return true;
}
 
Example 10
Source File: XbaseReferenceProposalCreator.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
protected Image computeImage(JvmFeature feature) {
	int flags = 0;
	int decorator = 0;
	switch(feature.getVisibility()) {
		case PUBLIC: flags = Flags.AccPublic; break;
		case PROTECTED: flags = Flags.AccProtected; break;
		case PRIVATE: flags = Flags.AccPrivate; break;
		case DEFAULT: flags = Flags.AccDefault; break;
	}
	JvmDeclaredType declaringType = feature.getDeclaringType();
	boolean interfaceOrAnnotation = false;
	if (declaringType instanceof JvmGenericType) {
		interfaceOrAnnotation = ((JvmGenericType) declaringType).isInterface();
	} else if (declaringType instanceof JvmAnnotationType) {
		interfaceOrAnnotation = true;
	}
	if (feature instanceof JvmConstructor) {
		decorator = JavaElementImageDescriptor.CONSTRUCTOR;
		if (declaringType.isAbstract()) {
			flags |= Flags.AccAbstract;
			decorator |= JavaElementImageDescriptor.ABSTRACT;
		}
		return computeConstructorImage(declaringType.getDeclaringType() != null, interfaceOrAnnotation, flags, decorator);
	} else if (feature instanceof JvmOperation) {
		JvmOperation operation = (JvmOperation) feature;
		if (operation.isStatic()) {
			flags |= Flags.AccStatic;
			decorator |= JavaElementImageDescriptor.STATIC;
		}
		if (operation.isAbstract()) {
			flags |= Flags.AccAbstract;
			decorator |= JavaElementImageDescriptor.ABSTRACT;
		}
		if (operation.isFinal()) {
			flags |= Flags.AccFinal;
			decorator |= JavaElementImageDescriptor.FINAL;
		}
		return computeMethodImage(interfaceOrAnnotation, flags, decorator);
	} else if (feature instanceof JvmField) {
		JvmField field = (JvmField) feature;
		if (field.isStatic()) {
			flags |= Flags.AccStatic;
			decorator |= JavaElementImageDescriptor.STATIC;
		}
		if (field.isFinal()) {
			flags |= Flags.AccFinal;
			decorator |= JavaElementImageDescriptor.FINAL;
		}
		if (declaringType instanceof JvmEnumerationType)
			flags |= Flags.AccEnum;
		return computeFieldImage(interfaceOrAnnotation, flags, decorator);
	} 
	return null;
}
 
Example 11
Source File: JdtTypesProposalProvider.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Compute the JVM modifiers that corresponds to the given description.
 *
 * <p>This function fixes the issue related to the missed modifiers given to the content assist.
 *
 * @param context the current content assist context.
 * @param description the description.
 * @return the JVM modifiers.
 * @since 2.11
 */
protected int getDirtyStateModifiers(ContentAssistContext context, IEObjectDescription description) {
	EObject eobject = description.getEObjectOrProxy();
	if (eobject.eIsProxy()) {
		eobject = EcoreUtil.resolve(eobject, context.getResource().getResourceSet());
	}
	int accessModifiers = Flags.AccPublic;
	int otherModifiers = 0;
	if (eobject instanceof JvmMember) {
		final JvmMember member = (JvmMember) eobject;
		switch (member.getVisibility()) {
		case PUBLIC:
			accessModifiers = Flags.AccPublic;
			break;
		case PRIVATE:
			accessModifiers = Flags.AccPrivate;
			break;
		case PROTECTED:
			accessModifiers = Flags.AccProtected;
			break;
		case DEFAULT:
		default:
			accessModifiers = Flags.AccDefault;
			break;
		}
		if (DeprecationUtil.isDeprecated(member)) {
			otherModifiers |= Flags.AccDeprecated;
		}
		if (eobject instanceof JvmDeclaredType) {
			final JvmDeclaredType type = (JvmDeclaredType) eobject;
			if (type.isFinal()) {
				otherModifiers |= Flags.AccFinal;
			}
			if (type.isAbstract()) {
				otherModifiers |= Flags.AccAbstract;
			}
			if (type.isStatic()) {
				otherModifiers |= Flags.AccStatic;
			}
			if (type instanceof JvmEnumerationType) {
                otherModifiers |= Flags.AccEnum;
            } else  if (type instanceof JvmAnnotationType) {
                otherModifiers |= Flags.AccAnnotation;
            } else if (type instanceof JvmGenericType) {
                if (((JvmGenericType) type).isInterface()) {
                    otherModifiers |= Flags.AccInterface;
                }
            }
		}
	}
	return accessModifiers | otherModifiers;
}
 
Example 12
Source File: JavaSetterOperatorConstraintTest.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
private MethodSignature aPublicMethod(final String name, final String... parametersType) {
    return new MethodSignature(Flags.AccPublic, name, parametersType);
}
 
Example 13
Source File: JavaGetterExpressionConstraintTest.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
private MethodSignature aPublicMethod(final String name, final String returnType) {
    return new MethodSignature(Flags.AccPublic, name, returnType);
}
 
Example 14
Source File: GroovyFieldAccessorMethod.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
@Override
public int getFlags() throws JavaModelException {
	return Flags.AccPublic;
}