List of usage examples for org.eclipse.jdt.core Flags isPublic
public static boolean isPublic(int flags)
public modifier. From source file:at.bestsolution.efxclipse.tooling.fxgraph.ui.util.JDTHelper.java
License:Open Source License
private TypeData createData(List<IMethod> allMethods, IJavaProject jproject) throws JavaModelException { TypeData d = new TypeData(); for (IMethod m : allMethods) { if (!Flags.isPublic(m.getFlags())) { continue; }/*from w w w . jav a 2 s .com*/ if (m.getElementName().startsWith("impl_") || m.getElementName().startsWith("getImpl_")) { continue; } if (m.getElementName().startsWith("get") && m.getParameterNames().length == 0) { String returnSignature = Signature.toString(m.getReturnType()); if (returnSignature.startsWith("javafx.event.EventHandler<? super ") || returnSignature.startsWith("javafx.event.EventHandler<")) { String eventType; if (returnSignature.startsWith("javafx.event.EventHandler<? super ")) { eventType = returnSignature.substring("javafx.event.EventHandler<? super ".length(), returnSignature.length() - 1); } else { eventType = returnSignature.substring("javafx.event.EventHandler<".length(), returnSignature.length() - 1); } EventValueProperty p = new EventValueProperty(m, extractAttributename(m.getElementName()), m.getParent().getElementName(), eventType); d.properties.add(p); } else { String propName = extractAttributename(m.getElementName()); String ownerName = m.getParent().getElementName(); boolean isReadonly = isReadonlySetter(propName, allMethods); if ("double".equals(returnSignature) || "float".equals(returnSignature)) { if (!isReadonly) { FloatingValueProperty p = new FloatingValueProperty(m, propName, ownerName, returnSignature); d.properties.add(p); } } else if ("int".equals(returnSignature) || "long".equals(returnSignature) || "short".equals(returnSignature) || "byte".equals(returnSignature) || "char".equals(returnSignature)) { if (!isReadonly) { IntegerValueProperty p = new IntegerValueProperty(m, propName, ownerName, returnSignature); d.properties.add(p); } } else { IType type; if (returnSignature.indexOf('<') == -1) { type = jproject.findType(returnSignature); } else { type = jproject.findType(returnSignature.substring(0, returnSignature.indexOf('<'))); } if (type == null) { continue; } if (type.isEnum()) { if (!isReadonly) { EnumValueProperty p = new EnumValueProperty(m, propName, ownerName, returnSignature, type); d.properties.add(p); } } else { boolean isLists = false; boolean isMap = false; if ("java.util.List".equals(type.getFullyQualifiedName())) { isLists = true; } else { for (String i : type.getSuperInterfaceNames()) { if (i.equals("java.util.List")) { isLists = true; } } } if (!isLists) { if ("java.util.Map".equals(type.getFullyQualifiedName())) { isMap = true; } else { for (String i : type.getSuperInterfaceNames()) { if (i.equals("java.util.Map")) { isMap = true; } } } } if (isLists) { String listType; if (returnSignature.indexOf('<') != -1) { listType = returnSignature.substring(returnSignature.indexOf('<') + 1, returnSignature.lastIndexOf('>')); } else { listType = "?"; } if (!propName.endsWith("Unmodifiable")) { ListValueProperty p = new ListValueProperty(m, propName, ownerName, listType, isReadonly); d.properties.add(p); } } else if (isMap) { MapValueProperty p = new MapValueProperty(m, propName, ownerName); d.properties.add(p); } else if (type.getFullyQualifiedName().equals("java.lang.String")) { if (!isReadonly) { StringValueProperty p = new StringValueProperty(m, propName, ownerName, returnSignature); d.properties.add(p); } } else { if (!isReadonly) { List<Proposal> props = getProposals(type, jproject); ElementValueProperty p = new ElementValueProperty(m, propName, ownerName, returnSignature, props); d.properties.add(p); } } } } } } else if (m.getElementName().startsWith("is") && m.getParameterNames().length == 0 && "Z".equals(m.getReturnType())) { String propName = extractAttributename(m.getElementName()); boolean isReadonly = isReadonlySetter(propName, allMethods); if (!isReadonly) { BooleanValueProperty p = new BooleanValueProperty(m, propName, m.getParent().getElementName(), "boolean"); d.properties.add(p); } } } return d; }
From source file:at.bestsolution.efxclipse.tooling.fxgraph.ui.util.JDTHelper.java
License:Open Source License
private boolean isReadonlySetter(String name, List<IMethod> methods) throws JavaModelException { for (IMethod m : methods) { if (!m.getElementName().startsWith("set") || !Flags.isPublic(m.getFlags())) { continue; }//from w w w.jav a 2 s .com if (name.equals(extractAttributename(m.getElementName()))) { return false; } } return true; }
From source file:at.bestsolution.efxclipse.tooling.model.internal.FXClass.java
License:Open Source License
@Override public IMethod getValueOf() { // if( ! valueOfResolved ) { try {/* w ww . ja va2s. c om*/ for (IMethod m : type.getMethods()) { if (Flags.isStatic(m.getFlags()) && Flags.isPublic(m.getFlags()) && "valueOf".equals(m.getElementName())) { if (m.getParameterTypes().length == 1) { // String fqnType = Util.toFQN((IType) m.getParent(),m.getParameterTypes()[0]); // if("java.lang.String".equals( fqnType) ) { valueOfMethod = m; break; // } } } } valueOfResolved = true; } catch (JavaModelException e) { // TODO Auto-generated catch block e.printStackTrace(); } // } return valueOfMethod; }
From source file:at.bestsolution.efxclipse.tooling.model.internal.FXCtrlEventMethod.java
License:Open Source License
@Override public Visibility getVisibility() { try {//from w w w.ja v a 2 s .co m int flags = method.getFlags(); if (Flags.isPublic(flags)) { return Visibility.PUBLIC; } else if (Flags.isPackageDefault(flags)) { return Visibility.PACKAGE; } else if (Flags.isProtected(flags)) { return Visibility.PROTECTED; } else { return Visibility.PRIVATE; } } catch (JavaModelException e) { FXPlugin.getLogger().log(LogService.LOG_ERROR, "Unable to retrieve visibility for method '" + method + "'", e); } return Visibility.PRIVATE; }
From source file:at.bestsolution.efxclipse.tooling.model.internal.FXObjectPoperty.java
License:Open Source License
public IMethod getValueOfMethod() { if (!valueOfMethodResolved) { try {//from w ww. j a va2 s . c om for (IMethod m : getElementType().getMethods()) { if (Flags.isStatic(m.getFlags()) && Flags.isPublic(m.getFlags()) && "valueOf".equals(m.getElementName())) { valueOfMethod = m; } } } catch (JavaModelException e) { // TODO Auto-generated catch block e.printStackTrace(); } valueOfMethodResolved = true; } return valueOfMethod; }
From source file:at.bestsolution.efxclipse.tooling.model.internal.utils.PropertiesUtil.java
License:Open Source License
public static Map<String, IFXProperty> resolveProperties(FXClass fxClass) throws JavaModelException { Map<String, IFXProperty> rv = new HashMap<String, IFXProperty>(); if ("java.lang.Object".equals(fxClass.getFQN())) { return rv; }// w w w . j a v a 2s. co m Map<String, IMethod> beanProperties = new HashMap<String, IMethod>(); Map<String, IMethod> builderProperties = new HashMap<String, IMethod>(); String builder = fxClass.getType().getFullyQualifiedName() + "Builder"; IType builderType = fxClass.getJavaProject().findType(builder); if (builderType != null) { for (IMethod m : builderType.getMethods()) { // Only public and none static methods if (!Flags.isPublic(m.getFlags()) || Flags.isStatic(m.getFlags())) { continue; } String name = m.getElementName(); // omit the build method if ("build".equals(name) || "applyTo".equals(name)) { continue; } if (m.getParameterNames().length == 1) { String param = m.getParameterTypes()[0]; if (Signature.getArrayCount(param) == 0) { builderProperties.put(name, m); } } } } for (IMethod m : fxClass.getType().getMethods()) { // Only public and none static methods if (!Flags.isPublic(m.getFlags()) || Flags.isStatic(m.getFlags())) { continue; } String name = m.getElementName(); // do not use impl methods they are private if (name.startsWith("getImpl") || name.startsWith("isImpl") || name.startsWith("setImpl") || name.contains("Unmodifiable")) { continue; } if (name.startsWith("get") || name.startsWith("is")) { name = name.startsWith("get") ? name.substring(3) : name.substring(2); name = Character.toLowerCase(name.charAt(0)) + name.substring(1); // Only set if there's not already one stored if (!beanProperties.containsKey(name)) { beanProperties.put(name, m); } } else if (m.getElementName().startsWith("set") && m.getParameters().length == 1) { name = name.substring(3); name = Character.toLowerCase(name.charAt(0)) + name.substring(1); beanProperties.put(name, m); } } for (Entry<String, IMethod> e : beanProperties.entrySet()) { FXProperty p = getProperty(fxClass, e.getKey(), e.getValue()); if (p != null) { rv.put(e.getKey(), p); } } for (Entry<String, IMethod> e : builderProperties.entrySet()) { IFXProperty p = rv.get(e.getKey()); if (p == null) { continue; } if (!(p instanceof IFXCollectionProperty)) { if (!p.isSetable()) { p = getProperty(fxClass, e.getKey(), e.getValue()); if (p != null) { rv.put(e.getKey(), p); } } } } return rv; }
From source file:at.bestsolution.efxclipse.tooling.model.internal.utils.PropertiesUtil.java
License:Open Source License
public static Map<String, IFXProperty> resolveStaticProperties(FXClass fxClass) throws JavaModelException { Map<String, IFXProperty> rv = new HashMap<String, IFXProperty>(); if ("java.lang.Object".equals(fxClass.getFQN())) { return rv; }// w w w . j a va 2 s . c o m for (IMethod m : fxClass.getType().getMethods()) { if (!Flags.isPublic(m.getFlags()) || !Flags.isStatic(m.getFlags())) { continue; } String name = m.getElementName(); if (name.startsWith("setImpl")) { continue; } if (name.startsWith("set") && m.getParameterTypes().length == 2) { name = name.substring(3); name = Character.toLowerCase(name.charAt(0)) + name.substring(1); FXProperty p = null; String signature = m.getParameterTypes()[1]; String genericType = Signature.toString(signature); if (FXPrimitiveProperty.isPrimitive(genericType)) { p = new FXPrimitiveProperty(fxClass, name, m, Type.parseType(genericType), true); } else { String erasedFQNType = Util.getFQNType((IType) m.getParent(), Signature.getTypeErasure(genericType)); if (erasedFQNType != null) { if (FXEnumProperty.isEnum(fxClass.getJavaProject(), erasedFQNType)) { p = new FXEnumProperty(fxClass, name, m, erasedFQNType, true); } else { p = new FXObjectPoperty(fxClass, name, m, erasedFQNType, true); } } } if (p != null) { rv.put(p.getName(), p); } } } return rv; }
From source file:at.bestsolution.fxide.jdt.corext.util.JavaModelUtil.java
License:Open Source License
/** * Evaluates if a member in the focus' element hierarchy is visible from * elements in a package.// w w w .j a v a2s.c o m * @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)); }
From source file:at.bestsolution.fxide.jdt.corext.util.JdtFlags.java
License:Open Source License
public static boolean isPublic(IMember member) throws JavaModelException { if (isInterfaceOrAnnotationMember(member)) return true; if (isEnumConstant(member)) return true; return Flags.isPublic(member.getFlags()); }
From source file:at.bestsolution.javafx.ide.jdt.internal.JavaEditor.java
License:Open Source License
@Inject public JavaEditor(BorderPane pane, IEditorInput input) { editor = new SourceEditor(); pane.setCenter(editor);//from w w w. j av a 2 s .co m IResourceFileInput fsInput = (IResourceFileInput) input; try { unit = ((ICompilationUnit) JavaCore.create(fsInput.getFile())) .getWorkingCopy(new FXWorkingCopyOwner(new IProblemRequestor() { private List<ProblemMarker> l = new ArrayList<>(); @Override public boolean isActive() { // TODO Auto-generated method stub return true; } @Override public void endReporting() { setMarkers(l); } @Override public void beginReporting() { l.clear(); } @Override public void acceptProblem(IProblem problem) { int linenumber = problem.getSourceLineNumber(); int startCol = problem.getSourceStart(); int endCol = problem.getSourceEnd(); if (endCol == startCol) { endCol++; } String description = problem.getMessage(); ProblemMarker marker = new ProblemMarker( problem.isError() ? at.bestsolution.javafx.ide.editor.ProblemMarker.Type.ERROR : at.bestsolution.javafx.ide.editor.ProblemMarker.Type.WARNING, linenumber, startCol, endCol, description); l.add(marker); } }), new NullProgressMonitor()); } catch (JavaModelException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } final Document doc = createDocument(unit); editor.setDocument(doc); editor.setContentProposalComputer(new ContentProposalComputer() { @Override public List<Proposal> computeProposals(String line, String prefix, int offset) { final List<Proposal> l = new ArrayList<ContentProposalComputer.Proposal>(); try { unit.codeComplete(offset, new CompletionRequestor() { @Override public void accept(CompletionProposal proposal) { String completion = new String(proposal.getCompletion()); if (!Flags.isPublic(proposal.getFlags())) { return; } if (proposal.getKind() == CompletionProposal.METHOD_REF) { String sig = Signature.toString(new String(proposal.getSignature()), new String(proposal.getName()), null, false, false); StyledString s = new StyledString(sig + " : " + Signature.getSimpleName(Signature .toString(Signature.getReturnType(new String(proposal.getSignature()))))); s.appendString( " - " + Signature.getSignatureSimpleName( new String(proposal.getDeclarationSignature())), Style.colored("#AAAAAA")); l.add(new Proposal(Type.METHOD, completion, s)); } else if (proposal.getKind() == CompletionProposal.FIELD_REF) { StyledString s = new StyledString( completion + " : " + (proposal.getSignature() != null ? Signature.getSignatureSimpleName( new String(proposal.getSignature())) : "<unknown>")); s.appendString( " - " + (proposal.getDeclarationSignature() != null ? Signature.getSignatureSimpleName( new String(proposal.getDeclarationSignature())) : "<unknown>"), Style.colored("#AAAAAA")); l.add(new Proposal(Type.FIELD, completion, s)); } else if (proposal.getKind() == CompletionProposal.TYPE_REF) { if (proposal.getAccessibility() == IAccessRule.K_NON_ACCESSIBLE) { return; } StyledString s = new StyledString( Signature.getSignatureSimpleName(new String(proposal.getSignature()))); s.appendString(" - " + new String(proposal.getDeclarationSignature()), Style.colored("#AAAAAA")); l.add(new Proposal(Type.TYPE, new String(proposal.getCompletion()), s)); } else { System.err.println(proposal); } } }); } catch (JavaModelException e) { // TODO Auto-generated catch block e.printStackTrace(); } return l; } }); editor.setSaveCallback(new Runnable() { @Override public void run() { try { unit.commitWorkingCopy(true, null); } catch (JavaModelException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); try { unit.reconcile(ICompilationUnit.NO_AST, true, null, null); } catch (JavaModelException e) { // TODO Auto-generated catch block e.printStackTrace(); } }